Skip to content

Commit

Permalink
Merge pull request #88 from tsoding/offline
Browse files Browse the repository at this point in the history
Make emoteJAM work offline
  • Loading branch information
rexim authored Nov 23, 2023
2 parents 88f9672 + 4e9128e commit d60b9e5
Show file tree
Hide file tree
Showing 13 changed files with 443 additions and 119 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: CI
on: [push, pull_request]

jobs:
node-13-typescript:
node-20-typescript:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '13'
node-version: '20'
- run: npm install
- run: ./node_modules/.bin/tsc
- run: npm run build
- run: git diff --exit-code
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,39 @@ $ python3 -m http.server 6969
$ iexplore.exe http://localhost:6969/
```

## Development Workflow
## Building

1. `$ npm install`
2. `$ ./node_modules/.bin/tsc -w`
3. `<edit files>`
The whole build is organized so you can just serve the repo via an HTTP server and it just works. This is done to simplify deployment to [GitHub pages](https://pages.github.com/). We just tell GitHub to service this repo as is. The build artifacts are also commited to the repo. So if you want to simply get the website working you don't even have to build anything. Just serve the repo.

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.
The build is done via the [./build.js](./build.js) script. It is recommended to read it to get an idea on how it works. It is also recommended to check the `"scripts"` section of [./package.json](./package.json) to get an idea on how it is called from `npm run`.

Before doing any building make sure you installed all the necessary dependencies:

```console
$ npm install
```

To build all the artifacts

```console
$ npm run build
```

## Watching

The [./build.js](./build.js) script enables you to [Watch](https://www.typescriptlang.org/docs/handbook/configuring-watch.html#handbook-content) the source code:

```console
$ npm run watch
```

## Serving and Watching

```console
$ npm run service
```

This starts both `python3 -m http.server 6969` and [Watching](#Watching) at the same time, providing a convenient development environment.

# Filter Development

Expand Down
99 changes: 99 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { spawn } from 'child_process';

function cmd(program, args) {
console.log('CMD:', program, args);
const p = spawn(program, args.flat()); // NOTE: flattening the args array enables you to group related arguments for better self-documentation of the running command
p.stdout.on('data', (data) => process.stdout.write(data));
p.stderr.on('data', (data) => process.stderr.write(data));
p.on('close', (code) => {
if (code !== 0) {
console.error(program, args, 'exited with', code);
}
});
return p;
}

const commonTscFlags = [
'--strict',
'--removeComments',
'--skipLibCheck',
];

const mainTs = [
'ts/eval.ts',
'ts/filters.ts',
'ts/grecha.ts',
'ts/index.ts'
];

function tscMain(...extraParams) {
cmd('tsc', [
...commonTscFlags,
['--outDir', 'js'],
...extraParams,
mainTs,
]);
}

function tscServiceWorker(...extraParams) {
cmd('tsc', [
...commonTscFlags,
['--lib', 'webworker'],
['--outFile', 'serviceworker.js'],
...extraParams,
'serviceworker.ts'
]);
}

function build(part, ...args) {
switch (part) {
case undefined:
tscServiceWorker();
tscMain();
break;
case 'main':
tscMain();
break;
case 'serviceworker':
tscServiceWorker();
break;
default:
throw new Error(`Unknown build part ${part}. Available parts: main, serviceworker.`);
}
}

function watch(part, ...args) {
switch (part) {
case undefined:
tscMain('-w', '--preserveWatchOutput');
tscServiceWorker('-w', '--preserveWatchOutput');
break;
case 'main':
tscMain('-w', '--preserveWatchOutput');
break;
case 'serviceworker':
tscServiceWorker('-w', '--preserveWatchOutput');
break;
default:
throw new Error(`Unknown watch part ${part}. Available parts: main, serviceworker.`);
}
}

const [nodePath, scriptPath, command, ...args] = process.argv;
switch (command) {
case undefined:
case 'build':
build(...args);
break;
case 'watch':
watch(...args);
break;
case 'serve':
// TODO: maybe replace Python with something from Node itself?
// Python is a pretty unreasonable dependency.
cmd('python3', [['-m', 'http.server'], '6969']);
watch();
break;
default:
throw new Error(`Unknown command ${command}. Available commands: build, watch.`);
}
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<title>emoteJAM &mdash; Generate animated emotes from static images</title>
Expand Down
12 changes: 6 additions & 6 deletions js/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var BINARY_OPS = {
}
};
var UNARY_OPS = {
'-': function (arg) { return -arg; },
'-': function (arg) { return -arg; }
};
var Lexer = (function () {
function Lexer(src) {
Expand Down Expand Up @@ -73,8 +73,8 @@ function parse_primary(lexer) {
"kind": "unary_op",
"payload": {
"op": token,
"operand": operand,
},
"operand": operand
}
};
}
else if (token === '(') {
Expand All @@ -98,7 +98,7 @@ function parse_primary(lexer) {
"kind": "funcall",
"payload": {
"name": token,
"args": args,
"args": args
}
};
}
Expand All @@ -119,7 +119,7 @@ function parse_primary(lexer) {
"kind": "funcall",
"payload": {
"name": token,
"args": args,
"args": args
}
};
}
Expand Down Expand Up @@ -155,7 +155,7 @@ function parse_expr(lexer, prec) {
"payload": {
"op": op_token,
"lhs": lhs,
"rhs": rhs,
"rhs": rhs
}
};
}
Expand Down
Loading

0 comments on commit d60b9e5

Please sign in to comment.