Make the build process a bit saner.

This commit is contained in:
ccd0 2016-04-20 04:30:18 -07:00
parent 2652ece83f
commit d782a29138
2 changed files with 34 additions and 19 deletions

View File

@ -73,11 +73,13 @@ imports = \
$(if $(filter $(uses_tests_enabled),$1),.tests_enabled) \
$(imports_$1)
dests_platform = $(addprefix tmp/,$(subst /,-,$(subst src/,,$(subst platform,platform_$2,$(subst .coffee,.js,$1)))))
dests_platform = $(addprefix tmp/,$(subst /,-,$(patsubst src/%,%.js,$(subst platform,platform_$2,$1))))
dests_of = $(sort $(call dests_platform,$1,crx) $(call dests_platform,$1,userscript))
dests = $(foreach s,$(sources),$(call dests_of,$(s)))
dests := $(foreach s,$(sources),$(call dests_of,$(s)))
updates := $(subst tmp/,.events/,$(dests))
pieces = \
tmp/LICENSE \
@ -117,7 +119,7 @@ ifneq "$(wildcard npm-shrinkwrap.json)" ""
echo -> $@
node_modules/%/package.json : .events/npm
$(if $(wildcard $@),,npm install && echo -> $^)
$(if $(wildcard $@),,npm install && echo -> $<)
else
@ -134,19 +136,32 @@ endif
echo -> $@
tmp/declaration.js : .events/declare
$(if $(wildcard $@),,node tools/declare.js && echo -> $^)
$(if $(wildcard $@),,node tools/declare.js && echo -> $<)
define force_compile
$$(call dests_of,$1) : $1 $$(call imports,$1) $$(template_deps) $$(coffee_deps) tools/chain.js
define check_source
$$(subst tmp/,.events/,$(call dests_of,$1)) : $1 $$(call imports,$1) | .events
echo -> $$(call QUOTE,$$@)
endef
$(foreach s,$(sources),$(eval $(call force_compile,$(subst $$,$$$$,$(s)))))
$(foreach s,$(sources),$(eval $(call check_source,$(subst $$,$$$$,$(s)))))
.events/compile : $(dests) | .events
node tools/chain.js $(call QUOTE,$?)
.events/compile : $(updates) $(template_deps) $(coffee_deps) tools/chain.js
node tools/chain.js $(call QUOTE, \
$(subst .events/,tmp/, \
$(if $(filter-out $(updates),$?), \
$(updates), \
$(filter $(updates),$?) \
) \
) \
)
echo -> $@
$(dests) : .events/compile
$(if $(wildcard $@),, \
node tools/chain.js $(filter-out $(wildcard $(dests)),$(dests)) \
&& echo -> $< \
)
tmp/eventPage.js : src/meta/eventPage.coffee $(coffee_deps) | tmp
$(coffee) -o tmp src/meta/eventPage.coffee
@ -211,12 +226,13 @@ index.html : test.html
tmp/.jshintrc : src/meta/jshint.json tmp/declaration.js src/globals/globals.js $(template_deps) | tmp
$(template) $< $@
.events/jshint.% : tmp/%.js tmp/.jshintrc node_modules/jshint/package.json | .events/compile
echo -> $(call QUOTE,$@)
.events/jshint : $(patsubst tmp/%.js,.events/jshint.%,$(dests))
$(BIN)jshint $(call QUOTE,$(patsubst .events/jshint.%,tmp/%.js,$?))
echo - $(addprefix && echo -> ,$(call QUOTE,$?))
.events/jshint : $(dests) tmp/.jshintrc node_modules/jshint/package.json
$(BIN)jshint $(call QUOTE, \
$(if $(filter-out $(dests),$?), \
$(dests), \
$(filter $(dests),$?) \
) \
)
echo -> $@
install.json :

View File

@ -4,13 +4,12 @@ var coffee = require('coffee-script');
for (var name of process.argv.slice(2)) {
try {
var parts = name.match(/^tmp\/([^_]*)(?:_(.*))?-(.*)\.js$/);
var basename = fs.readdirSync(`src/${parts[1]}`).filter(x => (x === `${parts[3]}.coffee` || x === `${parts[3]}.js`))[0];
var sourceName = `src/${parts[1]}/${basename}`;
var parts = name.match(/^tmp\/([^_]*)(?:_(.*))?-(.*)\.(.*)\.js$/);
var sourceName = `src/${parts[1]}/${parts[3]}.${parts[4]}`;
var script = fs.readFileSync(sourceName, 'utf8');
script = script.replace(/\r\n/g, '\n');
script = template(script, {type: parts[2]}, sourceName);
if (/\.coffee$/.test(basename)) {
if (parts[4] === 'coffee') {
script = coffee.compile(script);
if (/^[$A-Z][$\w]*$/.test(parts[3])) {
script = `${parts[3]} = ${script}`;