diff --git a/lib/command/build.js b/lib/command/build.js index 68d7235a..739522ca 100644 --- a/lib/command/build.js +++ b/lib/command/build.js @@ -30,18 +30,20 @@ build.run = function(options, callback) { var tasks = options.install ? [ 'simplely_read_cortex_json', + 'prepare_build_type', 'run_preinstall_script', 'run_prebuild_script', 'build_process', 'server_link' ] : [ 'read_cortex_json', + 'clean_cortex_json', + 'prepare_build_type', 'run_preinstall_script', 'run_prebuild_script', // #478 // `cortex.main` and many other files might have not been generated before `cortex.scripts` // so, we clean cortex_json - 'clean_cortex_json', 'build_process', 'server_link', 'run_postbuild_script', @@ -52,6 +54,29 @@ build.run = function(options, callback) { }, callback); }; +build.prepare_build_type = function(options, callback){ + var pkg = options.pkg; + var entries = pkg.entries; + var csses = pkg.css; + + function hasFile(list){ + return list.map(function(rel){ + return node_path.join(options.cwd, rel); + }).indexOf(options.file) > -1; + } + + if(hasFile(entries)){ + options.build_type = 'js'; + }else if(hasFile(csses)){ + options.build_type = 'css'; + }else if(isDir()){ + options.build_type = 'dir'; + }else{ + options.build_type = 'full'; + } + + callback(); +}; build.simplely_read_cortex_json = function (options, callback) { // If install from cache, cortex.json will be enhanced json. @@ -134,6 +159,10 @@ build.run_prebuild_script = function(options, callback) { if (!options.prebuild) { return callback(null); } + + if(options.build_type != 'full'){ + return callback(null); + } this.run_script('prebuild', options, callback); }; @@ -442,6 +471,11 @@ build.build_modules = function(options, callback) { var cwd = options.cwd; var to = options.to; var self = this; + + if(options.build_type == 'js'){ + entries = [node_path.relative(options.cwd, options.file)]; + } + async.eachSeries(entries, function (entry, done) { var from = node_path.join(cwd, entry); builder({ @@ -480,15 +514,28 @@ build.build_modules = function(options, callback) { }, callback); }; +build._is_type = function(build_type, type){ + // build_type is from step prepare filelist + return build_type == 'full' || build_type == type; +}; build.copy_csses = function (options, callback) { var css = options.pkg.css; if (!css) { return callback(null); } + + if(!this._is_type(options.build_type, 'css')){ + return callback(null); + } + var self = this; var to = options.to; + if(options.build_type == 'css'){ + css = [node_path.relative(options.cwd, options.file)]; + } + async.eachSeries(css, function (path, done) { var from = options.cwd; var css_path = node_path.join(from, path); diff --git a/lib/command/watch.js b/lib/command/watch.js index da473136..d92152a9 100644 --- a/lib/command/watch.js +++ b/lib/command/watch.js @@ -36,6 +36,7 @@ watch._createWatcher = function (options) { // only emitted on master watcher process }) .on('all', function(event, filepath) { + options.file = filepath; var dir = node_path.dirname(filepath); // cortex commander will santitize filepath to the right root directory of the repo self._rebuild(options, dir); @@ -210,7 +211,8 @@ watch._rebuild = function(options, cwd, init) { 'build', // Use --force to prevent grunt task interrupt the current process '--force', - '--cwd', cwd + '--cwd', cwd, + '--file', options.file ]; var prerelease = options.prerelease; diff --git a/lib/option/build.js b/lib/option/build.js index 1609c70c..6a268151 100644 --- a/lib/option/build.js +++ b/lib/option/build.js @@ -18,6 +18,11 @@ exports.options = { default: false }, + file: { + type: node_path, + default: '' + }, + prebuild: { enumerable: false, type: Boolean,