Skip to content

Commit b7dd022

Browse files
committed
Added a step to check advanced minify using terser
1 parent 797ec5c commit b7dd022

8 files changed

Lines changed: 129 additions & 67 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"javascript.updateImportsOnFileMove.enabled": "never",
3-
"files.exclude": {
3+
".files.exclude": {
44
"build": true,
55
"generated": true,
66
"template": true,

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<img src="./src/icon.svg?rand=8697" width="100" /><br>
1+
<img src="./src/icon.svg" width="100" /><br>
22
# Sample Addon
33
<i>Description</i> <br>
44
### Version 1.0.0.0
@@ -46,26 +46,26 @@ npm run dev
4646
## Actions
4747
| Action | Description | Params
4848
| --- | --- | --- |
49+
| Sample Action Combo | This is a sample action | Param1 *(combo)* <br> |
4950
| Sample Action | This is a sample action | Param1 *(string)* <br> |
5051
| Sample Action Async | This is a sample action | |
51-
| Sample Action Combo | This is a sample action | Param1 *(combo)* <br> |
5252
| Sample Action | This is a sample action | Param1 *(string)* <br> |
5353

5454

5555
---
5656
## Conditions
5757
| Condition | Description | Params
5858
| --- | --- | --- |
59+
| Sample Condition | This is a sample condition | Param1 *(combo)* <br> |
5960
| Sample Condition | This is a sample condition | Param1 *(string)* <br> |
6061
| Sample Trigger | This is a sample trigger | |
61-
| Sample Condition | This is a sample condition | Param1 *(combo)* <br> |
6262
| Sample Condition | This is a sample condition | |
6363

6464

6565
---
6666
## Expressions
6767
| Expression | Description | Return Type | Params
6868
| --- | --- | --- | --- |
69-
| Expression | Sample Expression | number | |
7069
| Expression2 | Sample Expression | string | |
70+
| Expression | Sample Expression | number | |
7171
| SampleExpression | This is a sample expression | string | |

build/build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const buildSteps = [
1717
"./generateAddonJSON.js",
1818
"./generateLangJSON.js",
1919
"./exportWebpack.js",
20+
"./validateTerser.js",
2021
"./buildDomside.js",
2122
"./generateWrapperExtension.js",
2223
"./processDependencies.js",

build/doDev.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ build([
1313
"./generateAddonJSON.js",
1414
"./generateLangJSON.js",
1515
"./exportWebpack.js",
16+
"./validateTerser.js",
1617
"./buildDomside.js",
1718
"./generateWrapperExtensionDev.js",
1819
"./processDependencies.js",

build/validateTerser.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import path from "path";
2+
import fs from "fs";
3+
import { fileURLToPath } from "url";
4+
import { minify } from "terser";
5+
import * as chalkUtils from "./chalkUtils.js";
6+
import fromConsole from "./fromConsole.js";
7+
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = path.dirname(__filename);
10+
11+
export default async function validateTerser() {
12+
chalkUtils.step("Validating Terser build (mangle-props keep_quoted)");
13+
14+
const filesToCheck = [
15+
"../dist/export/c3runtime/main.js",
16+
"../dist/export/editor.js",
17+
];
18+
19+
let hadError = false;
20+
21+
for (const file of filesToCheck) {
22+
const absolutePath = path.resolve(__dirname, file);
23+
if (!fs.existsSync(absolutePath)) {
24+
chalkUtils.info(`Skipping ${file} as it does not exist.`);
25+
continue;
26+
}
27+
28+
try {
29+
const code = fs.readFileSync(absolutePath, "utf8");
30+
const result = await minify(code, {
31+
mangle: {
32+
properties: {
33+
keep_quoted: true,
34+
},
35+
},
36+
compress: {
37+
dead_code: true,
38+
drop_console: false,
39+
drop_debugger: true,
40+
keep_classnames: false,
41+
keep_fargs: true,
42+
keep_fnames: false,
43+
keep_infinity: false,
44+
},
45+
});
46+
47+
if (result.error) {
48+
throw result.error;
49+
}
50+
chalkUtils.success(`Terser validation passed for ${file}`);
51+
} catch (error) {
52+
chalkUtils.error(`Terser validation failed for ${file}`);
53+
chalkUtils.error(error.message || error);
54+
hadError = true;
55+
}
56+
}
57+
58+
if (hadError) {
59+
chalkUtils.failed("Terser validation failed.");
60+
} else {
61+
chalkUtils.success("Terser validation successful!");
62+
}
63+
64+
return hadError;
65+
}
66+
67+
// if is being called from the command line
68+
if (fromConsole(import.meta.url)) {
69+
chalkUtils.fromCommandLine();
70+
validateTerser();
71+
}

package-lock.json

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

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
"cors": "^2.8.5",
88
"express": "^4.21.2",
99
"joi": "^17.13.3",
10+
"open": "^10.1.0",
11+
"terser": "^5.44.1",
1012
"vite": "^6.0.7",
1113
"webpack-cli": "^6.0.1",
12-
"yocto-spinner": "^0.1.2",
13-
"open": "^10.1.0"
14+
"yocto-spinner": "^0.1.2"
1415
},
1516
"type": "module",
1617
"scripts": {
@@ -25,6 +26,5 @@
2526
"init": "npm install && node build/init.js",
2627
"generateDocs": "cd build && node generateDocumentation.js",
2728
"publish": "cd build && node publish.js"
28-
},
29-
"dependencies": {}
30-
}
29+
}
30+
}

0 commit comments

Comments
 (0)