From 6714a4e8c72da21e38de98957ef6d81c6bcb240b Mon Sep 17 00:00:00 2001 From: ccd0 Date: Tue, 19 Apr 2016 04:58:30 -0700 Subject: [PATCH] Now we can rebuild at the level of individual files. --- Makefile | 65 ++++++++++++++++++++------------------------ src/meta/jshint.json | 2 +- tools/chain.js | 17 ++++++------ 3 files changed, 40 insertions(+), 44 deletions(-) diff --git a/Makefile b/Makefile index e4df36dd7..5ae047f34 100644 --- a/Makefile +++ b/Makefile @@ -47,11 +47,13 @@ parts := \ lang = $(if $(filter globals css,$1),js,coffee) # remove extension when sorting so X.coffee comes before X.Y.coffee -sources_lang = \ - $(subst !,.$2,$(sort $(subst .$2,!, \ - $(wildcard src/$1/*.$2)))) +sources_part = \ + $(subst !c,.coffee,$(subst !j,.js,$(sort $(subst .coffee,!c,$(subst .js,!j, \ + $(wildcard src/$1/*.coffee src/$1/*.js)))))) -sources = $(call sources_lang,$1,$(call lang,$1)) +sources := $(foreach p,$(parts),$(call sources_part,$(p))) + +part_of = $(patsubst src/%/,%,$(dir $1)) imports = \ $(filter-out %.coffee %.js,$(wildcard src/$1/*.* src/$1/*/*.* src/$1/*/*/*.*)) \ @@ -68,13 +70,17 @@ imports_css := \ imports_Monitoring := \ src/meta/icon128.png -intermediate = \ +dests_platform = $(addprefix tmp/,$(subst /,-,$(subst src/,,$(subst platform,platform_$2,$(subst .coffee,.js,$1))))) + +dests_of = $(sort $(call dests_platform,$1,crx) $(call dests_platform,$1,userscript)) + +dests = $(foreach s,$(sources),$(call dests_of,$(s))) + +pieces = \ LICENSE \ src/meta/fbegin.js \ tmp/declaration.js \ - $(foreach p, \ - $(subst platform,platform_$1,$(parts)) \ - ,tmp/$(p).js) \ + $(foreach s,$(sources),$(call dests_platform,$(s),$1)) \ src/meta/fend.js crx_contents := script.js eventPage.js icon16.png icon48.png icon128.png manifest.json @@ -91,8 +97,6 @@ script := $(foreach f,$(filter-out %.crx %.zip,$(release)),test$(f)) $(foreach t crx := $(foreach f,$(filter %.crx %.zip,$(release)),test$(f)) -jshint := $(foreach f,$(subst platform,platform_crx platform_userscript,$(parts)),.events/jshint.$(f)) - default : script jshint install all : default release @@ -126,27 +130,15 @@ endif tmp/declaration.js : .events/declare $(if $(wildcard $@),,node tools/declare.js && echo -> $^) -define concatenate -tmp/$1.jst : $$(call sources,$1) $(cat_deps) | tmp - $(cat) $$(subst $$$$,$$(ESC_DOLLAR),$$(call sources,$1)) $$@ -endef - -$(foreach p, \ - $(parts), \ - $(eval $(call concatenate,$(p))) \ -) - -to_compile := $(subst platform,platform_crx platform_userscript,$(parts)) - define force_compile -tmp/$1.js : tmp/$$(firstword $$(subst _, ,$1)).jst $$(call imports, $$(firstword $$(subst _, ,$1))) - $(RM) $$@ +$$(call dests_of,$1) : $1 $$(call imports,$$(call part_of,$1)) $$(template_deps) $$(coffee_deps) tools/globalize.js tools/chain.js + $(RM) $$(subst $$$$,$$(ESC_DOLLAR),$$@) endef -$(foreach p, $(to_compile), $(eval $(call force_compile,$(p)))) +$(foreach s,$(sources),$(eval $(call force_compile,$(subst $$,$$$$,$(s))))) -.events/compile : $(patsubst %,tmp/%.js,$(to_compile)) $(template_deps) $(coffee_deps) tools/globalize.js tools/chain.js | .events - node tools/chain.js $(filter $(to_compile),$(patsubst tmp/%.js,%,$?)) +.events/compile : $(dests) | .events + node tools/chain.js $(subst $$,$(ESC_DOLLAR),$?) echo -> $@ tmp/eventPage.js : src/meta/eventPage.coffee $(coffee_deps) | tmp @@ -157,8 +149,8 @@ define rules_channel testbuilds/crx$1 : $$(MKDIR) -testbuilds/crx$1/script.js : $(call intermediate,crx) $(cat_deps) | testbuilds/crx$1 .events/compile - $(cat) $(call intermediate,crx) $$@ +testbuilds/crx$1/script.js : $$(call pieces,crx) $(cat_deps) | testbuilds/crx$1 .events/compile + $(cat) $$(subst $$$$,$$(ESC_DOLLAR),$$(call pieces,crx)) $$@ testbuilds/crx$1/eventPage.js : tmp/eventPage.js | testbuilds/crx$1 $$(CP) @@ -183,8 +175,8 @@ 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 $(template) $$< $$@ type=userscript channel=$1 -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) $$@ +testbuilds/$(name)$1.user.js : testbuilds/$(name)$1.meta.js $$(call pieces,userscript) $(cat_deps) | .events/compile + $(cat) testbuilds/$(name)$1.meta.js $$(subst $$$$,$$(ESC_DOLLAR),$$(call pieces,userscript)) $$@ endef @@ -204,12 +196,15 @@ test.html : README.md template.jst tools/markdown.js node_modules/marked/package index.html : test.html $(CP) -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-globals.js $(template_deps) | tmp $(template) $< $@ .events/jshint.% : tmp/%.js tmp/.jshintrc node_modules/jshint/package.json | .events/compile - $(BIN)jshint $< - echo -> $@ + $(RM) $(subst $$,$(ESC_DOLLAR),$@) + +.events/jshint : $(patsubst tmp/%.js,.events/jshint.%,$(dests)) + $(BIN)jshint $(subst $$,$(ESC_DOLLAR),$(patsubst .events/jshint.%,tmp/%.js,$?)) + echo -> $@ $(addprefix && echo -> ,$(subst $$,$(ESC_DOLLAR),$?)) install.json : echo {}> $@ @@ -261,7 +256,7 @@ crx : $(crx) release : $(release) -jshint : $(jshint) +jshint : .events/jshint install : .events/install diff --git a/src/meta/jshint.json b/src/meta/jshint.json index 8e01d236d..2e8829fff 100644 --- a/src/meta/jshint.json +++ b/src/meta/jshint.json @@ -23,7 +23,7 @@ %><%= read('tmp/declaration.js').match(/^var (.*);/)[1].split(', ').map(x => `,\n "${x}": true`).join('') %><%= - read('tmp/globals.js').match(/^var (.*);/)[1].split(', ').map(x => `,\n "${x}": true`).join('') + read('tmp/globals-globals.js').match(/^var (.*);/)[1].split(', ').map(x => `,\n "${x}": true`).join('') %> } } diff --git a/tools/chain.js b/tools/chain.js index f6e94ec6c..bcce51f2a 100644 --- a/tools/chain.js +++ b/tools/chain.js @@ -5,17 +5,18 @@ 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'); + 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 script = fs.readFileSync(`src/${parts[1]}/${basename}`, '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 = template(script, {type: parts[2]}); + if (/\.coffee$/.test(basename)) { script = coffee.compile(script); - var varNames = globalize.getNames(name); - script = globalize.globalize(script, varNames); + if (/^([$A-Z][$\w]*)\.coffee$/.test(basename)) { + script = globalize.globalize(script, [parts[3]]); + } } - fs.writeFileSync(`tmp/${name}.js`, script); + fs.writeFileSync(name, script); } catch (err) { console.error(`Error processing ${name}`); throw err;