Titanium JIRA Archive
Alloy (ALOY)

[ALOY-879] Alloy: Properly expose Alloy NPM package as a CommonJS module

GitHub Issuen/a
TypeNew Feature
Affected Version/sn/a
Fix Version/sAlloy 2.0.0
Labelsalloy, tooling
ReporterFokke Zandbergen


Right now, the Alloy NPM package.json points to ./bin/alloy for the executable and ./Alloy/alloy for the main entry point when required externally using require('alloy');:
  "bin": {
    "alloy": "./bin/alloy"
  "scripts": {
    "test": "jake test:all"
  "main": "./Alloy/alloy",
However, under the hood the executable simply requires ./Alloy/alloy, which is not exporting any methods but instead just uses commander to manage the CLI. This makes an external require of Alloy absolutely useless.

Why support require?

Alloy is very well organised, with different utilities that are also of interest for stand-alone contributions like now promoted with the pluggable Titanium CLI in 3.2 master. For example: * ./Alloy/commands/compile/styler for reading TSS files etc. * ./Alloy/utils.js for XML view manipulation, searching for widgets etc. * ./Alloy/tiapp.js for reading and manipulating tiapp.xml. It would be nice if these would be available externally, e.g.:
var styler = require('alloy').styler;
style = styler.loadStyle('my.tss');


The easy way would just to add new file and change the main property in the package.json to point to it, containing e.g.:
exports.styler = require('./commands/compile/styler.js');
exports.utils = require('./utils.js');
exports.tiapp = require('./tiapp.js');
But I'd even recommend restructuring the files a little. Move the code currently in ./Alloy/alloy.js to ./bin/alloy or create a new ./Alloy/cli.js and require this from the executable. Then keep alloy.js as the entry point for external require's.


No comments

JSON Source