@@ -7,6 +7,8 @@ const execute = utils.promisify(exec);
7
7
const archiver = require ( "archiver" ) ;
8
8
const fg = require ( 'fast-glob' ) ;
9
9
10
+ const cwd = process . cwd ( ) ;
11
+
10
12
function zipDirectory ( sourceDir , outPath ) {
11
13
const archive = archiver ( 'zip' , { zlib : { level : 9 } } ) ;
12
14
const stream = createWriteStream ( outPath ) ;
@@ -28,24 +30,24 @@ function zipDirectory(sourceDir, outPath) {
28
30
29
31
( async function ( ) {
30
32
31
- let steps = readdirSync ( join ( process . cwd ( ) , "steps" ) ) ;
33
+ let steps = readdirSync ( join ( cwd , "steps" ) ) ;
32
34
// only consider directories
33
- steps = steps . filter ( ( step ) => statSync ( join ( process . cwd ( ) , "steps" , step ) ) . isDirectory ( ) ) ;
35
+ steps = steps . filter ( ( step ) => statSync ( join ( cwd , "steps" , step ) ) . isDirectory ( ) ) ;
34
36
35
- if ( existsSync ( join ( process . cwd ( ) , "dist" ) ) ) {
36
- rmSync ( join ( process . cwd ( ) , "dist" ) , { recursive : true } ) ;
37
+ if ( existsSync ( join ( cwd , "dist" ) ) ) {
38
+ rmSync ( join ( cwd , "dist" ) , { recursive : true } ) ;
37
39
}
38
40
39
- mkdirSync ( join ( process . cwd ( ) , "dist" ) , { recursive : true } ) ;
40
- mkdirSync ( join ( process . cwd ( ) , "dist/build" ) , { recursive : true } ) ;
41
+ mkdirSync ( join ( cwd , "dist" ) , { recursive : true } ) ;
42
+ mkdirSync ( join ( cwd , "dist/build" ) , { recursive : true } ) ;
41
43
42
44
await Promise . all ( steps . map ( ( step ) => {
43
- return zipDirectory ( join ( process . cwd ( ) , "steps" , step ) , join ( process . cwd ( ) , "dist" , `ui5-typescript-walkthrough-step-${ step } .zip` ) )
45
+ return zipDirectory ( join ( cwd , "steps" , step ) , join ( cwd , "dist" , `ui5-typescript-walkthrough-step-${ step } .zip` ) )
44
46
} ) ) ;
45
47
for ( const step of steps ) {
46
- console . log ( `npx ui5 build --dest ${ join ( process . cwd ( ) , "dist" , "build" , `${ step } ` ) } ` ) ;
47
- await execute ( `npx ui5 build --dest ${ join ( process . cwd ( ) , "dist" , "build" , `${ step } ` ) } ` , {
48
- cwd : join ( process . cwd ( ) , "steps" , step )
48
+ console . log ( `npx ui5 build --dest ${ join ( cwd , "dist" , "build" , `${ step } ` ) } ` ) ;
49
+ await execute ( `npx ui5 build --dest ${ join ( cwd , "dist" , "build" , `${ step } ` ) } ` , {
50
+ cwd : join ( cwd , "steps" , step )
49
51
} ) ;
50
52
}
51
53
@@ -57,20 +59,20 @@ function zipDirectory(sourceDir, outPath) {
57
59
writeFileSync ( file , content , { encoding : "utf8" } ) ;
58
60
}
59
61
60
- copyFileSync ( join ( process . cwd ( ) , "README.md" ) , join ( process . cwd ( ) , "dist/index.md" ) ) ;
61
- rewriteLinks ( join ( process . cwd ( ) , "dist/index.md" ) ) ;
62
- const readmes = fg . globSync ( [ "steps/**/README.md" ] ) ;
62
+ copyFileSync ( join ( cwd , "README.md" ) , join ( cwd , "dist/index.md" ) ) ;
63
+ rewriteLinks ( join ( cwd , "dist/index.md" ) ) ;
64
+ const readmes = fg . globSync ( [ "steps/**/README.md" ] , { cwd } ) ;
63
65
readmes . forEach ( ( readme ) => {
64
66
const [ , path , step ] = readme . match ( "steps/((.*)/README.md)" ) ;
65
- mkdirSync ( join ( process . cwd ( ) , `dist/build/${ step } ` ) , { recursive : true } ) ;
66
- copyFileSync ( join ( process . cwd ( ) , readme ) , join ( process . cwd ( ) , `dist/build/${ path } ` ) ) ;
67
- rewriteLinks ( join ( process . cwd ( ) , `dist/build/${ path } ` ) , `${ path } ` ) ;
67
+ mkdirSync ( join ( cwd , `dist/build/${ step } ` ) , { recursive : true } ) ;
68
+ copyFileSync ( join ( cwd , readme ) , join ( cwd , `dist/build/${ path } ` ) ) ;
69
+ rewriteLinks ( join ( cwd , `dist/build/${ path } ` ) , `${ path } ` ) ;
68
70
} ) ;
69
71
70
72
await Promise . all ( steps . map ( ( step ) => {
71
- const jsStepBaseDir = join ( process . cwd ( ) , "steps" , step ) ;
72
- const buildOutputDir = join ( process . cwd ( ) , "dist" , "build" , `${ step } ` ) ;
73
- const targetDir = join ( process . cwd ( ) , "dist" , "steps" , `${ step } ` ) ;
73
+ const jsStepBaseDir = join ( cwd , "steps" , step ) ;
74
+ const buildOutputDir = join ( cwd , "dist" , "build" , `${ step } ` ) ;
75
+ const targetDir = join ( cwd , "dist" , "steps" , `${ step } ` ) ;
74
76
75
77
// copy all files from buildOutputDir to targetDir except of TS files
76
78
const files = fg . sync ( [ "**/*" ] , { cwd : jsStepBaseDir , dot : true } ) ;
@@ -106,7 +108,7 @@ function zipDirectory(sourceDir, outPath) {
106
108
} ) ;
107
109
108
110
console . log ( `${ jsStepBaseDir } -> ${ buildOutputDir } ` ) ;
109
- return zipDirectory ( join ( process . cwd ( ) , "dist" , "steps" , `${ step } ` ) , join ( process . cwd ( ) , "dist" , `ui5-typescript-walkthrough-step-${ step } -js.zip` ) )
111
+ return zipDirectory ( join ( cwd , "dist" , "steps" , `${ step } ` ) , join ( cwd , "dist" , `ui5-typescript-walkthrough-step-${ step } -js.zip` ) )
110
112
} ) ) ;
111
113
112
114
} ( ) ) ;
0 commit comments