@tremho/mist-lift 1.0.2-pre-release.4 → 1.0.2-pre-release.5
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/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
package/src/commands/deploy.ts
CHANGED
|
@@ -1,171 +1,158 @@
|
|
|
1
1
|
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from
|
|
3
|
+
LambdaClient,
|
|
4
|
+
CreateFunctionCommand,
|
|
5
|
+
DeleteFunctionCommand,
|
|
6
|
+
AddPermissionCommand
|
|
7
|
+
} from '@aws-sdk/client-lambda'
|
|
8
8
|
|
|
9
|
-
import md5 from
|
|
9
|
+
import md5 from 'md5'
|
|
10
10
|
|
|
11
|
-
import path from
|
|
12
|
-
import fs
|
|
13
|
-
import {resolvePaths} from
|
|
11
|
+
import path from 'path'
|
|
12
|
+
import fs from 'fs'
|
|
13
|
+
import { resolvePaths } from '../lib/pathResolve'
|
|
14
14
|
|
|
15
|
-
import * as ac from
|
|
15
|
+
import * as ac from 'ansi-colors'
|
|
16
16
|
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {delay} from "../lib/utils"
|
|
23
|
-
import {doBuildAsync} from "./build";
|
|
24
|
-
import {doPackageAsync} from "./package";
|
|
25
|
-
import {Md5} from "@smithy/md5-js";
|
|
26
|
-
import {getAWSCredentials, getSettings, RuntimeType} from "../lib/LiftConfig";
|
|
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'
|
|
27
22
|
|
|
28
|
-
let projectPaths:{basePath: string, buildPath: string, functionPath: string, packagePath: string, verified: boolean}
|
|
23
|
+
let projectPaths: { basePath: string, buildPath: string, functionPath: string, packagePath: string, verified: boolean }
|
|
29
24
|
|
|
30
|
-
let deploymentRecord:any = {} // a map of last deployment times
|
|
25
|
+
let deploymentRecord: any = {} // a map of last deployment times
|
|
31
26
|
|
|
32
27
|
// package then deploy
|
|
33
|
-
export async function doDeployAsync(
|
|
34
|
-
|
|
35
|
-
): Promise<number>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
28
|
+
export async function doDeployAsync (
|
|
29
|
+
args: string[]
|
|
30
|
+
): Promise<number> {
|
|
31
|
+
projectPaths = resolvePaths()
|
|
32
|
+
|
|
33
|
+
const deploymentRecordPath = path.join(projectPaths.basePath, '.deployed')
|
|
34
|
+
try { deploymentRecord = JSON.parse(fs.readFileSync(deploymentRecordPath).toString()) } catch {}
|
|
35
|
+
|
|
36
|
+
const funcsToDeploy: string[] = []
|
|
37
|
+
const options: string[] = []
|
|
38
|
+
for (const arg of args) {
|
|
39
|
+
if (arg.charAt(0) === '-') {
|
|
40
|
+
options.push(arg.toLowerCase())
|
|
41
|
+
} else funcsToDeploy.push(arg)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!options.includes('--no-package')) {
|
|
45
|
+
const ret = await doPackageAsync(args)
|
|
46
|
+
if (ret !== 0) return ret
|
|
47
|
+
else await delay(2500)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (options.includes('--clean')) {
|
|
51
|
+
deploymentRecord = {}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (funcsToDeploy.length === 0) {
|
|
55
|
+
let firstDepth = 0
|
|
56
|
+
recurseDirectory(projectPaths.functionPath, (filepath, stats) => {
|
|
57
|
+
const depth = filepath.split(path.sep).length
|
|
58
|
+
if (firstDepth === 0) firstDepth = depth
|
|
59
|
+
if (stats.isDirectory() && depth === firstDepth) {
|
|
60
|
+
funcsToDeploy.push(path.basename(filepath))
|
|
61
|
+
}
|
|
62
|
+
return false
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (const funcName of funcsToDeploy) {
|
|
67
|
+
const zipFile = path.join(projectPaths.basePath, 'MistLift_Zips', funcName + '.zip')
|
|
68
|
+
if (fs.existsSync(zipFile)) {
|
|
69
|
+
const zipTime = fs.statSync(zipFile).mtime
|
|
70
|
+
if (zipTime.getTime() > (deploymentRecord[funcName] ?? 0)) {
|
|
71
|
+
await deployPackage(funcName)
|
|
72
|
+
deploymentRecord[funcName] = Date.now()
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
console.error('deploy: ' + zipFile + ac.red.bold(` ${funcName} does not exist`))
|
|
76
|
+
return -1
|
|
57
77
|
}
|
|
78
|
+
}
|
|
58
79
|
|
|
59
|
-
|
|
60
|
-
let ret = await doPackageAsync(args)
|
|
61
|
-
if (ret) return ret;
|
|
62
|
-
else await delay(2500);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if(options.indexOf("--clean") !== -1) {
|
|
66
|
-
deploymentRecord = {};
|
|
67
|
-
}
|
|
80
|
+
try { fs.writeFileSync(deploymentRecordPath, JSON.stringify(deploymentRecord)) } catch {}
|
|
68
81
|
|
|
69
|
-
|
|
70
|
-
let firstDepth = 0
|
|
71
|
-
recurseDirectory(projectPaths.functionPath, (filepath, stats) => {
|
|
72
|
-
let depth = filepath.split(path.sep).length
|
|
73
|
-
if (!firstDepth) firstDepth = depth
|
|
74
|
-
if (stats.isDirectory() && depth == firstDepth) {
|
|
75
|
-
funcsToDeploy.push(path.basename(filepath))
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const all: Promise<any>[] = [];
|
|
81
|
-
let error = 0;
|
|
82
|
-
|
|
83
|
-
for (let funcName of funcsToDeploy) {
|
|
84
|
-
// console.log("Deploy "+funcName)
|
|
85
|
-
const zipFile = path.join(projectPaths.basePath, 'MistLift_Zips', funcName+".zip")
|
|
86
|
-
if(fs.existsSync(zipFile)) {
|
|
87
|
-
let zipTime = fs.statSync(zipFile).mtime;
|
|
88
|
-
if(zipTime.getTime() > (deploymentRecord[funcName] ?? 0)) {
|
|
89
|
-
await deployPackage(funcName);
|
|
90
|
-
deploymentRecord[funcName] = Date.now();
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
console.error("deploy: " +zipFile + ac.red.bold(` ${funcName} does not exist`))
|
|
94
|
-
return -1;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
try {fs.writeFileSync(deploymentRecordPath, JSON.stringify(deploymentRecord)) } catch {}
|
|
99
|
-
|
|
100
|
-
return 0;
|
|
82
|
+
return 0
|
|
101
83
|
}
|
|
102
84
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
export async function deployPackage(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
85
|
+
// ------------
|
|
86
|
+
|
|
87
|
+
export async function deployPackage (
|
|
88
|
+
funcName: string,
|
|
89
|
+
zipFile?: string
|
|
90
|
+
): Promise<void> {
|
|
91
|
+
// first off, anchor a base directory
|
|
92
|
+
zipFile ??= path.join(projectPaths.basePath, 'MistLift_Zips', funcName + '.zip')
|
|
93
|
+
|
|
94
|
+
// funcname gets decorated with current instance identifier
|
|
95
|
+
const idsrc = md5((getProjectName() ?? '') + (getProjectVersion()?.toString() ?? ''))
|
|
96
|
+
const dFuncName = funcName + '_' + idsrc
|
|
97
|
+
|
|
98
|
+
// See if function exists
|
|
99
|
+
const client: any = new LambdaClient(getAWSCredentials())
|
|
100
|
+
const command: any = new DeleteFunctionCommand({
|
|
101
|
+
FunctionName: dFuncName
|
|
102
|
+
})
|
|
103
|
+
client.send(command).then((response: any) => {
|
|
104
|
+
}).catch((e: any) => {
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
// console.log(ac.green.italic("deploying ")+ac.green.bold(funcName)+"...")
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const response: any = await CreateCloudFunction(dFuncName, zipFile)
|
|
111
|
+
const parts = response.FunctionArn.split(':')
|
|
112
|
+
const principal = parts[4]
|
|
113
|
+
await AddPermissions(client, dFuncName, principal)
|
|
114
|
+
console.log(ac.green.bold(`Successfully deployed ${funcName}`))
|
|
115
|
+
} catch (e: any) {
|
|
116
|
+
console.error(ac.red.bold.italic('Error deploying ' + funcName), e)
|
|
117
|
+
}
|
|
134
118
|
}
|
|
135
|
-
async function CreateCloudFunction(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return await client.send(command); // response
|
|
119
|
+
async function CreateCloudFunction (
|
|
120
|
+
funcName: string,
|
|
121
|
+
zipFile: string
|
|
122
|
+
|
|
123
|
+
): Promise<any> {
|
|
124
|
+
const settings = getSettings()
|
|
125
|
+
const nodeRuntime: RuntimeType | undefined = settings.awsNodeRuntime
|
|
126
|
+
const serviceRole: string = settings.awsServiceRoleARN ?? ''
|
|
127
|
+
const zipFileBase64: Uint8Array = fs.readFileSync(zipFile)
|
|
128
|
+
const client: any = new LambdaClient(getAWSCredentials())
|
|
129
|
+
const command: any = new CreateFunctionCommand({
|
|
130
|
+
FunctionName: funcName,
|
|
131
|
+
Runtime: nodeRuntime,
|
|
132
|
+
Role: serviceRole,
|
|
133
|
+
Handler: 'runmain.handler',
|
|
134
|
+
Code: {
|
|
135
|
+
ZipFile: zipFileBase64
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
const resp = await client.send(command) // response
|
|
139
|
+
return resp
|
|
157
140
|
}
|
|
158
141
|
|
|
159
|
-
function AddPermissions(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
142
|
+
async function AddPermissions (
|
|
143
|
+
client: LambdaClient,
|
|
144
|
+
funcName: string,
|
|
145
|
+
principal: string
|
|
146
|
+
): Promise<any> {
|
|
147
|
+
const region = getSettings().awsPreferredRegion ?? ''
|
|
148
|
+
const WSApi = '/' + funcName.toLowerCase()
|
|
149
|
+
const command: any = new AddPermissionCommand({
|
|
150
|
+
FunctionName: funcName,
|
|
151
|
+
StatementId: 'InvokePermission',
|
|
152
|
+
Action: 'lambda:invokeFunction',
|
|
153
|
+
Principal: 'apigateway.amazonaws.com',
|
|
154
|
+
SourceArn: `arn:aws:execute-api:${region}:${principal}:${WSApi}`
|
|
155
|
+
})
|
|
156
|
+
const resp = await client.send(command)
|
|
157
|
+
return resp
|
|
171
158
|
}
|
package/src/commands/doctor.ts
CHANGED
|
@@ -1,102 +1,106 @@
|
|
|
1
1
|
|
|
2
|
-
import * as ac from
|
|
3
|
-
import {VersionInfo, getLiftVersion, getProjectVersion, getProjectName} from
|
|
4
|
-
import {executeCommand} from
|
|
5
|
-
import {resolvePaths} from
|
|
6
|
-
import {areSettingsAvailable} from
|
|
2
|
+
import * as ac from 'ansi-colors'
|
|
3
|
+
import { VersionInfo, getLiftVersion, getProjectVersion, getProjectName } from '../lib/LiftVersion'
|
|
4
|
+
import { executeCommand } from '../lib/executeCommand'
|
|
5
|
+
import { resolvePaths } from '../lib/pathResolve'
|
|
6
|
+
import { areSettingsAvailable } from '../lib/LiftConfig'
|
|
7
7
|
|
|
8
|
-
export async function doDoctor():Promise<boolean>
|
|
9
|
-
|
|
10
|
-
console.log(ac.blue.bold('Lift doctor'));
|
|
8
|
+
export async function doDoctor (): Promise<boolean> {
|
|
9
|
+
console.log(ac.blue.bold('Lift doctor'))
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
const liftVersion = getLiftVersion()?.toString() ?? ''
|
|
12
|
+
const projectVersion = getProjectVersion()?.toString() ?? ''
|
|
13
|
+
const projectName = getProjectName() ?? ''
|
|
14
|
+
const typescriptVersion = await fetchTypescriptVersion() ?? ''
|
|
15
|
+
const nodeVersion = await fetchNodeVersion() ?? ''
|
|
16
|
+
const npmVersion = await fetchNpmVersion() ?? ''
|
|
17
|
+
const gitVersion = await fetchGitVersion() ?? ''
|
|
18
|
+
const settingsAvail = areSettingsAvailable()
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
console.log('Checking installed dependencies:')
|
|
21
|
+
let ok = report('MistLift', liftVersion, '0.1.0')
|
|
22
|
+
ok = ok && report('Typescript', typescriptVersion, '5.3.3')
|
|
23
|
+
ok = ok && report('Node', nodeVersion, '20.11.0')
|
|
24
|
+
ok = ok && report('Npm', npmVersion, '10.3.0')
|
|
25
|
+
report('Git', gitVersion, '2.0.0')
|
|
26
|
+
if (!settingsAvail) {
|
|
27
|
+
console.log('')
|
|
28
|
+
console.log(ac.yellow.dim.bold('Cloud Settings are not set. ') + ac.blue('run ' + ac.bold('lift settings')))
|
|
29
|
+
}
|
|
30
|
+
if (!ok) {
|
|
31
|
+
console.log('')
|
|
32
|
+
console.log(ac.red.bold('System needs updates before MistLift can be used.'))
|
|
33
|
+
} else {
|
|
34
|
+
console.log('')
|
|
35
|
+
console.log(ac.green.bold('Ready for MistLift'))
|
|
36
|
+
console.log('')
|
|
37
|
+
if (resolvePaths().verified) {
|
|
38
|
+
console.log(ac.blue.italic('Current project ' + projectName + ' ' + projectVersion))
|
|
30
39
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
console.log(ac.red.bold("System needs updates before MistLift can be used."));
|
|
34
|
-
} else {
|
|
35
|
-
console.log("")
|
|
36
|
-
console.log(ac.green.bold("Ready for MistLift"))
|
|
37
|
-
console.log("");
|
|
38
|
-
if(resolvePaths().verified) {
|
|
39
|
-
console.log(ac.blue.italic("Current project " + projectName + " " + projectVersion))
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return ok
|
|
40
|
+
}
|
|
41
|
+
return ok
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
function versionTrim(vstr:string)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return vstr.substring(i);
|
|
44
|
+
function versionTrim (vstr: string): string {
|
|
45
|
+
vstr = vstr.trim()
|
|
46
|
+
let i = -1
|
|
47
|
+
while (++i < vstr.length) {
|
|
48
|
+
const c = vstr.charAt(i)
|
|
49
|
+
if (c >= '0' && c <= '9') break
|
|
50
|
+
}
|
|
51
|
+
return vstr.substring(i)
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
async function fetchTypescriptVersion(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
async function fetchTypescriptVersion (
|
|
55
|
+
|
|
56
|
+
): Promise<string> {
|
|
57
|
+
const result = await executeCommand('tsc', ['-v'])
|
|
58
|
+
if (result.retcode !== 0) return 'Typescript not found'
|
|
59
|
+
const vstr = versionTrim(result.stdStr)
|
|
60
|
+
return vstr
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
async function fetchNodeVersion(
|
|
65
|
-
{
|
|
66
|
-
const result = await executeCommand('node', ['-v'])
|
|
67
|
-
if(result.retcode) return "Node not found"
|
|
68
|
-
var vstr = versionTrim(result.stdStr);
|
|
69
|
-
return vstr;
|
|
63
|
+
async function fetchNodeVersion (
|
|
70
64
|
|
|
65
|
+
): Promise<string> {
|
|
66
|
+
const result = await executeCommand('node', ['-v'])
|
|
67
|
+
if (result.retcode !== 0) return 'Node not found'
|
|
68
|
+
const vstr = versionTrim(result.stdStr)
|
|
69
|
+
return vstr
|
|
71
70
|
}
|
|
72
71
|
|
|
73
|
-
async function fetchNpmVersion(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
async function fetchNpmVersion (
|
|
73
|
+
|
|
74
|
+
): Promise<string> {
|
|
75
|
+
const result = await executeCommand('npm', ['-v'])
|
|
76
|
+
if (result.retcode !== 0) return 'npm not found'
|
|
77
|
+
const vstr = versionTrim(result.stdStr)
|
|
78
|
+
return vstr
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
async function fetchGitVersion(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
async function fetchGitVersion (
|
|
82
|
+
|
|
83
|
+
): Promise<string> {
|
|
84
|
+
const result = await executeCommand('git', ['-v'])
|
|
85
|
+
if (result.retcode !== 0) return 'Git not found'
|
|
86
|
+
const vstr = versionTrim(result.stdStr)
|
|
87
|
+
return vstr
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
// compare to a minimum and report ok or error
|
|
90
91
|
|
|
91
|
-
function report(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
92
|
+
function report (
|
|
93
|
+
name: string,
|
|
94
|
+
version: string,
|
|
95
|
+
minStr: string
|
|
96
|
+
): boolean {
|
|
97
|
+
const ver = new VersionInfo(version)
|
|
98
|
+
const minVer = new VersionInfo(minStr)
|
|
99
|
+
const ok = (ver.isGreaterThan(minVer) || ver.equals(minVer))
|
|
100
|
+
if (ok) {
|
|
101
|
+
console.log(ac.green.bold('√ ') + ac.black.bold(name) + ' ' + ac.grey(version))
|
|
102
|
+
} else {
|
|
103
|
+
console.log(ac.red.bold('X ') + ac.black.bold(name) + ac.red.bold(' does not meet minimum version of ') + ac.blue(minStr))
|
|
104
|
+
}
|
|
105
|
+
return ok
|
|
106
|
+
}
|