{ "id": "122286", "key": "ALOY-879", "fields": { "issuetype": { "id": "2", "description": "A new feature of the product, which has yet to be developed.", "name": "New Feature", "subtask": false }, "project": { "id": "11113", "key": "ALOY", "name": "Alloy", "projectCategory": { "id": "10400", "description": "Tools for developing applications", "name": "Tooling" } }, "fixVersions": [ { "id": "15404", "description": "Alloy 2.0.0", "name": "Alloy 2.0.0", "archived": false, "released": false } ], "resolution": null, "resolutiondate": null, "created": "2013-11-11T12:08:27.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "alloy", "tooling" ], "versions": [], "issuelinks": [], "assignee": null, "updated": "2018-03-07T22:26:07.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [ { "id": "13604", "name": "Tooling", "description": "Items related to Alloy tooling and workflow" } ], "description": "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');}}:\r\n\r\n{code:json}\r\n \"bin\": {\r\n \"alloy\": \"./bin/alloy\"\r\n },\r\n \"scripts\": {\r\n \"test\": \"jake test:all\"\r\n },\r\n \"main\": \"./Alloy/alloy\",\r\n{code}\r\n\r\nHowever, 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.\r\n\r\nh1. Why support {{require}}?\r\n\r\nAlloy 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:\r\n\r\n* {{./Alloy/commands/compile/styler}} for reading TSS files etc.\r\n* {{./Alloy/utils.js}} for XML view manipulation, searching for widgets etc.\r\n* {{./Alloy/tiapp.js}} for reading and manipulating {{tiapp.xml}}.\r\n\r\nIt would be nice if these would be available externally, e.g.:\r\n\r\n{code:javascript}\r\nvar styler = require('alloy').styler;\r\nstyle = styler.loadStyle('my.tss');\r\n{code}\r\n\r\nh1. How?\r\nThe easy way would just to add new file and change the {{main}} property in the {{package.json}} to point to it, containing e.g.:\r\n\r\n{code:javascript}\r\nexports.styler = require('./commands/compile/styler.js');\r\nexports.utils = require('./utils.js');\r\nexports.tiapp = require('./tiapp.js');\r\n{code}\r\n\r\nBut 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.", "attachment": [], "flagged": false, "summary": "Alloy: Properly expose Alloy NPM package as a CommonJS module", "creator": { "name": "fokkezb", "key": "fokke", "displayName": "Fokke Zandbergen", "active": true, "timeZone": "Europe/Amsterdam" }, "subtasks": [], "reporter": { "name": "fokkezb", "key": "fokke", "displayName": "Fokke Zandbergen", "active": true, "timeZone": "Europe/Amsterdam" }, "environment": "Alloy master", "comment": { "comments": [], "maxResults": 0, "total": 0, "startAt": 0 } } }