Skip to content

Commit 2019cb8

Browse files
committed
feat(generator): github release as external assets url
1 parent 690eae4 commit 2019cb8

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
- name: Build
3535
run: |
3636
nr build
37+
node dist/generator.js gen -m -e -r=${{ github.event.release.tag }}
3738
3839
- name: Rename
3940
run: |

packages/generator/index.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@ import { inject } from './functions/inject'
99
const hostnames = Array<string>()
1010
const scripts = Array<{ name: string, pattern: string, type: string }>()
1111
const externalUrl = `https://github.com/wibus-wee/activation-script/raw/gh-pages`
12+
const releaseAssetsUrl = `https://github.com/wibus-wee/activation-script/releases/download`
1213

13-
function MITM(hostnames: any[], external = false) {
14+
function MITM(hostnames: any[], external = false, release = '') {
15+
if (release.length > 0)
16+
external = true
1417
return `
1518
[MITM]
1619
hostname = ${external ? `%APPEND% ` : ''}${hostnames.join(', ')}
1720
`
1821
}
19-
function Script(_scripts: typeof scripts, external = false) {
20-
const scriptPath = external ? `${externalUrl}/activator.js` : `activator.js`
22+
function Script(_scripts: typeof scripts, external = false, release = '') {
23+
let _externalUrl = externalUrl
24+
if (release.length > 0) {
25+
external = true
26+
_externalUrl = `${releaseAssetsUrl}/${release}`
27+
}
28+
const scriptPath = external ? `${_externalUrl}/activator.js` : `activator.js`
2129
const scriptUpdateInternal = 86400
2230
return `
2331
[Script]
@@ -264,7 +272,8 @@ async function action(str: any, _options: any) {
264272
if (str.module) {
265273
console.log('Generating .sgmodule file...')
266274
let content = fs.readFileSync(path.join(process.cwd(), './template.sgmodule'), 'utf-8')
267-
content += `\n\n${MITM(hostnames, str.external)}\n\n${Script(scripts, str.external)}`
275+
console.log(str)
276+
content += `\n\n${MITM(hostnames, str.external, str.release)}\n\n${Script(scripts, str.external, str.release)}`
268277
fs.writeFileSync(path.join(process.cwd(), 'activator.sgmodule'), `${content}`)
269278
console.log('.sgmodule file generated.')
270279
}
@@ -281,6 +290,7 @@ program
281290
.option('-f, --fix', 'fix config file')
282291
.option('-m, --module', 'generate .sgmodule')
283292
.option('-e, --external', 'use external source url')
293+
.option('-r, --release <version>', 'use external source url (release version)')
284294
.action(action)
285295
program.command('inject').description('inject activator').action(inject)
286296
program.command('patch').description('patch config').action(patch)

0 commit comments

Comments
 (0)