@tremho/mist-lift 1.1.2 → 1.1.4-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 (169) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +66 -65
  3. package/build/QSTest/functions/IntegrationTest/integrationTest-tests/Sanity.test.js +14 -0
  4. package/build/QSTest/functions/IntegrationTest/integrationTest-tests/Sanity.test.js.map +1 -0
  5. package/build/QSTest/functions/IntegrationTest/src/local.js +33 -0
  6. package/build/QSTest/functions/IntegrationTest/src/local.js.map +1 -0
  7. package/build/QSTest/functions/IntegrationTest/src/main.js +29 -0
  8. package/build/QSTest/functions/IntegrationTest/src/main.js.map +1 -0
  9. package/build/{commands → src/commands}/actions/initQuestions.js +1 -1
  10. package/build/src/commands/actions/initQuestions.js.map +1 -0
  11. package/build/src/commands/actions/makePackageJson.js.map +1 -0
  12. package/build/src/commands/actions/setupPackageJson.js.map +1 -0
  13. package/build/{commands → src/commands}/build.js +7 -6
  14. package/build/src/commands/build.js.map +1 -0
  15. package/build/{commands → src/commands}/builtin/ApiDocMaker.js +9 -3
  16. package/build/src/commands/builtin/ApiDocMaker.js.map +1 -0
  17. package/build/src/commands/builtin/BuiltInHandler.js.map +1 -0
  18. package/build/src/commands/builtin/DeployBuiltInZip.js.map +1 -0
  19. package/build/src/commands/builtin/StageWebrootZip.js.map +1 -0
  20. package/build/src/commands/create.js.map +1 -0
  21. package/build/src/commands/deploy.js.map +1 -0
  22. package/build/{commands → src/commands}/doctor.js +2 -1
  23. package/build/src/commands/doctor.js.map +1 -0
  24. package/build/src/commands/help.js.map +1 -0
  25. package/build/src/commands/info.js.map +1 -0
  26. package/build/src/commands/init.js.map +1 -0
  27. package/build/src/commands/package.js.map +1 -0
  28. package/build/src/commands/publish.js.map +1 -0
  29. package/build/src/commands/settings.js.map +1 -0
  30. package/build/src/commands/start.js.map +1 -0
  31. package/build/src/commands/test.js.map +1 -0
  32. package/build/src/commands/user.js.map +1 -0
  33. package/build/src/expressRoutes/all.js.map +1 -0
  34. package/build/src/expressRoutes/api.js.map +1 -0
  35. package/build/src/expressRoutes/functionBinder.js.map +1 -0
  36. package/build/{integration-tests → src/integration-tests}/quickstart-scenario.test.js +13 -11
  37. package/build/src/integration-tests/quickstart-scenario.test.js.map +1 -0
  38. package/build/src/lib/CaseUtils.js.map +1 -0
  39. package/build/src/lib/DirectoryUtils.js.map +1 -0
  40. package/build/src/lib/LiftConfig.js.map +1 -0
  41. package/build/src/lib/LiftVersion.js.map +1 -0
  42. package/build/src/lib/Tests/fileCompare.test.js.map +1 -0
  43. package/build/src/lib/askQuestion.js.map +1 -0
  44. package/build/src/lib/executeCommand.js.map +1 -0
  45. package/build/src/lib/fileCompare.js.map +1 -0
  46. package/build/src/lib/openAPI/ApiBuildCollector.js.map +1 -0
  47. package/build/src/lib/openAPI/WebrootFileSupport.js.map +1 -0
  48. package/build/src/lib/openAPI/openApiConstruction.js.map +1 -0
  49. package/build/src/lib/pathResolve.js.map +1 -0
  50. package/build/src/lib/utils.js.map +1 -0
  51. package/build/{lift.js → src/lift.js} +0 -0
  52. package/build/src/lift.js.map +1 -0
  53. package/package.json +79 -75
  54. package/src/commands/actions/initQuestions.ts +133 -133
  55. package/src/commands/actions/setupPackageJson.ts +32 -32
  56. package/src/commands/build.ts +173 -170
  57. package/src/commands/builtin/ApiDocMaker.ts +106 -102
  58. package/src/commands/builtin/BuiltInHandler.ts +47 -47
  59. package/src/commands/builtin/DeployBuiltInZip.ts +25 -25
  60. package/src/commands/builtin/StageWebrootZip.ts +36 -36
  61. package/src/commands/create.ts +52 -52
  62. package/src/commands/deploy.ts +161 -161
  63. package/src/commands/doctor.ts +107 -106
  64. package/src/commands/help.ts +178 -178
  65. package/src/commands/info.ts +42 -42
  66. package/src/commands/init.ts +61 -61
  67. package/src/commands/package.ts +234 -234
  68. package/src/commands/publish.ts +330 -330
  69. package/src/commands/settings.ts +73 -73
  70. package/src/commands/start.ts +43 -43
  71. package/src/commands/test.ts +37 -37
  72. package/src/commands/user.ts +20 -20
  73. package/src/expressRoutes/all.ts +99 -99
  74. package/src/expressRoutes/api.ts +22 -22
  75. package/src/expressRoutes/functionBinder.ts +155 -155
  76. package/src/integration-tests/quickstart-scenario.test.ts +76 -74
  77. package/src/lib/CaseUtils.ts +63 -63
  78. package/src/lib/DirectoryUtils.ts +34 -34
  79. package/src/lib/LiftConfig.ts +74 -74
  80. package/src/lib/LiftVersion.ts +87 -87
  81. package/src/lib/Tests/fileCompare.test.ts +35 -35
  82. package/src/lib/askQuestion.ts +17 -17
  83. package/src/lib/executeCommand.ts +45 -45
  84. package/src/lib/fileCompare.ts +55 -55
  85. package/src/lib/openAPI/ApiBuildCollector.ts +47 -47
  86. package/src/lib/openAPI/WebrootFileSupport.ts +19 -19
  87. package/src/lib/openAPI/openApiConstruction.ts +196 -196
  88. package/src/lib/pathResolve.ts +26 -26
  89. package/src/lib/utils.ts +43 -43
  90. package/src/lift.ts +87 -87
  91. package/templateData/function-definition-template +20 -20
  92. package/templateData/function-local-ts +16 -16
  93. package/templateData/function-main-ts +16 -16
  94. package/templateData/function-runmain-mjs +6 -6
  95. package/templateData/function-test-template +11 -11
  96. package/templateData/swagger-ui-bundle.js +2 -2
  97. package/templateData/swagger-ui-standalone-preset.js +2 -2
  98. package/templateData/swagger-ui.css +2 -2
  99. package/tsconfig.json +28 -28
  100. package/build/commands/actions/initQuestions.js.map +0 -1
  101. package/build/commands/actions/makePackageJson.js.map +0 -1
  102. package/build/commands/actions/setupPackageJson.js.map +0 -1
  103. package/build/commands/build.js.map +0 -1
  104. package/build/commands/builtin/ApiDocMaker.js.map +0 -1
  105. package/build/commands/builtin/BuiltInHandler.js.map +0 -1
  106. package/build/commands/builtin/DeployBuiltInZip.js.map +0 -1
  107. package/build/commands/builtin/StageWebrootZip.js.map +0 -1
  108. package/build/commands/create.js.map +0 -1
  109. package/build/commands/deploy.js.map +0 -1
  110. package/build/commands/doctor.js.map +0 -1
  111. package/build/commands/help.js.map +0 -1
  112. package/build/commands/info.js.map +0 -1
  113. package/build/commands/init.js.map +0 -1
  114. package/build/commands/package.js.map +0 -1
  115. package/build/commands/publish.js.map +0 -1
  116. package/build/commands/settings.js.map +0 -1
  117. package/build/commands/start.js.map +0 -1
  118. package/build/commands/test.js.map +0 -1
  119. package/build/commands/user.js.map +0 -1
  120. package/build/expressRoutes/all.js.map +0 -1
  121. package/build/expressRoutes/api.js.map +0 -1
  122. package/build/expressRoutes/functionBinder.js.map +0 -1
  123. package/build/integration-tests/quickstart-scenario.test.js.map +0 -1
  124. package/build/lib/CaseUtils.js.map +0 -1
  125. package/build/lib/DirectoryUtils.js.map +0 -1
  126. package/build/lib/LiftConfig.js.map +0 -1
  127. package/build/lib/LiftVersion.js.map +0 -1
  128. package/build/lib/Tests/fileCompare.test.js.map +0 -1
  129. package/build/lib/askQuestion.js.map +0 -1
  130. package/build/lib/executeCommand.js.map +0 -1
  131. package/build/lib/fileCompare.js.map +0 -1
  132. package/build/lib/openAPI/ApiBuildCollector.js.map +0 -1
  133. package/build/lib/openAPI/WebrootFileSupport.js.map +0 -1
  134. package/build/lib/openAPI/openApiConstruction.js.map +0 -1
  135. package/build/lib/pathResolve.js.map +0 -1
  136. package/build/lib/utils.js.map +0 -1
  137. package/build/lift.js.map +0 -1
  138. /package/build/{commands → src/commands}/actions/makePackageJson.js +0 -0
  139. /package/build/{commands → src/commands}/actions/setupPackageJson.js +0 -0
  140. /package/build/{commands → src/commands}/builtin/BuiltInHandler.js +0 -0
  141. /package/build/{commands → src/commands}/builtin/DeployBuiltInZip.js +0 -0
  142. /package/build/{commands → src/commands}/builtin/StageWebrootZip.js +0 -0
  143. /package/build/{commands → src/commands}/create.js +0 -0
  144. /package/build/{commands → src/commands}/deploy.js +0 -0
  145. /package/build/{commands → src/commands}/help.js +0 -0
  146. /package/build/{commands → src/commands}/info.js +0 -0
  147. /package/build/{commands → src/commands}/init.js +0 -0
  148. /package/build/{commands → src/commands}/package.js +0 -0
  149. /package/build/{commands → src/commands}/publish.js +0 -0
  150. /package/build/{commands → src/commands}/settings.js +0 -0
  151. /package/build/{commands → src/commands}/start.js +0 -0
  152. /package/build/{commands → src/commands}/test.js +0 -0
  153. /package/build/{commands → src/commands}/user.js +0 -0
  154. /package/build/{expressRoutes → src/expressRoutes}/all.js +0 -0
  155. /package/build/{expressRoutes → src/expressRoutes}/api.js +0 -0
  156. /package/build/{expressRoutes → src/expressRoutes}/functionBinder.js +0 -0
  157. /package/build/{lib → src/lib}/CaseUtils.js +0 -0
  158. /package/build/{lib → src/lib}/DirectoryUtils.js +0 -0
  159. /package/build/{lib → src/lib}/LiftConfig.js +0 -0
  160. /package/build/{lib → src/lib}/LiftVersion.js +0 -0
  161. /package/build/{lib → src/lib}/Tests/fileCompare.test.js +0 -0
  162. /package/build/{lib → src/lib}/askQuestion.js +0 -0
  163. /package/build/{lib → src/lib}/executeCommand.js +0 -0
  164. /package/build/{lib → src/lib}/fileCompare.js +0 -0
  165. /package/build/{lib → src/lib}/openAPI/ApiBuildCollector.js +0 -0
  166. /package/build/{lib → src/lib}/openAPI/WebrootFileSupport.js +0 -0
  167. /package/build/{lib → src/lib}/openAPI/openApiConstruction.js +0 -0
  168. /package/build/{lib → src/lib}/pathResolve.js +0 -0
  169. /package/build/{lib → src/lib}/utils.js +0 -0
@@ -1,47 +1,47 @@
1
- import { StageWebrootZip } from './StageWebrootZip'
2
- import { DeployBuiltInZip } from './DeployBuiltInZip'
3
- import { GetWebrootServePaths } from '../../lib/openAPI/WebrootFileSupport'
4
-
5
- import fs from 'fs'
6
- import path from 'path'
7
-
8
- export async function DeployWebrootBuiltIn
9
- (
10
- ): Promise<void> {
11
- const wrZip = await StageWebrootZip()
12
- // console.log("Deploy Webroot Builtin from "+wrZip)
13
- await DeployBuiltInZip('Webroot', wrZip)
14
- // remove temp zip when done
15
- fs.rmSync(wrZip, { recursive: true })
16
- }
17
-
18
- export async function DeployRootFileserves
19
- (
20
- ): Promise<void> {
21
- // console.log("Deploy Root Fileserves")
22
- // Get root paths
23
- const roots = GetWebrootServePaths()
24
- // for each, deploy under the name of each
25
- const fileserveZip = path.join(__dirname, 'prebuilt-zips', 'FileServe.zip')
26
- const all: Array<Promise<any>> = []
27
- for (let root of roots) {
28
- root = root.trim()
29
- let name = 'fileserve_' + root
30
- while (name.includes('/')) {
31
- name = name.replace('/', '')
32
- }
33
- all.push(DeployBuiltInZip(name, fileserveZip))
34
- }
35
- // console.log('wait all');
36
- await Promise.all(all)
37
- // console.log('all complete');
38
- }
39
-
40
- export async function DeployApiBuiltin
41
- (
42
- ): Promise<any> {
43
- console.log('Deploy API Builtin')
44
- // get the prebuilt zip location
45
- const apiZip = path.join(__dirname, 'prebuilt-zips', 'API.zip')
46
- await DeployBuiltInZip('api', apiZip)
47
- }
1
+ import { StageWebrootZip } from './StageWebrootZip'
2
+ import { DeployBuiltInZip } from './DeployBuiltInZip'
3
+ import { GetWebrootServePaths } from '../../lib/openAPI/WebrootFileSupport'
4
+
5
+ import fs from 'fs'
6
+ import path from 'path'
7
+
8
+ export async function DeployWebrootBuiltIn
9
+ (
10
+ ): Promise<void> {
11
+ const wrZip = await StageWebrootZip()
12
+ // console.log("Deploy Webroot Builtin from "+wrZip)
13
+ await DeployBuiltInZip('Webroot', wrZip)
14
+ // remove temp zip when done
15
+ fs.rmSync(wrZip, { recursive: true })
16
+ }
17
+
18
+ export async function DeployRootFileserves
19
+ (
20
+ ): Promise<void> {
21
+ // console.log("Deploy Root Fileserves")
22
+ // Get root paths
23
+ const roots = GetWebrootServePaths()
24
+ // for each, deploy under the name of each
25
+ const fileserveZip = path.join(__dirname, 'prebuilt-zips', 'FileServe.zip')
26
+ const all: Array<Promise<any>> = []
27
+ for (let root of roots) {
28
+ root = root.trim()
29
+ let name = 'fileserve_' + root
30
+ while (name.includes('/')) {
31
+ name = name.replace('/', '')
32
+ }
33
+ all.push(DeployBuiltInZip(name, fileserveZip))
34
+ }
35
+ // console.log('wait all');
36
+ await Promise.all(all)
37
+ // console.log('all complete');
38
+ }
39
+
40
+ export async function DeployApiBuiltin
41
+ (
42
+ ): Promise<any> {
43
+ console.log('Deploy API Builtin')
44
+ // get the prebuilt zip location
45
+ const apiZip = path.join(__dirname, 'prebuilt-zips', 'API.zip')
46
+ await DeployBuiltInZip('api', apiZip)
47
+ }
@@ -1,25 +1,25 @@
1
-
2
- import * as path from 'path'
3
- import { deployPackage } from '../deploy'
4
-
5
- export async function DeployBuiltInZip
6
- (
7
- name: string,
8
- zipPath: string
9
- ): Promise<void> {
10
- // console.log(">> Deploying "+name)
11
- await deployPackage(name, zipPath)
12
- }
13
-
14
- export async function DeployFileserve
15
- (
16
- root: string
17
- ): Promise<void> {
18
- // rootName is without slash
19
- if (root !== '') {
20
- const rootName = root.replace('/', '')
21
- const name = 'fileserve_' + rootName
22
- const zipPath = path.join(__dirname, 'prebuilt-zips', 'FileServe.zip')
23
- await DeployBuiltInZip(name, zipPath)
24
- }
25
- }
1
+
2
+ import * as path from 'path'
3
+ import { deployPackage } from '../deploy'
4
+
5
+ export async function DeployBuiltInZip
6
+ (
7
+ name: string,
8
+ zipPath: string
9
+ ): Promise<void> {
10
+ // console.log(">> Deploying "+name)
11
+ await deployPackage(name, zipPath)
12
+ }
13
+
14
+ export async function DeployFileserve
15
+ (
16
+ root: string
17
+ ): Promise<void> {
18
+ // rootName is without slash
19
+ if (root !== '') {
20
+ const rootName = root.replace('/', '')
21
+ const name = 'fileserve_' + rootName
22
+ const zipPath = path.join(__dirname, 'prebuilt-zips', 'FileServe.zip')
23
+ await DeployBuiltInZip(name, zipPath)
24
+ }
25
+ }
@@ -1,36 +1,36 @@
1
- import { MakePublicApiDoc } from './ApiDocMaker'
2
-
3
- import * as path from 'path'
4
- import * as fs from 'fs'
5
- import { resolvePaths } from '../../lib/pathResolve'
6
- import { recurseDirectory } from '../../lib/DirectoryUtils'
7
- import { FolderToZip, UnzipToFolder } from '../../lib/utils'
8
-
9
- export async function StageWebrootZip
10
- (
11
- ): Promise<string> {
12
- // console.log(">> staging webroot to zip")
13
- const projectPaths = resolvePaths()
14
- // make a public yaml
15
- await MakePublicApiDoc() // writes apidoc.yaml to docs
16
- const builtinPath = path.join(__dirname, 'prebuilt-zips', 'Webroot.zip')
17
- const exdir = path.join(projectPaths.basePath, '.package_temp')
18
- await UnzipToFolder(builtinPath, exdir)
19
- const webroot = path.join(projectPaths.basePath, 'webroot')
20
- const packageTemp = path.join(projectPaths.basePath, '.package_temp')
21
- const zipFilesPath = path.join(packageTemp, 'Webroot', '__files__')
22
- await recurseDirectory(webroot, (filepath, stats) => {
23
- const relPath = filepath.substring(webroot.length)
24
- if (stats.isDirectory()) {
25
- fs.mkdirSync(zipFilesPath + relPath, { recursive: true })
26
- } else {
27
- fs.copyFileSync(filepath, zipFilesPath + relPath)
28
- }
29
- return false
30
- })
31
- const webrootZip = path.join(projectPaths.basePath, 'a.zip')
32
-
33
- await FolderToZip(path.join(packageTemp, 'Webroot'), webrootZip)
34
- // return path to this zip
35
- return webrootZip
36
- }
1
+ import { MakePublicApiDoc } from './ApiDocMaker'
2
+
3
+ import * as path from 'path'
4
+ import * as fs from 'fs'
5
+ import { resolvePaths } from '../../lib/pathResolve'
6
+ import { recurseDirectory } from '../../lib/DirectoryUtils'
7
+ import { FolderToZip, UnzipToFolder } from '../../lib/utils'
8
+
9
+ export async function StageWebrootZip
10
+ (
11
+ ): Promise<string> {
12
+ // console.log(">> staging webroot to zip")
13
+ const projectPaths = resolvePaths()
14
+ // make a public yaml
15
+ await MakePublicApiDoc() // writes apidoc.yaml to docs
16
+ const builtinPath = path.join(__dirname, 'prebuilt-zips', 'Webroot.zip')
17
+ const exdir = path.join(projectPaths.basePath, '.package_temp')
18
+ await UnzipToFolder(builtinPath, exdir)
19
+ const webroot = path.join(projectPaths.basePath, 'webroot')
20
+ const packageTemp = path.join(projectPaths.basePath, '.package_temp')
21
+ const zipFilesPath = path.join(packageTemp, 'Webroot', '__files__')
22
+ await recurseDirectory(webroot, (filepath, stats) => {
23
+ const relPath = filepath.substring(webroot.length)
24
+ if (stats.isDirectory()) {
25
+ fs.mkdirSync(zipFilesPath + relPath, { recursive: true })
26
+ } else {
27
+ fs.copyFileSync(filepath, zipFilesPath + relPath)
28
+ }
29
+ return false
30
+ })
31
+ const webrootZip = path.join(projectPaths.basePath, 'a.zip')
32
+
33
+ await FolderToZip(path.join(packageTemp, 'Webroot'), webrootZip)
34
+ // return path to this zip
35
+ return webrootZip
36
+ }
@@ -1,52 +1,52 @@
1
- /** Handles fucntion creation via the create command */
2
-
3
- import * as fs from 'fs'
4
- import * as path from 'path'
5
- import * as ac from 'ansi-colors'
6
- import { resolvePaths } from '../lib/pathResolve'
7
- import { camelCase } from '../lib/CaseUtils'
8
- import { helpCreate } from './help'
9
-
10
- /// Create command
11
- export function doCreate (
12
- funcName?: string // name of function to create
13
- ): void {
14
- if (funcName === '' || funcName === undefined) {
15
- helpCreate()
16
- } else {
17
- console.log(ac.green.bold('Creating new function named ') + funcName)
18
-
19
- const projectPaths = resolvePaths()
20
- if (!projectPaths.verified) {
21
- console.log(ac.bold.magenta('current directory is not at project root'))
22
- return
23
- }
24
- const funcPath = path.join(projectPaths.functionPath, funcName)
25
- if (!fs.existsSync(funcPath)) fs.mkdirSync(funcPath)
26
- const dataDir = path.join(__dirname, '..', '..', 'templateData')
27
-
28
- const testdirname = camelCase(funcName) + '-tests'
29
- if (!fs.existsSync(path.join(funcPath, testdirname))) fs.mkdirSync(path.join(funcPath, testdirname))
30
- if (!fs.existsSync(path.join(funcPath, 'src'))) fs.mkdirSync(path.join(funcPath, 'src'))
31
-
32
- let localsrc = fs.readFileSync(path.join(dataDir, 'function-local-ts')).toString()
33
- while (localsrc.includes('$$FUNCTION_NAME$$')) {
34
- localsrc = localsrc.replace('$$FUNCTION_NAME$$', funcName)
35
- }
36
- fs.writeFileSync(path.join(funcPath, 'src', 'local.ts'), localsrc)
37
- let defsrc = fs.readFileSync(path.join(dataDir, 'function-definition-template')).toString()
38
- while (defsrc.includes('$$FUNCTION_NAME$$')) {
39
- defsrc = defsrc.replace('$$FUNCTION_NAME$$', funcName)
40
- }
41
- const defpathMap = '/' + funcName.toLowerCase()
42
- defsrc = defsrc.replace('$$PATHMAP$$', defpathMap)
43
- fs.writeFileSync(path.join(funcPath, 'src', 'definition.json'), defsrc)
44
- let mainsrc = fs.readFileSync(path.join(dataDir, 'function-main-ts')).toString()
45
- while (mainsrc.includes('$$TemplateName$$')) {
46
- mainsrc = mainsrc.replace('$$TemplateName$$', funcName)
47
- }
48
- fs.writeFileSync(path.join(funcPath, 'src', 'main.ts'), mainsrc)
49
- fs.copyFileSync(path.join(dataDir, 'function-test-template'), path.join(funcPath, testdirname, 'Sanity.test.ts'))
50
- fs.copyFileSync(path.join(dataDir, 'function-runmain-mjs'), path.join(funcPath, 'runmain.mjs'))
51
- }
52
- }
1
+ /** Handles fucntion creation via the create command */
2
+
3
+ import * as fs from 'fs'
4
+ import * as path from 'path'
5
+ import * as ac from 'ansi-colors'
6
+ import { resolvePaths } from '../lib/pathResolve'
7
+ import { camelCase } from '../lib/CaseUtils'
8
+ import { helpCreate } from './help'
9
+
10
+ /// Create command
11
+ export function doCreate (
12
+ funcName?: string // name of function to create
13
+ ): void {
14
+ if (funcName === '' || funcName === undefined) {
15
+ helpCreate()
16
+ } else {
17
+ console.log(ac.green.bold('Creating new function named ') + funcName)
18
+
19
+ const projectPaths = resolvePaths()
20
+ if (!projectPaths.verified) {
21
+ console.log(ac.bold.magenta('current directory is not at project root'))
22
+ return
23
+ }
24
+ const funcPath = path.join(projectPaths.functionPath, funcName)
25
+ if (!fs.existsSync(funcPath)) fs.mkdirSync(funcPath)
26
+ const dataDir = path.join(__dirname, '..', '..', 'templateData')
27
+
28
+ const testdirname = camelCase(funcName) + '-tests'
29
+ if (!fs.existsSync(path.join(funcPath, testdirname))) fs.mkdirSync(path.join(funcPath, testdirname))
30
+ if (!fs.existsSync(path.join(funcPath, 'src'))) fs.mkdirSync(path.join(funcPath, 'src'))
31
+
32
+ let localsrc = fs.readFileSync(path.join(dataDir, 'function-local-ts')).toString()
33
+ while (localsrc.includes('$$FUNCTION_NAME$$')) {
34
+ localsrc = localsrc.replace('$$FUNCTION_NAME$$', funcName)
35
+ }
36
+ fs.writeFileSync(path.join(funcPath, 'src', 'local.ts'), localsrc)
37
+ let defsrc = fs.readFileSync(path.join(dataDir, 'function-definition-template')).toString()
38
+ while (defsrc.includes('$$FUNCTION_NAME$$')) {
39
+ defsrc = defsrc.replace('$$FUNCTION_NAME$$', funcName)
40
+ }
41
+ const defpathMap = '/' + funcName.toLowerCase()
42
+ defsrc = defsrc.replace('$$PATHMAP$$', defpathMap)
43
+ fs.writeFileSync(path.join(funcPath, 'src', 'definition.json'), defsrc)
44
+ let mainsrc = fs.readFileSync(path.join(dataDir, 'function-main-ts')).toString()
45
+ while (mainsrc.includes('$$TemplateName$$')) {
46
+ mainsrc = mainsrc.replace('$$TemplateName$$', funcName)
47
+ }
48
+ fs.writeFileSync(path.join(funcPath, 'src', 'main.ts'), mainsrc)
49
+ fs.copyFileSync(path.join(dataDir, 'function-test-template'), path.join(funcPath, testdirname, 'Sanity.test.ts'))
50
+ fs.copyFileSync(path.join(dataDir, 'function-runmain-mjs'), path.join(funcPath, 'runmain.mjs'))
51
+ }
52
+ }
@@ -1,161 +1,161 @@
1
-
2
- import {
3
- LambdaClient,
4
- CreateFunctionCommand,
5
- DeleteFunctionCommand,
6
- AddPermissionCommand
7
- } from '@aws-sdk/client-lambda'
8
-
9
- import md5 from 'md5'
10
-
11
- import path from 'path'
12
- import fs from 'fs'
13
- import { resolvePaths } from '../lib/pathResolve'
14
-
15
- import * as ac from 'ansi-colors'
16
-
17
- import { recurseDirectory } from '../lib/DirectoryUtils'
18
- import { getProjectName, getProjectVersion } from '../lib/LiftVersion'
19
- import { delay } from '../lib/utils'
20
- import { doPackageAsync } from './package'
21
- import { getAWSCredentials, getSettings, RuntimeType } from '../lib/LiftConfig'
22
-
23
- let projectPaths: { basePath: string, buildPath: string, functionPath: string, packagePath: string, verified: boolean }
24
-
25
- let deploymentRecord: any = {} // a map of last deployment times
26
-
27
- // package then deploy
28
- export async function doDeployAsync (
29
- args: string[]
30
- ): Promise<number> {
31
- projectPaths = resolvePaths()
32
- if (!projectPaths.verified) {
33
- console.log(ac.bold.magenta('current directory is not at project root'))
34
- return -1
35
- }
36
- const deploymentRecordPath = path.join(projectPaths.basePath, '.deployed')
37
- try { deploymentRecord = JSON.parse(fs.readFileSync(deploymentRecordPath).toString()) } catch {}
38
-
39
- const funcsToDeploy: string[] = []
40
- const options: string[] = []
41
- for (const arg of args) {
42
- if (arg.charAt(0) === '-') {
43
- options.push(arg.toLowerCase())
44
- } else funcsToDeploy.push(arg)
45
- }
46
-
47
- if (!options.includes('--no-package')) {
48
- const ret = await doPackageAsync(args)
49
- if (ret !== 0) return ret
50
- else await delay(2500)
51
- }
52
-
53
- if (options.includes('--clean')) {
54
- deploymentRecord = {}
55
- }
56
-
57
- if (funcsToDeploy.length === 0) {
58
- let firstDepth = 0
59
- recurseDirectory(projectPaths.functionPath, (filepath, stats) => {
60
- const depth = filepath.split(path.sep).length
61
- if (firstDepth === 0) firstDepth = depth
62
- if (stats.isDirectory() && depth === firstDepth) {
63
- funcsToDeploy.push(path.basename(filepath))
64
- }
65
- return false
66
- })
67
- }
68
-
69
- for (const funcName of funcsToDeploy) {
70
- const zipFile = path.join(projectPaths.basePath, 'MistLift_Zips', funcName + '.zip')
71
- if (fs.existsSync(zipFile)) {
72
- const zipTime = fs.statSync(zipFile).mtime
73
- if (zipTime.getTime() > (deploymentRecord[funcName] ?? 0)) {
74
- await deployPackage(funcName)
75
- deploymentRecord[funcName] = Date.now()
76
- }
77
- } else {
78
- console.error('deploy: ' + zipFile + ac.red.bold(` ${funcName} does not exist`))
79
- return -1
80
- }
81
- }
82
-
83
- try { fs.writeFileSync(deploymentRecordPath, JSON.stringify(deploymentRecord)) } catch {}
84
-
85
- return 0
86
- }
87
-
88
- // ------------
89
-
90
- export async function deployPackage (
91
- funcName: string,
92
- zipFile?: string
93
- ): Promise<void> {
94
- // first off, anchor a base directory
95
- zipFile ??= path.join(projectPaths.basePath, 'MistLift_Zips', funcName + '.zip')
96
-
97
- // funcname gets decorated with current instance identifier
98
- const idsrc = md5((getProjectName() ?? '') + (getProjectVersion()?.toString() ?? ''))
99
- const dFuncName = funcName + '_' + idsrc
100
-
101
- // See if function exists
102
- const client: any = new LambdaClient(getAWSCredentials())
103
- const command: any = new DeleteFunctionCommand({
104
- FunctionName: dFuncName
105
- })
106
- client.send(command).then((response: any) => {
107
- }).catch((e: any) => {
108
- })
109
-
110
- // console.log(ac.green.italic("deploying ")+ac.green.bold(funcName)+"...")
111
-
112
- try {
113
- const response: any = await CreateCloudFunction(dFuncName, zipFile)
114
- const parts = response.FunctionArn.split(':')
115
- const principal = parts[4]
116
- await AddPermissions(client, dFuncName, principal)
117
- console.log(ac.green.bold(`Successfully deployed ${funcName}`))
118
- } catch (e: any) {
119
- console.error(ac.red.bold.italic('Error deploying ' + funcName), e)
120
- }
121
- }
122
- async function CreateCloudFunction (
123
- funcName: string,
124
- zipFile: string
125
-
126
- ): Promise<any> {
127
- const settings = getSettings()
128
- const nodeRuntime: RuntimeType | undefined = settings.awsNodeRuntime
129
- const serviceRole: string = settings.awsServiceRoleARN ?? ''
130
- const zipFileBase64: Uint8Array = fs.readFileSync(zipFile)
131
- const client: any = new LambdaClient(getAWSCredentials())
132
- const command: any = new CreateFunctionCommand({
133
- FunctionName: funcName,
134
- Runtime: nodeRuntime,
135
- Role: serviceRole,
136
- Handler: 'runmain.handler',
137
- Code: {
138
- ZipFile: zipFileBase64
139
- }
140
- })
141
- const resp = await client.send(command) // response
142
- return resp
143
- }
144
-
145
- async function AddPermissions (
146
- client: LambdaClient,
147
- funcName: string,
148
- principal: string
149
- ): Promise<any> {
150
- const region = getSettings().awsPreferredRegion ?? ''
151
- const WSApi = '/' + funcName.toLowerCase()
152
- const command: any = new AddPermissionCommand({
153
- FunctionName: funcName,
154
- StatementId: 'InvokePermission',
155
- Action: 'lambda:invokeFunction',
156
- Principal: 'apigateway.amazonaws.com',
157
- SourceArn: `arn:aws:execute-api:${region}:${principal}:${WSApi}`
158
- })
159
- const resp = await client.send(command)
160
- return resp
161
- }
1
+
2
+ import {
3
+ LambdaClient,
4
+ CreateFunctionCommand,
5
+ DeleteFunctionCommand,
6
+ AddPermissionCommand
7
+ } from '@aws-sdk/client-lambda'
8
+
9
+ import md5 from 'md5'
10
+
11
+ import path from 'path'
12
+ import fs from 'fs'
13
+ import { resolvePaths } from '../lib/pathResolve'
14
+
15
+ import * as ac from 'ansi-colors'
16
+
17
+ import { recurseDirectory } from '../lib/DirectoryUtils'
18
+ import { getProjectName, getProjectVersion } from '../lib/LiftVersion'
19
+ import { delay } from '../lib/utils'
20
+ import { doPackageAsync } from './package'
21
+ import { getAWSCredentials, getSettings, RuntimeType } from '../lib/LiftConfig'
22
+
23
+ let projectPaths: { basePath: string, buildPath: string, functionPath: string, packagePath: string, verified: boolean }
24
+
25
+ let deploymentRecord: any = {} // a map of last deployment times
26
+
27
+ // package then deploy
28
+ export async function doDeployAsync (
29
+ args: string[]
30
+ ): Promise<number> {
31
+ projectPaths = resolvePaths()
32
+ if (!projectPaths.verified) {
33
+ console.log(ac.bold.magenta('current directory is not at project root'))
34
+ return -1
35
+ }
36
+ const deploymentRecordPath = path.join(projectPaths.basePath, '.deployed')
37
+ try { deploymentRecord = JSON.parse(fs.readFileSync(deploymentRecordPath).toString()) } catch {}
38
+
39
+ const funcsToDeploy: string[] = []
40
+ const options: string[] = []
41
+ for (const arg of args) {
42
+ if (arg.charAt(0) === '-') {
43
+ options.push(arg.toLowerCase())
44
+ } else funcsToDeploy.push(arg)
45
+ }
46
+
47
+ if (!options.includes('--no-package')) {
48
+ const ret = await doPackageAsync(args)
49
+ if (ret !== 0) return ret
50
+ else await delay(2500)
51
+ }
52
+
53
+ if (options.includes('--clean')) {
54
+ deploymentRecord = {}
55
+ }
56
+
57
+ if (funcsToDeploy.length === 0) {
58
+ let firstDepth = 0
59
+ recurseDirectory(projectPaths.functionPath, (filepath, stats) => {
60
+ const depth = filepath.split(path.sep).length
61
+ if (firstDepth === 0) firstDepth = depth
62
+ if (stats.isDirectory() && depth === firstDepth) {
63
+ funcsToDeploy.push(path.basename(filepath))
64
+ }
65
+ return false
66
+ })
67
+ }
68
+
69
+ for (const funcName of funcsToDeploy) {
70
+ const zipFile = path.join(projectPaths.basePath, 'MistLift_Zips', funcName + '.zip')
71
+ if (fs.existsSync(zipFile)) {
72
+ const zipTime = fs.statSync(zipFile).mtime
73
+ if (zipTime.getTime() > (deploymentRecord[funcName] ?? 0)) {
74
+ await deployPackage(funcName)
75
+ deploymentRecord[funcName] = Date.now()
76
+ }
77
+ } else {
78
+ console.error('deploy: ' + zipFile + ac.red.bold(` ${funcName} does not exist`))
79
+ return -1
80
+ }
81
+ }
82
+
83
+ try { fs.writeFileSync(deploymentRecordPath, JSON.stringify(deploymentRecord)) } catch {}
84
+
85
+ return 0
86
+ }
87
+
88
+ // ------------
89
+
90
+ export async function deployPackage (
91
+ funcName: string,
92
+ zipFile?: string
93
+ ): Promise<void> {
94
+ // first off, anchor a base directory
95
+ zipFile ??= path.join(projectPaths.basePath, 'MistLift_Zips', funcName + '.zip')
96
+
97
+ // funcname gets decorated with current instance identifier
98
+ const idsrc = md5((getProjectName() ?? '') + (getProjectVersion()?.toString() ?? ''))
99
+ const dFuncName = funcName + '_' + idsrc
100
+
101
+ // See if function exists
102
+ const client: any = new LambdaClient(getAWSCredentials())
103
+ const command: any = new DeleteFunctionCommand({
104
+ FunctionName: dFuncName
105
+ })
106
+ client.send(command).then((response: any) => {
107
+ }).catch((e: any) => {
108
+ })
109
+
110
+ // console.log(ac.green.italic("deploying ")+ac.green.bold(funcName)+"...")
111
+
112
+ try {
113
+ const response: any = await CreateCloudFunction(dFuncName, zipFile)
114
+ const parts = response.FunctionArn.split(':')
115
+ const principal = parts[4]
116
+ await AddPermissions(client, dFuncName, principal)
117
+ console.log(ac.green.bold(`Successfully deployed ${funcName}`))
118
+ } catch (e: any) {
119
+ console.error(ac.red.bold.italic('Error deploying ' + funcName), e)
120
+ }
121
+ }
122
+ async function CreateCloudFunction (
123
+ funcName: string,
124
+ zipFile: string
125
+
126
+ ): Promise<any> {
127
+ const settings = getSettings()
128
+ const nodeRuntime: RuntimeType | undefined = settings.awsNodeRuntime
129
+ const serviceRole: string = settings.awsServiceRoleARN ?? ''
130
+ const zipFileBase64: Uint8Array = fs.readFileSync(zipFile)
131
+ const client: any = new LambdaClient(getAWSCredentials())
132
+ const command: any = new CreateFunctionCommand({
133
+ FunctionName: funcName,
134
+ Runtime: nodeRuntime,
135
+ Role: serviceRole,
136
+ Handler: 'runmain.handler',
137
+ Code: {
138
+ ZipFile: zipFileBase64
139
+ }
140
+ })
141
+ const resp = await client.send(command) // response
142
+ return resp
143
+ }
144
+
145
+ async function AddPermissions (
146
+ client: LambdaClient,
147
+ funcName: string,
148
+ principal: string
149
+ ): Promise<any> {
150
+ const region = getSettings().awsPreferredRegion ?? ''
151
+ const WSApi = '/' + funcName.toLowerCase()
152
+ const command: any = new AddPermissionCommand({
153
+ FunctionName: funcName,
154
+ StatementId: 'InvokePermission',
155
+ Action: 'lambda:invokeFunction',
156
+ Principal: 'apigateway.amazonaws.com',
157
+ SourceArn: `arn:aws:execute-api:${region}:${principal}:${WSApi}`
158
+ })
159
+ const resp = await client.send(command)
160
+ return resp
161
+ }