added JS merger
This commit is contained in:
parent
7362b4dc5c
commit
bd6d9f3399
5 changed files with 45 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,5 +2,6 @@ node_modules/
|
||||||
public/assets/*.png
|
public/assets/*.png
|
||||||
public/assets/*.json
|
public/assets/*.json
|
||||||
public/css/*.css
|
public/css/*.css
|
||||||
|
public/js/*.js
|
||||||
public/favicon.ico
|
public/favicon.ico
|
||||||
|
|
||||||
|
|
15
Makefile
15
Makefile
|
@ -8,9 +8,11 @@ SNAKE = public/assets/snake.json
|
||||||
|
|
||||||
CSS = public/css/snek.css
|
CSS = public/css/snek.css
|
||||||
|
|
||||||
OUTPUT = $(ICON) $(APPLE) $(WALL) $(SNAKE) $(CSS)
|
JS = public/js/snek.js
|
||||||
|
|
||||||
all: icon css apple wall snake
|
OUTPUT = $(ICON) $(APPLE) $(WALL) $(SNAKE) $(CSS) $(JS)
|
||||||
|
|
||||||
|
all: icon apple wall snake css js
|
||||||
icon: $(ICON)
|
icon: $(ICON)
|
||||||
apple: $(APPLE)
|
apple: $(APPLE)
|
||||||
wall: $(WALL)
|
wall: $(WALL)
|
||||||
|
@ -19,6 +21,8 @@ snake: $(SNAKE)
|
||||||
|
|
||||||
css: $(CSS)
|
css: $(CSS)
|
||||||
|
|
||||||
|
js: $(JS)
|
||||||
|
|
||||||
public/assets/icon32.png: assets/icon.jpg
|
public/assets/icon32.png: assets/icon.jpg
|
||||||
convert $^ -resize 32x $@
|
convert $^ -resize 32x $@
|
||||||
public/assets/icon256.png: assets/icon.jpg
|
public/assets/icon256.png: assets/icon.jpg
|
||||||
|
@ -35,8 +39,11 @@ public/assets/wall32.png: assets/wall.png
|
||||||
public/assets/snake.json: assets/snake.json
|
public/assets/snake.json: assets/snake.json
|
||||||
cp $^ $@
|
cp $^ $@
|
||||||
|
|
||||||
public/css/snek.css: src/less/snek.less
|
public/css/snek.css: src/less/snek.less $(wildcard src/less/*.less)
|
||||||
lessc $^ $@
|
lessc $< $@
|
||||||
|
|
||||||
|
public/js/snek.js: $(wildcard src/js/*.js)
|
||||||
|
node mergejs.js $^ > $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OUTPUT)
|
rm -f $(OUTPUT)
|
||||||
|
|
29
mergejs.js
Normal file
29
mergejs.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
const fs=require('fs');
|
||||||
|
|
||||||
|
const requireFn=`
|
||||||
|
const require=function require(name) {
|
||||||
|
if(require.cache[name]) return require.cache[name];
|
||||||
|
if(!require.source[name]) throw new Error("Cannot require "+name+": not found");
|
||||||
|
require.cache[name]=require.source[name]() || true;
|
||||||
|
return require.cache[name];
|
||||||
|
};
|
||||||
|
require.cache=Object.create(null);
|
||||||
|
require.source=Object.create(null);
|
||||||
|
window.require=require;
|
||||||
|
`;
|
||||||
|
|
||||||
|
let outputCode=[requireFn];
|
||||||
|
process.argv
|
||||||
|
.slice(2)
|
||||||
|
.map(a => [a, a.match(/([a-zA-Z_][a-zA-Z0-9_-]*).js$/)[1]])
|
||||||
|
.forEach(([modFile, modName]) => {
|
||||||
|
const modSource=fs.readFileSync(modFile, 'utf8');
|
||||||
|
outputCode.push(`
|
||||||
|
require.source['${modName}']=(a => a.bind(a)) (function ${modName}() {
|
||||||
|
'use strict';
|
||||||
|
${modSource}
|
||||||
|
});
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.writeSync(1, outputCode.join('\n'));
|
0
public/js/.gitkeep
Normal file
0
public/js/.gitkeep
Normal file
|
@ -1,3 +1,5 @@
|
||||||
|
const Assets=require('assets');
|
||||||
|
|
||||||
const [EMPTY, FOOD, WALL, SNAKE]=Array(4).keys();
|
const [EMPTY, FOOD, WALL, SNAKE]=Array(4).keys();
|
||||||
|
|
||||||
const ifNaN=(v, r) => isNaN(v)?r:v;
|
const ifNaN=(v, r) => isNaN(v)?r:v;
|
||||||
|
@ -191,3 +193,5 @@ class SnekGame {
|
||||||
requestAnimationFrame(() => this.tick());
|
requestAnimationFrame(() => this.tick());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return SnekGame;
|
Loading…
Reference in a new issue