-
Notifications
You must be signed in to change notification settings - Fork 15
Recipes
To write packages that work both on Node and Titanium you just need to add a single property on your package.json file, which is guid
:
{
"name": "my-module",
"version": "1.0.0",
"guid": "b876a690-6550-415c-9d0e-0976e32553e6"
}
See this package as an example.
If you want to have a different require name (the one you use with require('module-name')
) between Node and Titanium, you have to override the manifest of the generated module. In you package.json file write the following:
{
"name": "my-module",
"version": "1.0.0",
"titaniumManifest": {
"moduleid": "it.smc.mymodule",
"guid": "b876a690-6550-415c-9d0e-0976e32553e6"
}
}
See this package from Fokke Zanderberg as an example.
If the package you’re porting requires changes or some monkey-patching to make it work in Titanium, then you can easily wrap it, do your job, and export your module with the original name.
// index.js
module.exports = require('wrapped-module');
module.exports.somethingThatYouNeedToPatch = function () {
// your patch…
};
{
"name": "ti-wrapped-module",
"version": "1.0.0",
"titaniumManifest": {
"moduleid": "wrapped-module"
}
}
See this package which wraps superagent
as an example.
If a dependency of your package doesn’t work in Titanium you can shim (re-implement) it with either a different package or a local file.
For example, if you want to use superagent
you’ll need ti-superagent
to make it work in Titanium.
To make the substitution work use the following form in your package.json file:
{
"name": "my-module",
// you need both as a dependency
"dependencies": {
"superagent": "*",
"ti-superagent": "*"
},
// and then inside `titanium` you can replace the packages
"titanium": {
"superagent": "ti-superagent"
}
}
If you want to shim it locally then you can also do this:
{
"name": "my-module",
"dependencies": {
"a-node-only-dep": "*"
},
"titaniumifier": {
"a-node-only-dep": "./path/to/a/local/shim"
}
}
// ./path/to/a/local/shim.js
module.exports = function () {
return Titanium.Platform.architecture;
};
Titaniumifier is humbly made by the spry ladies and gents at SMC
© Copyright 2016 SMC Treviso S.r.l. — Licensed under LGPL 2.1