@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.
- package/README.md +12 -0
- package/build/commands/actions/initQuestions.js +24 -22
- package/build/commands/actions/initQuestions.js.map +1 -1
- package/build/commands/actions/setupPackageJson.js +4 -4
- package/build/commands/actions/setupPackageJson.js.map +1 -1
- package/build/commands/build.js +31 -25
- package/build/commands/build.js.map +1 -1
- package/build/commands/builtin/ApiDocMaker.js +60 -23
- package/build/commands/builtin/ApiDocMaker.js.map +1 -1
- package/build/commands/builtin/BuiltInHandler.js +6 -6
- package/build/commands/builtin/BuiltInHandler.js.map +1 -1
- package/build/commands/builtin/DeployBuiltInZip.js +4 -4
- package/build/commands/builtin/DeployBuiltInZip.js.map +1 -1
- package/build/commands/builtin/StageWebrootZip.js +1 -0
- package/build/commands/builtin/StageWebrootZip.js.map +1 -1
- package/build/commands/create.js +10 -11
- package/build/commands/create.js.map +1 -1
- package/build/commands/deploy.js +38 -42
- package/build/commands/deploy.js.map +1 -1
- package/build/commands/doctor.js +38 -37
- package/build/commands/doctor.js.map +1 -1
- package/build/commands/help.js +93 -93
- package/build/commands/help.js.map +1 -1
- package/build/commands/init.js +7 -7
- package/build/commands/init.js.map +1 -1
- package/build/commands/package.js +50 -51
- package/build/commands/package.js.map +1 -1
- package/build/commands/publish.js +98 -102
- package/build/commands/publish.js.map +1 -1
- package/build/commands/settings.js +19 -18
- package/build/commands/settings.js.map +1 -1
- package/build/commands/start.js +4 -4
- package/build/commands/start.js.map +1 -1
- package/build/commands/test.js +3 -3
- package/build/commands/test.js.map +1 -1
- package/build/commands/user.js +1 -1
- package/build/commands/user.js.map +1 -1
- package/build/expressRoutes/all.js +27 -26
- package/build/expressRoutes/all.js.map +1 -1
- package/build/expressRoutes/api.js +9 -7
- package/build/expressRoutes/api.js.map +1 -1
- package/build/expressRoutes/functionBinder.js +38 -36
- package/build/expressRoutes/functionBinder.js.map +1 -1
- package/build/lib/CaseUtils.js +2 -2
- package/build/lib/CaseUtils.js.map +1 -1
- package/build/lib/DirectoryUtils.js +4 -3
- package/build/lib/DirectoryUtils.js.map +1 -1
- package/build/lib/LiftConfig.js +18 -20
- package/build/lib/LiftConfig.js.map +1 -1
- package/build/lib/LiftVersion.js +17 -12
- package/build/lib/LiftVersion.js.map +1 -1
- package/build/lib/Tests/fileCompare.test.js +11 -10
- package/build/lib/Tests/fileCompare.test.js.map +1 -1
- package/build/lib/askQuestion.js +3 -2
- package/build/lib/askQuestion.js.map +1 -1
- package/build/lib/executeCommand.js +46 -33
- package/build/lib/executeCommand.js.map +1 -1
- package/build/lib/fileCompare.js +9 -8
- package/build/lib/fileCompare.js.map +1 -1
- package/build/lib/openAPI/ApiBuildCollector.js +9 -8
- package/build/lib/openAPI/ApiBuildCollector.js.map +1 -1
- package/build/lib/openAPI/WebrootFileSupport.js +4 -3
- package/build/lib/openAPI/WebrootFileSupport.js.map +1 -1
- package/build/lib/openAPI/openApiConstruction.js +62 -61
- package/build/lib/openAPI/openApiConstruction.js.map +1 -1
- package/build/lib/pathResolve.js +4 -4
- package/build/lib/pathResolve.js.map +1 -1
- package/build/lib/utils.js +5 -4
- package/build/lib/utils.js.map +1 -1
- package/build/lift.js +14 -15
- package/build/lift.js.map +1 -1
- package/package.json +2 -1
- package/src/commands/actions/initQuestions.ts +112 -112
- package/src/commands/actions/setupPackageJson.ts +21 -25
- package/src/commands/build.ts +143 -146
- package/src/commands/builtin/ApiDocMaker.ts +86 -54
- package/src/commands/builtin/BuiltInHandler.ts +31 -35
- package/src/commands/builtin/DeployBuiltInZip.ts +15 -17
- package/src/commands/builtin/StageWebrootZip.ts +29 -32
- package/src/commands/create.ts +40 -47
- package/src/commands/deploy.ts +139 -152
- package/src/commands/doctor.ts +86 -82
- package/src/commands/help.ts +152 -153
- package/src/commands/init.ts +37 -39
- package/src/commands/package.ts +201 -204
- package/src/commands/publish.ts +277 -312
- package/src/commands/settings.ts +67 -70
- package/src/commands/start.ts +32 -37
- package/src/commands/test.ts +15 -16
- package/src/commands/user.ts +1 -1
- package/src/expressRoutes/all.ts +73 -78
- package/src/expressRoutes/api.ts +14 -16
- package/src/expressRoutes/functionBinder.ts +144 -151
- package/src/lib/CaseUtils.ts +49 -54
- package/src/lib/DirectoryUtils.ts +25 -27
- package/src/lib/LiftConfig.ts +46 -54
- package/src/lib/LiftVersion.ts +69 -77
- package/src/lib/Tests/fileCompare.test.ts +27 -26
- package/src/lib/askQuestion.ts +12 -13
- package/src/lib/executeCommand.ts +40 -33
- package/src/lib/fileCompare.ts +46 -37
- package/src/lib/openAPI/ApiBuildCollector.ts +36 -36
- package/src/lib/openAPI/WebrootFileSupport.ts +15 -17
- package/src/lib/openAPI/openApiConstruction.ts +169 -175
- package/src/lib/pathResolve.ts +22 -28
- package/src/lib/utils.ts +31 -33
- 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
|
|
4
|
+
import { OpenApiBuilder } from 'openapi3-ts/oas30'
|
|
5
|
+
import fs from 'fs'
|
|
6
6
|
import path from 'path'
|
|
7
|
-
import {resolvePaths} from
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
68
|
+
builder.addSchema('Empty', {
|
|
69
|
+
title: 'Empty Schema',
|
|
70
|
+
type: 'object'
|
|
71
|
+
})
|
|
72
|
+
}
|
|
78
73
|
|
|
79
|
-
|
|
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
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
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
|
-
|
|
99
|
-
|
|
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
|
-
|
|
104
|
-
|
|
98
|
+
ref.properties[prop] = scType
|
|
99
|
+
}
|
|
105
100
|
|
|
106
|
-
|
|
101
|
+
builder.addSchema(schemaName, ref)
|
|
107
102
|
}
|
|
108
103
|
|
|
109
|
-
function addFunctionMethod(pathDef:any, method:string, def:any) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
description:
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
120
|
+
}
|
|
121
|
+
pathDef[method] = methData
|
|
130
122
|
}
|
|
131
|
-
function addCORSOptionMethod(pathDef:any) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
}
|
package/src/lib/pathResolve.ts
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import fs from
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
2
|
-
import
|
|
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
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
):Promise<Uint8Array>
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
}
|