Skip to content

Commit 336c7c2

Browse files
committed
add build
1 parent c39bf6e commit 336c7c2

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

.github/workflows/main.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Release JS File
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch: # 允许手动触发
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
# Checkout the repository
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
18+
- name: Read and parse JSON file
19+
id: read-json
20+
run: |
21+
config=$(cat ./manifest.json)
22+
echo "Config content: $config"
23+
version=$(echo "$config" | jq -r '.version')
24+
echo "version=$version" >> $GITHUB_ENV
25+
- name: Debug Environment
26+
run: env
27+
28+
# Install Node.js and dependencies
29+
- name: Setup Node.js
30+
uses: actions/setup-node@v3
31+
with:
32+
node-version: '18' # 你使用的 Node.js 版本
33+
34+
# Build the project (根据你的构建命令调整)
35+
- name: Build project
36+
run: node build.js
37+
38+
# Upload artifact to GitHub Releases
39+
- name: Create Release
40+
uses: ncipollo/release-action@v1
41+
with:
42+
artifacts: ./dist/main.js # 需要上传的文件路径
43+
token: ${{ secrets.GITHUB_TOKEN }} # 用于认证
44+
tag: ${{ env.version }} # 当前的 tag
45+
body: |
46+
Release notes for ${{ env.version }}
47+
draft: false # 是否保存为草稿
48+
prerelease: false # 是否标记为预发布
49+
allowUpdates: true

build.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const manifest = require('./manifest.json');
4+
5+
6+
// 要添加到文件头部的内容
7+
const headerContent = `
8+
// ==UserScript==
9+
// @name ${manifest.name}
10+
// @namespace Violentmonkey Scripts
11+
// @match *://*.figma.com/*
12+
// @grant none
13+
// @version ${manifest.version}
14+
// @author figma.cool,Yancy Min,Coiven,YorKun,Pluwen,Neko,诺墨 and ts8zs
15+
// @description ${manifest.description}
16+
// @license GPL-3.0 license
17+
// ==/UserScript==
18+
19+
`;
20+
21+
const inputFilePath = path.join(__dirname, 'js/content.js');
22+
const outputFolderPath = path.join(__dirname, 'dist');
23+
const outputFilePath = path.join(outputFolderPath, 'main.js');
24+
25+
fs.readFile(inputFilePath, 'utf8', (err, data) => {
26+
if (err) {
27+
console.error('Error reading input file:', err);
28+
return;
29+
}
30+
31+
const newContent = headerContent + data;
32+
33+
try {
34+
if (!fs.existsSync(outputFolderPath)) {
35+
fs.mkdirSync(outputFolderPath);
36+
}
37+
} catch (err) {
38+
console.error(err);
39+
}
40+
41+
fs.writeFile(outputFilePath, newContent, 'utf8', (err) => {
42+
if (err) {
43+
console.error('Error writing to output file:', err);
44+
return;
45+
}
46+
47+
console.log('File successfully updated and saved to', outputFilePath);
48+
});
49+
});

0 commit comments

Comments
 (0)