Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19392] Load JS files and image assets relative to a different codebase than resourcesDirectory

GitHub Issuen/a
TypeNew Feature
PriorityNone
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 4.1.0
Fix Version/sn/a
ComponentsCore
Labelsn/a
ReporterFokke Zandbergen
AssigneeUnknown
Created2015-08-21T07:31:02.000+0000
Updated2018-02-28T19:55:02.000+0000

Description

There's a growing number of use cases where you would want to require() JavaScript files and image assets from a different codebase than the default Ti.Filesystem.resourcesDirectory. * [LiveViewer](https://github.com/appcelerator/appc-liveviewer-app), TiShadow and potentially LiveView. * Apps or frameworks for apps built on Titanium that let you update an app by pushing new scripts and images to it, much like [ChariTi](https://github.com/mcongrove/ChariTi), GoodBarber.com and AppMachine.com These currently require to modify loaded JavaScript files to reroute calls to require() and paths to image assets to custom methods that look up the actual full path and use that with the original methods. This is hacky and often not that stable.

Desired behaviour

*app.js*

// only once use full path
var b = require(Ti.Filesystem.applicationDataDirectory + 'foo/b');
*b.js*

// this will load relative to dirname(b.js)
var c = require('./c');

var i = Ti.UI.createImageView({
  // this will load relative to dirname(b.js)
  image: './i.png'
});

Possible solutions

Requiring from a full path already works. What needs to be done is that calls to require() and image assets that start with ./ - like NodeJS - will be resolved relative to the directory of the JavaScript file. So somehow, our API needs to be aware of this context. This is probably related to if not included by TIMOB-16078.

Comments

No comments

JSON Source