@tremho/mist-lift 1.0.2-pre-release.4 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/build/commands/actions/initQuestions.js +24 -22
- package/build/commands/actions/initQuestions.js.map +1 -1
- package/build/commands/actions/setupPackageJson.js +4 -4
- package/build/commands/actions/setupPackageJson.js.map +1 -1
- package/build/commands/build.js +31 -25
- package/build/commands/build.js.map +1 -1
- package/build/commands/builtin/ApiDocMaker.js +60 -23
- package/build/commands/builtin/ApiDocMaker.js.map +1 -1
- package/build/commands/builtin/BuiltInHandler.js +6 -6
- package/build/commands/builtin/BuiltInHandler.js.map +1 -1
- package/build/commands/builtin/DeployBuiltInZip.js +4 -4
- package/build/commands/builtin/DeployBuiltInZip.js.map +1 -1
- package/build/commands/builtin/StageWebrootZip.js +1 -0
- package/build/commands/builtin/StageWebrootZip.js.map +1 -1
- package/build/commands/create.js +10 -11
- package/build/commands/create.js.map +1 -1
- package/build/commands/deploy.js +38 -42
- package/build/commands/deploy.js.map +1 -1
- package/build/commands/doctor.js +38 -37
- package/build/commands/doctor.js.map +1 -1
- package/build/commands/help.js +93 -93
- package/build/commands/help.js.map +1 -1
- package/build/commands/init.js +7 -7
- package/build/commands/init.js.map +1 -1
- package/build/commands/package.js +50 -51
- package/build/commands/package.js.map +1 -1
- package/build/commands/publish.js +98 -102
- package/build/commands/publish.js.map +1 -1
- package/build/commands/settings.js +19 -18
- package/build/commands/settings.js.map +1 -1
- package/build/commands/start.js +4 -4
- package/build/commands/start.js.map +1 -1
- package/build/commands/test.js +3 -3
- package/build/commands/test.js.map +1 -1
- package/build/commands/user.js +1 -1
- package/build/commands/user.js.map +1 -1
- package/build/expressRoutes/all.js +27 -26
- package/build/expressRoutes/all.js.map +1 -1
- package/build/expressRoutes/api.js +9 -7
- package/build/expressRoutes/api.js.map +1 -1
- package/build/expressRoutes/functionBinder.js +38 -36
- package/build/expressRoutes/functionBinder.js.map +1 -1
- package/build/lib/CaseUtils.js +2 -2
- package/build/lib/CaseUtils.js.map +1 -1
- package/build/lib/DirectoryUtils.js +4 -3
- package/build/lib/DirectoryUtils.js.map +1 -1
- package/build/lib/LiftConfig.js +18 -20
- package/build/lib/LiftConfig.js.map +1 -1
- package/build/lib/LiftVersion.js +17 -12
- package/build/lib/LiftVersion.js.map +1 -1
- package/build/lib/Tests/fileCompare.test.js +11 -10
- package/build/lib/Tests/fileCompare.test.js.map +1 -1
- package/build/lib/askQuestion.js +3 -2
- package/build/lib/askQuestion.js.map +1 -1
- package/build/lib/executeCommand.js +46 -33
- package/build/lib/executeCommand.js.map +1 -1
- package/build/lib/fileCompare.js +9 -8
- package/build/lib/fileCompare.js.map +1 -1
- package/build/lib/openAPI/ApiBuildCollector.js +9 -8
- package/build/lib/openAPI/ApiBuildCollector.js.map +1 -1
- package/build/lib/openAPI/WebrootFileSupport.js +4 -3
- package/build/lib/openAPI/WebrootFileSupport.js.map +1 -1
- package/build/lib/openAPI/openApiConstruction.js +62 -61
- package/build/lib/openAPI/openApiConstruction.js.map +1 -1
- package/build/lib/pathResolve.js +4 -4
- package/build/lib/pathResolve.js.map +1 -1
- package/build/lib/utils.js +5 -4
- package/build/lib/utils.js.map +1 -1
- package/build/lift.js +14 -15
- package/build/lift.js.map +1 -1
- package/package.json +2 -1
- package/src/commands/actions/initQuestions.ts +112 -112
- package/src/commands/actions/setupPackageJson.ts +21 -25
- package/src/commands/build.ts +143 -146
- package/src/commands/builtin/ApiDocMaker.ts +86 -54
- package/src/commands/builtin/BuiltInHandler.ts +31 -35
- package/src/commands/builtin/DeployBuiltInZip.ts +15 -17
- package/src/commands/builtin/StageWebrootZip.ts +29 -32
- package/src/commands/create.ts +40 -47
- package/src/commands/deploy.ts +139 -152
- package/src/commands/doctor.ts +86 -82
- package/src/commands/help.ts +152 -153
- package/src/commands/init.ts +37 -39
- package/src/commands/package.ts +201 -204
- package/src/commands/publish.ts +277 -312
- package/src/commands/settings.ts +67 -70
- package/src/commands/start.ts +32 -37
- package/src/commands/test.ts +15 -16
- package/src/commands/user.ts +1 -1
- package/src/expressRoutes/all.ts +73 -78
- package/src/expressRoutes/api.ts +14 -16
- package/src/expressRoutes/functionBinder.ts +144 -151
- package/src/lib/CaseUtils.ts +49 -54
- package/src/lib/DirectoryUtils.ts +25 -27
- package/src/lib/LiftConfig.ts +46 -54
- package/src/lib/LiftVersion.ts +69 -77
- package/src/lib/Tests/fileCompare.test.ts +27 -26
- package/src/lib/askQuestion.ts +12 -13
- package/src/lib/executeCommand.ts +40 -33
- package/src/lib/fileCompare.ts +46 -37
- package/src/lib/openAPI/ApiBuildCollector.ts +36 -36
- package/src/lib/openAPI/WebrootFileSupport.ts +15 -17
- package/src/lib/openAPI/openApiConstruction.ts +169 -175
- package/src/lib/pathResolve.ts +22 -28
- package/src/lib/utils.ts +31 -33
- package/src/lift.ts +68 -67
|
@@ -3,129 +3,129 @@
|
|
|
3
3
|
|
|
4
4
|
import * as path from 'path'
|
|
5
5
|
import * as fs from 'fs'
|
|
6
|
-
import {executeCommand} from
|
|
7
|
-
import {ask} from
|
|
6
|
+
import { executeCommand } from '../../lib/executeCommand'
|
|
7
|
+
import { ask } from '../../lib/askQuestion'
|
|
8
8
|
|
|
9
|
-
export async function interrogateUserForPackageJsonSettings(
|
|
10
|
-
|
|
11
|
-
)
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// spdx licence
|
|
9
|
+
export async function interrogateUserForPackageJsonSettings (
|
|
10
|
+
projectPath: string
|
|
11
|
+
): Promise<void> {
|
|
12
|
+
// get existing package.json or {}
|
|
13
|
+
// name of project - module name, display name, short name
|
|
14
|
+
// description
|
|
15
|
+
// set version
|
|
16
|
+
// gitAuthor ?? Author
|
|
17
|
+
// create a repository under gitAuthor?
|
|
18
|
+
// copyright
|
|
19
|
+
// spdx licence
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
const gitAuthor = await findGitAuthor()
|
|
22
|
+
const pkgJson = existingPackageJson(projectPath)
|
|
23
|
+
let name = pkgJson.name ?? nameFromProjectPath(projectPath)
|
|
24
|
+
let version = pkgJson.version ?? '1.0.0-prerelease.1'
|
|
25
|
+
let description = pkgJson.description ?? ''
|
|
26
|
+
let author = pkgJson.author ?? gitAuthor
|
|
27
|
+
let copyright = pkgJson.copyright ?? defaultCopyright(author)
|
|
28
|
+
let spdx = pkgJson.license ?? 'MIT'
|
|
30
29
|
|
|
30
|
+
let ok = false
|
|
31
|
+
while (!ok) {
|
|
32
|
+
name = ask('Module name of this project',
|
|
33
|
+
'module name',
|
|
34
|
+
name
|
|
35
|
+
)
|
|
36
|
+
ok = name !== undefined && name.indexOf(' ') === -1
|
|
37
|
+
}
|
|
38
|
+
ok = false
|
|
39
|
+
while (!ok) {
|
|
40
|
+
version = ask('Project version. Use prerelease suffix for development versions. Use Semantic Versioning (https://semver.org).',
|
|
41
|
+
'version',
|
|
42
|
+
version ?? '0.1.0-prerelease.1'
|
|
43
|
+
)
|
|
44
|
+
ok = version !== undefined && version.indexOf('.') !== -1
|
|
45
|
+
}
|
|
46
|
+
ok = false
|
|
47
|
+
while (!ok) {
|
|
48
|
+
description = ask('Give a brief description of what this project does / what it is for',
|
|
49
|
+
'description',
|
|
50
|
+
description ?? ''
|
|
51
|
+
)
|
|
52
|
+
ok = description !== ''
|
|
53
|
+
}
|
|
54
|
+
ok = false
|
|
55
|
+
while (!ok) {
|
|
56
|
+
author = ask('Identify yourself as the author of this project',
|
|
57
|
+
'name',
|
|
58
|
+
author
|
|
59
|
+
)
|
|
60
|
+
ok = author !== ''
|
|
61
|
+
}
|
|
62
|
+
ok = false
|
|
63
|
+
while (!ok) {
|
|
64
|
+
copyright = ask('Specify a displayable copyright notice',
|
|
65
|
+
'Copyright',
|
|
66
|
+
copyright
|
|
67
|
+
)
|
|
68
|
+
ok = copyright !== ''
|
|
69
|
+
}
|
|
70
|
+
ok = false
|
|
71
|
+
while (!ok) {
|
|
72
|
+
spdx = ask('Specify the appropriate SPDX license identifier for this project. See https://spdx.org/licenses/ for more info.',
|
|
73
|
+
'spdx identifier',
|
|
74
|
+
spdx
|
|
75
|
+
)
|
|
76
|
+
ok = spdx !== ''
|
|
77
|
+
}
|
|
31
78
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
ok = name && name.indexOf(' ') === -1
|
|
39
|
-
}
|
|
40
|
-
ok = false
|
|
41
|
-
while(!ok) {
|
|
42
|
-
version = ask("Project version. Use prerelease suffix for development versions. Use Semantic Versioning (https://semver.org).",
|
|
43
|
-
"version",
|
|
44
|
-
version ?? "0.1.0-prerelease.1"
|
|
45
|
-
)
|
|
46
|
-
ok = version && version.indexOf('.') !== -1
|
|
47
|
-
}
|
|
48
|
-
ok = false
|
|
49
|
-
while(!ok) {
|
|
50
|
-
description = ask("Give a brief description of what this project does / what it is for",
|
|
51
|
-
"description",
|
|
52
|
-
description ?? ""
|
|
53
|
-
)
|
|
54
|
-
ok = description !== "";
|
|
55
|
-
}
|
|
56
|
-
ok = false
|
|
57
|
-
while(!ok) {
|
|
58
|
-
author = ask("Identify yourself as the author of this project",
|
|
59
|
-
"name",
|
|
60
|
-
author
|
|
61
|
-
)
|
|
62
|
-
ok = author !== "";
|
|
63
|
-
}
|
|
64
|
-
ok = false
|
|
65
|
-
while(!ok) {
|
|
66
|
-
copyright = ask("Specify a displayable copyright notice",
|
|
67
|
-
"Copyright",
|
|
68
|
-
copyright
|
|
69
|
-
)
|
|
70
|
-
ok = copyright !== ""
|
|
71
|
-
}
|
|
72
|
-
ok = false
|
|
73
|
-
while(!ok) {
|
|
74
|
-
spdx = ask("Specify the appropriate SPDX license identifier for this project. See https://spdx.org/licenses/ for more info.",
|
|
75
|
-
"spdx identifier",
|
|
76
|
-
spdx
|
|
77
|
-
)
|
|
78
|
-
ok = spdx !== ""
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
pkgJson.name = name
|
|
83
|
-
pkgJson.version = version
|
|
84
|
-
pkgJson.description = description
|
|
85
|
-
pkgJson.author = author
|
|
86
|
-
pkgJson.copyright = copyright
|
|
87
|
-
pkgJson.license = spdx
|
|
88
|
-
|
|
89
|
-
const pkgPath = path.join(projectPath, "package.json");
|
|
90
|
-
fs.writeFileSync(pkgPath,
|
|
91
|
-
JSON.stringify(pkgJson, null, 2))
|
|
79
|
+
pkgJson.name = name
|
|
80
|
+
pkgJson.version = version
|
|
81
|
+
pkgJson.description = description
|
|
82
|
+
pkgJson.author = author
|
|
83
|
+
pkgJson.copyright = copyright
|
|
84
|
+
pkgJson.license = spdx
|
|
92
85
|
|
|
86
|
+
const pkgPath = path.join(projectPath, 'package.json')
|
|
87
|
+
fs.writeFileSync(pkgPath,
|
|
88
|
+
JSON.stringify(pkgJson, null, 2))
|
|
93
89
|
}
|
|
94
90
|
|
|
95
|
-
async function findGitAuthor(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
91
|
+
async function findGitAuthor (
|
|
92
|
+
): Promise<string> {
|
|
93
|
+
return await executeCommand('git', ['config', '--get', 'user.name']).then((rt: any) => {
|
|
94
|
+
const rrt: { retcode: number | undefined, stdStr: string | undefined, errStr: string | undefined } = rt
|
|
95
|
+
let name: string | undefined = ''
|
|
96
|
+
if (rrt?.retcode !== 0) {
|
|
97
|
+
console.error(`Error ${rrt.retcode}`, rrt.errStr)
|
|
98
|
+
} else {
|
|
99
|
+
name = rrt?.stdStr?.trim().toLowerCase()
|
|
100
|
+
}
|
|
101
|
+
return name ?? ''
|
|
102
|
+
})
|
|
106
103
|
}
|
|
107
104
|
|
|
108
|
-
function defaultCopyright(
|
|
109
|
-
|
|
105
|
+
function defaultCopyright (
|
|
106
|
+
name: string
|
|
107
|
+
): string {
|
|
108
|
+
return `(C) ${new Date(Date.now()).getFullYear()} ${name}. All rights reserved.`
|
|
110
109
|
}
|
|
111
110
|
|
|
112
|
-
function nameFromProjectPath(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
function nameFromProjectPath (
|
|
112
|
+
refPath: string
|
|
113
|
+
): string {
|
|
114
|
+
const n = refPath.lastIndexOf('/') + 1
|
|
115
|
+
return refPath.substring(n)
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
function existingPackageJson(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
118
|
+
function existingPackageJson (
|
|
119
|
+
refPath: string
|
|
120
|
+
): any {
|
|
121
|
+
let packageJson: any = {}
|
|
122
|
+
const pkgPath = path.join(refPath, 'package.json')
|
|
123
|
+
if (fs.existsSync((pkgPath))) {
|
|
124
|
+
try {
|
|
125
|
+
packageJson = JSON.parse(fs.readFileSync(pkgPath).toString())
|
|
126
|
+
} catch (e: any) {
|
|
127
|
+
// error in existing package.json. Please fix or remove and try again.
|
|
129
128
|
}
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
}
|
|
130
|
+
return packageJson
|
|
131
|
+
}
|
|
@@ -2,35 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
import * as path from 'path'
|
|
4
4
|
import * as fs from 'fs'
|
|
5
|
-
import {executeCommand} from
|
|
5
|
+
import { executeCommand } from '../../lib/executeCommand'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Adds necessary scripts to package.json
|
|
9
9
|
*/
|
|
10
|
-
export function addPackageScripts(
|
|
11
|
-
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
pkgJson.script = script;
|
|
20
|
-
|
|
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
|
|
21
19
|
}
|
|
22
|
-
export async function installPackage(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
return executeCommand("npm", ["i", packageName], projectPath, true)
|
|
20
|
+
export async function installPackage (
|
|
21
|
+
projectPath: string,
|
|
22
|
+
packageName: string
|
|
23
|
+
): Promise<void> {
|
|
24
|
+
await executeCommand('npm', ['i', packageName], projectPath, true)
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
export async function installDevPackage(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
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
|
@@ -2,164 +2,161 @@
|
|
|
2
2
|
|
|
3
3
|
import * as path from 'path'
|
|
4
4
|
import * as fs from 'fs'
|
|
5
|
-
import * as ac from
|
|
6
|
-
import {resolvePaths} from
|
|
7
|
-
import {recurseDirectory} from
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {executeCommand} from "../lib/executeCommand";
|
|
11
|
-
import {buildOpenApi} from "../lib/openAPI/openApiConstruction";
|
|
12
|
-
import {gatherFunctionDefinitions} from "../lib/openAPI/ApiBuildCollector";
|
|
13
|
-
import {delay} from "../lib/utils"
|
|
14
|
-
import {mkdirSync} from "fs";
|
|
15
|
-
|
|
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'
|
|
16
10
|
|
|
17
11
|
// Build command
|
|
18
|
-
export async function doBuildAsync(
|
|
19
|
-
|
|
20
|
-
): Promise<number>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
else funcsToBuild.push(arg)
|
|
30
|
-
}
|
|
12
|
+
export async function doBuildAsync (
|
|
13
|
+
args: string[] // zero or more functions to build. zero means build all
|
|
14
|
+
): Promise<number> {
|
|
15
|
+
const projectPaths = resolvePaths()
|
|
16
|
+
const funcsToBuild: string[] = []
|
|
17
|
+
const options: string[] = []
|
|
18
|
+
for (const arg of args) {
|
|
19
|
+
if (arg.charAt(0) === '-') {
|
|
20
|
+
options.push(arg.toLowerCase())
|
|
21
|
+
} else funcsToBuild.push(arg)
|
|
22
|
+
}
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
24
|
+
if (funcsToBuild.length === 0) {
|
|
25
|
+
let firstDepth = 0
|
|
26
|
+
recurseDirectory(projectPaths.functionPath, (filepath, stats) => {
|
|
27
|
+
const depth = filepath.split(path.sep).length
|
|
28
|
+
if (firstDepth === 0) firstDepth = depth
|
|
29
|
+
if (stats.isDirectory() && depth === firstDepth) {
|
|
30
|
+
funcsToBuild.push(path.basename(filepath))
|
|
31
|
+
}
|
|
32
|
+
return false
|
|
33
|
+
})
|
|
34
|
+
}
|
|
43
35
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
36
|
+
let fails = 0
|
|
37
|
+
let failFast = options.includes('--failfast')
|
|
38
|
+
if (options.includes('--deferfail')) failFast = false
|
|
39
|
+
for (const func of funcsToBuild) {
|
|
40
|
+
const funcDir = path.join(projectPaths.functionPath, func)
|
|
41
|
+
if (fs.existsSync(funcDir)) {
|
|
42
|
+
fails += await buildSingleFunction(funcDir, options)
|
|
43
|
+
if (fails > 0 && failFast) break
|
|
44
|
+
} else {
|
|
45
|
+
console.log(ac.red.bold(`${func} does not exist as a function`))
|
|
46
|
+
fails++
|
|
47
|
+
if (failFast) break
|
|
57
48
|
}
|
|
58
|
-
|
|
49
|
+
}
|
|
50
|
+
return fails
|
|
59
51
|
}
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
53
|
+
// build command for a single function
|
|
54
|
+
async function buildSingleFunction (
|
|
55
|
+
funcDir: string,
|
|
56
|
+
options: string[]
|
|
57
|
+
): Promise<number> {
|
|
58
|
+
const funcName = funcDir.substring(funcDir.lastIndexOf('/') + 1)
|
|
59
|
+
const buildPath = path.normalize(path.join(funcDir, '..', '..', 'build', 'functions', funcName))
|
|
60
|
+
if (options.includes('--clean')) {
|
|
61
|
+
if (fs.existsSync(buildPath)) {
|
|
62
|
+
fs.rmSync(buildPath, { recursive: true })
|
|
68
63
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
}
|
|
65
|
+
// 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
|
|
66
|
+
return await buildFunctionModules(funcName, funcDir, buildPath, options)
|
|
72
67
|
}
|
|
73
|
-
async function buildFunctionModules(
|
|
74
|
-
funcName:string,
|
|
75
|
-
funcDir:string,
|
|
76
|
-
buildPath:string,
|
|
77
|
-
options: string[]
|
|
78
68
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
let failFast = options.indexOf("--failfast") !== -1
|
|
86
|
-
if(options.indexOf("--deferfail") !== -1) failFast = false
|
|
87
|
-
const all:Promise<void>[] = [];
|
|
88
|
-
recurseDirectory(funcDir, (filepath, stats) => {
|
|
89
|
-
if(path.extname(filepath) === ".ts") {
|
|
90
|
-
let relPath = filepath.substring(funcDir.length);
|
|
91
|
-
relPath = relPath.substring(0, relPath.lastIndexOf('/'));
|
|
92
|
-
let outDir = path.join(buildPath, relPath);
|
|
93
|
-
// console.log(`tsc --esModuleInterop true --outdir ${outDir} ${filepath}`);
|
|
94
|
-
if(!(fails && failFast)) {
|
|
95
|
-
if (isNewer(filepath, outDir)) {
|
|
96
|
-
if (!announced) {
|
|
97
|
-
announced = true
|
|
98
|
-
console.log(announce)
|
|
99
|
-
}
|
|
100
|
-
builds++;
|
|
101
|
-
all.push(executeCommand('tsc', [
|
|
102
|
-
'--esModuleInterop', 'true',
|
|
103
|
-
'--target', 'ES2015',
|
|
104
|
-
'--module', 'commonjs',
|
|
105
|
-
'--lib', 'dom,es2015,scripthost,es2015.proxy',
|
|
106
|
-
'--strict', 'true',
|
|
107
|
-
'--noImplicitAny', 'false',
|
|
108
|
-
'--skipLibCheck', 'true',
|
|
109
|
-
'--forceConsistentCasingInFileNames', 'true',
|
|
110
|
-
'--sourceMap', 'true',
|
|
111
|
-
'--outdir', outDir,
|
|
112
|
-
filepath
|
|
113
|
-
], '', true).then(result => {
|
|
114
|
-
if (result.retcode) {
|
|
115
|
-
fails++
|
|
116
|
-
// console.log("error detected", fails)
|
|
117
|
-
const now = new Date()
|
|
118
|
-
fs.utimesSync(filepath, now, now) // touch file so it is not skipped next build
|
|
119
|
-
}
|
|
120
|
-
}))
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
})
|
|
125
|
-
return Promise.all(all).then( async () => {
|
|
126
|
-
fails += await doPostBuildSteps(funcDir, buildPath)
|
|
127
|
-
return fails
|
|
128
|
-
})
|
|
129
|
-
}
|
|
69
|
+
// build all the function modules in path
|
|
70
|
+
async function buildFunctionModules (
|
|
71
|
+
funcName: string,
|
|
72
|
+
funcDir: string,
|
|
73
|
+
buildPath: string,
|
|
74
|
+
options: string[]
|
|
130
75
|
|
|
131
|
-
|
|
132
|
-
{
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
76
|
+
): Promise<number> {
|
|
77
|
+
const announce = ac.blue.dim(`building ${funcName}...`)
|
|
78
|
+
let announced = false
|
|
79
|
+
let fails = 0
|
|
80
|
+
// let builds = 0
|
|
81
|
+
let failFast = options.includes('--failfast')
|
|
82
|
+
if (options.includes('--deferfail')) failFast = false
|
|
83
|
+
const all: Array<Promise<void>> = []
|
|
84
|
+
recurseDirectory(funcDir, (filepath, stats) => {
|
|
85
|
+
if (path.extname(filepath) === '.ts') {
|
|
86
|
+
let relPath = filepath.substring(funcDir.length)
|
|
87
|
+
relPath = relPath.substring(0, relPath.lastIndexOf('/'))
|
|
88
|
+
const outDir = path.join(buildPath, relPath)
|
|
89
|
+
// console.log(`tsc --esModuleInterop true --outdir ${outDir} ${filepath}`);
|
|
90
|
+
if (!(fails > 0 && failFast)) {
|
|
91
|
+
if (isNewer(filepath, outDir)) {
|
|
92
|
+
if (!announced) {
|
|
93
|
+
announced = true
|
|
94
|
+
console.log(announce)
|
|
95
|
+
}
|
|
96
|
+
// builds++
|
|
97
|
+
all.push(executeCommand('tsc', [
|
|
98
|
+
'--esModuleInterop', 'true',
|
|
99
|
+
'--target', 'ES2015',
|
|
100
|
+
'--module', 'commonjs',
|
|
101
|
+
'--lib', 'dom,es2015,scripthost,es2015.proxy',
|
|
102
|
+
'--strict', 'true',
|
|
103
|
+
'--noImplicitAny', 'false',
|
|
104
|
+
'--skipLibCheck', 'true',
|
|
105
|
+
'--forceConsistentCasingInFileNames', 'true',
|
|
106
|
+
'--sourceMap', 'true',
|
|
107
|
+
'--outdir', outDir,
|
|
108
|
+
filepath
|
|
109
|
+
], '', true).then((result: { retcode: number | undefined, stdOut:string, stdErr:string }) => {
|
|
110
|
+
if (result.retcode !== 0) {
|
|
111
|
+
fails++
|
|
112
|
+
// console.log("error detected", fails)
|
|
113
|
+
const now = new Date()
|
|
114
|
+
fs.utimesSync(filepath, now, now) // touch file so it is not skipped next build
|
|
157
115
|
}
|
|
158
|
-
|
|
116
|
+
}))
|
|
117
|
+
}
|
|
118
|
+
}
|
|
159
119
|
}
|
|
160
|
-
return
|
|
120
|
+
return false
|
|
121
|
+
})
|
|
122
|
+
return await Promise.all(all).then(async () => {
|
|
123
|
+
fails += await doPostBuildSteps(funcDir, buildPath)
|
|
124
|
+
return fails
|
|
125
|
+
})
|
|
161
126
|
}
|
|
162
127
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
128
|
+
// do the steps after the build (file copies, etc)
|
|
129
|
+
async function doPostBuildSteps (
|
|
130
|
+
funcDir: string,
|
|
131
|
+
buildPath: string
|
|
132
|
+
): Promise<number> {
|
|
133
|
+
// copy the definitions,json file over
|
|
134
|
+
const srcdef = path.join(funcDir, 'src', 'definition.json')
|
|
135
|
+
const dstdef = path.join(buildPath, 'src', 'definition.json')
|
|
136
|
+
if (fs.existsSync(srcdef)) {
|
|
137
|
+
fs.copyFileSync(srcdef, dstdef)
|
|
138
|
+
} else {
|
|
139
|
+
console.error(ac.red.bold('no definition file found at ' + srcdef))
|
|
140
|
+
return 1
|
|
141
|
+
}
|
|
142
|
+
// copy the __files__ folder if it exists
|
|
143
|
+
const filedirPath = path.join(funcDir, '__files__')
|
|
144
|
+
if (fs.existsSync(filedirPath)) {
|
|
145
|
+
const bfiles = path.join(buildPath, '__files__')
|
|
146
|
+
if (!fs.existsSync(bfiles)) fs.mkdirSync(bfiles, { recursive: true })
|
|
147
|
+
recurseDirectory(filedirPath, (filepath, stats) => {
|
|
148
|
+
let relPath = filepath.substring(funcDir.length)
|
|
149
|
+
relPath = relPath.substring(0, relPath.lastIndexOf('/'))
|
|
150
|
+
const outDir = path.join(buildPath, relPath)
|
|
151
|
+
const target = path.join(outDir, path.basename(filepath))
|
|
152
|
+
if (stats.isDirectory() && !fs.existsSync(target)) {
|
|
153
|
+
fs.mkdirSync(target, { recursive: true })
|
|
154
|
+
}
|
|
155
|
+
if (stats.isFile()) {
|
|
156
|
+
fs.copyFileSync(filepath, target)
|
|
157
|
+
}
|
|
158
|
+
return false
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
return 0
|
|
162
|
+
}
|