Skip to content

Commit 02fc51c

Browse files
committed
#5 #4 auto minification+publish
1 parent b970509 commit 02fc51c

File tree

5 files changed

+153
-11
lines changed

5 files changed

+153
-11
lines changed

.github/workflows/build.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build and deploy
2+
3+
on:
4+
push:
5+
paths:
6+
- 'package.json'
7+
pull_request:
8+
paths:
9+
- 'package.json'
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
name: Build
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Setup NodeJS
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 20
23+
- name: Install Closure Compiler
24+
run: npm install google-closure-compiler
25+
- name: Build
26+
run: npm run build
27+
- name: Publish to npm
28+
if: github.ref == 'refs/heads/main'
29+
env:
30+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
31+
run: npm publish

.npmignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.github/
2+
config/
3+
data/
4+
node_modules/
5+
build.js
6+
changes_before_git.txt
7+
package-lock.json
8+
rtjscomp.json
9+
spam.csv

build.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env node
2+
3+
"use strict";
4+
5+
(async () => {
6+
7+
const {
8+
execSync,
9+
} = await import('child_process');
10+
const {
11+
readFile,
12+
unlink,
13+
writeFile,
14+
} = await import('fs/promises');
15+
16+
const GCC_COMMAND = './node_modules/.bin/google-closure-compiler --';
17+
18+
const {version} = require('./package.json', 'utf8');
19+
20+
try {
21+
if (
22+
!execSync(GCC_COMMAND + 'version')
23+
.toString()
24+
.includes('Version: v202')
25+
) {
26+
console.error('newer google closure compiler required!');
27+
throw null;
28+
}
29+
}
30+
catch (e) {
31+
console.error('maybe run: npm install google-closure-compiler');
32+
process.exit(1);
33+
}
34+
35+
console.log(`build ${version}...`);
36+
37+
let code = (await readFile('rtjscomp.js', 'utf8'))
38+
.replace(
39+
"require('./package.json').version",
40+
JSON.stringify(version)
41+
)
42+
.replace(
43+
'await import(',
44+
'await import_hiddenfromgcc('
45+
);
46+
47+
let name_count = 0;
48+
for (const name of 'dependencies_paths file_function handler_stop path_split promise_deps_resolve promise_deps promise_stopped_resolve promise_stopped watcher'.split(' ')) {
49+
code = code.replaceAll(
50+
name,
51+
'x' + (name_count++).toString(36)
52+
);
53+
}
54+
55+
await writeFile(
56+
'/tmp/rtjscomp.js',
57+
code,
58+
'utf8'
59+
);
60+
61+
execSync(
62+
GCC_COMMAND +
63+
[
64+
'compilation_level SIMPLE',
65+
'js /tmp/rtjscomp.js',
66+
'js_output_file /tmp/rtjscomp.min.js',
67+
'language_in ECMASCRIPT_2017',
68+
'language_out ECMASCRIPT_2017',
69+
'module_resolution NODE',
70+
'rewrite_polyfills false',
71+
'use_types_for_optimization',
72+
'warning_level VERBOSE',
73+
'jscomp_off undefinedVars',
74+
'jscomp_off missingProperties',
75+
]
76+
.join(' --')
77+
);
78+
79+
await writeFile(
80+
'rtjscomp.js',
81+
'#!/usr/bin/env node\n"use strict";' +
82+
(await readFile('/tmp/rtjscomp.min.js', 'ascii'))
83+
.replace(
84+
'await import_hiddenfromgcc(',
85+
'await import('
86+
),
87+
'ascii'
88+
);
89+
90+
await unlink('/tmp/rtjscomp.js');
91+
await unlink('/tmp/rtjscomp.min.js');
92+
93+
console.log('done.');
94+
95+
})();

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rtjscomp",
3-
"version": "0.9.2",
3+
"version": "0.9.3",
44
"description": "php-like server but with javascript",
55
"repository": {
66
"type": "git",
@@ -15,7 +15,8 @@
1515
"querystring": "latest"
1616
},
1717
"scripts": {
18-
"start": "./rtjscomp.js"
18+
"start": "./rtjscomp.js",
19+
"build": "./build.js"
1920
},
2021
"bin": {
2122
"rtjscomp": "./rtjscomp.js"

rtjscomp.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
/**
3-
RTJSCOMP by L3P3, 2017-2025
3+
@preserve RTJSCOMP by L3P3, 2017-2025
44
*/
55

66
"use strict";
@@ -474,7 +474,7 @@ const service_start = async service_object => {
474474
service_object.status = SERVICE_STATUS_ACTIVE;
475475
}
476476
catch (err) {
477-
if (!err instanceof Error) {
477+
if (!(err instanceof Error)) {
478478
err = new Error(err + '?! wtf');
479479
}
480480
log(`[error] ${
@@ -667,6 +667,7 @@ const get_prop_list = (obj, prop) => {
667667
const value = obj[prop];
668668
if (
669669
typeof value !== 'object' ||
670+
!value ||
670671
value.length == null ||
671672
value.some(item => typeof item !== 'string')
672673
) {
@@ -683,6 +684,7 @@ const get_prop_map = (obj, prop) => {
683684
let value = obj[prop];
684685
if (
685686
typeof value !== 'object' ||
687+
!value ||
686688
(
687689
value = Object.entries(value)
688690
).some(([_, item]) => typeof item !== 'string')
@@ -1097,15 +1099,19 @@ const request_handle = async (request, response, https) => {
10971099
body_raw,
10981100
content_type.split('boundary=')[1].split(';')[0]
10991101
)
1100-
.map(({ name, ...value }) => [
1101-
name,
1102-
value.type ? value : value.data.toString()
1103-
])
1102+
.map(value => {
1103+
const {name} = value;
1104+
delete value.name;
1105+
return [
1106+
name,
1107+
value.type ? value : value.data.toString()
1108+
];
1109+
})
11041110
);
11051111
}
11061112
}
11071113
if (body) {
1108-
Object.assign(file_function_input, body);
1114+
Object.assign(file_function_input, /** @type {!Object} */ (body));
11091115
}
11101116
}
11111117
catch (err) {
@@ -1397,13 +1403,13 @@ await file_keep_new(PATH_CONFIG + 'init.js', async data => {
13971403
json['path_aliases'] = parse_old_map(old_path_aliases);
13981404
}
13991405
if (old_port_http) {
1400-
const number = parseInt(old_port_http);
1406+
const number = Number(old_port_http);
14011407
if (!isNaN(number)) {
14021408
json['port_http'] = number;
14031409
}
14041410
}
14051411
if (old_port_https) {
1406-
const number = parseInt(old_port_https);
1412+
const number = Number(old_port_https);
14071413
if (!isNaN(number)) {
14081414
json['port_https'] = number;
14091415
}

0 commit comments

Comments
 (0)