Skip to content

Commit e0f2e14

Browse files
committed
Introduce build.js
1 parent 2141308 commit e0f2e14

File tree

10 files changed

+159
-118
lines changed

10 files changed

+159
-118
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ $ python3 -m http.server 6969
1717
$ iexplore.exe http://localhost:6969/
1818
```
1919

20-
## Development Workflow
20+
## Building
2121

22-
1. `$ npm install`
23-
2. `$ ./node_modules/.bin/tsc -w`
24-
3. `<edit files>`
22+
TBD
2523

26-
Make sure that you commit the generated `js/*` files along with your changes. This is important for the project to retain that "Just deploy the repo" attitude.
24+
## Watching
25+
26+
TBD
2727

2828
# Filter Development
2929

build.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
const child_process = require("child_process");
2+
const spawn = child_process.spawn;
3+
4+
function cmd(program, args) {
5+
console.log('CMD:', program, args);
6+
const p = spawn(program, args);
7+
p.stdout.on('data', (data) => process.stdout.write(data));
8+
p.stderr.on('data', (data) => process.stderr.write(data));
9+
p.on('close', (code) => {
10+
if (code !== 0) {
11+
console.error(program, args, 'exited with', code);
12+
}
13+
});
14+
}
15+
16+
const commonTscFlags = [
17+
'--strict', 'true',
18+
'--removeComments', 'true'
19+
];
20+
21+
const mainTs = [
22+
'ts/eval.ts',
23+
'ts/filters.ts',
24+
'ts/grecha.ts',
25+
'ts/index.ts'
26+
];
27+
28+
function tscMain(...extraParams) {
29+
cmd('tsc', [
30+
...commonTscFlags,
31+
'--outDir', 'js',
32+
...extraParams,
33+
...mainTs,
34+
]);
35+
}
36+
37+
function tscServiceWorker(...extraParams) {
38+
cmd('tsc', [
39+
...commonTscFlags,
40+
'--lib', 'webworker',
41+
'--skipLibCheck', 'true',
42+
'--outFile', 'serviceworker.js',
43+
...extraParams,
44+
'serviceworker.ts'
45+
]);
46+
}
47+
48+
function build(target, ...args) {
49+
if (target === undefined) {
50+
tscServiceWorker();
51+
tscMain();
52+
} else if (target === 'main') {
53+
tscMain();
54+
} else if (target === 'serviceworker') {
55+
tscServiceWorker();
56+
} else {
57+
throw new Error(`Unknown build target {target}`);
58+
}
59+
}
60+
61+
function watch(target, ...args) {
62+
if (target === undefined || target === 'main') {
63+
tscMain('-w');
64+
} else if (target === 'serviceworker') {
65+
tscServiceWorker('-w');
66+
} else {
67+
throw new Error(`Unknown watch target {target}`);
68+
}
69+
}
70+
71+
const [nodePath, scriptPath, command, ...args] = process.argv;
72+
73+
if (command === undefined) {
74+
build(...args);
75+
} else if (command === 'watch') {
76+
watch(...args);
77+
} else {
78+
throw new Error(`Unknown command {command}`);
79+
}

js/eval.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var BINARY_OPS = {
2828
}
2929
};
3030
var UNARY_OPS = {
31-
'-': function (arg) { return -arg; },
31+
'-': function (arg) { return -arg; }
3232
};
3333
var Lexer = (function () {
3434
function Lexer(src) {
@@ -73,8 +73,8 @@ function parse_primary(lexer) {
7373
"kind": "unary_op",
7474
"payload": {
7575
"op": token,
76-
"operand": operand,
77-
},
76+
"operand": operand
77+
}
7878
};
7979
}
8080
else if (token === '(') {
@@ -98,7 +98,7 @@ function parse_primary(lexer) {
9898
"kind": "funcall",
9999
"payload": {
100100
"name": token,
101-
"args": args,
101+
"args": args
102102
}
103103
};
104104
}
@@ -119,7 +119,7 @@ function parse_primary(lexer) {
119119
"kind": "funcall",
120120
"payload": {
121121
"name": token,
122-
"args": args,
122+
"args": args
123123
}
124124
};
125125
}
@@ -155,7 +155,7 @@ function parse_expr(lexer, prec) {
155155
"payload": {
156156
"op": op_token,
157157
"lhs": lhs,
158-
"rhs": rhs,
158+
"rhs": rhs
159159
}
160160
};
161161
}

js/filters.js

Lines changed: 28 additions & 28 deletions
Large diffs are not rendered by default.

js/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function loadFilterProgram(gl, filter, vertexAttribs) {
7171
var uniforms = {
7272
"resolution": gl.getUniformLocation(id, 'resolution'),
7373
"time": gl.getUniformLocation(id, 'time'),
74-
"emoteSize": gl.getUniformLocation(id, 'emoteSize'),
74+
"emoteSize": gl.getUniformLocation(id, 'emoteSize')
7575
};
7676
var paramsPanel = div().att$("class", "widget-element");
7777
var paramsInputs = {};
@@ -129,7 +129,7 @@ function loadFilterProgram(gl, filter, vertexAttribs) {
129129
"uniforms": uniforms,
130130
"duration": compile_expr(filter.duration),
131131
"transparent": filter.transparent,
132-
"paramsPanel": paramsPanel,
132+
"paramsPanel": paramsPanel
133133
};
134134
}
135135
function ImageSelector() {
@@ -286,7 +286,7 @@ function FilterSelector() {
286286
quality: 10,
287287
width: CANVAS_WIDTH,
288288
height: CANVAS_HEIGHT,
289-
transparent: program.transparent,
289+
transparent: program.transparent
290290
});
291291
var context = {
292292
"vars": {
@@ -346,7 +346,7 @@ function FilterSelector() {
346346
}
347347
gif.addFrame(new ImageData(pixels, CANVAS_WIDTH, CANVAS_HEIGHT), {
348348
delay: dt * 1000,
349-
dispose: 2,
349+
dispose: 2
350350
});
351351
renderProgress.style.width = (t / duration) * 50 + "%";
352352
t += dt;
@@ -382,7 +382,9 @@ function FilterSelector() {
382382
return root;
383383
}
384384
window.onload = function () {
385-
fetch("gif.worker.js");
385+
fetch("gif.worker.js").then(function () {
386+
console.log("Prefetched gif.worker.js");
387+
});
386388
if ("serviceWorker" in navigator) {
387389
navigator.serviceWorker.register('/serviceworker.js').then(function (registration) {
388390
console.log("Registered a Service Worker ", registration);

package-lock.json

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"description": "Simple website that generates animated BTTV emotes from static images",
55
"main": "index.js",
66
"scripts": {
7+
"build": "node build.js",
8+
"watch": "node build.js watch",
79
"test": "echo \"Error: no test specified\" && exit 1"
810
},
911
"repository": {
@@ -27,6 +29,7 @@
2729
"homepage": "https://github.com/tsoding/emoteJAM#readme",
2830
"devDependencies": {
2931
"@types/gif.js": "^0.2.1",
32+
"@types/node": "^20.9.3",
3033
"typescript": "^4.3.2"
3134
}
3235
}
File renamed without changes.

ts/serviceworker.ts renamed to serviceworker.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
self.addEventListener("install", (event) => {
32
console.log("Pog! Looks like we installed something! I have no idea what that means, but here is an object the browser sent us", event);
43
});
@@ -28,4 +27,3 @@ self.addEventListener("fetch", (e) => {
2827
})());
2928
}
3029
});
31-

tsconfig.json

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)