npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-alloy-theme-switcher

v0.3.0

Published

A grunt plugin to make easier theme switching AND make possible themes inheritance in a titanium's alloy project.

Downloads

8

Readme

grunt-alloy-theme-switcher

NPM

A grunt plugin to make easier theme switching AND make possible themes inheritance in a titanium's alloy project.

Reasons

This grunt plugin was made to fix 3 problems when using alloy's themes system:

  • tiapp.xml files could not be themed and we had to manually edit tiapps when building themes (including android manifest and google maps api key which is lost inside the manifest)
  • i18n/*/strings.xml could not be redefined by themes
  • if 2 themes (or more) had files in common, we were obliged to manually copy those files

what this plugin does

  1. if the chosen theme inherits from another, it creates a tmp theme to merge files from the different themes (furher reading below)
  2. update tiapp.xml based on theme.json configuration (add properties, update settings like app id, remove specified modules...)
  3. merge theme's strings.xml into app/i18n folder

Warning

When running this plugin, tiapp.xml and i18n files will be overwritten so be sure to keep a backup of those files before running it. If you project is under git, you can add this task to your Gruntfile just to clean everything whenever you want:

grunt.initConfig({
    shell: {
        multiple: {
            command: [
                'git checkout tiapp.xml i18n/* app/config.json',
                'rm -rf app/themes/mergedTheme'
            ].join('&&')
        }
    }
});
grunt.registerTask('clean', ['shell']);

Getting Started

This plugin requires Grunt ~0.4.5

npm install grunt-alloy-theme-switcher --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-alloy-theme-switcher');

The "theme.json" configuration file

You have to put a theme.json inside the root folder of your theme.

Example

Here is a complete example of what you can put inside this file:

{
    "baseTheme":"noOptionalWidgets",
    "settings": {
        "name": "mySuperApp",
        "version": "0.0.1",
        "id": "com.mycompany.myapp"
    },
    "properties": [
        {
            "name": "myproperty",
            "value": "a super value",
            "type": "String"
        }
    ],
    "modulesToRemove":[
        {
            "id": "yy.logcatcher",
            "platform": ["android", "iphone"]
        }
    ]
    "android":{
        "versionCode":"14",
        "MAPS_V2_API_KEY": "myincomprehensiblegmapstoken"
    }
}

Parameters

baseTheme

Themes can inherit from one another, read Themes inheritance part for more details.

settings

You can currently put any top level tiapp.xml node in the settings object, so publisher, copyright, icon etc

properties

An array of properties can be set, and for each item you must provide a name and optionnally the value and type (cf http://docs.appcelerator.com/titanium/3.0/#!/guide/tiapp.xml_and_timodule.xml_Reference-section-29004921_tiapp.xmlandtimodule.xmlReference-app_properties)

android

This part is used to generate the android's manifest. You MUST have a manifest inside you app's for this feature to work. If no manifest is found, it will raise an error. Both versionCode and MAPS_V2_API_KEY are optionnals.

modulesToRemove

Modules can be removed from tiapp.xml. For instance you can remove a crash or error reporter. A property called modulesRemoved will be added to tell js which modules were actually removed. This property is a JSON representation of an array containing removed modules ids.

Themes inheritance

what's the purpose?

Imagine you have to themes sharing a view (needed to remove a widget for instance). With theme inheritance you can create a theme containing this view and make the two other themes inherit this newly created theme. So those two child themes will be only variations (concerning assets for instance) of the parent theme.

how it works?

When choosing a theme, this plugin will look for a baseTheme property inside the theme.json file. If one is found and exist, it will create a temp directory called "mergedTheme" to put the content of the resulting merge of those two themes. The directories views, styles and i18n will just be copied recursively, and the theme.json files merged.

Remark

This inheritance is recursive and can have n levels but a theme MUST be used at only one level of a hierarchy. After that, the mergedTheme folder will be used to generate the tiapp and merge i18n xml files.

The "alloy_theme_switcher" task

Overview

This is the main task. It will parse your themes directory and ask you to what theme you'd like to switch.

Options

options.themes_folder

Type: String Default value: ./app/themes/

Location of the alloy's themes folder (with a trailing slash).

theme

Type: String Default value: none

You can provide a theme to build as follows:

grunt alloy_theme_switcher --theme=mySuperTheme

Usage Examples

In your Gruntfile:

grunt.loadNpmTasks('grunt-alloy-theme-switcher');
grunt.registerTask('default', 'alloy_theme_switcher');

And then in shell

grunt

TODO

  • ~~add titanium build~~ can be done using https://github.com/tonylukasavage/grunt-titanium
  • find a way to leave untouched tiapp.xml, app/config.json and i18n folder
  • find a way to do the merge without creating a new folder

Thanks