Skip to content

Commit bebbec4

Browse files
committed
upload via files
1 parent 8e32543 commit bebbec4

File tree

16 files changed

+1316
-0
lines changed

16 files changed

+1316
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
yarn.lock
3+
dist.zip
4+
dist

.vscode/pack-zip.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
const jszip = require('jszip');
4+
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');
9+
10+
if (!fs.existsSync(readmeDotMd)) {
11+
readmeDotMd = path.join(__dirname, '../README.md');
12+
}
13+
14+
// create zip file of dist folder
15+
16+
const zip = new jszip();
17+
18+
zip.file('icon.png', fs.readFileSync(iconFile));
19+
zip.file('plugin.json', fs.readFileSync(pluginJSON));
20+
zip.file('readme.md', fs.readFileSync(readmeDotMd));
21+
22+
loadFile('', distFolder);
23+
24+
zip
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.');
29+
});
30+
31+
function loadFile(root, folder) {
32+
const distFiles = fs.readdirSync(folder);
33+
distFiles.forEach((file) => {
34+
35+
const stat = fs.statSync(path.join(folder, file));
36+
37+
if (stat.isDirectory()) {
38+
zip.folder(file);
39+
loadFile(path.join(root, file), path.join(folder, file));
40+
return;
41+
}
42+
43+
if (!/LICENSE.txt/.test(file)) {
44+
zip.file(path.join(root, file), fs.readFileSync(path.join(folder, file)));
45+
}
46+
});
47+
}

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

icon.png

22.2 KB
Loading

0 commit comments

Comments
 (0)