@tremho/mist-lift 1.1.4 → 1.1.6-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 +70 -66
  3. package/build/commands/actions/initQuestions.js.map +1 -0
  4. package/build/commands/actions/makePackageJson.js.map +1 -0
  5. package/build/commands/actions/setupPackageJson.js.map +1 -0
  6. package/build/commands/build.js.map +1 -0
  7. package/build/{src/commands → commands}/builtin/ApiDocMaker.js +0 -1
  8. package/build/commands/builtin/ApiDocMaker.js.map +1 -0
  9. package/build/commands/builtin/BuiltInHandler.js.map +1 -0
  10. package/build/commands/builtin/DeployBuiltInZip.js.map +1 -0
  11. package/build/commands/builtin/StageWebrootZip.js.map +1 -0
  12. package/build/commands/create.js.map +1 -0
  13. package/build/commands/deploy.js.map +1 -0
  14. package/build/{src/commands → commands}/doctor.js +12 -1
  15. package/build/commands/doctor.js.map +1 -0
  16. package/build/commands/help.js.map +1 -0
  17. package/build/commands/info.js.map +1 -0
  18. package/build/{src/commands → commands}/init.js +1 -2
  19. package/build/commands/init.js.map +1 -0
  20. package/build/commands/package.js.map +1 -0
  21. package/build/commands/publish.js.map +1 -0
  22. package/build/commands/settings.js.map +1 -0
  23. package/build/commands/start.js.map +1 -0
  24. package/build/commands/test.js.map +1 -0
  25. package/build/commands/user.js.map +1 -0
  26. package/build/expressRoutes/all.js.map +1 -0
  27. package/build/expressRoutes/api.js.map +1 -0
  28. package/build/expressRoutes/functionBinder.js.map +1 -0
  29. package/build/integration-tests/quickstart-scenario.test.js.map +1 -0
  30. package/build/lib/CaseUtils.js.map +1 -0
  31. package/build/lib/DirectoryUtils.js.map +1 -0
  32. package/build/lib/LiftConfig.js.map +1 -0
  33. package/build/{src/lib → lib}/LiftVersion.js +1 -1
  34. package/build/lib/LiftVersion.js.map +1 -0
  35. package/build/lib/Tests/fileCompare.test.js.map +1 -0
  36. package/build/lib/askQuestion.js.map +1 -0
  37. package/build/lib/executeCommand.js.map +1 -0
  38. package/build/lib/fileCompare.js.map +1 -0
  39. package/build/lib/openAPI/ApiBuildCollector.js.map +1 -0
  40. package/build/lib/openAPI/WebrootFileSupport.js.map +1 -0
  41. package/build/lib/openAPI/openApiConstruction.js.map +1 -0
  42. package/build/lib/pathResolve.js.map +1 -0
  43. package/build/lib/utils.js.map +1 -0
  44. package/build/{src/lift.js → lift.js} +0 -0
  45. package/build/lift.js.map +1 -0
  46. package/package.json +78 -79
  47. package/src/commands/actions/initQuestions.ts +133 -133
  48. package/src/commands/actions/setupPackageJson.ts +32 -32
  49. package/src/commands/build.ts +173 -173
  50. package/src/commands/builtin/ApiDocMaker.ts +105 -106
  51. package/src/commands/builtin/BuiltInHandler.ts +47 -47
  52. package/src/commands/builtin/DeployBuiltInZip.ts +25 -25
  53. package/src/commands/builtin/StageWebrootZip.ts +36 -36
  54. package/src/commands/create.ts +52 -52
  55. package/src/commands/deploy.ts +161 -161
  56. package/src/commands/doctor.ts +118 -107
  57. package/src/commands/help.ts +178 -178
  58. package/src/commands/info.ts +42 -42
  59. package/src/commands/init.ts +60 -61
  60. package/src/commands/package.ts +234 -234
  61. package/src/commands/publish.ts +330 -330
  62. package/src/commands/settings.ts +73 -73
  63. package/src/commands/start.ts +43 -43
  64. package/src/commands/test.ts +37 -37
  65. package/src/commands/user.ts +20 -20
  66. package/src/expressRoutes/all.ts +99 -99
  67. package/src/expressRoutes/api.ts +22 -22
  68. package/src/expressRoutes/functionBinder.ts +155 -155
  69. package/src/integration-tests/quickstart-scenario.test.ts +76 -76
  70. package/src/lib/CaseUtils.ts +63 -63
  71. package/src/lib/DirectoryUtils.ts +34 -34
  72. package/src/lib/LiftConfig.ts +74 -74
  73. package/src/lib/LiftVersion.ts +87 -87
  74. package/src/lib/Tests/fileCompare.test.ts +35 -35
  75. package/src/lib/askQuestion.ts +17 -17
  76. package/src/lib/executeCommand.ts +45 -45
  77. package/src/lib/fileCompare.ts +55 -55
  78. package/src/lib/openAPI/ApiBuildCollector.ts +47 -47
  79. package/src/lib/openAPI/WebrootFileSupport.ts +19 -19
  80. package/src/lib/openAPI/openApiConstruction.ts +196 -196
  81. package/src/lib/pathResolve.ts +26 -26
  82. package/src/lib/utils.ts +43 -43
  83. package/src/lift.ts +87 -87
  84. package/templateData/function-definition-template +20 -20
  85. package/templateData/function-local-ts +16 -16
  86. package/templateData/function-main-ts +16 -16
  87. package/templateData/function-runmain-mjs +6 -6
  88. package/templateData/function-test-template +11 -11
  89. package/templateData/swagger-ui-bundle.js +2 -2
  90. package/templateData/swagger-ui-standalone-preset.js +2 -2
  91. package/templateData/swagger-ui.css +2 -2
  92. package/tsconfig.json +28 -28
  93. package/build/QSTest/functions/IntegrationTest/integrationTest-tests/Sanity.test.js +0 -14
  94. package/build/QSTest/functions/IntegrationTest/integrationTest-tests/Sanity.test.js.map +0 -1
  95. package/build/QSTest/functions/IntegrationTest/src/local.js +0 -33
  96. package/build/QSTest/functions/IntegrationTest/src/local.js.map +0 -1
  97. package/build/QSTest/functions/IntegrationTest/src/main.js +0 -29
  98. package/build/QSTest/functions/IntegrationTest/src/main.js.map +0 -1
  99. package/build/src/commands/actions/initQuestions.js.map +0 -1
  100. package/build/src/commands/actions/makePackageJson.js.map +0 -1
  101. package/build/src/commands/actions/setupPackageJson.js.map +0 -1
  102. package/build/src/commands/build.js.map +0 -1
  103. package/build/src/commands/builtin/ApiDocMaker.js.map +0 -1
  104. package/build/src/commands/builtin/BuiltInHandler.js.map +0 -1
  105. package/build/src/commands/builtin/DeployBuiltInZip.js.map +0 -1
  106. package/build/src/commands/builtin/StageWebrootZip.js.map +0 -1
  107. package/build/src/commands/create.js.map +0 -1
  108. package/build/src/commands/deploy.js.map +0 -1
  109. package/build/src/commands/doctor.js.map +0 -1
  110. package/build/src/commands/help.js.map +0 -1
  111. package/build/src/commands/info.js.map +0 -1
  112. package/build/src/commands/init.js.map +0 -1
  113. package/build/src/commands/package.js.map +0 -1
  114. package/build/src/commands/publish.js.map +0 -1
  115. package/build/src/commands/settings.js.map +0 -1
  116. package/build/src/commands/start.js.map +0 -1
  117. package/build/src/commands/test.js.map +0 -1
  118. package/build/src/commands/user.js.map +0 -1
  119. package/build/src/expressRoutes/all.js.map +0 -1
  120. package/build/src/expressRoutes/api.js.map +0 -1
  121. package/build/src/expressRoutes/functionBinder.js.map +0 -1
  122. package/build/src/integration-tests/quickstart-scenario.test.js.map +0 -1
  123. package/build/src/lib/CaseUtils.js.map +0 -1
  124. package/build/src/lib/DirectoryUtils.js.map +0 -1
  125. package/build/src/lib/LiftConfig.js.map +0 -1
  126. package/build/src/lib/LiftVersion.js.map +0 -1
  127. package/build/src/lib/Tests/fileCompare.test.js.map +0 -1
  128. package/build/src/lib/askQuestion.js.map +0 -1
  129. package/build/src/lib/executeCommand.js.map +0 -1
  130. package/build/src/lib/fileCompare.js.map +0 -1
  131. package/build/src/lib/openAPI/ApiBuildCollector.js.map +0 -1
  132. package/build/src/lib/openAPI/WebrootFileSupport.js.map +0 -1
  133. package/build/src/lib/openAPI/openApiConstruction.js.map +0 -1
  134. package/build/src/lib/pathResolve.js.map +0 -1
  135. package/build/src/lib/utils.js.map +0 -1
  136. package/build/src/lift.js.map +0 -1
  137. /package/build/{src/commands → commands}/actions/initQuestions.js +0 -0
  138. /package/build/{src/commands → commands}/actions/makePackageJson.js +0 -0
  139. /package/build/{src/commands → commands}/actions/setupPackageJson.js +0 -0
  140. /package/build/{src/commands → commands}/build.js +0 -0
  141. /package/build/{src/commands → commands}/builtin/BuiltInHandler.js +0 -0
  142. /package/build/{src/commands → commands}/builtin/DeployBuiltInZip.js +0 -0
  143. /package/build/{src/commands → commands}/builtin/StageWebrootZip.js +0 -0
  144. /package/build/{src/commands → commands}/create.js +0 -0
  145. /package/build/{src/commands → commands}/deploy.js +0 -0
  146. /package/build/{src/commands → commands}/help.js +0 -0
  147. /package/build/{src/commands → commands}/info.js +0 -0
  148. /package/build/{src/commands → commands}/package.js +0 -0
  149. /package/build/{src/commands → commands}/publish.js +0 -0
  150. /package/build/{src/commands → commands}/settings.js +0 -0
  151. /package/build/{src/commands → commands}/start.js +0 -0
  152. /package/build/{src/commands → commands}/test.js +0 -0
  153. /package/build/{src/commands → commands}/user.js +0 -0
  154. /package/build/{src/expressRoutes → expressRoutes}/all.js +0 -0
  155. /package/build/{src/expressRoutes → expressRoutes}/api.js +0 -0
  156. /package/build/{src/expressRoutes → expressRoutes}/functionBinder.js +0 -0
  157. /package/build/{src/integration-tests → integration-tests}/quickstart-scenario.test.js +0 -0
  158. /package/build/{src/lib → lib}/CaseUtils.js +0 -0
  159. /package/build/{src/lib → lib}/DirectoryUtils.js +0 -0
  160. /package/build/{src/lib → lib}/LiftConfig.js +0 -0
  161. /package/build/{src/lib → lib}/Tests/fileCompare.test.js +0 -0
  162. /package/build/{src/lib → lib}/askQuestion.js +0 -0
  163. /package/build/{src/lib → lib}/executeCommand.js +0 -0
  164. /package/build/{src/lib → lib}/fileCompare.js +0 -0
  165. /package/build/{src/lib → lib}/openAPI/ApiBuildCollector.js +0 -0
  166. /package/build/{src/lib → lib}/openAPI/WebrootFileSupport.js +0 -0
  167. /package/build/{src/lib → lib}/openAPI/openApiConstruction.js +0 -0
  168. /package/build/{src/lib → lib}/pathResolve.js +0 -0
  169. /package/build/{src/lib → lib}/utils.js +0 -0
@@ -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
+ }