@tremho/mist-lift 1.1.1 → 1.1.3-pre-release.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +65 -65
- package/build/commands/actions/initQuestions.js +35 -33
- package/build/commands/actions/initQuestions.js.map +1 -1
- package/build/commands/build.js +1 -1
- package/build/commands/build.js.map +1 -1
- package/build/commands/create.js +1 -1
- package/build/commands/create.js.map +1 -1
- package/build/commands/deploy.js +1 -1
- package/build/commands/deploy.js.map +1 -1
- package/build/commands/info.js +1 -1
- package/build/commands/info.js.map +1 -1
- package/build/commands/init.js +2 -2
- package/build/commands/init.js.map +1 -1
- package/build/commands/package.js +2 -2
- package/build/commands/package.js.map +1 -1
- package/build/commands/publish.js +2 -2
- package/build/commands/publish.js.map +1 -1
- package/build/expressRoutes/functionBinder.js.map +1 -1
- package/build/integration-tests/quickstart-scenario.test.js +76 -0
- package/build/integration-tests/quickstart-scenario.test.js.map +1 -0
- package/build/lib/utils.js +1 -1
- package/build/lib/utils.js.map +1 -1
- package/build/lift.js +1 -1
- package/build/lift.js.map +1 -1
- package/package.json +79 -72
- package/src/commands/actions/initQuestions.ts +133 -131
- package/src/commands/actions/setupPackageJson.ts +32 -32
- package/src/commands/build.ts +170 -170
- package/src/commands/builtin/ApiDocMaker.ts +102 -102
- package/src/commands/builtin/BuiltInHandler.ts +47 -47
- package/src/commands/builtin/DeployBuiltInZip.ts +25 -25
- package/src/commands/builtin/StageWebrootZip.ts +36 -36
- package/src/commands/create.ts +52 -52
- package/src/commands/deploy.ts +161 -161
- package/src/commands/doctor.ts +106 -106
- package/src/commands/help.ts +178 -178
- package/src/commands/info.ts +42 -43
- package/src/commands/init.ts +61 -60
- package/src/commands/package.ts +234 -234
- package/src/commands/publish.ts +330 -330
- package/src/commands/settings.ts +73 -73
- package/src/commands/start.ts +43 -43
- package/src/commands/test.ts +37 -37
- package/src/commands/user.ts +20 -20
- package/src/expressRoutes/all.ts +99 -99
- package/src/expressRoutes/api.ts +22 -22
- package/src/expressRoutes/functionBinder.ts +155 -156
- package/src/integration-tests/quickstart-scenario.test.ts +74 -0
- package/src/lib/CaseUtils.ts +63 -63
- package/src/lib/DirectoryUtils.ts +34 -34
- package/src/lib/LiftConfig.ts +74 -74
- package/src/lib/LiftVersion.ts +87 -87
- package/src/lib/Tests/fileCompare.test.ts +35 -35
- package/src/lib/askQuestion.ts +17 -17
- package/src/lib/executeCommand.ts +45 -45
- package/src/lib/fileCompare.ts +55 -55
- package/src/lib/openAPI/ApiBuildCollector.ts +47 -47
- package/src/lib/openAPI/WebrootFileSupport.ts +19 -19
- package/src/lib/openAPI/openApiConstruction.ts +196 -196
- package/src/lib/pathResolve.ts +26 -26
- package/src/lib/utils.ts +43 -43
- package/src/lift.ts +87 -87
- package/templateData/function-definition-template +20 -20
- package/templateData/function-local-ts +16 -16
- package/templateData/function-main-ts +16 -16
- package/templateData/function-runmain-mjs +6 -6
- package/templateData/function-test-template +11 -11
- package/templateData/swagger-ui-bundle.js +2 -2
- package/templateData/swagger-ui-standalone-preset.js +2 -2
- package/templateData/swagger-ui.css +2 -2
- package/tsconfig.json +28 -28
- /package/build/commands/builtin/{prebuilt-zips → prebult-zips}/API.zip +0 -0
- /package/build/commands/builtin/{prebuilt-zips → prebult-zips}/FileServe.zip +0 -0
- /package/build/commands/builtin/{prebuilt-zips → prebult-zips}/Webroot.zip +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
|
+
}
|
package/src/commands/build.ts
CHANGED
|
@@ -1,170 +1,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
|
|
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(
|
|
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 =
|
|
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
|
+
// 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,102 +1,102 @@
|
|
|
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
|
+
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
|
+
}
|