Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client side compile for simulator - faster simulator #238

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
24 changes: 24 additions & 0 deletions modules/devkit-simulator-client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ exports.onLaunch = function () {
GLOBAL.NATIVE.onBackButton && GLOBAL.NATIVE.onBackButton(evt);
});

/** Puts preserveCache on localStorage so that jsio knows to preserve (and then request)
suggestions next load. Optionally also sets partialLoad, which causes jsio to wait for
a partialLoadContinue signal to actually load the app, after preloading suggestions. */
channel.on('reload', function (data, req) {
localStorage.setItem(jsio.__env.getNamespace('preserveCache'), true);

if (data) {
if (data.partialLoad) {
localStorage.setItem(jsio.__env.getNamespace('partialLoad'), true);
}
}

req.send(true);
});

/** partialLoadContinue is to be used in conjunction with partialLoad */
channel.on('partialLoadContinue', function (data, req) {
var cb = window._continueLoadCallback;
if (cb) {
cb();
}
req.send(true);
});

channel.on('screenshot', function (data, req) {
devkit.debugging.screenshot(function (err, res) {
if (err) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"bluebird": "^2.9.24",
"body-parser": "1.x",
"chalk": "^1.0.0",
"chokidar": "^1.0.5",
"compression": "^1.4.3",
"express": "4.x",
"ff": "^0.2.1",
Expand Down
41 changes: 41 additions & 0 deletions src/build/DirectoryBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var path = require('path');
var fs = require('fs');
var logger = require('../util/logging').get('build-directories');

// class for representing a list of resource directories
function DirectoryBuilder(base) {
this._base = base;
this._directories = [];
}

DirectoryBuilder.prototype.add = function (src, target) {
var directory;
if (arguments.length === 1) {
directory = {
src: path.join(this._base, src),
target: src
};
} else {
directory = {
src: src,
target: target
};
}

if (fs.existsSync(directory.src)) {
this._directories.push(directory);
} else {
logger.warn('Directory does not exist, ignoring files from',
directory);
}
};

DirectoryBuilder.prototype.getPaths = function () {
return this._directories.map(function (dir) { return dir.src; });
};

DirectoryBuilder.prototype.getDirectories = function () {
return this._directories;
};

module.exports = DirectoryBuilder;
29 changes: 22 additions & 7 deletions src/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,31 @@ exports.build = function (appPath, argv, cb) {
require('./steps/createDirectories').createDirectories(app, config, f());
}, function () {
require('./steps/buildHooks').getDependencies(app, config, f());
}, function (deps) {
// deps is an array of objects, merge them into one object and get all keys with false values
deps = merge.apply(this, deps);
var toRemove = Object.keys(deps).filter(function (name) { return deps[name] === false; });
app.removeModules(toRemove);
}, function (res) {
var modules = res.reduce(function (modules, res) {
var toRemove = Object.keys(res.data)
.filter(function (name) {
return res.data[name] === false;
});

if (toRemove.length) {
logger.log('module', res.module.name, 'getDependencies:');
toRemove.forEach(function (module) {
logger.log(' removing module', module);
});
}
return modules.concat(toRemove);
}, []);

app.removeModules(modules);
}, function () {
require('./steps/addDebugCode')(app, config, f());
}, function () {
require('./steps/moduleConfig').getConfig(app, config, f());
}, function () {
require('./steps/buildHooks').getResourceDirectories(app, config, f());
}, function (directories) {
config.directories = directories;
}, function () {
require('./steps/buildHooks').onBeforeBuild(app, config, f());
}, function () {
Expand All @@ -72,9 +88,8 @@ exports.build = function (appPath, argv, cb) {
// ONLY print config to stdout
process.stdout.write(JSON.stringify(merge({title: app.manifest.title}, config)));
process.exit(0);
} else {
require('./steps/logConfig').log(app, config, f());
}
require('./steps/logConfig').log(app, config, f());
}, function () {
require('./steps/executeTargetBuild').build(app, config, f());
}, function () {
Expand Down
94 changes: 78 additions & 16 deletions src/build/steps/buildHooks.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,94 @@
var ff = require('ff');
var path = require('path');
var Promise = require('bluebird');
var api = require('../../api');
var DirectoryBuilder = require('../DirectoryBuilder');
var fs = require('fs');

var readDir = Promise.promisify(fs.readdir);
var stat = Promise.promisify(fs.stat);

exports.getDependencies = function (app, config, cb) {
app.reloadModules();

// allows modules to disable other modules
executeHook('getDependencies', app, config, cb);
}
executeHook('getDependencies', app, config)
.nodeify(cb);
};

exports.onBeforeBuild = function (app, config, cb) {
executeHook('onBeforeBuild', app, config, cb);
}
executeHook('onBeforeBuild', app, config)
.nodeify(cb);
};

exports.onAfterBuild = function (app, config, cb) {
executeHook('onAfterBuild', app, config, cb);
}
executeHook('onAfterBuild', app, config)
.nodeify(cb);
};

exports.getResourceDirectories = function (app, config, cb) {
var builder = new DirectoryBuilder(app.paths.root);
builder.add('resources');
executeHook('getResourceDirectories', app, config)
.map(function (res) {
var module = res.module;
var directories = res.data;
directories.forEach(function (directory) {
var target = path.join('modules', module.name, directory.target);
builder.add(directory.src, target);
});
console.log(res);
})
.then(function () {
// add any localized resource directories
return readDir(app.paths.root);
})
.filter(function (filename) {
if (/^resources-/.test(filename)) {
return stat(path.join(app.paths.root, filename)).then(function (info) {
return info.isDirectory();
}, function onStatFail() {
return false;
});
}

return false;
})
.map(function (filename) {
builder.add(filename);
})
.then(function () {
return builder.getDirectories();
})
.nodeify(cb);
};

function executeHook(buildHook, app, config, cb) {
function executeHook(buildHook, app, config) {
var modules = app.getModules();

Promise.all(Object.keys(modules).map(function (moduleName) {
var module = modules[moduleName];
var buildExtension = module.loadExtension('build');
if (!buildExtension || !buildExtension[buildHook]) {
return;
}
return Promise.resolve(Object.keys(modules))
.map(function (moduleName) {
var module = modules[moduleName];
var buildExtension = module.loadExtension('build');
if (!buildExtension || !buildExtension[buildHook]) {
return;
}
return new Promise(function (resolve, reject) {
var retVal = buildExtension[buildHook](api, app.toJSON(), config, function (err, res) {
if (err) {
reject(err);
} else {
resolve(res);
}
});

return Promise.fromNode(buildExtension[buildHook].bind(buildExtension, api, app.toJSON(), config));
})).nodeify(cb);
if (retVal) { resolve(retVal); }
})
.then(function (data) {
return {
module: module,
data: data
};
});
})
.filter(function (res) { return res; });
}
1 change: 0 additions & 1 deletion src/build/steps/executeTargetBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ exports.build = function (app, config, cb) {
}

moduleKeys.forEach(function (moduleName) {
console.log(moduleName)
if (!buildModule) {
var module = modules[moduleName];
buildModule = module.loadBuildTarget(config.target);
Expand Down
Loading