Get rid of recursive file imports.
This commit is contained in:
parent
10bad506d7
commit
e2aaefa7df
18
Makefile
18
Makefile
@ -66,8 +66,8 @@ sources := \
|
|||||||
src/General/Main.coffee
|
src/General/Main.coffee
|
||||||
|
|
||||||
imports := \
|
imports := \
|
||||||
node_modules/font-awesome/package.json \
|
tmp/font-awesome.css \
|
||||||
$(wildcard src/Linkification/icons/*.png) \
|
tmp/style.css \
|
||||||
src/Archive/archives.json \
|
src/Archive/archives.json \
|
||||||
src/meta/icon48.png \
|
src/meta/icon48.png \
|
||||||
$(wildcard src/Monitoring/Favicon/*/*.png) \
|
$(wildcard src/Monitoring/Favicon/*/*.png) \
|
||||||
@ -80,6 +80,12 @@ imports := \
|
|||||||
$(wildcard src/css/*.css) \
|
$(wildcard src/css/*.css) \
|
||||||
.tests_enabled
|
.tests_enabled
|
||||||
|
|
||||||
|
imports_font_awesome := \
|
||||||
|
node_modules/font-awesome/css/font-awesome.css \
|
||||||
|
node_modules/font-awesome/fonts/fontawesome-webfont.woff
|
||||||
|
imports_style := \
|
||||||
|
$(wildcard src/Linkification/icons/*.png)
|
||||||
|
|
||||||
bds := \
|
bds := \
|
||||||
$(foreach f, \
|
$(foreach f, \
|
||||||
$(foreach c,. -beta.,$(name)$(c)crx updates$(c)xml $(name)$(c)user.js $(name)$(c)meta.js) \
|
$(foreach c,. -beta.,$(name)$(c)crx updates$(c)xml $(name)$(c)user.js $(name)$(c)meta.js) \
|
||||||
@ -103,12 +109,18 @@ all : jshint bds install
|
|||||||
npm install
|
npm install
|
||||||
echo -> $@
|
echo -> $@
|
||||||
|
|
||||||
node_modules/%/package.json : .events/npm
|
node_modules/% : .events/npm
|
||||||
|
|
||||||
|
|
||||||
.tests_enabled :
|
.tests_enabled :
|
||||||
echo false> .tests_enabled
|
echo false> .tests_enabled
|
||||||
|
|
||||||
|
tmp/font-awesome.css : src/css/font-awesome.css $(imports_font_awesome) $(template_deps) | tmp
|
||||||
|
$(template) $< $@
|
||||||
|
|
||||||
|
tmp/style.css : src/css/style.css $(imports_style) $(template_deps) | tmp
|
||||||
|
$(template) $< $@
|
||||||
|
|
||||||
tmp/script.coffee : $(sources) $(cat_deps) | tmp
|
tmp/script.coffee : $(sources) $(cat_deps) | tmp
|
||||||
$(cat) $(sources) $@
|
$(cat) $(sources) $@
|
||||||
|
|
||||||
|
|||||||
@ -391,7 +391,7 @@ Main =
|
|||||||
$.ready ->
|
$.ready ->
|
||||||
cb() if Main.isThisPageLegit()
|
cb() if Main.isThisPageLegit()
|
||||||
|
|
||||||
css: `<%= importCSS('font-awesome', 'style', 'yotsuba', 'yotsuba-b', 'futaba', 'burichan', 'tomorrow', 'photon', 'supports') %>`
|
css: `<%= importCSS('../../tmp/font-awesome', '../../tmp/style', 'yotsuba', 'yotsuba-b', 'futaba', 'burichan', 'tomorrow', 'photon', 'supports') %>`
|
||||||
|
|
||||||
cssWWW: `<%= importCSS('www') %>`
|
cssWWW: `<%= importCSS('www') %>`
|
||||||
|
|
||||||
|
|||||||
@ -4,29 +4,26 @@ var _ = require('lodash');
|
|||||||
// disable ES6 delimiters
|
// disable ES6 delimiters
|
||||||
_.templateSettings.interpolate = /<%=([\s\S]+?)%>/g;
|
_.templateSettings.interpolate = /<%=([\s\S]+?)%>/g;
|
||||||
|
|
||||||
var pkg = {};
|
var obj = {};
|
||||||
|
|
||||||
var read = pkg.read = filename => fs.readFileSync(filename, 'utf8').replace(/\r\n/g, '\n');
|
var read = obj.read = filename => fs.readFileSync(filename, 'utf8').replace(/\r\n/g, '\n');
|
||||||
var readJSON = pkg.readJSON = filename => JSON.parse(read(filename));
|
var readJSON = obj.readJSON = filename => JSON.parse(read(filename));
|
||||||
pkg.readBase64 = filename => fs.readFileSync(filename).toString('base64');
|
obj.readBase64 = filename => fs.readFileSync(filename).toString('base64');
|
||||||
pkg.ls = pathname => fs.readdirSync(pathname);
|
obj.ls = pathname => fs.readdirSync(pathname);
|
||||||
|
|
||||||
_.assign(pkg, readJSON('package.json'));
|
|
||||||
_.assign(pkg.meta, readJSON('version.json'));
|
|
||||||
|
|
||||||
// Convert JSON object to Coffeescript expression (via embedded JS).
|
// Convert JSON object to Coffeescript expression (via embedded JS).
|
||||||
var constExpression = data => '`' + JSON.stringify(data).replace(/`/g, '\\`') + '`';
|
var constExpression = data => '`' + JSON.stringify(data).replace(/`/g, '\\`') + '`';
|
||||||
|
|
||||||
pkg.importCSS = function() {
|
obj.importCSS = function() {
|
||||||
var text = Array.prototype.slice.call(arguments).map(name => read(`src/css/${name}.css`)).join('');
|
var text = Array.prototype.slice.call(arguments).map(name => read(`src/css/${name}.css`)).join('');
|
||||||
text = _.template(text)(pkg);
|
text = _.template(text)(pkg); // variables only; no recursive imports
|
||||||
return text.trim().replace(/\n+/g, '\n').split(/^/m).map(JSON.stringify).join(' +\n').replace(/`/g, '\\`');
|
return text.trim().replace(/\n+/g, '\n').split(/^/m).map(JSON.stringify).join(' +\n').replace(/`/g, '\\`');
|
||||||
};
|
};
|
||||||
|
|
||||||
pkg.importHTML = function(filename) {
|
obj.importHTML = function(filename) {
|
||||||
var text = read(`src/${filename}.html`).replace(/^ +/gm, '').replace(/\r?\n/g, '');
|
var text = read(`src/${filename}.html`).replace(/^ +/gm, '').replace(/\r?\n/g, '');
|
||||||
text = _.template(text)(pkg);
|
text = _.template(text)(pkg); // variables only; no recursive imports
|
||||||
return pkg.html(text);
|
return obj.html(text);
|
||||||
};
|
};
|
||||||
|
|
||||||
function TextStream(text) {
|
function TextStream(text) {
|
||||||
@ -155,7 +152,7 @@ Placeholder.prototype.build = function() {
|
|||||||
|
|
||||||
// HTML template generator with placeholders of forms ${}, &{}, @{}, and ?{}{}{} (see Placeholder.prototype.build)
|
// HTML template generator with placeholders of forms ${}, &{}, @{}, and ?{}{}{} (see Placeholder.prototype.build)
|
||||||
// that checks safety of generated expressions at compile time.
|
// that checks safety of generated expressions at compile time.
|
||||||
pkg.html = function(template) {
|
obj.html = function(template) {
|
||||||
var stream = new TextStream(template);
|
var stream = new TextStream(template);
|
||||||
var output = parseHTMLTemplate(stream);
|
var output = parseHTMLTemplate(stream);
|
||||||
if (stream.text) {
|
if (stream.text) {
|
||||||
@ -164,16 +161,23 @@ pkg.html = function(template) {
|
|||||||
return `(innerHTML: ${output})`;
|
return `(innerHTML: ${output})`;
|
||||||
};
|
};
|
||||||
|
|
||||||
pkg.assert = function(statement) {
|
obj.assert = function(statement) {
|
||||||
if (!pkg.tests_enabled) return '';
|
if (!obj.tests_enabled) return '';
|
||||||
return `throw new Error 'Assertion failed: ' + ${constExpression(statement)} unless ${statement}`;
|
return `throw new Error 'Assertion failed: ' + ${constExpression(statement)} unless ${statement}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Import variables from package.json and version.json.
|
||||||
|
var pkg = readJSON('package.json');
|
||||||
|
_.assign(pkg.meta, readJSON('version.json'));
|
||||||
|
|
||||||
|
// Take variables from command line.
|
||||||
for (var i = 4; i < process.argv.length; i++) {
|
for (var i = 4; i < process.argv.length; i++) {
|
||||||
var m = process.argv[i].match(/(.*?)=(.*)/);
|
var m = process.argv[i].match(/(.*?)=(.*)/);
|
||||||
pkg[m[1]] = m[2];
|
pkg[m[1]] = m[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_.assign(obj, pkg);
|
||||||
|
|
||||||
var text = read(process.argv[2]);
|
var text = read(process.argv[2]);
|
||||||
text = _.template(text)(pkg);
|
text = _.template(text)(obj);
|
||||||
fs.writeFileSync(process.argv[3], text);
|
fs.writeFileSync(process.argv[3], text);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user