@tremho/mist-lift 1.0.2-pre-release.4 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +12 -0
  2. package/build/commands/actions/initQuestions.js +24 -22
  3. package/build/commands/actions/initQuestions.js.map +1 -1
  4. package/build/commands/actions/setupPackageJson.js +4 -4
  5. package/build/commands/actions/setupPackageJson.js.map +1 -1
  6. package/build/commands/build.js +31 -25
  7. package/build/commands/build.js.map +1 -1
  8. package/build/commands/builtin/ApiDocMaker.js +60 -23
  9. package/build/commands/builtin/ApiDocMaker.js.map +1 -1
  10. package/build/commands/builtin/BuiltInHandler.js +6 -6
  11. package/build/commands/builtin/BuiltInHandler.js.map +1 -1
  12. package/build/commands/builtin/DeployBuiltInZip.js +4 -4
  13. package/build/commands/builtin/DeployBuiltInZip.js.map +1 -1
  14. package/build/commands/builtin/StageWebrootZip.js +1 -0
  15. package/build/commands/builtin/StageWebrootZip.js.map +1 -1
  16. package/build/commands/create.js +10 -11
  17. package/build/commands/create.js.map +1 -1
  18. package/build/commands/deploy.js +38 -42
  19. package/build/commands/deploy.js.map +1 -1
  20. package/build/commands/doctor.js +38 -37
  21. package/build/commands/doctor.js.map +1 -1
  22. package/build/commands/help.js +93 -93
  23. package/build/commands/help.js.map +1 -1
  24. package/build/commands/init.js +7 -7
  25. package/build/commands/init.js.map +1 -1
  26. package/build/commands/package.js +50 -51
  27. package/build/commands/package.js.map +1 -1
  28. package/build/commands/publish.js +98 -102
  29. package/build/commands/publish.js.map +1 -1
  30. package/build/commands/settings.js +19 -18
  31. package/build/commands/settings.js.map +1 -1
  32. package/build/commands/start.js +4 -4
  33. package/build/commands/start.js.map +1 -1
  34. package/build/commands/test.js +3 -3
  35. package/build/commands/test.js.map +1 -1
  36. package/build/commands/user.js +1 -1
  37. package/build/commands/user.js.map +1 -1
  38. package/build/expressRoutes/all.js +27 -26
  39. package/build/expressRoutes/all.js.map +1 -1
  40. package/build/expressRoutes/api.js +9 -7
  41. package/build/expressRoutes/api.js.map +1 -1
  42. package/build/expressRoutes/functionBinder.js +38 -36
  43. package/build/expressRoutes/functionBinder.js.map +1 -1
  44. package/build/lib/CaseUtils.js +2 -2
  45. package/build/lib/CaseUtils.js.map +1 -1
  46. package/build/lib/DirectoryUtils.js +4 -3
  47. package/build/lib/DirectoryUtils.js.map +1 -1
  48. package/build/lib/LiftConfig.js +18 -20
  49. package/build/lib/LiftConfig.js.map +1 -1
  50. package/build/lib/LiftVersion.js +17 -12
  51. package/build/lib/LiftVersion.js.map +1 -1
  52. package/build/lib/Tests/fileCompare.test.js +11 -10
  53. package/build/lib/Tests/fileCompare.test.js.map +1 -1
  54. package/build/lib/askQuestion.js +3 -2
  55. package/build/lib/askQuestion.js.map +1 -1
  56. package/build/lib/executeCommand.js +46 -33
  57. package/build/lib/executeCommand.js.map +1 -1
  58. package/build/lib/fileCompare.js +9 -8
  59. package/build/lib/fileCompare.js.map +1 -1
  60. package/build/lib/openAPI/ApiBuildCollector.js +9 -8
  61. package/build/lib/openAPI/ApiBuildCollector.js.map +1 -1
  62. package/build/lib/openAPI/WebrootFileSupport.js +4 -3
  63. package/build/lib/openAPI/WebrootFileSupport.js.map +1 -1
  64. package/build/lib/openAPI/openApiConstruction.js +62 -61
  65. package/build/lib/openAPI/openApiConstruction.js.map +1 -1
  66. package/build/lib/pathResolve.js +4 -4
  67. package/build/lib/pathResolve.js.map +1 -1
  68. package/build/lib/utils.js +5 -4
  69. package/build/lib/utils.js.map +1 -1
  70. package/build/lift.js +14 -15
  71. package/build/lift.js.map +1 -1
  72. package/package.json +2 -1
  73. package/src/commands/actions/initQuestions.ts +112 -112
  74. package/src/commands/actions/setupPackageJson.ts +21 -25
  75. package/src/commands/build.ts +143 -146
  76. package/src/commands/builtin/ApiDocMaker.ts +86 -54
  77. package/src/commands/builtin/BuiltInHandler.ts +31 -35
  78. package/src/commands/builtin/DeployBuiltInZip.ts +15 -17
  79. package/src/commands/builtin/StageWebrootZip.ts +29 -32
  80. package/src/commands/create.ts +40 -47
  81. package/src/commands/deploy.ts +139 -152
  82. package/src/commands/doctor.ts +86 -82
  83. package/src/commands/help.ts +152 -153
  84. package/src/commands/init.ts +37 -39
  85. package/src/commands/package.ts +201 -204
  86. package/src/commands/publish.ts +277 -312
  87. package/src/commands/settings.ts +67 -70
  88. package/src/commands/start.ts +32 -37
  89. package/src/commands/test.ts +15 -16
  90. package/src/commands/user.ts +1 -1
  91. package/src/expressRoutes/all.ts +73 -78
  92. package/src/expressRoutes/api.ts +14 -16
  93. package/src/expressRoutes/functionBinder.ts +144 -151
  94. package/src/lib/CaseUtils.ts +49 -54
  95. package/src/lib/DirectoryUtils.ts +25 -27
  96. package/src/lib/LiftConfig.ts +46 -54
  97. package/src/lib/LiftVersion.ts +69 -77
  98. package/src/lib/Tests/fileCompare.test.ts +27 -26
  99. package/src/lib/askQuestion.ts +12 -13
  100. package/src/lib/executeCommand.ts +40 -33
  101. package/src/lib/fileCompare.ts +46 -37
  102. package/src/lib/openAPI/ApiBuildCollector.ts +36 -36
  103. package/src/lib/openAPI/WebrootFileSupport.ts +15 -17
  104. package/src/lib/openAPI/openApiConstruction.ts +169 -175
  105. package/src/lib/pathResolve.ts +22 -28
  106. package/src/lib/utils.ts +31 -33
  107. package/src/lift.ts +68 -67
@@ -1,202 +1,196 @@
1
1
  /**
2
2
  * This is part 2 of 2 -- we take our pre-built json array of definitions and apply them to openApi in this phase.
3
3
  */
4
- import { OpenApiBuilder } from 'openapi3-ts/oas30';
5
- import fs, {mkdirSync} from 'fs'
4
+ import { OpenApiBuilder } from 'openapi3-ts/oas30'
5
+ import fs from 'fs'
6
6
  import path from 'path'
7
- import {resolvePaths} from "../pathResolve";
8
- import {recurseDirectory} from "../DirectoryUtils";
9
- import {getSettings} from "../LiftConfig";
10
-
11
- export async function buildOpenApi(
12
- defs:any[],
13
- includePrivate:boolean = false,
14
- yamlFile?:string
15
- ):Promise<Uint8Array>
16
- {
17
- const builder = new OpenApiBuilder();
18
-
19
- const projectPaths = await resolvePaths();
20
- if(!projectPaths.verified) return new Uint8Array(0); // don't continue if not valid
21
-
22
- // Read our package.json and construct info from that
23
- const pkgFile = projectPaths.packagePath;
24
- let pkg:any = {}
25
- try { pkg = JSON.parse(fs.readFileSync(pkgFile).toString()); } catch {}
26
- let title = pkg.name;
27
- // let summary = pkg.description;
28
- let spdx = pkg.license;
29
- let contactName = pkg.author;
30
- let version = pkg.version;
31
-
32
- // license and version definitely come from package.json
33
- // description and title might get overridden by service.info file
34
- const infoFile = path.join(projectPaths.functionPath, "apiService.info.json")
35
- var svcInfo:any = {};
36
- if(fs.existsSync(infoFile)) {
37
- svcInfo = JSON.parse(fs.readFileSync(infoFile).toString())
7
+ import { resolvePaths } from '../pathResolve'
8
+
9
+ export async function buildOpenApi (
10
+ defs: any[],
11
+ includePrivate: boolean = false,
12
+ yamlFile?: string
13
+ ): Promise<Uint8Array> {
14
+ const builder = new OpenApiBuilder()
15
+
16
+ const projectPaths = await resolvePaths()
17
+ if (!projectPaths.verified) return new Uint8Array(0) // don't continue if not valid
18
+
19
+ // Read our package.json and construct info from that
20
+ const pkgFile = projectPaths.packagePath
21
+ let pkg: any = {}
22
+ try { pkg = JSON.parse(fs.readFileSync(pkgFile).toString()) } catch {}
23
+ const title: string = pkg.name ?? ''
24
+ // let summary = pkg.description;
25
+ // let spdx: string = pkg.license ?? ''
26
+ // const contactName: string = pkg.author ?? ''
27
+ const version: string = pkg.version ?? ''
28
+
29
+ // license and version definitely come from package.json
30
+ // description and title might get overridden by service.info file
31
+ const infoFile = path.join(projectPaths.functionPath, 'apiService.info.json')
32
+ let svcInfo: any = {}
33
+ if (fs.existsSync(infoFile)) {
34
+ svcInfo = JSON.parse(fs.readFileSync(infoFile).toString())
35
+ }
36
+ // spdx = svcInfo.contact?.spdx ?? spdx
37
+
38
+ const info = {
39
+ title: svcInfo.name ?? title,
40
+ // summary: summary,
41
+ description: svcInfo.description,
42
+ version: svcInfo.version ?? version ?? new Date().toUTCString()
43
+ }
44
+ builder.addInfo(info)
45
+
46
+ // map our defs into openApi values
47
+ for (const def of defs) {
48
+ const pathDef = {}
49
+ if (def.private === true && !includePrivate) continue // skip private
50
+
51
+ const parameters = def.parameters ?? []
52
+ const methods = def.allowedMethods.split(',')
53
+ const schemas = def.schemas ?? {}
54
+ for (const schemaName of Object.getOwnPropertyNames(schemas)) {
55
+ const schema = schemas[schemaName]
56
+ addTypeSchema(builder, schemaName, schema)
38
57
  }
39
- spdx = svcInfo.contact?.spdx ?? spdx;
40
-
41
- const info = {
42
- title: svcInfo.name ?? title,
43
- // summary: summary,
44
- description: svcInfo.description,
45
- version: svcInfo.version ?? version ?? new Date().toUTCString()
46
- }
47
- builder.addInfo(info)
48
-
49
- // map our defs into openApi values
50
- for (let def of defs) {
51
- let pathDef = {}
52
- if(def.private && !includePrivate) continue; // skip private
53
-
54
- const parameters = def.parameters ?? []
55
- const methods = def.allowedMethods.split(',')
56
- const schemas = def.schemas ?? {}
57
- for(let schemaName of Object.getOwnPropertyNames(schemas)) {
58
- const schema = schemas[schemaName];
59
- addTypeSchema(builder, schemaName, schema)
60
- }
61
- for (let method of methods) {
62
- method = method.trim().toLowerCase()
63
- addFunctionMethod(pathDef, method, def)
64
- for (let param of parameters) {
65
- addParameter(pathDef, param)
66
- }
67
- }
68
- addCORSOptionMethod(pathDef)
69
- builder.addPath((def.pathMap ?? "/"+def.name), pathDef)
70
-
71
- builder.addSchema("Empty",{
72
- title : "Empty Schema",
73
- type:"object"
74
- })
58
+ for (let method of methods) {
59
+ method = method.trim().toLowerCase()
60
+ addFunctionMethod(pathDef, method, def)
61
+ for (const param of parameters) {
62
+ addParameter(pathDef, param)
63
+ }
75
64
  }
65
+ addCORSOptionMethod(pathDef)
66
+ builder.addPath((def.pathMap ?? '/' + (def.name as string)), pathDef)
76
67
 
77
- const outFile = yamlFile ?? path.join(projectPaths.basePath, 'webroot', 'docs','apidoc.yaml')
68
+ builder.addSchema('Empty', {
69
+ title: 'Empty Schema',
70
+ type: 'object'
71
+ })
72
+ }
78
73
 
79
- const str2ab = (str:string):Uint8Array => {
80
- var buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char
81
- var bufView = new Uint8Array(buf);
82
- for (var i = 0, strLen = str.length; i < strLen; i++) {
83
- bufView[i] = str.charCodeAt(i);
84
- }
85
- return bufView;
86
- }
74
+ const outFile = yamlFile ?? path.join(projectPaths.basePath, 'webroot', 'docs', 'apidoc.yaml')
87
75
 
88
- const yaml = builder.getSpecAsYaml();
89
- const bytes = str2ab(yaml);
90
- if(!includePrivate) {
91
- fs.writeFileSync(outFile, yaml)
76
+ const str2ab = (str: string): Uint8Array => {
77
+ const buf = new ArrayBuffer(str.length * 2) // 2 bytes for each char
78
+ const bufView = new Uint8Array(buf)
79
+ for (let i = 0, strLen = str.length; i < strLen; i++) {
80
+ bufView[i] = str.charCodeAt(i)
92
81
  }
93
- return bytes
82
+ return bufView
83
+ }
84
+
85
+ const yaml = builder.getSpecAsYaml()
86
+ const bytes = str2ab(yaml)
87
+ if (!includePrivate) {
88
+ fs.writeFileSync(outFile, yaml)
89
+ }
90
+ return bytes
94
91
  }
95
92
 
96
- function addTypeSchema(builder:any, schemaName:string, schema:any)
97
- {
98
- const ref:any = {title: schemaName, type:"object", properties:{}}
99
- for(let prop of Object.getOwnPropertyNames(schema))
100
- {
101
- const scType:any = schemaType("", schema[prop],false)
93
+ function addTypeSchema (builder: any, schemaName: string, schema: any): void {
94
+ const ref: any = { title: schemaName, type: 'object', properties: {} }
95
+ for (const prop of Object.getOwnPropertyNames(schema)) {
96
+ const scType: any = schemaType('', schema[prop], false)
102
97
 
103
- ref.properties[prop] = scType
104
- }
98
+ ref.properties[prop] = scType
99
+ }
105
100
 
106
- builder.addSchema(schemaName, ref)
101
+ builder.addSchema(schemaName, ref)
107
102
  }
108
103
 
109
- function addFunctionMethod(pathDef:any, method:string, def:any) {
110
-
111
- // TODO: Define a return schema and put that here
112
- const retDef:any = (def.returns as any)["200"];
113
- const content:any = {}
114
- const mime = retDef?.content ?? retDef?.mime ?? "text/plain"
115
- content[mime] = {}
116
-
117
- const region = getSettings().awsPreferredRegion;
118
- const accountId = "545650260286";
119
- const methData = {
120
- summary: def.name,
121
- description: def.description,
122
- responses: {
123
- "200": {
124
- description: retDef?.description ?? "Success Response",
125
- content
126
- }
127
- }
104
+ function addFunctionMethod (pathDef: any, method: string, def: any): void {
105
+ // TODO: Define a return schema and put that here
106
+ const retDef: any = (def.returns)['200']
107
+ const content: any = {}
108
+ const mime = retDef?.content ?? retDef?.mime ?? 'text/plain'
109
+ content[mime] = {}
110
+
111
+ const methData = {
112
+ summary: def.name,
113
+ description: def.description,
114
+ responses: {
115
+ 200: {
116
+ description: retDef?.description ?? 'Success Response',
117
+ content
118
+ }
128
119
  }
129
- pathDef[method] = methData;
120
+ }
121
+ pathDef[method] = methData
130
122
  }
131
- function addCORSOptionMethod(pathDef:any) {
132
- if (pathDef["options"]) return; // already assinged by definition
133
- // add options for CORS
134
- pathDef["options"] = {
135
- "responses" : {
136
- "200" : {
137
- "description" : "200 response",
138
- "content" : {
139
- "application/json" : {
140
- "schema" : {
141
- "$ref" : "#/components/schemas/Empty"
142
- }
143
- }
144
- }
123
+ function addCORSOptionMethod (pathDef: any): void {
124
+ if (pathDef.options === undefined) return // already assinged by definition
125
+ // add options for CORS
126
+ pathDef.options = {
127
+ responses: {
128
+ 200: {
129
+ description: '200 response',
130
+ content: {
131
+ 'application/json': {
132
+ schema: {
133
+ $ref: '#/components/schemas/Empty'
145
134
  }
146
- },
147
- "x-amazon-apigateway-integration" : {
148
- "responses" : {
149
- "default" : {
150
- "statusCode" : "200"
151
- }
152
- },
153
- "requestTemplates" : {
154
- "application/json" : "{\"statusCode\": 200}"
155
- },
156
- "passthroughBehavior" : "when_no_match",
157
- "type" : "mock"
135
+ }
136
+ }
137
+ }
138
+ },
139
+ 'x-amazon-apigateway-integration': {
140
+ responses: {
141
+ default: {
142
+ statusCode: '200'
158
143
  }
144
+ },
145
+ requestTemplates: {
146
+ 'application/json': '{"statusCode": 200}'
147
+ },
148
+ passthroughBehavior: 'when_no_match',
149
+ type: 'mock'
159
150
  }
151
+ }
160
152
  }
161
153
 
162
- function addParameter(pathDef:any, param:any) {
163
- if(!pathDef.parameters) pathDef.parameters = [];
164
- const parameters = pathDef.parameters
165
- const example = param.example ?? param.default ?? "";
166
- const type = param.type ?? typeof example
167
- let deflt = param.default ?? example
168
-
169
- parameters.push({
170
- in: param.in,
171
- name: param.name,
172
- description: param.description,
173
- example: example,
174
- required: param.required,
175
- schema: schemaType(deflt, type, true)
176
- })
177
-
154
+ function addParameter (pathDef: any, param: any): void {
155
+ if (pathDef.parameters === undefined) pathDef.parameters = []
156
+ const parameters = pathDef.parameters
157
+ const example = param.example ?? param.default ?? ''
158
+ const type = param.type ?? typeof example
159
+ const deflt = param.default ?? example
160
+
161
+ parameters.push({
162
+ in: param.in,
163
+ name: param.name,
164
+ description: param.description,
165
+ example,
166
+ required: param.required,
167
+ schema: schemaType(deflt, type, true)
168
+ })
178
169
  }
179
170
 
180
- function schemaType(deflt:string, namedType:string, innerOnly:boolean) {
181
- if(typeof namedType == "object") return namedType;
182
- const typeFormat = namedType.split(':')
183
- let type = typeFormat[0]
184
- const format = typeFormat.length > 1 ? typeFormat[1] : undefined
185
- if(!( type === "string"
186
- || type === "number"
187
- || type === "integer"
188
- || type === "boolean"
189
- || type === "int"
190
- || type === "bool"
191
- )) {
192
- return innerOnly ? {
171
+ function schemaType (deflt: string, namedType: string, innerOnly: boolean): any {
172
+ if (typeof namedType === 'object') return namedType
173
+ const typeFormat = namedType.split(':')
174
+ let type = typeFormat[0]
175
+ const format = typeFormat.length > 1 ? typeFormat[1] : undefined
176
+ if (!(type === 'string' ||
177
+ type === 'number' ||
178
+ type === 'integer' ||
179
+ type === 'boolean' ||
180
+ type === 'int' ||
181
+ type === 'bool'
182
+ )) {
183
+ return innerOnly
184
+ ? {
185
+ $ref: `#/components/schemas/${type}`
186
+ }
187
+ : {
188
+ schema: {
193
189
  $ref: `#/components/schemas/${type}`
194
- } : { schema: {
195
- $ref: `#/components/schemas/${type}`
196
- } }
197
- }
198
- if( type === 'int') type = 'integer';
199
- if( type === 'bool') type = 'boolean';
200
- return innerOnly ? { type, format, example:deflt } : { schema: { type, format, example:deflt } }
201
-
190
+ }
191
+ }
192
+ }
193
+ if (type === 'int') type = 'integer'
194
+ if (type === 'bool') type = 'boolean'
195
+ return innerOnly ? { type, format, example: deflt } : { schema: { type, format, example: deflt } }
202
196
  }
@@ -1,32 +1,26 @@
1
- import path from "path";
2
- import fs from "fs";
3
-
1
+ import path from 'path'
2
+ import fs from 'fs'
4
3
 
5
4
  // Find the path roots in the project directory
6
- export function resolvePaths(
7
- ) : {
8
- basePath:string, // project base
9
- buildPath:string, // build folder
10
- functionPath:string, // functions folder
11
- packagePath:string, // package.json
12
- verified:boolean // all of these exist if true, else, may be incomplete project
13
- }
14
- {
15
- const cwd = process.cwd()
16
- let funcPath = path.join(cwd, 'functions')
17
- while(true)
18
- {
19
- if(!fs.existsSync(funcPath))
20
- {
21
- funcPath = path.normalize(path.join(funcPath, ".."))
22
- }
23
- else
24
- {
25
- const basePath = path.normalize(path.join(funcPath, ".."))
26
- const buildPath = path.join(basePath, "build");
27
- const packagePath = path.join(basePath,"package.json");
28
- const verified = fs.existsSync(basePath) && fs.existsSync(funcPath) && fs.existsSync(packagePath);
29
- return {basePath, buildPath, functionPath:funcPath, packagePath, verified}
30
- }
5
+ export function resolvePaths (
6
+ ): {
7
+ basePath: string // project base
8
+ buildPath: string // build folder
9
+ functionPath: string // functions folder
10
+ packagePath: string // package.json
11
+ verified: boolean // all of these exist if true, else, may be incomplete project
12
+ } {
13
+ const cwd = process.cwd()
14
+ let funcPath = path.join(cwd, 'functions')
15
+ while (true) {
16
+ if (!fs.existsSync(funcPath)) {
17
+ funcPath = path.normalize(path.join(funcPath, '..'))
18
+ } else {
19
+ const basePath = path.normalize(path.join(funcPath, '..'))
20
+ const buildPath = path.join(basePath, 'build')
21
+ const packagePath = path.join(basePath, 'package.json')
22
+ const verified = fs.existsSync(basePath) && fs.existsSync(funcPath) && fs.existsSync(packagePath)
23
+ return { basePath, buildPath, functionPath: funcPath, packagePath, verified }
31
24
  }
25
+ }
32
26
  }
package/src/lib/utils.ts CHANGED
@@ -1,5 +1,6 @@
1
- import {executeCommand} from "./executeCommand";
2
- import * as ac from "ansi-colors";
1
+ /* eslint @typescript-eslint/no-var-requires: "off" */
2
+ import { executeCommand } from './executeCommand'
3
+ import * as ac from 'ansi-colors'
3
4
  import * as fs from 'fs'
4
5
 
5
6
  /** General utilities */
@@ -7,39 +8,36 @@ import * as fs from 'fs'
7
8
  const zipDir = require('zip-dir')
8
9
 
9
10
  // pause the given number of milliseconds
10
- export async function delay(
11
- ms:number // milliseconds to delay
12
- )
13
- {
14
- return new Promise(resolve => {setTimeout(resolve, ms)})
11
+ export async function delay (
12
+ ms: number // milliseconds to delay
13
+ ): Promise<void> {
14
+ return await new Promise(resolve => { setTimeout(resolve, ms) })
15
15
  }
16
16
 
17
- export async function FolderToZip(
18
- folderPath:string,
19
- zipPath: string
20
- ):Promise<Uint8Array>
21
- {
22
- return new Promise(resolve => {
23
- zipDir(folderPath, { saveTo: zipPath }, function (err:any, buffer:Uint8Array) {
24
- if(err) throw err
25
- // `buffer` is the buffer of the zipped file
26
- // And the buffer was saved to `~/myzip.zip`
27
- resolve(buffer);
28
- })
17
+ export async function FolderToZip (
18
+ folderPath: string,
19
+ zipPath: string
20
+ ): Promise<Uint8Array> {
21
+ return new Promise(resolve => {
22
+ zipDir(folderPath, { saveTo: zipPath }, function (err: any, buffer: Uint8Array) {
23
+ if (err !== '' && err !== undefined && err !== null) throw err
24
+ // `buffer` is the buffer of the zipped file
25
+ // And the buffer was saved to `~/myzip.zip`
26
+ resolve(buffer)
29
27
  })
28
+ })
30
29
  }
31
- export async function UnzipToFolder(
32
- zipPath:string,
33
- folderPath:string,
34
- replace:boolean = true
35
- )
36
- {
37
- // TODO: using CLI -- find a good package. "unzip" has vulnerabilities. Try others.
30
+ export async function UnzipToFolder (
31
+ zipPath: string,
32
+ folderPath: string,
33
+ replace: boolean = true
34
+ ): Promise<void> {
35
+ // TODO: using CLI -- find a good package. "unzip" has vulnerabilities. Try others.
38
36
 
39
- if(replace) fs.rmSync(folderPath, {recursive: true, force: true})
40
- let result = await executeCommand('unzip', [zipPath,'-d', folderPath])
41
- if (result.retcode) {
42
- console.error(ac.red.bold(`failed to stage webroot (${result.retcode}): ${result.errStr}`));
43
- throw Error();
44
- }
45
- }
37
+ if (replace) fs.rmSync(folderPath, { recursive: true, force: true })
38
+ const result: { retcode: number, errStr: string } = await executeCommand('unzip', [zipPath, '-d', folderPath])
39
+ if (result.retcode !== 0) {
40
+ console.error(ac.red.bold(`failed to stage webroot (${result.retcode}): ${result.errStr}`))
41
+ throw Error()
42
+ }
43
+ }