1+ import chalk from 'chalk' ;
2+ import { program } from 'commander' ;
3+ import { createWriteStream , readFileSync , statSync , writeFileSync } from 'fs' ;
4+ import { globSync } from 'glob' ;
5+ import { dirname , join , relative } from 'path' ;
6+ import { fileURLToPath } from 'url' ;
7+ import yazl from 'yazl'
8+
9+ const __dirname = dirname ( fileURLToPath ( import . meta. url ) )
10+ const basePath = join ( __dirname , '..' )
11+
12+ program
13+ . requiredOption ( "--version <platform>" , "the target platform" )
14+ . parse ( ) ;
15+
16+ const version = program . opts ( ) . version ;
17+ if ( ! version . match ( / \d + \. \d + \. \d + / ) ) throw new Error ( `invalid version format: ${ version } ` ) ;
18+
19+ console . log ( chalk . cyan ( "rewriting manifest.json's version field to " + version ) ) ;
20+ const manifest = JSON . parse ( readFileSync ( `${ basePath } /manifest.json` , 'utf-8' ) ) ;
21+ manifest . version = version ;
22+ writeFileSync ( `${ basePath } /manifest.json` , JSON . stringify ( manifest ) ) ;
23+
24+ console . log ( chalk . cyan ( "rewriting package.json's version field to " + version ) ) ;
25+ const packageJSON = JSON . parse ( readFileSync ( `${ basePath } /package.json` , 'utf-8' ) ) ;
26+ packageJSON . version = version ;
27+ writeFileSync ( `${ basePath } /package.json` , JSON . stringify ( packageJSON ) ) ;
28+
29+ console . log ( chalk . cyan ( "packaging .ccx" ) ) ;
30+ const zipList = [
31+ './manifest.json' ,
32+ './i18n/**/*' ,
33+ './icon/**/*' ,
34+ './jimp/**/*' ,
35+ './scripts/**/*' ,
36+ './typescripts/dist/**/*' ,
37+ './utility/**/*' ,
38+ './server/**/*' ,
39+ './*.js' ,
40+ './package.json' ,
41+ './tsconfig.json' ,
42+ './*.html' ,
43+ './*.py' ,
44+ './*.txt' ,
45+ './*.md' ,
46+ './*.png' ,
47+ ]
48+
49+ const zipfile = new yazl . ZipFile ( ) ;
50+
51+ zipList . forEach ( globber => {
52+ globSync (
53+ join ( basePath , globber ) . replace ( / \\ / g, '/' )
54+ ) . forEach ( filepath => {
55+ if ( statSync ( filepath ) . isDirectory ( ) ) return ;
56+
57+ const rpath = relative ( basePath , filepath ) ;
58+ zipfile . addFile ( filepath , rpath )
59+ } )
60+ } )
61+
62+ zipfile . outputStream . pipe (
63+ createWriteStream ( join ( basePath , `Auto.Photoshop.SD.plugin_v${ version } .ccx` ) )
64+ ) ;
65+ zipfile . outputStream . pipe (
66+ createWriteStream ( join ( basePath , `Auto.Photoshop.SD.plugin_v${ version } .zip` ) )
67+ ) ;
68+
69+ zipfile . end ( )
0 commit comments