@tremho/mist-lift 1.1.1 → 1.1.3-pre-release.1

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 (75) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +65 -65
  3. package/build/commands/actions/initQuestions.js +35 -33
  4. package/build/commands/actions/initQuestions.js.map +1 -1
  5. package/build/commands/build.js +1 -1
  6. package/build/commands/build.js.map +1 -1
  7. package/build/commands/create.js +1 -1
  8. package/build/commands/create.js.map +1 -1
  9. package/build/commands/deploy.js +1 -1
  10. package/build/commands/deploy.js.map +1 -1
  11. package/build/commands/info.js +1 -1
  12. package/build/commands/info.js.map +1 -1
  13. package/build/commands/init.js +2 -2
  14. package/build/commands/init.js.map +1 -1
  15. package/build/commands/package.js +2 -2
  16. package/build/commands/package.js.map +1 -1
  17. package/build/commands/publish.js +2 -2
  18. package/build/commands/publish.js.map +1 -1
  19. package/build/expressRoutes/functionBinder.js.map +1 -1
  20. package/build/integration-tests/quickstart-scenario.test.js +76 -0
  21. package/build/integration-tests/quickstart-scenario.test.js.map +1 -0
  22. package/build/lib/utils.js +1 -1
  23. package/build/lib/utils.js.map +1 -1
  24. package/build/lift.js +1 -1
  25. package/build/lift.js.map +1 -1
  26. package/package.json +79 -72
  27. package/src/commands/actions/initQuestions.ts +133 -131
  28. package/src/commands/actions/setupPackageJson.ts +32 -32
  29. package/src/commands/build.ts +170 -170
  30. package/src/commands/builtin/ApiDocMaker.ts +102 -102
  31. package/src/commands/builtin/BuiltInHandler.ts +47 -47
  32. package/src/commands/builtin/DeployBuiltInZip.ts +25 -25
  33. package/src/commands/builtin/StageWebrootZip.ts +36 -36
  34. package/src/commands/create.ts +52 -52
  35. package/src/commands/deploy.ts +161 -161
  36. package/src/commands/doctor.ts +106 -106
  37. package/src/commands/help.ts +178 -178
  38. package/src/commands/info.ts +42 -43
  39. package/src/commands/init.ts +61 -60
  40. package/src/commands/package.ts +234 -234
  41. package/src/commands/publish.ts +330 -330
  42. package/src/commands/settings.ts +73 -73
  43. package/src/commands/start.ts +43 -43
  44. package/src/commands/test.ts +37 -37
  45. package/src/commands/user.ts +20 -20
  46. package/src/expressRoutes/all.ts +99 -99
  47. package/src/expressRoutes/api.ts +22 -22
  48. package/src/expressRoutes/functionBinder.ts +155 -156
  49. package/src/integration-tests/quickstart-scenario.test.ts +74 -0
  50. package/src/lib/CaseUtils.ts +63 -63
  51. package/src/lib/DirectoryUtils.ts +34 -34
  52. package/src/lib/LiftConfig.ts +74 -74
  53. package/src/lib/LiftVersion.ts +87 -87
  54. package/src/lib/Tests/fileCompare.test.ts +35 -35
  55. package/src/lib/askQuestion.ts +17 -17
  56. package/src/lib/executeCommand.ts +45 -45
  57. package/src/lib/fileCompare.ts +55 -55
  58. package/src/lib/openAPI/ApiBuildCollector.ts +47 -47
  59. package/src/lib/openAPI/WebrootFileSupport.ts +19 -19
  60. package/src/lib/openAPI/openApiConstruction.ts +196 -196
  61. package/src/lib/pathResolve.ts +26 -26
  62. package/src/lib/utils.ts +43 -43
  63. package/src/lift.ts +87 -87
  64. package/templateData/function-definition-template +20 -20
  65. package/templateData/function-local-ts +16 -16
  66. package/templateData/function-main-ts +16 -16
  67. package/templateData/function-runmain-mjs +6 -6
  68. package/templateData/function-test-template +11 -11
  69. package/templateData/swagger-ui-bundle.js +2 -2
  70. package/templateData/swagger-ui-standalone-preset.js +2 -2
  71. package/templateData/swagger-ui.css +2 -2
  72. package/tsconfig.json +28 -28
  73. /package/build/commands/builtin/{prebuilt-zips → prebult-zips}/API.zip +0 -0
  74. /package/build/commands/builtin/{prebuilt-zips → prebult-zips}/FileServe.zip +0 -0
  75. /package/build/commands/builtin/{prebuilt-zips → prebult-zips}/Webroot.zip +0 -0
@@ -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) => {
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
- 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
+ }