@tremho/mist-lift 1.1.4-pre-release.1 → 1.1.5
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/LICENSE +21 -21
- package/README.md +70 -66
- package/build/QSTest/functions/IntegrationTest/src/main.js +1 -1
- package/build/src/commands/builtin/ApiDocMaker.js +0 -1
- package/build/src/commands/builtin/ApiDocMaker.js.map +1 -1
- package/build/src/commands/doctor.js +12 -1
- package/build/src/commands/doctor.js.map +1 -1
- package/build/src/lib/LiftVersion.js +1 -1
- package/build/src/lib/LiftVersion.js.map +1 -1
- package/package.json +79 -79
- package/src/commands/actions/initQuestions.ts +133 -133
- package/src/commands/actions/setupPackageJson.ts +32 -32
- package/src/commands/build.ts +173 -173
- package/src/commands/builtin/ApiDocMaker.ts +105 -106
- package/src/commands/builtin/BuiltInHandler.ts +47 -47
- package/src/commands/builtin/DeployBuiltInZip.ts +25 -25
- package/src/commands/builtin/StageWebrootZip.ts +36 -36
- package/src/commands/create.ts +52 -52
- package/src/commands/deploy.ts +161 -161
- package/src/commands/doctor.ts +118 -107
- package/src/commands/help.ts +178 -178
- package/src/commands/info.ts +42 -42
- package/src/commands/init.ts +61 -61
- package/src/commands/package.ts +234 -234
- package/src/commands/publish.ts +330 -330
- package/src/commands/settings.ts +73 -73
- package/src/commands/start.ts +43 -43
- package/src/commands/test.ts +37 -37
- package/src/commands/user.ts +20 -20
- package/src/expressRoutes/all.ts +99 -99
- package/src/expressRoutes/api.ts +22 -22
- package/src/expressRoutes/functionBinder.ts +155 -155
- package/src/integration-tests/quickstart-scenario.test.ts +76 -76
- package/src/lib/CaseUtils.ts +63 -63
- package/src/lib/DirectoryUtils.ts +34 -34
- package/src/lib/LiftConfig.ts +74 -74
- package/src/lib/LiftVersion.ts +87 -87
- package/src/lib/Tests/fileCompare.test.ts +35 -35
- package/src/lib/askQuestion.ts +17 -17
- package/src/lib/executeCommand.ts +45 -45
- package/src/lib/fileCompare.ts +55 -55
- package/src/lib/openAPI/ApiBuildCollector.ts +47 -47
- package/src/lib/openAPI/WebrootFileSupport.ts +19 -19
- package/src/lib/openAPI/openApiConstruction.ts +196 -196
- package/src/lib/pathResolve.ts +26 -26
- package/src/lib/utils.ts +43 -43
- package/src/lift.ts +87 -87
- package/templateData/function-definition-template +20 -20
- package/templateData/function-local-ts +16 -16
- package/templateData/function-main-ts +16 -16
- package/templateData/function-runmain-mjs +6 -6
- package/templateData/function-test-template +11 -11
- package/templateData/swagger-ui-bundle.js +2 -2
- package/templateData/swagger-ui-standalone-preset.js +2 -2
- package/templateData/swagger-ui.css +2 -2
- package/tsconfig.json +28 -28
- package/build/commands/builtin/prebuilt-zips/API.zip +0 -0
- package/build/commands/builtin/prebuilt-zips/FileServe.zip +0 -0
- package/build/commands/builtin/prebuilt-zips/Webroot.zip +0 -0
package/src/commands/package.ts
CHANGED
|
@@ -1,234 +1,234 @@
|
|
|
1
|
-
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import fs, { Stats } from 'fs'
|
|
4
|
-
import { resolvePaths } from '../lib/pathResolve'
|
|
5
|
-
|
|
6
|
-
import * as ac from 'ansi-colors'
|
|
7
|
-
|
|
8
|
-
import { recurseDirectory } from '../lib/DirectoryUtils'
|
|
9
|
-
import { getLiftVersion, getProjectName, getProjectVersion } from '../lib/LiftVersion'
|
|
10
|
-
import { executeCommand } from '../lib/executeCommand'
|
|
11
|
-
import { isNewerFile } from '../lib/fileCompare'
|
|
12
|
-
import { doBuildAsync } from './build'
|
|
13
|
-
import { FolderToZip } from '../lib/utils'
|
|
14
|
-
|
|
15
|
-
// test then package
|
|
16
|
-
export async function doPackageAsync (
|
|
17
|
-
args: string[]
|
|
18
|
-
): Promise<number> {
|
|
19
|
-
const projectPaths = resolvePaths()
|
|
20
|
-
if (!projectPaths.verified) {
|
|
21
|
-
console.log(ac.bold.magenta('current directory is not at project root'))
|
|
22
|
-
return -1
|
|
23
|
-
}
|
|
24
|
-
const workPath = path.join(projectPaths.basePath, '.package_temp')
|
|
25
|
-
|
|
26
|
-
if (fs.existsSync(workPath)) fs.rmSync(workPath, { recursive: true })
|
|
27
|
-
fs.mkdirSync(workPath)
|
|
28
|
-
|
|
29
|
-
const buildFunctionsPath = path.join(projectPaths.buildPath, 'functions')
|
|
30
|
-
|
|
31
|
-
const funcsToPackage: string[] = []
|
|
32
|
-
const options: string[] = []
|
|
33
|
-
for (const arg of args) {
|
|
34
|
-
if (arg.charAt(0) === '-') {
|
|
35
|
-
options.push(arg.toLowerCase())
|
|
36
|
-
} else funcsToPackage.push(arg)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const ret = await doBuildAsync(args)
|
|
40
|
-
if (ret !== 0) return ret
|
|
41
|
-
|
|
42
|
-
if (funcsToPackage.length === 0) {
|
|
43
|
-
let firstDepth = 0
|
|
44
|
-
recurseDirectory(buildFunctionsPath, (filepath, stats) => {
|
|
45
|
-
const depth = filepath.split(path.sep).length
|
|
46
|
-
if (firstDepth === 0) firstDepth = depth
|
|
47
|
-
if (stats.isDirectory() && depth === firstDepth) {
|
|
48
|
-
funcsToPackage.push(path.basename(filepath))
|
|
49
|
-
}
|
|
50
|
-
return false
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
let error = 0
|
|
55
|
-
|
|
56
|
-
const recurse = async (i: number): Promise<any> => {
|
|
57
|
-
if (i >= funcsToPackage.length) return
|
|
58
|
-
const funcName = funcsToPackage[i]
|
|
59
|
-
const pe = await packageFunction(funcName)
|
|
60
|
-
if (pe !== 0) {
|
|
61
|
-
error = pe
|
|
62
|
-
return error
|
|
63
|
-
}
|
|
64
|
-
await recurse(++i)
|
|
65
|
-
}
|
|
66
|
-
await recurse(0)
|
|
67
|
-
return error
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function packageFunction (funcName: string): Promise<number> {
|
|
71
|
-
const projectPaths = resolvePaths()
|
|
72
|
-
const buildFunctionsPath = path.join(projectPaths.buildPath, 'functions')
|
|
73
|
-
const all: Array<Promise<any>> = []
|
|
74
|
-
const error = 0
|
|
75
|
-
const funcPath = path.join(buildFunctionsPath, funcName)
|
|
76
|
-
if (!fs.existsSync(funcPath)) {
|
|
77
|
-
console.error(ac.red.bold(`${funcName} does not exist`) + ', cannot package')
|
|
78
|
-
return -1
|
|
79
|
-
}
|
|
80
|
-
const zipdir = path.join(projectPaths.basePath, 'MistLift_Zips')
|
|
81
|
-
const zipFile = path.join(zipdir, funcName + '.zip')
|
|
82
|
-
|
|
83
|
-
if (!fs.existsSync(zipdir)) {
|
|
84
|
-
fs.mkdirSync(zipdir)
|
|
85
|
-
}
|
|
86
|
-
const zfx = fs.existsSync(zipFile)
|
|
87
|
-
if (zfx) {
|
|
88
|
-
if (!isNewerFile(funcPath, zipFile, '.js', '.zip')) {
|
|
89
|
-
return 0
|
|
90
|
-
}
|
|
91
|
-
fs.unlinkSync(zipFile)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const projectName = getProjectName() ?? ''
|
|
95
|
-
const projectVersion = getProjectVersion()?.toString() ?? ''
|
|
96
|
-
const liftVersion = getLiftVersion()?.toString() ?? ''
|
|
97
|
-
|
|
98
|
-
// the main package json that has all imports
|
|
99
|
-
const mainPkgJsonPath = path.join(projectPaths.packagePath)
|
|
100
|
-
const mainPkgSrc = fs.readFileSync(mainPkgJsonPath).toString()
|
|
101
|
-
const mainPkgJson = JSON.parse(mainPkgSrc)
|
|
102
|
-
const workPath = path.join(projectPaths.basePath, '.package_temp')
|
|
103
|
-
|
|
104
|
-
console.log(ac.green.italic('packaging ') + ac.green.bold(funcName))
|
|
105
|
-
|
|
106
|
-
// make a nominal package.json
|
|
107
|
-
const pkgjson = {
|
|
108
|
-
name: funcName,
|
|
109
|
-
description: 'Lambda function ' + funcName + ' for ' + projectName + ', created with MistLift ' + liftVersion,
|
|
110
|
-
version: projectVersion,
|
|
111
|
-
main: 'runmain.mjs',
|
|
112
|
-
scripts: {
|
|
113
|
-
test: 'echo "No Tests Defined" && exit 1'
|
|
114
|
-
},
|
|
115
|
-
dependencies: {},
|
|
116
|
-
keywords: [],
|
|
117
|
-
author: '',
|
|
118
|
-
license: 'MIT'
|
|
119
|
-
}
|
|
120
|
-
// find all the imports in the sources
|
|
121
|
-
const imports = findAllImports(funcPath)
|
|
122
|
-
pkgjson.dependencies = reconcileVersionImports(imports, mainPkgJson)
|
|
123
|
-
// - write out new package.json to workPath
|
|
124
|
-
// console.log("writing package.json", pkgjson)
|
|
125
|
-
fs.writeFileSync(path.join(workPath, 'package.json'), JSON.stringify(pkgjson, null, 2))
|
|
126
|
-
// - execute npm i at workpath, create node_modules
|
|
127
|
-
await executeCommand('npm i', [], workPath).then(() => {
|
|
128
|
-
// copy the lambda function
|
|
129
|
-
recurseDirectory(funcPath, (filepath: string, stats: Stats) => {
|
|
130
|
-
if (filepath.substring(0, funcPath.length) === funcPath) {
|
|
131
|
-
const endpath = filepath.substring(funcPath.length)
|
|
132
|
-
if (!endpath.toLowerCase().includes(`${funcName}-tests`.toLowerCase())) { // skip tests
|
|
133
|
-
const fromPath = path.join(funcPath, endpath)
|
|
134
|
-
const toPath = path.join(workPath, endpath)
|
|
135
|
-
if (stats.isDirectory() && !fs.existsSync(toPath)) {
|
|
136
|
-
fs.mkdirSync(toPath)
|
|
137
|
-
}
|
|
138
|
-
if (stats.isFile()) {
|
|
139
|
-
fs.copyFileSync(fromPath, toPath)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return false
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
// put a runmain.mjs into place
|
|
147
|
-
const templatePath = path.join(__dirname, '..', '..', 'templateData', 'function-runmain-mjs')
|
|
148
|
-
const runmainPath = path.join(workPath, 'runmain.mjs')
|
|
149
|
-
fs.writeFileSync(runmainPath, fs.readFileSync(templatePath))
|
|
150
|
-
|
|
151
|
-
all.push(FolderToZip(workPath, zipFile))
|
|
152
|
-
// console.log("now zip it")
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
return await Promise.all(all).then(() => {
|
|
156
|
-
return error
|
|
157
|
-
})
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function findAllImports (folder: string): string[] {
|
|
161
|
-
const imports: string[] = []
|
|
162
|
-
if (fs.existsSync(folder)) {
|
|
163
|
-
recurseDirectory(folder, (filepath, stats) => {
|
|
164
|
-
// console.log(`filepath = ${filepath}`);
|
|
165
|
-
if (!filepath.includes('__files__')) {
|
|
166
|
-
if (!stats.isDirectory()) {
|
|
167
|
-
const content = fs.readFileSync(filepath).toString()
|
|
168
|
-
for (const m of findImports(content)) {
|
|
169
|
-
// console.log(' import', m)
|
|
170
|
-
imports.push(m)
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return false
|
|
175
|
-
})
|
|
176
|
-
}
|
|
177
|
-
return imports
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function findImports (content: string): string[] {
|
|
181
|
-
const imports: string[] = []
|
|
182
|
-
const regexp = /require\s*\(\s*["|'](.+)["|']/gm
|
|
183
|
-
const matches = content.matchAll(regexp)
|
|
184
|
-
for (const m of matches) {
|
|
185
|
-
imports.push(m[1])
|
|
186
|
-
}
|
|
187
|
-
return imports
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function reconcileVersionImports (
|
|
191
|
-
imports: string[],
|
|
192
|
-
mainPkgJson: any
|
|
193
|
-
): any {
|
|
194
|
-
const dependencies = mainPkgJson.dependencies ?? {}
|
|
195
|
-
const devDependencies = mainPkgJson.devDependencies ?? {}
|
|
196
|
-
|
|
197
|
-
const builtins = [
|
|
198
|
-
'fs',
|
|
199
|
-
'path',
|
|
200
|
-
'process',
|
|
201
|
-
'crypto',
|
|
202
|
-
'http'
|
|
203
|
-
]
|
|
204
|
-
|
|
205
|
-
const depsOut: any = {}
|
|
206
|
-
|
|
207
|
-
for (const m of imports) {
|
|
208
|
-
let isDev = false
|
|
209
|
-
let r: string | undefined = dependencies[m]
|
|
210
|
-
if (r === undefined) {
|
|
211
|
-
isDev = true
|
|
212
|
-
r = devDependencies[m]
|
|
213
|
-
}
|
|
214
|
-
if (r !== undefined) {
|
|
215
|
-
if (depsOut[m] !== undefined && depsOut[m] !== r) {
|
|
216
|
-
console.error(ac.red.bold(` Version mismatch on ${m}: ${r} vs ${depsOut[m] as string}`))
|
|
217
|
-
}
|
|
218
|
-
if (isDev) {
|
|
219
|
-
console.error(ac.magenta(` ${m} import is dev-only, not migrated`))
|
|
220
|
-
} else {
|
|
221
|
-
if (depsOut[m] !== undefined) console.log(ac.blue.dim(` ${m} exported as ${r}`))
|
|
222
|
-
depsOut[m] = r
|
|
223
|
-
}
|
|
224
|
-
} else {
|
|
225
|
-
// if not a builtin and not local..
|
|
226
|
-
if (!builtins.includes(m)) {
|
|
227
|
-
if (m.charAt(0) !== '.') {
|
|
228
|
-
console.error(ac.red.bold(' ERROR - Found no dependency reference for import'), m)
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return depsOut
|
|
234
|
-
}
|
|
1
|
+
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import fs, { Stats } from 'fs'
|
|
4
|
+
import { resolvePaths } from '../lib/pathResolve'
|
|
5
|
+
|
|
6
|
+
import * as ac from 'ansi-colors'
|
|
7
|
+
|
|
8
|
+
import { recurseDirectory } from '../lib/DirectoryUtils'
|
|
9
|
+
import { getLiftVersion, getProjectName, getProjectVersion } from '../lib/LiftVersion'
|
|
10
|
+
import { executeCommand } from '../lib/executeCommand'
|
|
11
|
+
import { isNewerFile } from '../lib/fileCompare'
|
|
12
|
+
import { doBuildAsync } from './build'
|
|
13
|
+
import { FolderToZip } from '../lib/utils'
|
|
14
|
+
|
|
15
|
+
// test then package
|
|
16
|
+
export async function doPackageAsync (
|
|
17
|
+
args: string[]
|
|
18
|
+
): Promise<number> {
|
|
19
|
+
const projectPaths = resolvePaths()
|
|
20
|
+
if (!projectPaths.verified) {
|
|
21
|
+
console.log(ac.bold.magenta('current directory is not at project root'))
|
|
22
|
+
return -1
|
|
23
|
+
}
|
|
24
|
+
const workPath = path.join(projectPaths.basePath, '.package_temp')
|
|
25
|
+
|
|
26
|
+
if (fs.existsSync(workPath)) fs.rmSync(workPath, { recursive: true })
|
|
27
|
+
fs.mkdirSync(workPath)
|
|
28
|
+
|
|
29
|
+
const buildFunctionsPath = path.join(projectPaths.buildPath, 'functions')
|
|
30
|
+
|
|
31
|
+
const funcsToPackage: string[] = []
|
|
32
|
+
const options: string[] = []
|
|
33
|
+
for (const arg of args) {
|
|
34
|
+
if (arg.charAt(0) === '-') {
|
|
35
|
+
options.push(arg.toLowerCase())
|
|
36
|
+
} else funcsToPackage.push(arg)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const ret = await doBuildAsync(args)
|
|
40
|
+
if (ret !== 0) return ret
|
|
41
|
+
|
|
42
|
+
if (funcsToPackage.length === 0) {
|
|
43
|
+
let firstDepth = 0
|
|
44
|
+
recurseDirectory(buildFunctionsPath, (filepath, stats) => {
|
|
45
|
+
const depth = filepath.split(path.sep).length
|
|
46
|
+
if (firstDepth === 0) firstDepth = depth
|
|
47
|
+
if (stats.isDirectory() && depth === firstDepth) {
|
|
48
|
+
funcsToPackage.push(path.basename(filepath))
|
|
49
|
+
}
|
|
50
|
+
return false
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let error = 0
|
|
55
|
+
|
|
56
|
+
const recurse = async (i: number): Promise<any> => {
|
|
57
|
+
if (i >= funcsToPackage.length) return
|
|
58
|
+
const funcName = funcsToPackage[i]
|
|
59
|
+
const pe = await packageFunction(funcName)
|
|
60
|
+
if (pe !== 0) {
|
|
61
|
+
error = pe
|
|
62
|
+
return error
|
|
63
|
+
}
|
|
64
|
+
await recurse(++i)
|
|
65
|
+
}
|
|
66
|
+
await recurse(0)
|
|
67
|
+
return error
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function packageFunction (funcName: string): Promise<number> {
|
|
71
|
+
const projectPaths = resolvePaths()
|
|
72
|
+
const buildFunctionsPath = path.join(projectPaths.buildPath, 'functions')
|
|
73
|
+
const all: Array<Promise<any>> = []
|
|
74
|
+
const error = 0
|
|
75
|
+
const funcPath = path.join(buildFunctionsPath, funcName)
|
|
76
|
+
if (!fs.existsSync(funcPath)) {
|
|
77
|
+
console.error(ac.red.bold(`${funcName} does not exist`) + ', cannot package')
|
|
78
|
+
return -1
|
|
79
|
+
}
|
|
80
|
+
const zipdir = path.join(projectPaths.basePath, 'MistLift_Zips')
|
|
81
|
+
const zipFile = path.join(zipdir, funcName + '.zip')
|
|
82
|
+
|
|
83
|
+
if (!fs.existsSync(zipdir)) {
|
|
84
|
+
fs.mkdirSync(zipdir)
|
|
85
|
+
}
|
|
86
|
+
const zfx = fs.existsSync(zipFile)
|
|
87
|
+
if (zfx) {
|
|
88
|
+
if (!isNewerFile(funcPath, zipFile, '.js', '.zip')) {
|
|
89
|
+
return 0
|
|
90
|
+
}
|
|
91
|
+
fs.unlinkSync(zipFile)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const projectName = getProjectName() ?? ''
|
|
95
|
+
const projectVersion = getProjectVersion()?.toString() ?? ''
|
|
96
|
+
const liftVersion = getLiftVersion()?.toString() ?? ''
|
|
97
|
+
|
|
98
|
+
// the main package json that has all imports
|
|
99
|
+
const mainPkgJsonPath = path.join(projectPaths.packagePath)
|
|
100
|
+
const mainPkgSrc = fs.readFileSync(mainPkgJsonPath).toString()
|
|
101
|
+
const mainPkgJson = JSON.parse(mainPkgSrc)
|
|
102
|
+
const workPath = path.join(projectPaths.basePath, '.package_temp')
|
|
103
|
+
|
|
104
|
+
console.log(ac.green.italic('packaging ') + ac.green.bold(funcName))
|
|
105
|
+
|
|
106
|
+
// make a nominal package.json
|
|
107
|
+
const pkgjson = {
|
|
108
|
+
name: funcName,
|
|
109
|
+
description: 'Lambda function ' + funcName + ' for ' + projectName + ', created with MistLift ' + liftVersion,
|
|
110
|
+
version: projectVersion,
|
|
111
|
+
main: 'runmain.mjs',
|
|
112
|
+
scripts: {
|
|
113
|
+
test: 'echo "No Tests Defined" && exit 1'
|
|
114
|
+
},
|
|
115
|
+
dependencies: {},
|
|
116
|
+
keywords: [],
|
|
117
|
+
author: '',
|
|
118
|
+
license: 'MIT'
|
|
119
|
+
}
|
|
120
|
+
// find all the imports in the sources
|
|
121
|
+
const imports = findAllImports(funcPath)
|
|
122
|
+
pkgjson.dependencies = reconcileVersionImports(imports, mainPkgJson)
|
|
123
|
+
// - write out new package.json to workPath
|
|
124
|
+
// console.log("writing package.json", pkgjson)
|
|
125
|
+
fs.writeFileSync(path.join(workPath, 'package.json'), JSON.stringify(pkgjson, null, 2))
|
|
126
|
+
// - execute npm i at workpath, create node_modules
|
|
127
|
+
await executeCommand('npm i', [], workPath).then(() => {
|
|
128
|
+
// copy the lambda function
|
|
129
|
+
recurseDirectory(funcPath, (filepath: string, stats: Stats) => {
|
|
130
|
+
if (filepath.substring(0, funcPath.length) === funcPath) {
|
|
131
|
+
const endpath = filepath.substring(funcPath.length)
|
|
132
|
+
if (!endpath.toLowerCase().includes(`${funcName}-tests`.toLowerCase())) { // skip tests
|
|
133
|
+
const fromPath = path.join(funcPath, endpath)
|
|
134
|
+
const toPath = path.join(workPath, endpath)
|
|
135
|
+
if (stats.isDirectory() && !fs.existsSync(toPath)) {
|
|
136
|
+
fs.mkdirSync(toPath)
|
|
137
|
+
}
|
|
138
|
+
if (stats.isFile()) {
|
|
139
|
+
fs.copyFileSync(fromPath, toPath)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return false
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
// put a runmain.mjs into place
|
|
147
|
+
const templatePath = path.join(__dirname, '..', '..', 'templateData', 'function-runmain-mjs')
|
|
148
|
+
const runmainPath = path.join(workPath, 'runmain.mjs')
|
|
149
|
+
fs.writeFileSync(runmainPath, fs.readFileSync(templatePath))
|
|
150
|
+
|
|
151
|
+
all.push(FolderToZip(workPath, zipFile))
|
|
152
|
+
// console.log("now zip it")
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
return await Promise.all(all).then(() => {
|
|
156
|
+
return error
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function findAllImports (folder: string): string[] {
|
|
161
|
+
const imports: string[] = []
|
|
162
|
+
if (fs.existsSync(folder)) {
|
|
163
|
+
recurseDirectory(folder, (filepath, stats) => {
|
|
164
|
+
// console.log(`filepath = ${filepath}`);
|
|
165
|
+
if (!filepath.includes('__files__')) {
|
|
166
|
+
if (!stats.isDirectory()) {
|
|
167
|
+
const content = fs.readFileSync(filepath).toString()
|
|
168
|
+
for (const m of findImports(content)) {
|
|
169
|
+
// console.log(' import', m)
|
|
170
|
+
imports.push(m)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return false
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
return imports
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function findImports (content: string): string[] {
|
|
181
|
+
const imports: string[] = []
|
|
182
|
+
const regexp = /require\s*\(\s*["|'](.+)["|']/gm
|
|
183
|
+
const matches = content.matchAll(regexp)
|
|
184
|
+
for (const m of matches) {
|
|
185
|
+
imports.push(m[1])
|
|
186
|
+
}
|
|
187
|
+
return imports
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function reconcileVersionImports (
|
|
191
|
+
imports: string[],
|
|
192
|
+
mainPkgJson: any
|
|
193
|
+
): any {
|
|
194
|
+
const dependencies = mainPkgJson.dependencies ?? {}
|
|
195
|
+
const devDependencies = mainPkgJson.devDependencies ?? {}
|
|
196
|
+
|
|
197
|
+
const builtins = [
|
|
198
|
+
'fs',
|
|
199
|
+
'path',
|
|
200
|
+
'process',
|
|
201
|
+
'crypto',
|
|
202
|
+
'http'
|
|
203
|
+
]
|
|
204
|
+
|
|
205
|
+
const depsOut: any = {}
|
|
206
|
+
|
|
207
|
+
for (const m of imports) {
|
|
208
|
+
let isDev = false
|
|
209
|
+
let r: string | undefined = dependencies[m]
|
|
210
|
+
if (r === undefined) {
|
|
211
|
+
isDev = true
|
|
212
|
+
r = devDependencies[m]
|
|
213
|
+
}
|
|
214
|
+
if (r !== undefined) {
|
|
215
|
+
if (depsOut[m] !== undefined && depsOut[m] !== r) {
|
|
216
|
+
console.error(ac.red.bold(` Version mismatch on ${m}: ${r} vs ${depsOut[m] as string}`))
|
|
217
|
+
}
|
|
218
|
+
if (isDev) {
|
|
219
|
+
console.error(ac.magenta(` ${m} import is dev-only, not migrated`))
|
|
220
|
+
} else {
|
|
221
|
+
if (depsOut[m] !== undefined) console.log(ac.blue.dim(` ${m} exported as ${r}`))
|
|
222
|
+
depsOut[m] = r
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
// if not a builtin and not local..
|
|
226
|
+
if (!builtins.includes(m)) {
|
|
227
|
+
if (m.charAt(0) !== '.') {
|
|
228
|
+
console.error(ac.red.bold(' ERROR - Found no dependency reference for import'), m)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return depsOut
|
|
234
|
+
}
|