Combine templating+compiling+afterprocessing into one step.
This commit is contained in:
parent
c89a977963
commit
033031c905
28
Makefile
28
Makefile
@ -136,33 +136,17 @@ $(foreach p, \
|
|||||||
$(eval $(call concatenate,$(p))) \
|
$(eval $(call concatenate,$(p))) \
|
||||||
)
|
)
|
||||||
|
|
||||||
tmp/platform_crx.jst tmp/platform_userscript.jst : tmp/platform.jst
|
to_compile := $(subst platform,platform_crx platform_userscript,$(parts))
|
||||||
$(CP)
|
|
||||||
|
|
||||||
to_interpolate := $(filter-out platform,$(parts)) platform_crx platform_userscript
|
define force_compile
|
||||||
|
tmp/$1.js : tmp/$$(firstword $$(subst _, ,$1)).jst $$(call imports, $$(firstword $$(subst _, ,$1)))
|
||||||
define interpolate
|
|
||||||
tmp/$1.$$(call lang,$1) : tmp/$1.jst $$(call imports,$1) $(template_deps)
|
|
||||||
$(template) $$< $$@ $$(if $$(findstring platform_,$1),type=$$(subst platform_,,$1))
|
|
||||||
endef
|
|
||||||
|
|
||||||
$(foreach p, $(to_interpolate), $(eval $(call interpolate,$(p))))
|
|
||||||
|
|
||||||
tmp/platform_%.coffee : tmp/platform.jst $(call imports,platform) $(template_deps)
|
|
||||||
$(template) $< $@ type=$*
|
|
||||||
|
|
||||||
to_compile := $(filter-out globals css platform,$(parts)) platform_crx platform_userscript
|
|
||||||
|
|
||||||
define compile
|
|
||||||
tmp/$1.js : tmp/$1.coffee $(coffee_deps) tools/globalize.js
|
|
||||||
$(RM) $$@
|
$(RM) $$@
|
||||||
endef
|
endef
|
||||||
|
|
||||||
$(foreach p, $(to_compile), $(eval $(call compile,$(p))))
|
$(foreach p, $(to_compile), $(eval $(call force_compile,$(p))))
|
||||||
|
|
||||||
.events/compile : $(foreach p, $(to_compile), tmp/$(p).js) | .events
|
.events/compile : $(patsubst %,tmp/%.js,$(to_compile)) $(template_deps) $(coffee_deps) tools/globalize.js tools/chain.js | .events
|
||||||
$(coffee) $(subst .js,.coffee,$?)
|
node tools/chain.js $(filter $(to_compile),$(patsubst tmp/%.js,%,$?))
|
||||||
node tools/globalize.js $(subst tmp/,,$(subst .js,,$?))
|
|
||||||
echo -> $@
|
echo -> $@
|
||||||
|
|
||||||
tmp/eventPage.js : src/meta/eventPage.coffee $(coffee_deps) | tmp
|
tmp/eventPage.js : src/meta/eventPage.coffee $(coffee_deps) | tmp
|
||||||
|
|||||||
25
tools/chain.js
Normal file
25
tools/chain.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
var fs = require('fs');
|
||||||
|
var template = require('./template');
|
||||||
|
var coffee = require('coffee-script');
|
||||||
|
var globalize = require('./globalize');
|
||||||
|
|
||||||
|
for (var name of process.argv.slice(2)) {
|
||||||
|
try {
|
||||||
|
var parts = name.split('_');
|
||||||
|
var basename = parts[0]; // e.g. template_crx -> template
|
||||||
|
var script = fs.readFileSync(`tmp/${basename}.jst`, 'utf8');
|
||||||
|
script = script.replace(/\r\n/g, '\n');
|
||||||
|
script = template(script, {type: parts[1]});
|
||||||
|
if (fs.readdirSync(`src/${basename}`).some(f => /\.coffee$/.test(f))) {
|
||||||
|
script = coffee.compile(script);
|
||||||
|
var varNames = globalize.getNames(name);
|
||||||
|
script = globalize.globalize(script, varNames);
|
||||||
|
}
|
||||||
|
fs.writeFileSync(`tmp/${name}.js`, script);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Error processing ${name}`);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user