@maccesar/titools 3.3.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +27 -61
  2. package/lib/cleanup.js +29 -0
  3. package/lib/commands/agents.js +8 -7
  4. package/lib/commands/skills.js +118 -23
  5. package/lib/config.js +13 -15
  6. package/lib/installer.js +5 -3
  7. package/lib/utils.js +36 -0
  8. package/package.json +1 -1
  9. package/skills/alloy-guides/SKILL.md +188 -0
  10. package/skills/alloy-guides/references/CLI_TASKS.md +233 -0
  11. package/skills/alloy-guides/references/CONCEPTS.md +171 -0
  12. package/skills/alloy-guides/references/CONTROLLERS.md +279 -0
  13. package/skills/alloy-guides/references/MODELS.md +742 -0
  14. package/skills/alloy-guides/references/MODELS_ADVANCED.md +482 -0
  15. package/skills/alloy-guides/references/PURGETSS.md +57 -0
  16. package/skills/alloy-guides/references/VIEWS_DYNAMIC.md +235 -0
  17. package/skills/alloy-guides/references/VIEWS_STYLES.md +375 -0
  18. package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +102 -0
  19. package/skills/alloy-guides/references/VIEWS_XML.md +581 -0
  20. package/skills/alloy-guides/references/WIDGETS.md +160 -0
  21. package/skills/alloy-howtos/SKILL.md +179 -0
  22. package/skills/alloy-howtos/references/best_practices.md +121 -0
  23. package/skills/alloy-howtos/references/cli_reference.md +230 -0
  24. package/skills/alloy-howtos/references/config_files.md +158 -0
  25. package/skills/alloy-howtos/references/custom_tags.md +148 -0
  26. package/skills/alloy-howtos/references/debugging_troubleshooting.md +78 -0
  27. package/skills/alloy-howtos/references/samples.md +156 -0
  28. package/skills/purgetss/SKILL.md +6 -3
  29. package/skills/purgetss/references/EXAMPLES.md +8 -6
  30. package/skills/purgetss/references/app-branding.md +5 -0
  31. package/skills/purgetss/references/apply-directive.md +1 -1
  32. package/skills/purgetss/references/class-categories.md +1 -1
  33. package/skills/purgetss/references/class-index-properties.md +618 -0
  34. package/skills/purgetss/references/class-index.md +4 -610
  35. package/skills/purgetss/references/cli-commands.md +15 -0
  36. package/skills/purgetss/references/custom-fonts.md +39 -36
  37. package/skills/purgetss/references/custom-rules.md +1 -1
  38. package/skills/purgetss/references/customization-deep-dive.md +64 -1
  39. package/skills/purgetss/references/icon-fonts.md +2 -0
  40. package/skills/purgetss/references/migration-guide.md +53 -1
  41. package/skills/purgetss/references/multi-density-images.md +53 -2
  42. package/skills/purgetss/references/svg-pipeline.md +249 -0
  43. package/skills/purgetss/references/tikit-components.md +2 -2
  44. package/skills/purgetss/references/titanium-resets.md +2 -2
  45. package/skills/purgetss/references/ui-ux-design.md +7 -5
  46. package/skills/purgetss/references/version-history.md +12 -0
  47. package/skills/ti-api/SKILL.md +128 -0
  48. package/skills/ti-api/references/api-android.md +675 -0
  49. package/skills/ti-api/references/api-app-platform.md +636 -0
  50. package/skills/ti-api/references/api-core.md +764 -0
  51. package/skills/ti-api/references/api-data-network.md +641 -0
  52. package/skills/ti-api/references/api-media.md +655 -0
  53. package/skills/ti-api/references/api-modules-ble-bluetooth.md +657 -0
  54. package/skills/ti-api/references/api-modules-coremotion-urlsession.md +411 -0
  55. package/skills/ti-api/references/api-modules-map.md +632 -0
  56. package/skills/ti-api/references/api-modules-nfc.md +725 -0
  57. package/skills/ti-api/references/api-modules-social-misc.md +526 -0
  58. package/skills/ti-api/references/api-services.md +700 -0
  59. package/skills/ti-api/references/api-ui-android.md +499 -0
  60. package/skills/ti-api/references/api-ui-extras.md +702 -0
  61. package/skills/ti-api/references/api-ui-ios-animator.md +378 -0
  62. package/skills/ti-api/references/api-ui-ios.md +756 -0
  63. package/skills/ti-api/references/api-ui-lists.md +581 -0
  64. package/skills/ti-api/references/api-ui-text-input.md +607 -0
  65. package/skills/ti-api/references/api-ui-views.md +572 -0
  66. package/skills/ti-api/references/api-ui-windows-navigation.md +676 -0
  67. package/skills/ti-api/references/api-xml-global.md +743 -0
  68. package/skills/ti-guides/SKILL.md +82 -0
  69. package/skills/ti-guides/references/advanced-data-and-images.md +155 -0
  70. package/skills/ti-guides/references/android-manifest.md +97 -0
  71. package/skills/ti-guides/references/app-distribution.md +373 -0
  72. package/skills/ti-guides/references/application-frameworks.md +366 -0
  73. package/skills/ti-guides/references/cli-reference.md +700 -0
  74. package/skills/ti-guides/references/coding-best-practices.md +150 -0
  75. package/skills/ti-guides/references/commonjs-advanced.md +279 -0
  76. package/skills/ti-guides/references/hello-world.md +99 -0
  77. package/skills/ti-guides/references/hyperloop-native-access.md +458 -0
  78. package/skills/ti-guides/references/javascript-primer.md +402 -0
  79. package/skills/ti-guides/references/reserved-words.md +36 -0
  80. package/skills/ti-guides/references/resources.md +172 -0
  81. package/skills/ti-guides/references/style-and-conventions.md +104 -0
  82. package/skills/ti-guides/references/tiapp-config.md +655 -0
  83. package/skills/ti-howtos/SKILL.md +131 -0
  84. package/skills/ti-howtos/references/android-platform-deep-dives.md +609 -0
  85. package/skills/ti-howtos/references/automation-fastlane-appium.md +96 -0
  86. package/skills/ti-howtos/references/buffer-codec-streams.md +162 -0
  87. package/skills/ti-howtos/references/cross-platform-development.md +358 -0
  88. package/skills/ti-howtos/references/debugging-profiling.md +473 -0
  89. package/skills/ti-howtos/references/extending-titanium.md +684 -0
  90. package/skills/ti-howtos/references/google-maps-v2.md +172 -0
  91. package/skills/ti-howtos/references/ios-map-kit.md +149 -0
  92. package/skills/ti-howtos/references/ios-platform-deep-dives.md +595 -0
  93. package/skills/ti-howtos/references/local-data-sources.md +310 -0
  94. package/skills/ti-howtos/references/location-and-maps.md +267 -0
  95. package/skills/ti-howtos/references/media-apis.md +268 -0
  96. package/skills/ti-howtos/references/notification-services.md +539 -0
  97. package/skills/ti-howtos/references/remote-data-sources.md +339 -0
  98. package/skills/ti-howtos/references/tutorials.md +552 -0
  99. package/skills/ti-howtos/references/using-modules.md +182 -0
  100. package/skills/ti-howtos/references/web-content-integration.md +288 -0
  101. package/skills/ti-howtos/references/webpack-build-pipeline.md +125 -0
@@ -0,0 +1,160 @@
1
+ # Alloy Widgets
2
+
3
+ ## Introduction
4
+
5
+ Widgets are self-contained components that can be easily dropped into Alloy-powered Titanium projects. They were conceived as a way to reuse code in multiple applications or to be used multiple times in the same application. Widgets have their own views, controllers, styles and assets and are laid out the same as the `app` directory in the Alloy project.
6
+
7
+ ## Using Widgets
8
+
9
+ See [Importing Widgets](./VIEWS_XML.md#importing-widgets) for more information on using widgets in your project.
10
+
11
+ ## Creating Widgets
12
+
13
+ Widgets should be built in their own directory in the Alloy project's `app/widgets/` directory. Widgets have their own views, controllers, models, styles and assets and are laid out the same as the `app` directory in the Alloy project. Also, since widgets are self-contained, they should not reference any code or assets not within its path, except for internationalization and localization files, which are located in the `i18n` folder.
14
+
15
+ ## Assets and Libs
16
+
17
+ For any files in the `assets` or `libs` folder, use the `WPATH()` macro to automatically map the path relative from the widget's root folder.
18
+
19
+ For example, if you have a library located at `app/widgets/foo/lib/helper.js`, to require it:
20
+
21
+ ```javascript
22
+ require(WPATH('helper'))
23
+ ```
24
+
25
+ If you have an image located at `app/widgets/foo/assets/images/foo.png`, to reference it:
26
+
27
+ ```javascript
28
+ WPATH('images/foo.png')
29
+ ```
30
+
31
+ ## Configuration
32
+
33
+ Widgets have their own configuration file called `widget.json` located in the widget's root directory.
34
+
35
+ Example **widget.json**:
36
+
37
+ ```json
38
+ {
39
+ "id": "com.example.widget",
40
+ "name": "My Widget",
41
+ "description": "A sample widget",
42
+ "author": "Your Name",
43
+ "version": "1.0",
44
+ "platform": [
45
+ "android",
46
+ "ios"
47
+ ],
48
+ "min_alloy": "1.0"
49
+ }
50
+ ```
51
+
52
+ ## Controllers
53
+
54
+ The main controller is called `widget.js` instead of `index.js`.
55
+
56
+ To use another view-controller besides `widget.js`/`widget.xml`, use the `Widget.createController(controller_name, [params])` method to create a new instance and the `getView()` method to access the Titanium proxy object.
57
+
58
+ **app/widgets/foo/controllers/widget.js**
59
+
60
+ ```javascript
61
+ const button = Widget.createController('button').getView();
62
+ $.widget.add(button);
63
+ ```
64
+
65
+ All methods in the widget controller are private unless you prefix the method with `$`, which makes it accessible to the Alloy project and other widgets.
66
+
67
+ **app/widgets/foo/controllers/widget.js**
68
+
69
+ ```javascript
70
+ $.init = args => {
71
+ $.button.title = args.title || 'Yes';
72
+ $.button.color = args.color || 'black';
73
+ const message = args.message || 'Hello World';
74
+ }
75
+ ```
76
+
77
+ Then, in the Alloy project:
78
+
79
+ ```javascript
80
+ $.foo.init({title:'Yes', color:'gray', message:'I pity the foo.'});
81
+ ```
82
+
83
+ ## Models
84
+
85
+ Use models the same way as with a regular Alloy project except to create a model or collection inside a widget controller, use the `Widget.createModel(model_name, [params])` and `Widget.createCollection(model_name, [params])` methods, respectively.
86
+
87
+ You can also use the `Model` and `Collection` tags in widget views.
88
+
89
+ ## Styles
90
+
91
+ The main TSS file is called `widget.tss` instead of `index.tss`.
92
+
93
+ ## Themes
94
+
95
+ Widget themes work the same as project themes except for the placement of the files. Inside your theme folder (`app/themes/<THEME_NAME>`), create `widgets/<WIDGET_NAME>` folders, where `<THEME_NAME>` is the name of the theme and `<WIDGET_NAME>` is the name of the widget. When using a theme, the files in these folders replace the files in the widget's folders.
96
+
97
+ Create two folders, `assets` and `styles`, to place your custom images and styles for your widget, respectively.
98
+
99
+ ```
100
+ app
101
+ ├── themes
102
+ │ └── mytheme
103
+ │ └── widgets
104
+ │ └── mywidget
105
+ │ ├── assets
106
+ │ │ ├── ios
107
+ │ │ │ └── star_half.png
108
+ │ │ ├── star.png
109
+ │ │ └── star_off.png
110
+ │ └── styles
111
+ │ ├── ios
112
+ │ │ └── star.tss
113
+ │ └── star.tss
114
+ └── widgets
115
+ └── mywidget
116
+ ├── assets
117
+ │ ├── star.png
118
+ │ ├── star_half.png
119
+ │ └── star_off.png
120
+ ├── controllers
121
+ │ ├── star.js
122
+ │ └── widget.js
123
+ ├── styles
124
+ │ ├── star.tss
125
+ │ └── widget.tss
126
+ ├── views
127
+ │ ├── star.xml
128
+ │ └── widget.xml
129
+ └── widget.json
130
+ ```
131
+
132
+ To use a theme, in the project's `config.json` file, add the `theme` key with the name of the theme folder as the value.
133
+
134
+ ## Views
135
+
136
+ The main view is called `widget.xml` instead of `index.xml`.
137
+
138
+ Specifying the `id` attribute in the XML markup components will make it easier to access and override Titanium object properties. For example, if you have a Button object in a widget view with id `button` and in the Alloy project the widget id is `foo`:
139
+
140
+ ```javascript
141
+ Ti.API.info("button state: " + $.foo.button.enabled);
142
+ ```
143
+
144
+ For widgets that have multiple view-controllers, to include a widget's view-controller in another widget's view, use the `Widget` tag and assign the `name` attribute with the name of the view-controller minus the file extension. Since Alloy 1.5.0, if you omit the `src` attribute, Alloy assumes you are referencing the current widget. For Alloy 1.4.x and prior, you need to assign the `src` attribute to the widget's name.
145
+
146
+ **app/widgets/foo/views/widget.xml**
147
+
148
+ ```xml
149
+ <Alloy>
150
+ <View>
151
+ <Widget src="foo" name="button"/>
152
+ </View>
153
+ </Alloy>
154
+ ```
155
+
156
+ ## Widgets
157
+
158
+ Widgets can also contain other widgets. Follow the same directions from [Importing Widgets](./VIEWS_XML.md#importing-widgets) except the widget's configuration file is called `widget.json` instead of `config.json`.
159
+
160
+ To create a widget inside a widget controller, use the `Widget.createWidget(widget_name, [controller_name], [params])` method.
@@ -0,0 +1,179 @@
1
+ ---
2
+ name: alloy-howtos
3
+ description: Use when an Alloy MVC project needs help with the Alloy CLI (`alloy new`, `alloy generate`, `alloy compile`, `alloy extract-i18n`), configuration files (`alloy.jmk` build hooks, `config.json` env/platform precedence, `widget.json`), conditional views (`if=` attribute in XML/TSS), custom XML tags via `app/lib/`, Backbone.Events for cross-controller communication, or debugging Alloy compilation errors. Triggers include `app/views/` + `app/controllers/`, `alloy.jmk`, or `config.json` in the project root.
4
+ ---
5
+
6
+ # alloy-howtos
7
+
8
+ ## Overview
9
+
10
+ Practical reference for Titanium Alloy MVC projects: CLI usage, project configuration, conditional rendering, custom XML tags, cross-controller communication, and common compilation/runtime errors. Reference-style — load the relevant file from `references/` for deeper detail.
11
+
12
+ ## When to use
13
+
14
+ Use this skill when:
15
+
16
+ - The project contains `app/views/` + `app/controllers/`, `alloy.jmk`, or `config.json`
17
+ - Running or scripting the Alloy CLI (`alloy new`, `alloy generate`, `alloy compile`, ...)
18
+ - Configuring `alloy.jmk` build hooks or `config.json` environment / platform precedence
19
+ - Writing conditional views with `if=` in XML or TSS
20
+ - Building reusable custom XML tags in `app/lib/`
21
+ - Wiring cross-controller communication via `Backbone.Events`
22
+ - Diagnosing Alloy compilation errors or platform-specific runtime issues
23
+
24
+ Do NOT use for:
25
+
26
+ - Alloy MVC concepts, controllers, models, or data binding (use `alloy-guides`)
27
+ - Titanium SDK fundamentals, `tiapp.xml`, Hyperloop, or app distribution (use `ti-guides`)
28
+ - Native module dependency updates (use `ti-module-update`)
29
+
30
+ ## Quick reference
31
+
32
+ | Topic | Reference |
33
+ |---|---|
34
+ | Coding standards, naming, global events patterns | [best_practices.md](references/best_practices.md) |
35
+ | All CLI commands with options and model schema format | [cli_reference.md](references/cli_reference.md) |
36
+ | `alloy.jmk` tasks, `config.json` structure, `widget.json` format | [config_files.md](references/config_files.md) |
37
+ | Creating reusable custom XML tags without widgets | [custom_tags.md](references/custom_tags.md) |
38
+ | Common errors with solutions | [debugging_troubleshooting.md](references/debugging_troubleshooting.md) |
39
+ | Controller examples, conditional views, data-binding patterns | [samples.md](references/samples.md) |
40
+
41
+ ## Key practices
42
+
43
+ ### Naming conventions
44
+
45
+ - **Never use double underscore prefixes** (`__foo`) — reserved for Alloy
46
+ - **Never use JavaScript reserved words as IDs**
47
+
48
+ ### Global events — use Backbone.Events
49
+
50
+ Avoid `Ti.App.fireEvent` / `Ti.App.addEventListener`. They cross the native-JS bridge and can cause memory leaks and slower execution.
51
+
52
+ Use the Backbone.Events pattern:
53
+
54
+ ```javascript
55
+ // In alloy.js
56
+ Alloy.Events = _.clone(Backbone.Events);
57
+
58
+ // Listener
59
+ Alloy.Events.on('updateMainUI', refreshData);
60
+
61
+ // Clean up on close
62
+ $.controller.addEventListener('close', () => {
63
+ Alloy.Events.off('updateMainUI');
64
+ });
65
+
66
+ // Trigger
67
+ Alloy.Events.trigger('updateMainUI');
68
+ ```
69
+
70
+ ### Global variables in non-controller files
71
+
72
+ Always require Alloy modules:
73
+
74
+ ```javascript
75
+ const Alloy = require('alloy');
76
+ const Backbone = require('alloy/backbone');
77
+ const _ = require('alloy/underscore')._;
78
+ ```
79
+
80
+ ## Conditional views
81
+
82
+ Use `if` attributes in XML for conditional rendering (evaluated before render):
83
+
84
+ ```xml
85
+ <Alloy>
86
+ <Window>
87
+ <View if="Alloy.Globals.isLoggedIn()" id="loggedIn">
88
+ <Label text="Logged in" />
89
+ </View>
90
+ <View if="!Alloy.Globals.isLoggedIn()" id="notLoggedIn">
91
+ <Label text="Not logged in" />
92
+ </View>
93
+ </Window>
94
+ </Alloy>
95
+ ```
96
+
97
+ Conditional TSS styles:
98
+
99
+ ```tss
100
+ "#info[if=Alloy.Globals.isIos7Plus]": {
101
+ font: { textStyle: Ti.UI.TEXT_STYLE_FOOTNOTE }
102
+ }
103
+ ```
104
+
105
+ Data-binding conditionals:
106
+
107
+ ```xml
108
+ <TableViewRow if="$model.shouldShowCommentRow()">
109
+ ```
110
+
111
+ ## Common error solutions
112
+
113
+ | Error | Solution |
114
+ |---|---|
115
+ | `No app.js found` | Run `alloy compile --config platform=<platform>` |
116
+ | Android assets not showing | Use absolute paths (prepend `/`) |
117
+ | `Alloy is not defined` (non-controller) | Add `const Alloy = require('alloy');` |
118
+ | iOS `invalid method passed to UIModule` | Creating Android-only object — use `platform` attribute |
119
+
120
+ ## CLI quick reference
121
+
122
+ ```bash
123
+ # New project
124
+ alloy new [path] [template]
125
+
126
+ # Generate components
127
+ alloy generate controller <name>
128
+ alloy generate model <name> <adapter> <schema>
129
+ alloy generate style --all
130
+
131
+ # Compile
132
+ alloy compile [--config platform=android,deploytype=test]
133
+
134
+ # Extract i18n strings
135
+ alloy extract-i18n en --apply
136
+
137
+ # Copy / move / remove controllers
138
+ alloy copy <old> <new>
139
+ alloy move <old> <new>
140
+ alloy remove <name>
141
+ ```
142
+
143
+ ## Configuration files priority
144
+
145
+ `config.json` precedence: `os:<platform>` > `env:<environment>` > `global`
146
+
147
+ Access at runtime: `Alloy.CFG.<key>`
148
+
149
+ ## Custom XML tags
150
+
151
+ Reusable components without the overhead of widgets. Drop a file in `app/lib/`:
152
+
153
+ **`app/lib/checkbox.js`**
154
+ ```javascript
155
+ exports.createCheckBox = args => {
156
+ const wrapper = Ti.UI.createView({ layout: 'horizontal', checked: false });
157
+ const box = Ti.UI.createView({ width: 15, height: 15, borderWidth: 1 });
158
+ // ... build component, return Ti.UI.* object
159
+ return wrapper;
160
+ };
161
+ ```
162
+
163
+ **`view.xml`**
164
+ ```xml
165
+ <CheckBox module="checkbox" id="terms" caption="I agree" onChange="onCheck" />
166
+ ```
167
+
168
+ The `module` attribute points to the file in `app/lib/` (without `.js`). The function must be `create<TagName>`.
169
+
170
+ See [custom_tags.md](references/custom_tags.md) for the complete worked example.
171
+
172
+ ## Related skills
173
+
174
+ | Task | Use this skill |
175
+ |---|---|
176
+ | Alloy MVC concepts, controllers, models, data binding | `alloy-guides` |
177
+ | Titanium SDK config, Hyperloop, app distribution | `ti-guides` |
178
+ | Titanium API lookup (Ti.UI, Ti.Network, modules) | `ti-api` |
179
+ | Native module dependency updates | `ti-module-update` |
@@ -0,0 +1,121 @@
1
+ # Alloy best practices and recommendations
2
+
3
+ Recommendations for writing Alloy apps. This supplements the Titanium SDK [Best Practices and Recommendations](https://titaniumsdk.com/guide/Titanium_SDK/Titanium_SDK_Guide/Best_Practices_and_Recommendations/) guide and focuses on coding style and conventions.
4
+
5
+ ## Titanium-to-Alloy Guidance
6
+
7
+ ### Loading Libraries in Alloy
8
+
9
+ If you need global functionality, require modules in all controllers or create a single global reference:
10
+
11
+ **alloy.js**
12
+ ```javascript
13
+ // Alloy.Globals.refToYourModule will be available in all controllers
14
+ Alloy.Globals.refToYourModule = require('yourModule');
15
+ ```
16
+
17
+ ### Performance Best Practices
18
+
19
+ The same best practices from traditional Titanium development apply to Alloy. Alloy controllers can do what classic controllers can.
20
+
21
+ Use compiler directives to reduce runtime work (see Conditional Code in Alloy Controllers).
22
+
23
+ ### Project Organization
24
+
25
+ Decide whether to adapt Alloy to your existing structure, or to adopt Alloy's structure. Alloy standardizes common Titanium patterns and makes projects easier to maintain.
26
+
27
+ ## Coding Style Best Practices
28
+
29
+ ### Naming Conventions
30
+
31
+ - **Do not use double underscore prefixes** on variables, properties, or function names (e.g., `__foo`). They are reserved for Alloy and may cause conflicts and unexpected behavior.
32
+ - **Do not use JavaScript reserved words as IDs.** See [Titanium SDK Reserved Words](https://titaniumsdk.com/guide/Titanium_SDK/Titanium_SDK_Guide/Best_Practices_and_Recommendations/Reserved_Words/) for the complete list.
33
+
34
+ ### Global Variables
35
+
36
+ Avoid declaring globals in app.js and using them in other files. It still works, but it is not recommended and may be deprecated.
37
+
38
+ Instead, declare these in your JS files:
39
+
40
+ ```javascript
41
+ const Alloy = require('alloy');
42
+ const Backbone = require('alloy/backbone');
43
+ const _ = require('alloy/underscore')._;
44
+ ```
45
+
46
+ Safe pattern for non-controller files:
47
+
48
+ ```javascript
49
+ if (typeof Alloy === 'undefined') {
50
+ var Alloy = require('alloy');
51
+ }
52
+ if (typeof Backbone === 'undefined') {
53
+ var Backbone = require('alloy/backbone');
54
+ }
55
+ if (typeof _ === 'undefined') {
56
+ var _ = require('alloy/underscore')._;
57
+ }
58
+
59
+ const loading = Alloy.createWidget("com.titaniumsdk.loading");
60
+ ```
61
+
62
+ ### Global Events
63
+
64
+ **Avoid `Ti.App.fireEvent` and `Ti.App.addEventListener`.** It crosses the native-JS bridge and can cause memory leaks and slower execution.
65
+
66
+ #### Use Callbacks for Master-Child Communication
67
+
68
+ **master.js**
69
+ ```javascript
70
+ function openChild() {
71
+ Alloy.createController('child', {callback: refreshData});
72
+ }
73
+
74
+ function refreshData(value) {
75
+ // Refresh master data here
76
+ }
77
+ ```
78
+
79
+ **child.js**
80
+ ```javascript
81
+ const args = arguments[0] || {};
82
+
83
+ function refreshParent() {
84
+ // Pass return value to parent
85
+ args.callback(true);
86
+ }
87
+ ```
88
+
89
+ #### Use Backbone.Events for App-Wide Communication
90
+
91
+ **alloy.js**
92
+ ```javascript
93
+ Alloy.Events = _.clone(Backbone.Events);
94
+ ```
95
+
96
+ **controller_a.js** (listener)
97
+ ```javascript
98
+ Alloy.Events.on('updateMainUI', refreshData);
99
+
100
+ function refreshData(value) {
101
+ // Do work here
102
+ // Optionally disable one-time events
103
+ // Alloy.Events.off('updateMainUI');
104
+ }
105
+
106
+ // Clean up when closing to avoid memory leaks
107
+ $.controller_a.addEventListener('close', () => {
108
+ Alloy.Events.off('updateMainUI');
109
+ });
110
+ ```
111
+
112
+ **controller_b.js** (trigger)
113
+ ```javascript
114
+ Alloy.Events.trigger('updateMainUI');
115
+ ```
116
+
117
+ **Note:** Alloy controllers are Backbone event dispatchers. You can also use:
118
+ ```javascript
119
+ Alloy.createController('child').on('refresh', refreshData);
120
+ ```
121
+ This is a simpler way to do cross-controller communication with Backbone events.
@@ -0,0 +1,230 @@
1
+ # Alloy command-line interface reference
2
+
3
+ The Alloy CLI manages and builds Alloy projects.
4
+
5
+ ## Installation
6
+
7
+ The Alloy CLI is installed when you install the `alloy` package.
8
+
9
+ ### Manual Installation
10
+
11
+ Install Node.js from [nodejs.org](http://nodejs.org/#download) first, then:
12
+
13
+ ```bash
14
+ sudo npm install -g alloy
15
+ ```
16
+
17
+ For a specific version:
18
+ ```bash
19
+ sudo npm install -g alloy@1.10.0
20
+ ```
21
+
22
+ ### Development install
23
+
24
+ ```bash
25
+ git clone https://github.com/tidev/alloy.git
26
+ cd alloy
27
+ [sudo] npm install -g .
28
+ ```
29
+
30
+ ## Commands
31
+
32
+ ### new
33
+
34
+ Creates a new Alloy project on top of an existing Titanium project (create the classic Titanium project first, then run this command from inside the project directory).
35
+
36
+ ```bash
37
+ alloy new [<project_path>] [<project_template>] [--force] [--no-colors]
38
+ ```
39
+
40
+ | Option | Description |
41
+ | -------------------- | --------------------------------------------------------------------------------- |
42
+ | `<project_path>` | Path to skeleton Titanium project (default: current directory) |
43
+ | `<project_template>` | **default** (single pane) or **two_tabbed** (tabbed app) |
44
+ | `--testapp <path>` | Relative path to a test application in the Alloy GitHub repo (under `test/apps/`) |
45
+ | `-f, --force` | Force execution |
46
+ | `-n, --no-colors` | Disable color output |
47
+
48
+ ### generate
49
+
50
+ Creates skeleton Alloy components.
51
+
52
+ ```bash
53
+ alloy generate <component> [--widgetname <widget_name>] [--outputPath <output_path>] [--platform <platform>] [--force] [--no-colors]
54
+ ```
55
+
56
+ | Component | Description |
57
+ | --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
58
+ | `controller <name>` | Create controller, view and style |
59
+ | `jmk` | Create `alloy.jmk` |
60
+ | `model <name> <adapter> [schema]` | Create model (see Model Format below) |
61
+ | `migration <model_name>` | Create migration file |
62
+ | `style <name>` or `--all` | Create style file (or all styles). If name matches a view-controller, it populates using IDs/classes from markup. Running again updates existing files with new attributes. |
63
+ | `view <name>` | Create view and style |
64
+ | `widget <name>` | Create widget |
65
+
66
+ | Option | Description |
67
+ | ------------------------- | ------------------------------------------------ |
68
+ | `--widgetname <name>` | Create component for specified widget |
69
+ | `-o, --outputPath <path>` | Output path (point to 'app' directory) |
70
+ | `--platform <platform>` | Create platform-specific component (android/ios) |
71
+ | `-f, --force` | Force execution |
72
+ | `-n, --no-colors` | Disable color output |
73
+
74
+ #### Model format
75
+
76
+ Select adapter type:
77
+ - `sql` - SQLite database for Android/iOS (also generates a migration file)
78
+ - `properties` - Local storage in Titanium SDK context
79
+
80
+ Schema format: space-delimited list of `field:type`
81
+ - Example: `name:string age:number sex:varchar dob:date`
82
+
83
+ SQLite type mapping:
84
+
85
+ | Datatype | SQLite Type |
86
+ | ---------------------------------------- | ----------- |
87
+ | string, varchar, text | TEXT |
88
+ | int, tinyint, smallint, bigint, integer | INTEGER |
89
+ | double, float, real | REAL |
90
+ | blob | BLOB |
91
+ | decimal, number, date, datetime, boolean | NUMERIC |
92
+ | null | NULL |
93
+ | unknown | TEXT |
94
+
95
+ ### install
96
+
97
+ Installs special Alloy project components.
98
+
99
+ ```bash
100
+ alloy install <module> [<project_path>]
101
+ ```
102
+
103
+ | Module | Description |
104
+ | ---------------- | ----------------------------------------- |
105
+ | `plugin` | Install compiler plugin for Studio |
106
+ | `<project_path>` | Project path (default: current directory) |
107
+
108
+ ### compile
109
+
110
+ Compiles Alloy code to Titanium SDK code.
111
+
112
+ ```bash
113
+ alloy compile [<project_path>] [--config <compiler_options>] [--no-colors]
114
+ ```
115
+
116
+ | Option | Description |
117
+ | ------------------------ | ------------------------------------------------------------------------- |
118
+ | `<project_path>` | Project path (default: current directory) |
119
+ | `-c, --config <options>` | Comma-delimited compiler options (e.g., `beautify=false,deploytype=test`) |
120
+ | `-n, --no-colors` | Disable color output |
121
+
122
+ Compiler options reference the `event.alloyConfig` object in [Build Configuration File (alloy.jmk)](config_files.md).
123
+
124
+ ### run
125
+
126
+ Use `titanium build` command to run Alloy projects. See [Titanium Command-Line Interface Reference](https://titaniumsdk.com/guide/Titanium_SDK/Titanium_SDK_Guide/Titanium_Command-Line_Interface_Reference/).
127
+
128
+ > **💡 Common ti build pitfalls**
129
+ >
130
+ > Using `-C` flag without UDID:
131
+ > ```bash
132
+ > # Prompts for simulator selection interactively
133
+ > ti build -p ios -T simulator -C
134
+ > ```
135
+ >
136
+ > Correct approach for simulator:
137
+ > ```bash
138
+ > # Runs on default simulator
139
+ > ti build -p ios -T simulator
140
+ > ```
141
+ >
142
+ > Using `--no-prompt` incorrectly:
143
+ > ```bash
144
+ > # Still may prompt for device selection if not specific
145
+ > ti build -p ios --no-prompt
146
+ > ```
147
+ >
148
+ > Always specify target:
149
+ > ```bash
150
+ > # Clear target specification
151
+ > ti build -p ios -T simulator --no-prompt
152
+ > ```
153
+ >
154
+ > **Common patterns:**
155
+ > ```bash
156
+ > # iOS Simulator (most common during development)
157
+ > ti build -p ios -T simulator
158
+ >
159
+ > # iOS Device (requires UDID)
160
+ > ti build -p ios -T device -V <udid>
161
+ >
162
+ > # Android Emulator
163
+ > ti build -p android -T emulator
164
+ >
165
+ > # Build only (don't run)
166
+ > ti build -p ios -T simulator --build-only
167
+ > ```
168
+
169
+ ### i18n-extract
170
+
171
+ Extracts i18n keys from TSS and JS files to strings.xml.
172
+
173
+ ```bash
174
+ alloy extract-i18n [<language>] [--apply]
175
+ ```
176
+
177
+ | Option | Description |
178
+ | ------------ | ------------------------------------------ |
179
+ | `<language>` | Two-letter language code (default: **en**) |
180
+ | `--apply` | Write to strings.xml (preview if absent) |
181
+
182
+ Supported functions:
183
+ - `Ti.Locale.getString()`
184
+ - `L()`
185
+
186
+ Usage examples:
187
+ ```bash
188
+ # Preview changes for default (English)
189
+ alloy extract-i18n
190
+
191
+ # Write changes to "app/i18n/en/strings.xml"
192
+ alloy extract-i18n --apply
193
+
194
+ # Specify "es" as the language and write the changes to "app/i18n/es/strings.xml"
195
+ alloy extract-i18n es --apply
196
+
197
+ # Preview Spanish changes
198
+ alloy extract-i18n es
199
+ ```
200
+
201
+ ### copy
202
+
203
+ Copy a view-controller (controller, XML, TSS).
204
+
205
+ ```bash
206
+ alloy copy <CONTROLLER_NAME> <COPIED_CONTROLLER_NAME>
207
+ ```
208
+
209
+ ### move
210
+
211
+ Rename a view-controller.
212
+
213
+ ```bash
214
+ alloy move <CONTROLLER_NAME> <NEW_CONTROLLER_NAME>
215
+ ```
216
+
217
+ ### remove
218
+
219
+ Remove a view-controller.
220
+
221
+ ```bash
222
+ alloy remove <CONTROLLER_NAME>
223
+ ```
224
+
225
+ ## Additional Options
226
+
227
+ | Option | Description |
228
+ | --------------- | --------------------- |
229
+ | `-h, --help` | Output command usage |
230
+ | `-v, --version` | Output version number |