1
+ import AdmZip from 'adm-zip' ;
2
+ import fs from 'fs' ;
3
+ import path from 'path' ;
4
+ import { execSync } from 'child_process' ;
5
+
6
+ ( async ( ) => {
7
+
8
+ const { identifier } = ( await import ( '../src/plugin.config' ) ) . default ;
9
+
10
+ // check that identifier has valid naming scheme, only lowercase letters, digits, dots and dashes
11
+ if ( ! / ^ [ a - z 0 - 9 . - ] + $ / . test ( identifier ) ) {
12
+ throw new Error ( `Invalid identifier: ${ identifier } ` ) ;
13
+ }
14
+
15
+ // run npm run build
16
+ execSync ( 'npm run build' ) ;
17
+
18
+ // The file that will be sent to the marketplace
19
+ const publishDir = path . resolve ( __dirname , '../publish' ) ;
20
+ // create a release dir if not exists and remove all files
21
+ if ( ! fs . existsSync ( publishDir ) ) {
22
+ fs . mkdirSync ( publishDir ) ;
23
+ } else {
24
+ fs . rmSync ( publishDir , { recursive : true } ) ;
25
+ fs . mkdirSync ( publishDir ) ;
26
+ }
27
+
28
+ const distDir = path . resolve ( __dirname , '../dist' ) ;
29
+ const buildContentDir = path . resolve ( __dirname , '../dist' ) ;
30
+
31
+ // make a publish dir
32
+ if ( ! fs . existsSync ( buildContentDir ) ) {
33
+ fs . mkdirSync ( buildContentDir ) ;
34
+ }
35
+
36
+ // write content of in dist/ to the root of the zip
37
+ const zip = new AdmZip ( ) ;
38
+ zip . addLocalFolder ( distDir ) ;
39
+ zip . writeZip ( path . resolve ( publishDir , `${ identifier } .zip` ) ) ;
40
+
41
+ } ) ( )
0 commit comments