[TIMOB-13444] TiAPI: getDirectoryListing used with compiled js files
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Low |
Status | Reopened |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Core |
Labels | js, production |
Reporter | Martin Guillon |
Assignee | Unknown |
Created | 2012-12-14T08:08:13.000+0000 |
Updated | 2018-06-21T02:13:20.000+0000 |
Description
using the code above you can test a difference in behavior in dev and production.
given the assets in attachment (unzip in your ressources dir), in development you will get a list of js files in the console.
In production you will get an empty list.
This is normal as the js are compiled and not really there. My question is could we get a behavior as with Titanium.Filesystem.File.exists which works on compiled js files (as shown is KitchenSink).
Thanks
var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'toto');
var dir_files = dir.getDirectoryListing();
if (!dir_files || dir_files === null || dir_files.length === 0){
Ti.API.info('no files to list in ' + dir.nativePath );
}
else{
for (var i = 0; i < dir_files.length; i++) {
Ti.API.info('found file ' + dir_files[i] );
}
}
Attachments
File | Date | Size |
---|---|---|
toto.zip | 2012-12-14T08:08:13.000+0000 | 661 |
So you want to be able to get a list of the JavaScript files of an application in production? Please could you explain why? Also note that the JavaScript files when compiled no longer exist at all... They're all encoded into a string...
Yes Daniel i know all about that and if you read carefully that s exactly what i wrote. But as i mentioned Titanium.Filesystem.File.exists works with compiled JS. (easily as it just goes through the array of compiled js and look for the file). So it is doable (i will code it by the way ;)) Also IT DOES MAKE SENSE. Why wouldn't go through your js files. I can think of 10 use cases right of my mind : - an app with multiple games, each one represented by a js file. Using getDirectoryListing you can know how many games you have (without having to manage a var for that) - using css (or call it jss, rjss ...)., getDirectoryListing allows you not have to maintain a definite list of files (which can be different on every platform). The later is actually one i use all the time. And it s the one blocking me right now in production.
I actually have this working in my branch. I use it a lot. The main reason for using getDirectoryListing with compile scripts is to be able to require/include compiled js files (js files in production).