@@ -7,6 +7,8 @@ const execute = utils.promisify(exec);
77const archiver = require ( "archiver" ) ;
88const fg = require ( 'fast-glob' ) ;
99
10+ const cwd = process . cwd ( ) ;
11+
1012function zipDirectory ( sourceDir , outPath ) {
1113 const archive = archiver ( 'zip' , { zlib : { level : 9 } } ) ;
1214 const stream = createWriteStream ( outPath ) ;
@@ -28,24 +30,24 @@ function zipDirectory(sourceDir, outPath) {
2830
2931( async function ( ) {
3032
31- let steps = readdirSync ( join ( process . cwd ( ) , "steps" ) ) ;
33+ let steps = readdirSync ( join ( cwd , "steps" ) ) ;
3234 // 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 ( ) ) ;
3436
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 } ) ;
3739 }
3840
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 } ) ;
4143
4244 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` ) )
4446 } ) ) ;
4547 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 )
4951 } ) ;
5052 }
5153
@@ -57,20 +59,20 @@ function zipDirectory(sourceDir, outPath) {
5759 writeFileSync ( file , content , { encoding : "utf8" } ) ;
5860 }
5961
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 } ) ;
6365 readmes . forEach ( ( readme ) => {
6466 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 } ` ) ;
6870 } ) ;
6971
7072 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 } ` ) ;
7476
7577 // copy all files from buildOutputDir to targetDir except of TS files
7678 const files = fg . sync ( [ "**/*" ] , { cwd : jsStepBaseDir , dot : true } ) ;
@@ -106,7 +108,7 @@ function zipDirectory(sourceDir, outPath) {
106108 } ) ;
107109
108110 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` ) )
110112 } ) ) ;
111113
112114} ( ) ) ;
0 commit comments