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