Skip to content

Commit 8eefe20

Browse files
committed
fix: linting and updated stuffs
1 parent 261c1ee commit 8eefe20

File tree

8 files changed

+958
-677
lines changed

8 files changed

+958
-677
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
AcodeX.zip
3+
dist.zip

.vscode/pack-zip.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,46 @@
1-
const path = require('path');
2-
const fs = require('fs');
3-
const jszip = require('jszip');
1+
const path = require("path");
2+
const fs = require("fs");
3+
const jszip = require("jszip");
44

5-
const iconFile = path.join(__dirname, '../icon.png');
6-
const pluginJSON = path.join(__dirname, '../plugin.json');
7-
const distFolder = path.join(__dirname, '../dist');
8-
let readmeDotMd = path.join(__dirname, '../readme.md');
5+
const iconFile = path.join(__dirname, "../icon.png");
6+
const pluginJSON = path.join(__dirname, "../plugin.json");
7+
const distFolder = path.join(__dirname, "../dist");
8+
let readmeDotMd = path.join(__dirname, "../readme.md");
99

1010
if (!fs.existsSync(readmeDotMd)) {
11-
readmeDotMd = path.join(__dirname, '../README.md');
11+
readmeDotMd = path.join(__dirname, "../README.md");
1212
}
1313

1414
// create zip file of dist folder
1515

1616
const zip = new jszip();
1717

18-
zip.file('icon.png', fs.readFileSync(iconFile));
19-
zip.file('plugin.json', fs.readFileSync(pluginJSON));
20-
zip.file('readme.md', fs.readFileSync(readmeDotMd));
18+
zip.file("icon.png", fs.readFileSync(iconFile));
19+
zip.file("plugin.json", fs.readFileSync(pluginJSON));
20+
zip.file("readme.md", fs.readFileSync(readmeDotMd));
2121

22-
loadFile('', distFolder);
22+
loadFile("", distFolder);
2323

2424
zip
25-
.generateNodeStream({ type: 'nodebuffer', streamFiles: true })
26-
.pipe(fs.createWriteStream(path.join(distFolder, '/AcodeX.zip')))
27-
.on('finish', () => {
28-
console.log('dist.zip written.');
25+
.generateNodeStream({ type: "nodebuffer", streamFiles: true })
26+
.pipe(fs.createWriteStream(path.join(__dirname, "../dist.zip")))
27+
.on("finish", () => {
28+
console.log("Plugin dist.zip written.");
2929
});
3030

3131
function loadFile(root, folder) {
3232
const distFiles = fs.readdirSync(folder);
3333
distFiles.forEach((file) => {
34-
const filePath = path.join(folder, file);
35-
const stat = fs.statSync(filePath);
36-
37-
// Skip AcodeX.zip
38-
if (file === 'AcodeX.zip') {
39-
return;
40-
}
34+
const stat = fs.statSync(path.join(folder, file));
4135

4236
if (stat.isDirectory()) {
4337
zip.folder(file);
44-
loadFile(path.join(root, file), filePath);
38+
loadFile(path.join(root, file), path.join(folder, file));
4539
return;
4640
}
4741

4842
if (!/LICENSE.txt/.test(file)) {
49-
zip.file(path.join(root, file), fs.readFileSync(filePath));
43+
zip.file(path.join(root, file), fs.readFileSync(path.join(folder, file)));
5044
}
5145
});
5246
}

build.mjs

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

dist/main.js

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

esbuild.config.mjs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as esbuild from "esbuild";
2+
import { sassPlugin } from "esbuild-sass-plugin";
3+
import { exec } from "node:child_process";
4+
5+
const isServe = process.argv.includes("--serve");
6+
7+
// Function to pack the ZIP file
8+
function packZip() {
9+
exec("node .vscode/pack-zip.js", (err, stdout, stderr) => {
10+
if (err) {
11+
console.error("Error packing zip:", err);
12+
return;
13+
}
14+
console.log(stdout.trim());
15+
});
16+
}
17+
18+
// Custom plugin to pack ZIP after build or rebuild
19+
const zipPlugin = {
20+
name: "zip-plugin",
21+
setup(build) {
22+
build.onEnd(() => {
23+
packZip();
24+
});
25+
},
26+
};
27+
28+
// Base build configuration
29+
const buildConfig = {
30+
entryPoints: ["src/main.js"],
31+
bundle: true,
32+
minify: true,
33+
logLevel: "info",
34+
color: true,
35+
outdir: "dist",
36+
plugins: [zipPlugin, sassPlugin()],
37+
};
38+
39+
// Main function to handle both serve and production builds
40+
(async () => {
41+
if (isServe) {
42+
console.log("Starting development server...");
43+
44+
// Watch and Serve Mode
45+
const ctx = await esbuild.context(buildConfig);
46+
47+
await ctx.watch();
48+
const { host, port } = await ctx.serve({
49+
servedir: ".",
50+
port: 3000,
51+
});
52+
} else {
53+
console.log("Building for production...");
54+
await esbuild.build(buildConfig);
55+
console.log("Production build complete.");
56+
}
57+
})();

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
"@xterm/addon-web-links": "0.10.0-beta.1",
1717
"@xterm/addon-webgl": "0.17.0-beta.1",
1818
"@xterm/xterm": "^5.5.0",
19-
"html-tag-js": "^1.7.1",
20-
"ollama": "^0.5.9"
19+
"html-tag-js": "^1.9.2",
20+
"ollama": "^0.5.13"
2121
},
2222
"devDependencies": {
2323
"esbuild": "^0.19.12",
2424
"esbuild-sass-plugin": "^2.16.1",
2525
"jszip": "^3.10.1"
2626
},
2727
"scripts": {
28-
"build": "node build.mjs",
29-
"serve": "node build.mjs --serve"
28+
"dev": "node esbuild.config.mjs --serve",
29+
"build": "node esbuild.config.mjs"
3030
},
3131
"browserslist": [
3232
"> 0.25%, not dead"

0 commit comments

Comments
 (0)