Reduce full build time by combining coffee shell commands.
This commit is contained in:
parent
a19e51d632
commit
44c9fc6f0e
21
Makefile
21
Makefile
@ -149,16 +149,19 @@ $(foreach p, \
|
|||||||
tmp/platform_%.coffee : tmp/platform.jst $(call imports,platform) $(template_deps)
|
tmp/platform_%.coffee : tmp/platform.jst $(call imports,platform) $(template_deps)
|
||||||
$(template) $< $@ type=$*
|
$(template) $< $@ type=$*
|
||||||
|
|
||||||
|
to_compile := $(filter-out globals css platform,$(parts)) platform_crx platform_userscript
|
||||||
|
|
||||||
define compile
|
define compile
|
||||||
tmp/$1.js : tmp/$1.coffee $(coffee_deps) tools/globalize.js
|
tmp/$1.js : tmp/$1.coffee $(coffee_deps) tools/globalize.js
|
||||||
$(coffee) $$<
|
$(RM) $$@
|
||||||
node tools/globalize.js $1
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
$(foreach p, \
|
$(foreach p, $(to_compile), $(eval $(call compile,$(p))))
|
||||||
$(filter-out globals css platform,$(parts)) platform_crx platform_userscript, \
|
|
||||||
$(eval $(call compile,$(p))) \
|
.events/compile : $(foreach p, $(to_compile), tmp/$(p).js) | .events
|
||||||
)
|
$(coffee) $(subst .js,.coffee,$?)
|
||||||
|
node tools/globalize.js $(subst tmp/,,$(subst .js,,$?))
|
||||||
|
echo -> $@
|
||||||
|
|
||||||
tmp/eventPage.js : src/meta/eventPage.coffee $(coffee_deps) | tmp
|
tmp/eventPage.js : src/meta/eventPage.coffee $(coffee_deps) | tmp
|
||||||
$(coffee) -o tmp src/meta/eventPage.coffee
|
$(coffee) -o tmp src/meta/eventPage.coffee
|
||||||
@ -168,7 +171,7 @@ define rules_channel
|
|||||||
testbuilds/crx$1 :
|
testbuilds/crx$1 :
|
||||||
$$(MKDIR)
|
$$(MKDIR)
|
||||||
|
|
||||||
testbuilds/crx$1/script.js : $(call intermediate,crx) $(cat_deps) | testbuilds/crx$1
|
testbuilds/crx$1/script.js : $(call intermediate,crx) $(cat_deps) | testbuilds/crx$1 .events/compile
|
||||||
$(cat) $(call intermediate,crx) $$@
|
$(cat) $(call intermediate,crx) $$@
|
||||||
|
|
||||||
testbuilds/crx$1/eventPage.js : tmp/eventPage.js | testbuilds/crx$1
|
testbuilds/crx$1/eventPage.js : tmp/eventPage.js | testbuilds/crx$1
|
||||||
@ -194,7 +197,7 @@ testbuilds/$(name)$1.crx : testbuilds/$(name)$1.crx.zip package.json tools/sign.
|
|||||||
testbuilds/$(name)$1.meta.js : src/meta/metadata.js src/meta/icon48.png version.json $(template_deps) | testbuilds
|
testbuilds/$(name)$1.meta.js : src/meta/metadata.js src/meta/icon48.png version.json $(template_deps) | testbuilds
|
||||||
$(template) $$< $$@ type=userscript channel=$1
|
$(template) $$< $$@ type=userscript channel=$1
|
||||||
|
|
||||||
testbuilds/$(name)$1.user.js : testbuilds/$(name)$1.meta.js $(call intermediate,userscript) $(cat_deps)
|
testbuilds/$(name)$1.user.js : testbuilds/$(name)$1.meta.js $(call intermediate,userscript) $(cat_deps) | .events/compile
|
||||||
$(cat) testbuilds/$(name)$1.meta.js $(call intermediate,userscript) $$@
|
$(cat) testbuilds/$(name)$1.meta.js $(call intermediate,userscript) $$@
|
||||||
|
|
||||||
endef
|
endef
|
||||||
@ -218,7 +221,7 @@ index.html : test.html
|
|||||||
tmp/.jshintrc : src/meta/jshint.json tmp/declaration.js tmp/globals.js $(template_deps) | tmp
|
tmp/.jshintrc : src/meta/jshint.json tmp/declaration.js tmp/globals.js $(template_deps) | tmp
|
||||||
$(template) $< $@
|
$(template) $< $@
|
||||||
|
|
||||||
.events/jshint.% : tmp/%.js tmp/.jshintrc node_modules/jshint/package.json | .events
|
.events/jshint.% : tmp/%.js tmp/.jshintrc node_modules/jshint/package.json | .events/compile
|
||||||
$(BIN)jshint $<
|
$(BIN)jshint $<
|
||||||
echo -> $@
|
echo -> $@
|
||||||
|
|
||||||
|
|||||||
@ -1,38 +1,40 @@
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
var filename = `tmp/${process.argv[2]}.js`;
|
for (var arg of process.argv.slice(2)) {
|
||||||
var basename = process.argv[2].split('_')[0]; // e.g. template_crx -> template
|
var filename = `tmp/${arg}.js`;
|
||||||
var sources = fs.readdirSync(`src/${basename}`);
|
var basename = arg.split('_')[0]; // e.g. template_crx -> template
|
||||||
|
var sources = fs.readdirSync(`src/${basename}`);
|
||||||
|
|
||||||
// Extract variables to be made global from source file list
|
// Extract variables to be made global from source file list
|
||||||
// e.g. ImageExpand from src/Images/ImageExpand.coffee
|
// e.g. ImageExpand from src/Images/ImageExpand.coffee
|
||||||
// but not QR.post or eventPage
|
// but not QR.post or eventPage
|
||||||
var names = [];
|
var names = [];
|
||||||
for (var f of sources) {
|
for (var f of sources) {
|
||||||
var m = f.match(/^([$A-Z][$\w]*)\.coffee$/);
|
var m = f.match(/^([$A-Z][$\w]*)\.coffee$/);
|
||||||
if (m) names.push(m[1]);
|
if (m) names.push(m[1]);
|
||||||
}
|
|
||||||
|
|
||||||
var script = fs.readFileSync(filename, 'utf8').replace(/\r\n/g, '\n');
|
|
||||||
|
|
||||||
var replaced = 0;
|
|
||||||
|
|
||||||
script = script.replace(
|
|
||||||
|
|
||||||
// matches declaration at the start of the function, not including helper function assignments
|
|
||||||
/^( *var )(.*)(,\n *|;\n)/m,
|
|
||||||
|
|
||||||
function(declaration, v, n, e) {
|
|
||||||
replaced++;
|
|
||||||
var n0 = names.sort().join(', ');
|
|
||||||
if (n0 !== n) throw new Error(`${filename}: expected variables (${n0}) found (${n})`);
|
|
||||||
return (e[0] === ',') ? v : '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
var script = fs.readFileSync(filename, 'utf8').replace(/\r\n/g, '\n');
|
||||||
|
|
||||||
if (replaced !== 1) {
|
var replaced = 0;
|
||||||
throw new Error(`${filename}: no declaration found`);
|
|
||||||
|
script = script.replace(
|
||||||
|
|
||||||
|
// matches declaration at the start of the function, not including helper function assignments
|
||||||
|
/^( *var )(.*)(,\n *|;\n)/m,
|
||||||
|
|
||||||
|
function(declaration, v, n, e) {
|
||||||
|
replaced++;
|
||||||
|
var n0 = names.sort().join(', ');
|
||||||
|
if (n0 !== n) throw new Error(`${filename}: expected variables (${n0}) found (${n})`);
|
||||||
|
return (e[0] === ',') ? v : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
if (replaced !== 1) {
|
||||||
|
throw new Error(`${filename}: no declaration found`);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(filename, script);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(filename, script);
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user