Skip to content

Commit 05c47da

Browse files
authored
refactor: replace shell scripts with JS for cross-platform support (#875)
Convert bin/ shell scripts to Node.js and npm scripts using shx and npm-run-all2. Remove unused build-icons.sh. Inlined simple scripts (build-docs-liquid, build-apidoc) as npm scripts. Made-with: Cursor
1 parent 66011d1 commit 05c47da

12 files changed

Lines changed: 503 additions & 132 deletions

bin/build-apidoc.sh

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

bin/build-changelog.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
4+
const root = path.resolve(__dirname, '..')
5+
const src = path.join(root, 'CHANGELOG.md')
6+
7+
let content = fs.readFileSync(src, 'utf8').replace(/\r\n/g, '\n')
8+
9+
const lines = content.split('\n')
10+
lines[0] = lines[0]
11+
.replace(/"/g, '"')
12+
.replace(/</g, '&lt;')
13+
.replace(/>/g, '&gt;')
14+
content = lines.join('\n')
15+
16+
content = content
17+
.replace(/{%/g, '{% raw %}{%{% endraw %}')
18+
.replace(/\{\{/g, '{% raw %}{{{% endraw %}')
19+
20+
const enFrontmatter = '---\ntitle: Changelog\nauto: true\n---\n\n'
21+
const zhFrontmatter = '---\ntitle: 更新日志\nauto: true\n---\n\n'
22+
23+
fs.writeFileSync(path.join(root, 'docs/source/tutorials/changelog.md'), enFrontmatter + content)
24+
fs.writeFileSync(path.join(root, 'docs/source/zh-cn/tutorials/changelog.md'), zhFrontmatter + content)

bin/build-changelog.sh

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

bin/build-contributors.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
4+
const root = path.resolve(__dirname, '..')
5+
const readme = fs.readFileSync(path.join(root, 'README.md'), 'utf8').replace(/\r\n/g, '\n')
6+
7+
function extractSection (text, beginMarker, endMarker) {
8+
const lines = text.split('\n')
9+
let inside = false
10+
const result = []
11+
for (const line of lines) {
12+
if (line.includes(endMarker)) inside = false
13+
if (inside) result.push(line)
14+
if (line.includes(beginMarker)) inside = true
15+
}
16+
return result.join('\n')
17+
}
18+
19+
function transformContributors (html) {
20+
return html
21+
.replace(/<br \/>.*?<\/td>/g, '</a></td>')
22+
.replace(/width="[^"]*"/g, '')
23+
.replace(/\n/g, '')
24+
.replace(/<\/tr>\s*<tr>/g, '')
25+
}
26+
27+
function transformFinancial (html) {
28+
return html
29+
.replace(/<br \/>.*?<\/td>/g, '</a></td>')
30+
.replace(/\n/g, '')
31+
.replace(/<\/tr>\s*<tr>/g, '')
32+
}
33+
34+
const allContributors = transformContributors(extractSection(readme, 'ALL-CONTRIBUTORS-LIST:START', 'ALL-CONTRIBUTORS-LIST:END'))
35+
const financialContributors = transformFinancial(extractSection(readme, 'FINANCIAL-CONTRIBUTORS-BEGIN', 'FINANCIAL-CONTRIBUTORS-END'))
36+
37+
const outDir = path.join(root, 'docs/themes/navy/layout/partial')
38+
fs.writeFileSync(path.join(outDir, 'all-contributors.swig'), allContributors)
39+
fs.writeFileSync(path.join(outDir, 'financial-contributors.swig'), financialContributors)

bin/build-contributors.sh

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

bin/build-docs-liquid.sh

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

bin/build-docs.sh

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

bin/build-icons.sh

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

bin/perf-diff.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { execSync } = require('child_process')
2+
const fs = require('fs')
3+
const path = require('path')
4+
5+
const root = path.resolve(__dirname, '..')
6+
const version = require(path.join(root, 'package.json')).version
7+
8+
const fileLocal = path.join(root, 'dist/liquid.node.js')
9+
const fileLatest = path.join(root, `dist/liquid.node.${version}.js`)
10+
11+
if (!fs.existsSync(fileLatest)) {
12+
const url = `https://unpkg.com/liquidjs@${version}/dist/liquid.node.js`
13+
console.log(`Downloading liquidjs@${version}...`)
14+
execSync(`curl -sL -o "${fileLatest}" "${url}"`)
15+
}
16+
17+
execSync(`node benchmark/diff.js "${fileLocal}" "${fileLatest}"`, { cwd: root, stdio: 'inherit' })

bin/perf-diff.sh

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

0 commit comments

Comments
 (0)