1
1
import s from 'shelljs' ;
2
2
import fs from 'fs' ;
3
3
import path from 'path' ;
4
+ import { TAPPortalAbout } from './src/utils/Globals' ;
5
+ import { OpenAPI as ApimConnectorOpenApi } from '@solace-iot-team/apim-connector-openapi-browser' ;
6
+ import { Constants } from './devel/lib/Constants' ;
7
+
4
8
5
9
const scriptName : string = path . basename ( __filename ) ;
6
10
const scriptDir : string = path . dirname ( __filename ) ;
7
- // files & dirs
8
- const apimPortalDir = `${ scriptDir } ` ;
9
- const outputAdminPortalAboutFile = `${ apimPortalDir } /public/admin-portal/about.json` ;
10
- const outputDeveloperPortalAboutFile = `${ apimPortalDir } /public/developer-portal/about.json` ;
11
+
12
+ const CONSTANTS = new Constants ( scriptDir ) ;
11
13
12
14
// names
13
15
const AdminPortalName = 'async-apim-admin-portal' ;
14
16
const AdminPortalDescription = 'Solace Async API Management Admin Portal' ;
15
17
const DeveloperPortalName = 'async-apim-developer-portal' ;
16
18
const DeveloperPortalDescription = 'Solace Async API Management Developer Portal' ;
17
- const ApimServerOpenApiBrowserPackageName = '@solace-iot-team/apim-server-openapi-browser' ;
18
- const ApimConnectorOpenApiBrowserPackageName = '@solace-iot-team/apim-connector-openapi-browser' ;
19
-
20
- type TAbout = {
21
- name : string ;
22
- description : string ;
23
- repository : {
24
- type : string ;
25
- url : string ;
26
- revision : {
27
- sha1 : string
28
- }
29
- } ,
30
- issues_url : string ;
31
- author : string ;
32
- license : string ;
33
- version : string ;
34
- 'apim-server-openapi-version' : string ;
35
- "apim-connector-open-api-version" : string ;
36
- }
37
19
38
20
const prepare = ( ) => {
39
21
const funcName = 'prepare' ;
40
22
const logName = `${ scriptDir } /${ scriptName } .${ funcName } ()` ;
41
23
console . log ( `${ logName } : starting ...` ) ;
42
- if ( s . rm ( '-f' , outputAdminPortalAboutFile ) . code !== 0 ) process . exit ( 1 ) ;
43
- if ( s . rm ( '-f' , outputDeveloperPortalAboutFile ) . code !== 0 ) process . exit ( 1 ) ;
24
+ if ( s . rm ( '-rf' , CONSTANTS . WorkingDir ) . code !== 0 ) process . exit ( 1 ) ;
25
+ if ( s . mkdir ( '-p' , CONSTANTS . WorkingDir ) . code !== 0 ) process . exit ( 1 ) ;
26
+ if ( s . rm ( '-rf' , CONSTANTS . OutputGeneratedApimServerOpenApiSrcDir ) . code !== 0 ) process . exit ( 1 ) ;
27
+ if ( s . rm ( '-f' , CONSTANTS . OutputAdminPortalAboutFile ) . code !== 0 ) process . exit ( 1 ) ;
28
+ if ( s . rm ( '-f' , CONSTANTS . OutputDeveloperPortalAboutFile ) . code !== 0 ) process . exit ( 1 ) ;
44
29
console . log ( `${ logName } : success.` ) ;
45
30
}
46
31
47
- const getApimServerOpenApiVersion = ( ) : string => {
48
- const funcName = 'getApimServerOpenApiVersion' ;
32
+ const copyApimServerSourcesToWorkingDir = ( ) => {
33
+ const funcName = 'copyApimServerSourcesToWorkingDir' ;
34
+ const logName = `${ scriptDir } /${ scriptName } .${ funcName } ()` ;
35
+ console . log ( `${ logName } : starting ...` ) ;
36
+
37
+ console . log ( `${ logName } : copying apim-server sources to working dir ...` ) ;
38
+ if ( s . cp ( '-rf' , CONSTANTS . ApimServerDir , CONSTANTS . WorkingDir ) . code !== 0 ) process . exit ( 1 ) ;
39
+ if ( s . rm ( '-rf' , `${ CONSTANTS . WorkingApimServerDir } /dist` ) . code !== 0 ) process . exit ( 1 ) ;
40
+ if ( s . rm ( '-rf' , `${ CONSTANTS . WorkingApimServerDir } /node_modules` ) . code !== 0 ) process . exit ( 1 ) ;
41
+ if ( s . rm ( '-rf' , `${ CONSTANTS . WorkingApimServerDir } /src/*` ) . code !== 0 ) process . exit ( 1 ) ;
42
+ if ( s . rm ( '-rf' , `${ CONSTANTS . WorkingApimServerDir } /server/@types` ) . code !== 0 ) process . exit ( 1 ) ;
43
+
44
+ console . log ( `${ logName } : success.` ) ;
45
+ }
46
+
47
+ const devBuildApimServer = ( ) => {
48
+ const funcName = 'devBuildApimServer' ;
49
+ const logName = `${ scriptDir } /${ scriptName } .${ funcName } ()` ;
50
+ console . log ( `${ logName } : starting ...` ) ;
51
+ s . cd ( `${ CONSTANTS . WorkingApimServerDir } ` ) ;
52
+ console . log ( `${ logName } : directory = ${ s . exec ( `pwd` ) } ` ) ;
53
+ if ( s . exec ( 'npm install' ) . code !== 0 ) process . exit ( 1 ) ;
54
+ if ( s . exec ( 'npm run dev:build' ) . code !== 0 ) process . exit ( 1 ) ;
55
+ if ( s . cd ( `${ scriptDir } ` ) . code !== 0 ) process . exit ( 1 ) ;
56
+ console . log ( `${ logName } : success.` ) ;
57
+ }
58
+
59
+ const copyApimServerAssets = ( ) => {
60
+ const funcName = 'copyApimServerAssets' ;
49
61
const logName = `${ scriptDir } /${ scriptName } .${ funcName } ()` ;
62
+
63
+ const copySrcs = ( srcDir : string , outDir : string ) => {
64
+ console . log ( `${ logName } : copy ${ srcDir } ` ) ;
65
+ if ( s . rm ( '-rf' , `${ outDir } ` ) . code !== 0 ) process . exit ( 1 ) ;
66
+ if ( s . mkdir ( '-p' , outDir ) . code !== 0 ) process . exit ( 1 ) ;
67
+ if ( s . cp ( '-r' , `${ srcDir } /*` , `${ outDir } ` ) . code !== 0 ) process . exit ( 1 ) ;
68
+ }
69
+
50
70
console . log ( `${ logName } : starting ...` ) ;
51
- const x = s . exec ( `npm list ${ ApimServerOpenApiBrowserPackageName } ` ) . stdout ;
52
- const invalidIdx : number = x . search ( 'invalid' ) ;
53
- if ( invalidIdx > - 1 ) throw new Error ( `${ logName } : invalid version of ${ ApimServerOpenApiBrowserPackageName } in package.json` ) ;
54
- const idx : number = x . lastIndexOf ( ApimServerOpenApiBrowserPackageName ) ;
55
- const y = x . slice ( idx ) . replace ( / \s / g, '' ) ;
71
+
72
+ copySrcs ( CONSTANTS . GeneratedApimServerOpenApiSrcDir , CONSTANTS . OutputGeneratedApimServerOpenApiSrcDir ) ;
73
+
56
74
console . log ( `${ logName } : success.` ) ;
57
- return y ;
58
75
}
59
76
77
+ const getApimServerOpenApiVersion = ( ) : string => {
78
+ const funcName = 'getApimServerOpenApiVersion' ;
79
+ const logName = `${ scriptDir } /${ scriptName } .${ funcName } ()` ;
80
+ console . log ( `${ logName } : starting ...` ) ;
81
+
82
+ const x = require ( `${ CONSTANTS . OutputGeneratedApimServerOpenApiSrcDir } /core/OpenAPI.ts` ) ;
83
+ return x . OpenAPI . VERSION ;
84
+ }
85
+
60
86
const getApimConnectorOpenApiVersion = ( ) : string => {
61
87
const funcName = 'getApimConnectorOpenApiVersion' ;
62
88
const logName = `${ scriptDir } /${ scriptName } .${ funcName } ()` ;
63
89
console . log ( `${ logName } : starting ...` ) ;
64
- const x = s . exec ( `npm list ${ ApimConnectorOpenApiBrowserPackageName } ` ) . stdout ;
65
- const invalidIdx : number = x . search ( 'invalid' ) ;
66
- if ( invalidIdx > - 1 ) throw new Error ( `${ logName } : invalid version of ${ ApimConnectorOpenApiBrowserPackageName } in package.json` ) ;
67
- const idx : number = x . lastIndexOf ( ApimConnectorOpenApiBrowserPackageName ) ;
68
- const y = x . slice ( idx ) . replace ( / \s / g, '' ) ;
69
- console . log ( `${ logName } : success.` ) ;
70
- return y ;
90
+
91
+ return ApimConnectorOpenApi . VERSION ;
92
+
93
+ // read from npm package
94
+ // const x = s.exec(`npm list ${ApimConnectorOpenApiBrowserPackageName}`).stdout;
95
+ // const invalidIdx: number = x.search('invalid');
96
+ // if(invalidIdx > -1) throw new Error(`${logName}: invalid version of ${ApimConnectorOpenApiBrowserPackageName} in package.json`);
97
+ // const idx: number = x.lastIndexOf(ApimConnectorOpenApiBrowserPackageName);
98
+ // const y = x.slice(idx).replace(/\s/g, '' );
99
+ // console.log(`${logName}: success.`);
100
+ // return y;
71
101
}
72
102
const buildAbouts = ( ) => {
73
103
const funcName = 'buildAbouts' ;
74
104
const logName = `${ scriptDir } /${ scriptName } .${ funcName } ()` ;
75
105
76
- const buildAbout = ( name : string , description : string , packageJson : any , sha1 : string ) : TAbout => {
77
- const about : TAbout = {
106
+ const buildAbout = ( name : string , description : string , packageJson : any , sha1 : string ) : TAPPortalAbout => {
107
+ const tsDate = new Date ( ) ;
108
+ const about : TAPPortalAbout = {
78
109
name : name ,
79
110
description : description ,
80
111
author : packageJson . author ,
81
112
license : packageJson . license ,
82
113
version : packageJson . version ,
83
- "apim-connector-open-api-version" : getApimConnectorOpenApiVersion ( ) ,
114
+ build_date : tsDate . toUTCString ( ) ,
115
+ "apim-connector-openapi-version" : getApimConnectorOpenApiVersion ( ) ,
84
116
"apim-server-openapi-version" : getApimServerOpenApiVersion ( ) ,
85
117
repository : {
86
118
type : packageJson . repository . type ,
@@ -93,7 +125,7 @@ const buildAbouts = () => {
93
125
}
94
126
return about ;
95
127
}
96
- const copyAbout = ( about : TAbout , outputFile : string ) => {
128
+ const copyAbout = ( about : TAPPortalAbout , outputFile : string ) => {
97
129
const funcName = 'copyAbout' ;
98
130
const logName = `${ scriptDir } /${ scriptName } .${ funcName } ()` ;
99
131
console . log ( `${ logName } : starting ...` ) ;
@@ -108,24 +140,30 @@ const buildAbouts = () => {
108
140
109
141
// func main
110
142
console . log ( `${ logName } : starting ...` ) ;
111
- const packageJsonFile = `${ apimPortalDir } /package.json` ;
143
+ const packageJsonFile = `${ CONSTANTS . ApimPortalDir } /package.json` ;
112
144
const packageJson = require ( `${ packageJsonFile } ` ) ;
113
145
const sha1 = s . exec ( 'git rev-parse HEAD' ) . stdout . slice ( 0 , - 1 ) ;
114
- const adminPortalAbout : TAbout = buildAbout ( AdminPortalName , AdminPortalDescription , packageJson , sha1 ) ;
146
+ const adminPortalAbout : TAPPortalAbout = buildAbout ( AdminPortalName , AdminPortalDescription , packageJson , sha1 ) ;
115
147
console . log ( `${ logName } : adminPortalAbout = ${ JSON . stringify ( adminPortalAbout , null , 2 ) } ` ) ;
116
- copyAbout ( adminPortalAbout , outputAdminPortalAboutFile ) ;
117
- const developerPortalAbout : TAbout = buildAbout ( DeveloperPortalName , DeveloperPortalDescription , packageJson , sha1 ) ;
148
+ copyAbout ( adminPortalAbout , CONSTANTS . OutputAdminPortalAboutFile ) ;
149
+ const developerPortalAbout : TAPPortalAbout = buildAbout ( DeveloperPortalName , DeveloperPortalDescription , packageJson , sha1 ) ;
118
150
console . log ( `${ logName } : developerPortalAbout = ${ JSON . stringify ( developerPortalAbout , null , 2 ) } ` ) ;
119
- copyAbout ( developerPortalAbout , outputDeveloperPortalAboutFile ) ;
151
+ copyAbout ( developerPortalAbout , CONSTANTS . OutputDeveloperPortalAboutFile ) ;
120
152
console . log ( `${ logName } : success.` ) ;
121
153
}
122
154
123
155
const main = ( ) => {
124
156
const funcName = 'main' ;
125
157
const logName = `${ scriptDir } /${ scriptName } .${ funcName } ()` ;
126
158
console . log ( `${ logName } : starting ...` ) ;
159
+ CONSTANTS . log ( ) ;
160
+
127
161
prepare ( ) ;
162
+ copyApimServerSourcesToWorkingDir ( ) ;
163
+ devBuildApimServer ( ) ;
164
+ copyApimServerAssets ( ) ;
128
165
buildAbouts ( ) ;
166
+
129
167
console . log ( `${ logName } : success.` ) ;
130
168
}
131
169
0 commit comments