Skip to content

Commit

Permalink
Add release
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscurrycc committed Nov 8, 2024
1 parent 342032d commit e3f2608
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Create GitHub Release with .bobplugin

on:
push:
tags:
- "v*.*.*"

jobs:
build-and-release:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "20"

- name: Install dependencies
run: npm install

- name: Build project
run: npm run build

- name: Upload .bobplugin to GitHub Release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
files: dist/bobplugin-maimemo-notebook.bobplugin
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"description": "Bob 查询的单词导入到墨墨背单词",
"main": "dist/main.js",
"scripts": {
"clean": "rm -rf dist",
"prebuild": "chmod +x scripts/zip.js",
"build": "rollup -c",
"build": "npm run clean && rollup -c",
"dev": "rollup -c rollup.config.dev.js --watch"
},
"devDependencies": {
Expand Down
25 changes: 24 additions & 1 deletion scripts/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,43 @@ const outputPath = path.resolve(
"../dist/bobplugin-maimemo-notebook.bobplugin"
);

function cleanDistFolder() {
const distPath = path.resolve(__dirname, "../dist");

fs.readdir(distPath, (err, files) => {
if (err) throw err;

files.forEach((file) => {
const filePath = path.join(distPath, file);

if (filePath !== outputPath) {
fs.rm(filePath, { recursive: true, force: true }, (err) => {
if (err) throw err;
console.log(`Deleted: ${filePath}`);
});
}
});
});
}

function zipAndRename() {
const output = fs.createWriteStream(outputPath);
const archive = archiver("zip", { zlib: { level: 9 } });

output.on("close", () => {
console.log(`Compress finish:${outputPath}`);
cleanDistFolder();
});

archive.on("error", (err) => {
throw err;
});

archive.pipe(output);
archive.directory("dist/", false);
archive.glob("**/*", {
cwd: path.resolve(__dirname, "../dist"),
ignore: [path.basename(outputPath)],
});
archive.finalize();
}

Expand Down

0 comments on commit e3f2608

Please sign in to comment.