@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,32 +1,32 @@
1
- /** Adds necessary scripts to package.json */
2
-
3
- import * as path from 'path'
4
- import * as fs from 'fs'
5
- import { executeCommand } from '../../lib/executeCommand'
6
-
7
- /**
8
- * Adds necessary scripts to package.json
9
- */
10
- export function addPackageScripts (
11
- projectPath: string
12
- ): void {
13
- const pkgPath = path.join(projectPath, 'package.json')
14
- let pkgJson: any = {}
15
- try { pkgJson = JSON.parse(fs.readFileSync(pkgPath).toString()) } catch {}
16
- const script = pkgJson.script ?? {}
17
- script.test = 'lift test'
18
- pkgJson.script = script
19
- }
20
- export async function installPackage (
21
- projectPath: string,
22
- packageName: string
23
- ): Promise<void> {
24
- await executeCommand('npm', ['i', packageName], projectPath, true)
25
- }
26
-
27
- export async function installDevPackage (
28
- projectPath: string,
29
- packageName: string
30
- ): Promise<void> {
31
- await executeCommand('npm', ['i', '--save-dev', packageName], projectPath, true)
32
- }
1
+ /** Adds necessary scripts to package.json */
2
+
3
+ import * as path from 'path'
4
+ import * as fs from 'fs'
5
+ import { executeCommand } from '../../lib/executeCommand'
6
+
7
+ /**
8
+ * Adds necessary scripts to package.json
9
+ */
10
+ export function addPackageScripts (
11
+ projectPath: string
12
+ ): void {
13
+ const pkgPath = path.join(projectPath, 'package.json')
14
+ let pkgJson: any = {}
15
+ try { pkgJson = JSON.parse(fs.readFileSync(pkgPath).toString()) } catch {}
16
+ const script = pkgJson.script ?? {}
17
+ script.test = 'lift test'
18
+ pkgJson.script = script
19
+ }
20
+ export async function installPackage (
21
+ projectPath: string,
22
+ packageName: string
23
+ ): Promise<void> {
24
+ await executeCommand('npm', ['i', packageName], projectPath, true)
25
+ }
26
+
27
+ export async function installDevPackage (
28
+ projectPath: string,
29
+ packageName: string
30
+ ): Promise<void> {
31
+ await executeCommand('npm', ['i', '--save-dev', packageName], projectPath, true)
32
+ }
@@ -1,170 +1,173 @@
1
- /** handles building in the project directory */
2
-
3
- import * as path from 'path'
4
- import * as fs from 'fs'
5
- import * as ac from 'ansi-colors'
6
- import { resolvePaths } from '../lib/pathResolve'
7
- import { recurseDirectory } from '../lib/DirectoryUtils'
8
- import { isNewer } from '../lib/fileCompare'
9
- import { executeCommand } from '../lib/executeCommand'
10
- import { mkdirSync } from 'fs'
11
-
12
- // Build command
13
- export async function doBuildAsync (
14
- args: string[] // zero or more functions to build. zero means build all
15
- ): Promise<number> {
16
- const projectPaths = resolvePaths()
17
- if (!projectPaths.verified) {
18
- console.log(ac.bold.magenta('current directory is not at project root'))
19
- return -1
20
- }
21
- const funcsToBuild: string[] = []
22
- const options: string[] = []
23
- for (const arg of args) {
24
- if (arg.charAt(0) === '-') {
25
- options.push(arg.toLowerCase())
26
- } else funcsToBuild.push(arg)
27
- }
28
-
29
- if (funcsToBuild.length === 0) {
30
- let firstDepth = 0
31
- recurseDirectory(projectPaths.functionPath, (filepath, stats) => {
32
- const depth = filepath.split(path.sep).length
33
- if (firstDepth === 0) firstDepth = depth
34
- if (stats.isDirectory() && depth === firstDepth) {
35
- funcsToBuild.push(path.basename(filepath))
36
- }
37
- return false
38
- })
39
- }
40
-
41
- let failFast = options.includes('--failfast')
42
- if (options.includes('--deferfail')) failFast = false
43
-
44
- let fails = 0
45
-
46
- for (const func of funcsToBuild) {
47
- const funcDir = path.join(projectPaths.functionPath, func)
48
- if (fs.existsSync(funcDir)) {
49
- fails += await buildSingleFunction(funcDir, options)
50
- if (fails > 0 && failFast) break
51
- } else {
52
- console.log(ac.red.bold(`${func} does not exist as a function`))
53
- fails++
54
- if (failFast) break
55
- }
56
- }
57
- return fails
58
- }
59
-
60
- // build command for a single function
61
- async function buildSingleFunction (
62
- funcDir: string,
63
- options: string[]
64
- ): Promise<number> {
65
- const funcName = funcDir.substring(funcDir.lastIndexOf('/') + 1)
66
- const buildPath = path.normalize(path.join(funcDir, '..', '..', 'build', 'functions', funcName))
67
- if (options.includes('--clean')) {
68
- if (fs.existsSync(buildPath)) {
69
- fs.rmSync(buildPath, { recursive: true })
70
- }
71
- }
72
- // strategy here is to invoke tsc on a per-folder basis rather than letting tsc do the recurse because it is easier to control this way
73
- return await buildFunctionModules(funcName, funcDir, buildPath, options)
74
- }
75
-
76
- // build all the function modules in path
77
- async function buildFunctionModules (
78
- funcName: string,
79
- funcDir: string,
80
- buildPath: string,
81
- options: string[]
82
- ): Promise<number> {
83
- const announce = ac.blue.dim(`building ${funcName}...`)
84
- let announced = false
85
- let fails = 0
86
- // let builds = 0
87
- let failFast = options.includes('--failfast')
88
- if (options.includes('--deferfail')) failFast = false
89
- const all: Array<Promise<void>> = []
90
- recurseDirectory(funcDir, (filepath, stats) => {
91
- if (path.extname(filepath) === '.ts') {
92
- let relPath = filepath.substring(funcDir.length)
93
- relPath = relPath.substring(0, relPath.lastIndexOf('/'))
94
- const outDir = path.join(buildPath, relPath)
95
-
96
- if (!(fails > 0 && failFast)) {
97
- if (isNewer(filepath, outDir)) {
98
- if (!announced) {
99
- announced = true
100
- console.log(announce)
101
- }
102
- // builds++
103
- all.push(executeCommand('tsc', [
104
- '--esModuleInterop', 'true',
105
- '--target', 'ES2015',
106
- '--module', 'commonjs',
107
- '--lib', 'dom,es2015,scripthost,es2015.proxy',
108
- '--strict', 'true',
109
- '--noImplicitAny', 'false',
110
- '--skipLibCheck', 'true',
111
- '--forceConsistentCasingInFileNames', 'true',
112
- '--sourceMap', 'true',
113
- '--outdir', outDir,
114
- filepath
115
- ], '', true).then((result: { retcode: number | undefined, stdOut: string, stdErr: string }) => {
116
- if (result.retcode !== 0) {
117
- fails++
118
- // console.log("error detected", fails)
119
- const now = new Date()
120
- fs.utimesSync(filepath, now, now) // touch file so it is not skipped next build
121
- }
122
- }))
123
- }
124
- }
125
- }
126
- fails += doPostBuildSteps(funcDir, buildPath)
127
- return false
128
- })
129
- return await Promise.all(all).then(async () => {
130
- return fails
131
- })
132
- }
133
-
134
- // do the steps after the build (file copies, etc)
135
- function doPostBuildSteps (
136
- funcDir: string,
137
- buildPath: string
138
- ): number {
139
- // copy the definitions,json file over
140
- const srcdef = path.join(funcDir, 'src', 'definition.json')
141
- const dstdef = path.join(buildPath, 'src', 'definition.json')
142
- if (fs.existsSync(srcdef)) {
143
- const destFolder = path.dirname(dstdef)
144
- if (!fs.existsSync((destFolder))) mkdirSync(destFolder, { recursive: true })
145
- fs.copyFileSync(srcdef, dstdef)
146
- } else {
147
- console.error(ac.red.bold('no definition file found at ' + srcdef))
148
- return 1
149
- }
150
- // copy the resources folder if it exists
151
- const filedirPath = path.join(funcDir, 'resources')
152
- if (fs.existsSync(filedirPath)) {
153
- const bfiles = path.join(buildPath, 'resources')
154
- if (!fs.existsSync(bfiles)) fs.mkdirSync(bfiles, { recursive: true })
155
- recurseDirectory(filedirPath, (filepath, stats) => {
156
- let relPath = filepath.substring(funcDir.length)
157
- relPath = relPath.substring(0, relPath.lastIndexOf('/'))
158
- const outDir = path.join(buildPath, relPath)
159
- const target = path.join(outDir, path.basename(filepath))
160
- if (stats.isDirectory() && !fs.existsSync(target)) {
161
- fs.mkdirSync(target, { recursive: true })
162
- }
163
- if (stats.isFile()) {
164
- fs.copyFileSync(filepath, target)
165
- }
166
- return false
167
- })
168
- }
169
- return 0
170
- }
1
+ /** handles building in the project directory */
2
+
3
+ import * as path from 'path'
4
+ import * as fs from 'fs'
5
+ import * as ac from 'ansi-colors'
6
+ import { resolvePaths } from '../lib/pathResolve'
7
+ import { recurseDirectory } from '../lib/DirectoryUtils'
8
+ import { isNewer } from '../lib/fileCompare'
9
+ import { executeCommand } from '../lib/executeCommand'
10
+ import { mkdirSync } from 'fs'
11
+
12
+ let projectPaths:any = {}
13
+
14
+ // Build command
15
+ export async function doBuildAsync (
16
+ args: string[] // zero or more functions to build. zero means build all
17
+ ): Promise<number> {
18
+ projectPaths = resolvePaths();
19
+ if (!projectPaths.verified) {
20
+ console.log(ac.bold.magenta('current directory is not at project root'))
21
+ return -1
22
+ }
23
+ const funcsToBuild: string[] = []
24
+ const options: string[] = []
25
+ for (const arg of args) {
26
+ if (arg.charAt(0) === '-') {
27
+ options.push(arg.toLowerCase())
28
+ } else funcsToBuild.push(arg)
29
+ }
30
+
31
+ if (funcsToBuild.length === 0) {
32
+ let firstDepth = 0
33
+ recurseDirectory(projectPaths.functionPath, (filepath, stats) => {
34
+ const depth = filepath.split(path.sep).length
35
+ if (firstDepth === 0) firstDepth = depth
36
+ if (stats.isDirectory() && depth === firstDepth) {
37
+ funcsToBuild.push(path.basename(filepath))
38
+ }
39
+ return false
40
+ })
41
+ }
42
+
43
+ let failFast = options.includes('--failfast')
44
+ if (options.includes('--deferfail')) failFast = false
45
+
46
+ let fails = 0
47
+
48
+ for (const func of funcsToBuild) {
49
+ const funcDir = path.join(projectPaths.functionPath, func)
50
+ if (fs.existsSync(funcDir)) {
51
+ fails += await buildSingleFunction(funcDir, options)
52
+ if (fails > 0 && failFast) break
53
+ } else {
54
+ console.log(ac.red.bold(`${func} does not exist as a function`))
55
+ fails++
56
+ if (failFast) break
57
+ }
58
+ }
59
+ return fails
60
+ }
61
+
62
+ // build command for a single function
63
+ async function buildSingleFunction (
64
+ funcDir: string,
65
+ options: string[]
66
+ ): Promise<number> {
67
+ const funcName = funcDir.substring(funcDir.lastIndexOf(path.sep) + 1)
68
+ const buildPath = path.join(projectPaths.basePath, 'build', 'functions', funcName)
69
+
70
+ if (options.includes('--clean')) {
71
+ if (fs.existsSync(buildPath)) {
72
+ fs.rmSync(buildPath, { recursive: true })
73
+ }
74
+ }
75
+ // strategy here is to invoke tsc on a per-folder basis rather than letting tsc do the recurse because it is easier to control this way
76
+ return await buildFunctionModules(funcName, funcDir, buildPath, options)
77
+ }
78
+
79
+ // build all the function modules in path
80
+ async function buildFunctionModules (
81
+ funcName: string,
82
+ funcDir: string,
83
+ buildPath: string,
84
+ options: string[]
85
+ ): Promise<number> {
86
+ const announce = ac.blue.dim(`building ${funcName}...`)
87
+ let announced = false
88
+ let fails = 0
89
+ // let builds = 0
90
+ let failFast = options.includes('--failfast')
91
+ if (options.includes('--deferfail')) failFast = false
92
+ const all: Array<Promise<void>> = []
93
+ recurseDirectory(funcDir, (filepath, stats) => {
94
+ if (path.extname(filepath) === '.ts') {
95
+ let relPath = filepath.substring(funcDir.length)
96
+ relPath = relPath.substring(0, relPath.lastIndexOf(path.sep))
97
+ const outDir = path.join(buildPath, relPath)
98
+
99
+ if (!(fails > 0 && failFast)) {
100
+ if (isNewer(filepath, outDir)) {
101
+ if (!announced) {
102
+ announced = true
103
+ console.log(announce)
104
+ }
105
+ // builds++
106
+ all.push(executeCommand('tsc', [
107
+ '--esModuleInterop', 'true',
108
+ '--target', 'ES2015',
109
+ '--module', 'commonjs',
110
+ '--lib', 'dom,es2015,scripthost,es2015.proxy',
111
+ '--strict', 'true',
112
+ '--noImplicitAny', 'false',
113
+ '--skipLibCheck', 'true',
114
+ '--forceConsistentCasingInFileNames', 'true',
115
+ '--sourceMap', 'true',
116
+ '--outdir', outDir,
117
+ filepath
118
+ ], '', true).then((result: { retcode: number | undefined, stdOut: string, stdErr: string }) => {
119
+ if (result.retcode !== 0) {
120
+ fails++
121
+ // console.log("error detected", fails)
122
+ const now = new Date()
123
+ fs.utimesSync(filepath, now, now) // touch file so it is not skipped next build
124
+ }
125
+ }))
126
+ }
127
+ }
128
+ }
129
+ fails += doPostBuildSteps(funcDir, buildPath)
130
+ return false
131
+ })
132
+ return await Promise.all(all).then(async () => {
133
+ return fails
134
+ })
135
+ }
136
+
137
+ // do the steps after the build (file copies, etc)
138
+ function doPostBuildSteps (
139
+ funcDir: string,
140
+ buildPath: string
141
+ ): number {
142
+ // copy the definitions,json file over
143
+ const srcdef = path.join(funcDir, 'src', 'definition.json')
144
+ const dstdef = path.join(buildPath, 'src', 'definition.json')
145
+ if (fs.existsSync(srcdef)) {
146
+ const destFolder = path.dirname(dstdef)
147
+ if (!fs.existsSync(destFolder)) mkdirSync(destFolder, { recursive: true })
148
+ fs.copyFileSync(srcdef, dstdef)
149
+ } else {
150
+ console.error(ac.red.bold('no definition file found at ' + srcdef))
151
+ return 1
152
+ }
153
+ // copy the resources folder if it exists
154
+ const filedirPath = path.join(funcDir, 'resources')
155
+ if (fs.existsSync(filedirPath)) {
156
+ const bfiles = path.join(buildPath, 'resources')
157
+ if (!fs.existsSync(bfiles)) fs.mkdirSync(bfiles, { recursive: true })
158
+ recurseDirectory(filedirPath, (filepath, stats) => {
159
+ let relPath = filepath.substring(funcDir.length)
160
+ relPath = relPath.substring(0, relPath.lastIndexOf(path.sep))
161
+ const outDir = path.join(buildPath, relPath)
162
+ const target = path.join(outDir, path.basename(filepath))
163
+ if (stats.isDirectory() && !fs.existsSync(target)) {
164
+ fs.mkdirSync(target, { recursive: true })
165
+ }
166
+ if (stats.isFile()) {
167
+ fs.copyFileSync(filepath, target)
168
+ }
169
+ return false
170
+ })
171
+ }
172
+ return 0
173
+ }
@@ -1,102 +1,106 @@
1
- import { gatherFunctionDefinitions } from '../../lib/openAPI/ApiBuildCollector'
2
- import { buildOpenApi } from '../../lib/openAPI/openApiConstruction'
3
- import { GetWebrootServePaths } from '../../lib/openAPI/WebrootFileSupport'
4
-
5
- export async function MakePublicApiDoc
6
- (
7
- ): Promise<Uint8Array> {
8
- const defs = gatherFunctionDefinitions()
9
- return await buildOpenApi(defs)
10
- }
11
-
12
- export async function MakeBuiltinApiDoc
13
- (
14
- yamlFile: string
15
-
16
- ): Promise<Uint8Array> {
17
- const defs = gatherFunctionDefinitions()
18
- addBuiltInDefinitions(defs)
19
- return await buildOpenApi(defs, false, yamlFile) //, true)
20
- }
21
-
22
- export function addBuiltInDefinitions (defs: any[]): void {
23
- // console.warn("NOT ADDING ANY BUILTIN API INTEGRATIONS")
24
- // console.log("ADDING apiDef");
25
- defs.push(apiDef)
26
- // console.log("ADDING webrootDef");
27
- defs.push(webrootDef)
28
-
29
- // console.warn("Adding webroot literals");
30
- // do just /docs and see how that goes
31
- const fsdef = Object.assign({}, fileServeDef) // copy
32
- fsdef.name = 'fileserve_docs'
33
- fsdef.pathMap = '/docs/{path}'
34
- defs.push(fsdef)
35
- const roots = GetWebrootServePaths()
36
- // console.log("roots", roots)
37
- for (const root of roots) {
38
- if (root !== '') {
39
- let rootName = root
40
- while (rootName.includes('/')) rootName = rootName.replace('/', '').toLowerCase().trim()
41
- const fileserve = Object.assign({}, fileServeDef) // copy
42
- fileserve.name = 'fileserve_' + rootName
43
- fileserve.pathMap = `${root}/{path}`
44
- defs.push(fileserve)
45
- }
46
- }
47
- }
48
-
49
- const apiDef = {
50
- name: 'API',
51
- description: '',
52
- version: '1.0.0',
53
- pathMap: '/api',
54
- allowedMethods: 'GET',
55
- logLevel: 'Debug',
56
- sessionRequired: false,
57
- userRequired: false,
58
- schemas: {},
59
- parameters: [],
60
- returns: {
61
- 200: { type: 'empty', description: 'successful response.' },
62
- 500: {
63
- type: 'string',
64
- description: 'Error details'
65
- }
66
- }
67
- }
68
-
69
- const fileServeDef = {
70
- name: 'FileServe',
71
- description: 'file service',
72
- version:
73
- '1.0.0',
74
- pathMap: '',
75
- allowedMethods: 'GET',
76
- logLevel: 'Debug',
77
- sessionRequired: false,
78
- userRequired: false,
79
- schemas: {},
80
- parameters: [{ name: 'path', in: 'path' }],
81
- returns: {
82
- 200: { type: 'empty', description: 'successful response.' },
83
- 500: { type: 'string', description: 'Error details' }
84
- }
85
- }
86
-
87
- const webrootDef = {
88
- name: 'Webroot',
89
- description: 'Serves files from the webroot /',
90
- version: '1.0.0',
91
- pathMap: '/{path}',
92
- allowedMethods: 'get',
93
- logLevel: 'Debug',
94
- sessionRequired: false,
95
- userRequired: false,
96
- schemas: {},
97
- parameters: [{ name: 'path', in: 'path' }],
98
- returns: {
99
- 200: { type: 'empty', description: 'successful response.' },
100
- 500: { type: 'string', description: 'Error details' }
101
- }
102
- }
1
+ import { gatherFunctionDefinitions } from '../../lib/openAPI/ApiBuildCollector'
2
+ import { buildOpenApi } from '../../lib/openAPI/openApiConstruction'
3
+ import { GetWebrootServePaths } from '../../lib/openAPI/WebrootFileSupport'
4
+
5
+ import path from 'path'
6
+
7
+ export async function MakePublicApiDoc
8
+ (
9
+ ): Promise<Uint8Array> {
10
+ const defs = gatherFunctionDefinitions()
11
+ return await buildOpenApi(defs)
12
+ }
13
+
14
+ export async function MakeBuiltinApiDoc
15
+ (
16
+ yamlFile: string
17
+
18
+ ): Promise<Uint8Array> {
19
+ const defs = gatherFunctionDefinitions()
20
+ addBuiltInDefinitions(defs)
21
+ return await buildOpenApi(defs, false, yamlFile) //, true)
22
+ }
23
+
24
+ export function addBuiltInDefinitions (defs: any[]): void {
25
+ // console.warn("NOT ADDING ANY BUILTIN API INTEGRATIONS")
26
+ // console.log("ADDING apiDef");
27
+ defs.push(apiDef)
28
+ // console.log("ADDING webrootDef");
29
+ defs.push(webrootDef)
30
+
31
+ // console.warn("Adding webroot literals");
32
+ // do just /docs and see how that goes
33
+ const fsdef = Object.assign({}, fileServeDef) // copy
34
+ fsdef.name = 'fileserve_docs'
35
+ fsdef.pathMap = '/docs/{path}'
36
+ defs.push(fsdef)
37
+ const roots = GetWebrootServePaths()
38
+ // console.log("roots", roots)
39
+ for (const root of roots) {
40
+ if (root !== '') {
41
+ let rootName = root
42
+ let rootPath = root.replace(path.sep, '/');
43
+ while (rootName.includes(path.sep)) rootName = rootName.replace(path.sep, '').toLowerCase().trim()
44
+ console.log("$$$$>> rootPath, rootName", rootPath, rootName)
45
+ const fileserve = Object.assign({}, fileServeDef) // copy
46
+ fileserve.name = 'fileserve_' + rootName
47
+ fileserve.pathMap = `${rootPath}/{path}`
48
+ defs.push(fileserve)
49
+ }
50
+ }
51
+ }
52
+
53
+ const apiDef = {
54
+ name: 'API',
55
+ description: '',
56
+ version: '1.0.0',
57
+ pathMap: '/api',
58
+ allowedMethods: 'GET',
59
+ logLevel: 'Debug',
60
+ sessionRequired: false,
61
+ userRequired: false,
62
+ schemas: {},
63
+ parameters: [],
64
+ returns: {
65
+ 200: { type: 'empty', description: 'successful response.' },
66
+ 500: {
67
+ type: 'string',
68
+ description: 'Error details'
69
+ }
70
+ }
71
+ }
72
+
73
+ const fileServeDef = {
74
+ name: 'FileServe',
75
+ description: 'file service',
76
+ version:
77
+ '1.0.0',
78
+ pathMap: '',
79
+ allowedMethods: 'GET',
80
+ logLevel: 'Debug',
81
+ sessionRequired: false,
82
+ userRequired: false,
83
+ schemas: {},
84
+ parameters: [{ name: 'path', in: 'path' }],
85
+ returns: {
86
+ 200: { type: 'empty', description: 'successful response.' },
87
+ 500: { type: 'string', description: 'Error details' }
88
+ }
89
+ }
90
+
91
+ const webrootDef = {
92
+ name: 'Webroot',
93
+ description: 'Serves files from the webroot /',
94
+ version: '1.0.0',
95
+ pathMap: '/{path}',
96
+ allowedMethods: 'get',
97
+ logLevel: 'Debug',
98
+ sessionRequired: false,
99
+ userRequired: false,
100
+ schemas: {},
101
+ parameters: [{ name: 'path', in: 'path' }],
102
+ returns: {
103
+ 200: { type: 'empty', description: 'successful response.' },
104
+ 500: { type: 'string', description: 'Error details' }
105
+ }
106
+ }