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

[TIMOB-13569] Removed the code processor from the CLI so it can be implemented as a pre-compile hook #4164

Merged
merged 3 commits into from
Apr 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions mobileweb/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ var ti = require('titanium-sdk'),
__n = i18n.__n,
cleanCSS = require('clean-css'),
afs = appc.fs,
xml = appc.xml,
parallel = appc.async.parallel,
UglifyJS = require('uglify-js'),
fs = require('fs'),
path = require('path'),
wrench = require('wrench'),
DOMParser = require('xmldom').DOMParser,
jsExtRegExp = /\.js$/,
HTML_HEADER = [
'<!--',
Expand Down Expand Up @@ -141,7 +139,6 @@ function build(logger, config, cli, finished) {
this.locales = [];
this.appNames = {};
this.splashHtml = '';
this.codeProcessor = cli.codeProcessor;

var pkgJson = this.readTiPackageJson();
this.packages = [{
Expand Down Expand Up @@ -189,6 +186,9 @@ function build(logger, config, cli, finished) {
// that build.pre.compile was fired.
ti.validateAppJsExists(this.projectDir, this.logger);

// Note: code processor is a pre-compile hook
this.codeProcessor = cli.codeProcessor;

parallel(this, [
'copyFiles',
'findProjectDependencies'
Expand Down Expand Up @@ -227,7 +227,7 @@ function build(logger, config, cli, finished) {
});
});
}.bind(this));
};
}

build.prototype = {

Expand Down Expand Up @@ -361,7 +361,7 @@ build.prototype = {
this.logger.info(__n('Searching for %s Titanium Module', 'Searching for %s Titanium Modules', this.tiapp.modules.length));
appc.timodule.find(this.tiapp.modules, 'mobileweb', this.deployType, this.titaniumSdkVersion, this.moduleSearchPaths, this.logger, function (modules) {
if (modules.missing.length) {
this.logger.error(__('Could not find all required Titanium Modules:'))
this.logger.error(__('Could not find all required Titanium Modules:'));
modules.missing.forEach(function (m) {
this.logger.error(' id: ' + m.id + '\t version: ' + (m.version || 'latest') + '\t platform: ' + m.platform + '\t deploy-type: ' + m.deployType);
}, this);
Expand Down Expand Up @@ -405,7 +405,7 @@ build.prototype = {

var libDir = ((pkgJson.directories && pkgJson.directories.lib) || '').replace(/^\//, '');

var mainFilePath = path.join(moduleDir, libDir, (pkgJson.main || '').replace(jsExtRegExp, '') + '.js')
var mainFilePath = path.join(moduleDir, libDir, (pkgJson.main || '').replace(jsExtRegExp, '') + '.js');
if (!afs.exists(mainFilePath)) {
this.logger.error(__('Invalid Titanium Mobile Module "%s": unable to find main file "%s"', module.id, pkgJson.main) + '\n');
process.exit(1);
Expand Down
118 changes: 8 additions & 110 deletions support/cli/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ var appc = require('node-appc'),
__n = i18n.__n,
afs = appc.fs,
ti = require('titanium-sdk'),
path = require('path'),
codeProcessor = require('titanium-code-processor');
path = require('path');

// TODO: need to support building modules... how do we know if --dir is a module or app? where is the module _build.js located?

Expand Down Expand Up @@ -124,113 +123,12 @@ exports.run = function (logger, config, cli) {
process.exit(1);
}

function buildModuleRun() {
require(buildModule).run(logger, config, cli, function (err) {
var delta = appc.time.prettyDiff(cli.startTime, Date.now());
if (err) {
logger.error(__('Project failed to build after %s', delta) + '\n');
} else {
logger.info(__('Project built successfully in %s', delta) + '\n');
}
});
}

// Run the code processor, if it is enabled
if (cli.tiapp['code-processor'] && cli.tiapp['code-processor'].enabled) {
var codeProcessorPluginDir = path.resolve(path.join(global.titaniumCodeProcessorLibDir, '..', 'plugins')),
parsedModules = {},
moduleSearchPaths,
plugins = [];

moduleSearchPaths = [ cli.argv['project-dir'], afs.resolvePath(path.join(__dirname, '..', '..')) ];
if (config.paths && Array.isArray(config.paths.modules)) {
moduleSearchPaths = moduleSearchPaths.concat(config.paths.modules);
require(buildModule).run(logger, config, cli, function (err) {
var delta = appc.time.prettyDiff(cli.startTime, Date.now());
if (err) {
logger.error(__('Project failed to build after %s', delta) + '\n');
} else {
logger.info(__('Project built successfully in %s', delta) + '\n');
}

// Get the list of modules
parsedModules.commonjs = {};
parsedModules[platform] = {};
appc.timodule.find(cli.tiapp.modules, cli.argv.$originalPlatform !== platform ?
[ cli.argv.$originalPlatform, platform ] : platform,
cli.argv['deploy-type'] || 'development', cli.tiapp['sdk-version'], moduleSearchPaths, logger, function (modules) {
modules.found.forEach(function (module) {
if (module.platform.indexOf(platform) !== -1) {
parsedModules[platform][module.id] = null;
} else if (module.platform.indexOf('commonjs') !== -1) {
parsedModules.commonjs[module.id] = module.modulePath;
}
});

// Run the code processor
codeProcessor.run(
appc.fs.resolvePath(path.join(cli.argv['project-dir'], 'Resources', 'app.js')),
appc.util.mix({
invokeMethods: true,
evaluateLoops: true,
processUnvisitedCode: true,
suppressResults: true,
logConsoleCalls: false,
}, cli.tiapp['code-processor'].options),
[
{
path: path.join(codeProcessorPluginDir, 'common-globals'),
options: {}
},
{
path: path.join(codeProcessorPluginDir, 'require-provider'),
options: {
platform: cli.argv.platform,
modules: parsedModules
}
},
{
path: path.join(codeProcessorPluginDir, 'ti-api-provider'),
options: {
platform: cli.argv.platform,
sdkPath: path.resolve(path.join(__dirname, '..', '..'))
}
},
{
path: path.join(codeProcessorPluginDir, 'ti-api-usage-finder'),
options: {}
},
{
path: path.join(codeProcessorPluginDir, 'ti-api-platform-validator'),
options: {
platform: cli.argv.platform
}
},
{
path: path.join(codeProcessorPluginDir, 'ti-api-deprecation-finder'),
options: {}
}
],
logger, function() {
// Parse the results
var codeProcessorResults = codeProcessor.getResults(),
errors = codeProcessorResults.errors,
warnings = codeProcessorResults.warnings,
data,
i, len;
for(i = 0, len = errors.length; i < len; i++) {
data = errors[i];
logger.error('Titanium Code Processor error: ' + data.description + ' (' + data.file + ':' + data.line + ':' + data.column + ')');
}
for(i = 0, len = warnings.length; i < len; i++) {
data = warnings[i];
logger.warn('Titanium Code Processor warning: ' + data.description + ' (' + data.file + ':' + data.line + ':' + data.column + ')');
}
if (errors.length) {
logger.warn('The Titanium Code Processor detected errors in the project, results will be discarded');
} else {
cli.codeProcessor = codeProcessorResults;
}

// Build the project
buildModuleRun();
});
});
} else {
buildModuleRun();
}
});
};
1 change: 0 additions & 1 deletion support/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"less": "1.3.0",
"node-appc": ">=0.1.17",
"node-uuid": "1.3.x",
"titanium-code-processor": "0.3.x",
"titanium-sdk": ">=0.1.0",
"uglify-js": "2.2.x",
"wrench": "1.3.x",
Expand Down