@@ -9,15 +9,23 @@ import { inject } from './functions/inject'
9
9
const hostnames = Array < string > ( )
10
10
const scripts = Array < { name : string , pattern : string , type : string } > ( )
11
11
const externalUrl = `https://github.com/wibus-wee/activation-script/raw/gh-pages`
12
+ const releaseAssetsUrl = `https://github.com/wibus-wee/activation-script/releases/download`
12
13
13
- function MITM ( hostnames : any [ ] , external = false ) {
14
+ function MITM ( hostnames : any [ ] , external = false , release = '' ) {
15
+ if ( release . length > 0 )
16
+ external = true
14
17
return `
15
18
[MITM]
16
19
hostname = ${ external ? `%APPEND% ` : '' } ${ hostnames . join ( ', ' ) }
17
20
`
18
21
}
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`
21
29
const scriptUpdateInternal = 86400
22
30
return `
23
31
[Script]
@@ -264,7 +272,8 @@ async function action(str: any, _options: any) {
264
272
if ( str . module ) {
265
273
console . log ( 'Generating .sgmodule file...' )
266
274
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 ) } `
268
277
fs . writeFileSync ( path . join ( process . cwd ( ) , 'activator.sgmodule' ) , `${ content } ` )
269
278
console . log ( '.sgmodule file generated.' )
270
279
}
@@ -281,6 +290,7 @@ program
281
290
. option ( '-f, --fix' , 'fix config file' )
282
291
. option ( '-m, --module' , 'generate .sgmodule' )
283
292
. option ( '-e, --external' , 'use external source url' )
293
+ . option ( '-r, --release <version>' , 'use external source url (release version)' )
284
294
. action ( action )
285
295
program . command ( 'inject' ) . description ( 'inject activator' ) . action ( inject )
286
296
program . command ( 'patch' ) . description ( 'patch config' ) . action ( patch )
0 commit comments