Skip to content

Commit bbce8fa

Browse files
committed
feat: add build script, add search_group_extension.json, search_group_userscript.json
1 parent 6cd64eb commit bbce8fa

15 files changed

+700
-12
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build and Update README
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'zh-CN/*.json'
9+
- 'scripts/*.js'
10+
- 'package.json'
11+
- 'zh-CN/config.yml'
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
17+
permissions:
18+
contents: write
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: '20'
30+
31+
- name: Install pnpm
32+
uses: pnpm/action-setup@v4
33+
with:
34+
version: 9
35+
36+
- name: Install dependencies
37+
run: pnpm install --frozen-lockfile
38+
39+
- name: Run build script
40+
run: pnpm run build
41+
42+
- name: Commit and push changes
43+
uses: stefanzweifel/git-auto-commit-action@v5
44+
with:
45+
commit_message: 'chore: update README and collections [skip ci]'
46+
file_pattern: 'zh-CN/README.md zh-CN/collections/*.json'

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
3+
4+
# dependencies
5+
/node_modules
6+
/coverage
7+
8+
.DS_Store

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/**
2+
LICENSE
3+
pnpm-lock.yaml
4+
tsconfig.json
5+
tsconfig.tsbuildinfo

.prettierrc.cjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @type {import('prettier').Options}
3+
*/
4+
module.exports = {
5+
printWidth: 80,
6+
tabWidth: 2,
7+
useTabs: false,
8+
semi: false,
9+
singleQuote: true,
10+
trailingComma: 'es5',
11+
bracketSpacing: true,
12+
bracketSameLine: true,
13+
overrides: [{ files: '*.json', options: { parser: 'json-stringify' } }],
14+
}

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "utags-shared-shortcuts",
3+
"version": "1.0.0",
4+
"description": "Shared shortcuts configuration for [UTags Shortcuts](https://github.com/utags/userscripts/tree/main/utags-shortcuts).",
5+
"main": "index.js",
6+
"scripts": {
7+
"format": "prettier --write .",
8+
"build": "node scripts/build_groups.js && node scripts/update_readme.js && prettier --write .",
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"keywords": [
12+
"utags",
13+
"shortcuts"
14+
],
15+
"author": "Pipecraft",
16+
"devDependencies": {
17+
"js-yaml": "^4.1.1",
18+
"prettier": "^3.7.4"
19+
}
20+
}

pnpm-lock.yaml

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

scripts/build_groups.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const yaml = require('js-yaml')
4+
5+
console.log('Script started')
6+
7+
const ROOT_DIR = path.resolve(__dirname, '..')
8+
const ZH_CN_DIR = path.join(ROOT_DIR, 'zh-CN')
9+
const COLLECTIONS_DIR = path.join(ZH_CN_DIR, 'collections')
10+
const CONFIG_FILE = path.join(ZH_CN_DIR, 'config.yml')
11+
12+
console.log('Collections Dir:', COLLECTIONS_DIR)
13+
14+
// Ensure output directory exists
15+
if (!fs.existsSync(COLLECTIONS_DIR)) {
16+
console.log('Creating directory...')
17+
fs.mkdirSync(COLLECTIONS_DIR, { recursive: true })
18+
} else {
19+
console.log('Directory exists.')
20+
}
21+
22+
try {
23+
// Read config.yml
24+
const configContent = fs.readFileSync(CONFIG_FILE, 'utf8')
25+
const config = yaml.load(configContent)
26+
27+
if (!config) {
28+
console.error('Error: config.yml is empty or invalid.')
29+
process.exit(1)
30+
}
31+
32+
// Iterate over each collection key in config
33+
for (const collectionName of Object.keys(config)) {
34+
const groupList = config[collectionName]
35+
36+
if (!Array.isArray(groupList)) {
37+
console.warn(
38+
`Warning: Key "${collectionName}" is not a list of groups. Skipping.`
39+
)
40+
continue
41+
}
42+
43+
console.log(`Processing collection: ${collectionName}`)
44+
const groups = []
45+
46+
// Iterate over each group in the current collection
47+
for (const groupName of groupList) {
48+
const groupFile = path.join(ZH_CN_DIR, `${groupName}.json`)
49+
50+
if (fs.existsSync(groupFile)) {
51+
try {
52+
const groupContent = fs.readFileSync(groupFile, 'utf8')
53+
const groupData = JSON.parse(groupContent)
54+
groups.push(groupData)
55+
console.log(` Loaded: ${groupName}.json`)
56+
} catch (e) {
57+
console.error(` Error reading or parsing ${groupName}.json:`, e)
58+
}
59+
} else {
60+
console.warn(` Warning: File not found: ${groupName}.json`)
61+
}
62+
}
63+
64+
// Create aggregated object
65+
const aggregatedData = {
66+
groups: groups,
67+
}
68+
69+
// Write to output file
70+
const outputFile = path.join(COLLECTIONS_DIR, `${collectionName}.json`)
71+
fs.writeFileSync(
72+
outputFile,
73+
JSON.stringify(aggregatedData, null, 2) + '\n',
74+
'utf8'
75+
)
76+
77+
console.log(` Successfully generated aggregated file at: ${outputFile}`)
78+
console.log(` Total groups aggregated: ${groups.length}`)
79+
console.log('---')
80+
}
81+
} catch (e) {
82+
console.error('Error processing groups:', e)
83+
process.exit(1)
84+
}

0 commit comments

Comments
 (0)