@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.
Files changed (106) hide show
  1. package/build/commands/actions/initQuestions.js +24 -22
  2. package/build/commands/actions/initQuestions.js.map +1 -1
  3. package/build/commands/actions/setupPackageJson.js +4 -4
  4. package/build/commands/actions/setupPackageJson.js.map +1 -1
  5. package/build/commands/build.js +31 -25
  6. package/build/commands/build.js.map +1 -1
  7. package/build/commands/builtin/ApiDocMaker.js +60 -23
  8. package/build/commands/builtin/ApiDocMaker.js.map +1 -1
  9. package/build/commands/builtin/BuiltInHandler.js +6 -6
  10. package/build/commands/builtin/BuiltInHandler.js.map +1 -1
  11. package/build/commands/builtin/DeployBuiltInZip.js +4 -4
  12. package/build/commands/builtin/DeployBuiltInZip.js.map +1 -1
  13. package/build/commands/builtin/StageWebrootZip.js +1 -0
  14. package/build/commands/builtin/StageWebrootZip.js.map +1 -1
  15. package/build/commands/create.js +10 -11
  16. package/build/commands/create.js.map +1 -1
  17. package/build/commands/deploy.js +38 -42
  18. package/build/commands/deploy.js.map +1 -1
  19. package/build/commands/doctor.js +38 -37
  20. package/build/commands/doctor.js.map +1 -1
  21. package/build/commands/help.js +93 -93
  22. package/build/commands/help.js.map +1 -1
  23. package/build/commands/init.js +7 -7
  24. package/build/commands/init.js.map +1 -1
  25. package/build/commands/package.js +50 -51
  26. package/build/commands/package.js.map +1 -1
  27. package/build/commands/publish.js +98 -102
  28. package/build/commands/publish.js.map +1 -1
  29. package/build/commands/settings.js +19 -18
  30. package/build/commands/settings.js.map +1 -1
  31. package/build/commands/start.js +4 -4
  32. package/build/commands/start.js.map +1 -1
  33. package/build/commands/test.js +3 -3
  34. package/build/commands/test.js.map +1 -1
  35. package/build/commands/user.js +1 -1
  36. package/build/commands/user.js.map +1 -1
  37. package/build/expressRoutes/all.js +27 -26
  38. package/build/expressRoutes/all.js.map +1 -1
  39. package/build/expressRoutes/api.js +9 -7
  40. package/build/expressRoutes/api.js.map +1 -1
  41. package/build/expressRoutes/functionBinder.js +38 -36
  42. package/build/expressRoutes/functionBinder.js.map +1 -1
  43. package/build/lib/CaseUtils.js +2 -2
  44. package/build/lib/CaseUtils.js.map +1 -1
  45. package/build/lib/DirectoryUtils.js +4 -3
  46. package/build/lib/DirectoryUtils.js.map +1 -1
  47. package/build/lib/LiftConfig.js +18 -20
  48. package/build/lib/LiftConfig.js.map +1 -1
  49. package/build/lib/LiftVersion.js +17 -12
  50. package/build/lib/LiftVersion.js.map +1 -1
  51. package/build/lib/Tests/fileCompare.test.js +11 -10
  52. package/build/lib/Tests/fileCompare.test.js.map +1 -1
  53. package/build/lib/askQuestion.js +3 -2
  54. package/build/lib/askQuestion.js.map +1 -1
  55. package/build/lib/executeCommand.js +46 -33
  56. package/build/lib/executeCommand.js.map +1 -1
  57. package/build/lib/fileCompare.js +9 -8
  58. package/build/lib/fileCompare.js.map +1 -1
  59. package/build/lib/openAPI/ApiBuildCollector.js +9 -8
  60. package/build/lib/openAPI/ApiBuildCollector.js.map +1 -1
  61. package/build/lib/openAPI/WebrootFileSupport.js +4 -3
  62. package/build/lib/openAPI/WebrootFileSupport.js.map +1 -1
  63. package/build/lib/openAPI/openApiConstruction.js +62 -61
  64. package/build/lib/openAPI/openApiConstruction.js.map +1 -1
  65. package/build/lib/pathResolve.js +4 -4
  66. package/build/lib/pathResolve.js.map +1 -1
  67. package/build/lib/utils.js +5 -4
  68. package/build/lib/utils.js.map +1 -1
  69. package/build/lift.js +14 -15
  70. package/build/lift.js.map +1 -1
  71. package/package.json +2 -1
  72. package/src/commands/actions/initQuestions.ts +112 -112
  73. package/src/commands/actions/setupPackageJson.ts +21 -25
  74. package/src/commands/build.ts +143 -146
  75. package/src/commands/builtin/ApiDocMaker.ts +86 -54
  76. package/src/commands/builtin/BuiltInHandler.ts +31 -35
  77. package/src/commands/builtin/DeployBuiltInZip.ts +15 -17
  78. package/src/commands/builtin/StageWebrootZip.ts +29 -32
  79. package/src/commands/create.ts +40 -47
  80. package/src/commands/deploy.ts +139 -152
  81. package/src/commands/doctor.ts +86 -82
  82. package/src/commands/help.ts +152 -153
  83. package/src/commands/init.ts +37 -39
  84. package/src/commands/package.ts +201 -204
  85. package/src/commands/publish.ts +277 -312
  86. package/src/commands/settings.ts +67 -70
  87. package/src/commands/start.ts +32 -37
  88. package/src/commands/test.ts +15 -16
  89. package/src/commands/user.ts +1 -1
  90. package/src/expressRoutes/all.ts +73 -78
  91. package/src/expressRoutes/api.ts +14 -16
  92. package/src/expressRoutes/functionBinder.ts +144 -151
  93. package/src/lib/CaseUtils.ts +49 -54
  94. package/src/lib/DirectoryUtils.ts +25 -27
  95. package/src/lib/LiftConfig.ts +46 -54
  96. package/src/lib/LiftVersion.ts +69 -77
  97. package/src/lib/Tests/fileCompare.test.ts +27 -26
  98. package/src/lib/askQuestion.ts +12 -13
  99. package/src/lib/executeCommand.ts +40 -33
  100. package/src/lib/fileCompare.ts +46 -37
  101. package/src/lib/openAPI/ApiBuildCollector.ts +36 -36
  102. package/src/lib/openAPI/WebrootFileSupport.ts +15 -17
  103. package/src/lib/openAPI/openApiConstruction.ts +169 -175
  104. package/src/lib/pathResolve.ts +22 -28
  105. package/src/lib/utils.ts +31 -33
  106. package/src/lift.ts +68 -67
@@ -1,171 +1,158 @@
1
1
 
2
2
  import {
3
- LambdaClient,
4
- CreateFunctionCommand,
5
- DeleteFunctionCommand,
6
- AddPermissionCommand
7
- } from "@aws-sdk/client-lambda";
3
+ LambdaClient,
4
+ CreateFunctionCommand,
5
+ DeleteFunctionCommand,
6
+ AddPermissionCommand
7
+ } from '@aws-sdk/client-lambda'
8
8
 
9
- import md5 from "md5";
9
+ import md5 from 'md5'
10
10
 
11
- import path from "path"
12
- import fs, {Stats} from "fs"
13
- import {resolvePaths} from "../lib/pathResolve"
11
+ import path from 'path'
12
+ import fs from 'fs'
13
+ import { resolvePaths } from '../lib/pathResolve'
14
14
 
15
- import * as ac from "ansi-colors"
15
+ import * as ac from 'ansi-colors'
16
16
 
17
- import {doTestAsync} from "./test"
18
- import {recurseDirectory} from "../lib/DirectoryUtils"
19
- import {getLiftVersion, getProjectName, getProjectVersion} from "../lib/LiftVersion"
20
- import {executeCommand} from "../lib/executeCommand"
21
- import {isNewerFile} from "../lib/fileCompare"
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
- args:string[]
35
- ): Promise<number>
36
- {
37
- projectPaths = resolvePaths()
38
-
39
- const deploymentRecordPath = path.join(projectPaths.basePath, '.deployed')
40
- try { deploymentRecord = JSON.parse(fs.readFileSync(deploymentRecordPath).toString()) } catch {}
41
-
42
- // the main package json that has all imports
43
- const mainPkgJsonPath = path.join(projectPaths.packagePath)
44
- const mainPkgSrc = fs.readFileSync(mainPkgJsonPath).toString()
45
- const mainPkgJson = JSON.parse(mainPkgSrc)
46
-
47
- const projectName = getProjectName()
48
- const projectVersion = getProjectVersion()
49
- const liftVersion = getLiftVersion()
50
-
51
- const funcsToDeploy: string[] = []
52
- const options: string[] = []
53
- for (let arg of args) {
54
- if (arg.charAt(0) == '-') {
55
- options.push(arg.toLowerCase())
56
- } else funcsToDeploy.push(arg)
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
- if (options.indexOf("--no-package") === -1) {
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
- if (!funcsToDeploy.length) {
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(funcName:string, zipFile?:string) {
106
- // first off, anchor a base directory
107
- zipFile ??= path.join(projectPaths.basePath, 'MistLift_Zips', funcName+".zip")
108
-
109
- // funcname gets decorated with current instance identifier
110
- var idsrc = md5((getProjectName()??"") + (getProjectVersion()??""))
111
- var dFuncName = funcName + "_"+idsrc
112
-
113
- // See if function exists
114
- const client:any = new LambdaClient(getAWSCredentials());
115
- const command:any = new DeleteFunctionCommand({
116
- FunctionName: dFuncName
117
- });
118
- client.send(command).then((response:any) => {
119
- }).catch((e:any) => {
120
- });
121
-
122
- // console.log(ac.green.italic("deploying ")+ac.green.bold(funcName)+"...")
123
-
124
- try {
125
- const response:any = await CreateCloudFunction(dFuncName, zipFile);
126
- const parts = response.FunctionArn.split(":");
127
- const principal = parts[4]
128
- await AddPermissions(client, dFuncName, principal);
129
- console.log(ac.green.bold(`Successfully deployed ${funcName}`));
130
- }
131
- catch(e:any) {
132
- console.error(ac.red.bold.italic("Error deploying "+funcName), e);
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
- funcName:string,
137
- zipFile:string
138
-
139
- ) : Promise<any>
140
- {
141
-
142
- const settings = getSettings();
143
- const nodeRuntime:RuntimeType|undefined = settings.awsNodeRuntime
144
- const serviceRole:string = settings.awsServiceRoleARN ?? ""
145
- const zipFileBase64:Uint8Array = fs.readFileSync(zipFile);
146
- const client:any = new LambdaClient(getAWSCredentials());
147
- const command:any = new CreateFunctionCommand({
148
- FunctionName: funcName,
149
- Runtime: nodeRuntime,
150
- Role: serviceRole,
151
- Handler: 'runmain.handler',
152
- Code: {
153
- ZipFile: zipFileBase64
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(client:LambdaClient, funcName:string, principal:string):Promise<any>
160
- {
161
- const region = getSettings().awsPreferredRegion
162
- const WSApi = "/"+funcName.toLowerCase();
163
- const command:any = new AddPermissionCommand({
164
- FunctionName: funcName,
165
- StatementId: "InvokePermission",
166
- Action: "lambda:invokeFunction",
167
- Principal: "apigateway.amazonaws.com",
168
- SourceArn: `arn:aws:execute-api:${region}:${principal}:${WSApi}`
169
- });
170
- return client.send(command);
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
  }
@@ -1,102 +1,106 @@
1
1
 
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";
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
- const liftVersion = getLiftVersion().toString()
13
- const projectVersion = getProjectVersion().toString()
14
- const projectName = getProjectName();
15
- const typescriptVersion = await fetchTypescriptVersion()
16
- const nodeVersion = await fetchNodeVersion()
17
- const npmVersion = await fetchNpmVersion()
18
- const gitVersion = await fetchGitVersion();
19
- const settingsAvail = areSettingsAvailable();
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
- console.log("Checking installed dependencies:")
22
- let ok = report("MistLift", liftVersion, "0.1.0")
23
- ok = ok && report("Typescript", typescriptVersion, "5.3.3")
24
- ok = ok && report("Node", nodeVersion, "20.11.0")
25
- ok = ok && report("Npm", npmVersion, "10.3.0")
26
- report("Git", gitVersion, "2.0.0")
27
- if(!settingsAvail) {
28
- console.log("")
29
- console.log(ac.yellow.dim.bold("Cloud Settings are not set. ")+ac.blue("run "+ac.bold("lift settings")))
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
- if(!ok) {
32
- console.log("")
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
- vstr = vstr.trim();
48
- let i = -1;
49
- while(++i < vstr.length) {
50
- let c = vstr.charAt(i);
51
- if(c >= '0' && c <= '9') break;
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
- const result = await executeCommand('tsc', ['-v'])
59
- if(result.retcode) return "Typescript not found"
60
- var vstr = versionTrim(result.stdStr);
61
- return vstr;
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
- const result = await executeCommand('npm', ['-v'])
76
- if(result.retcode) return "npm not found"
77
- var vstr = versionTrim(result.stdStr);
78
- return vstr;
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
- const result = await executeCommand('git', ['-v'])
84
- if(result.retcode) return "Git not found"
85
- var vstr = versionTrim(result.stdStr);
86
- return vstr;
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(name:string, version:string, minStr:string):boolean
92
- {
93
- const ver = new VersionInfo(version);
94
- const minVer = new VersionInfo(minStr);
95
- let ok = (ver.isGreaterThan(minVer) || ver.equals(minVer))
96
- if(ok) {
97
- console.log(ac.green.bold("√ ")+ac.black.bold(name)+" "+ac.grey(version))
98
- } else {
99
- console.log(ac.red.bold("X ")+ac.black.bold(name)+ac.red.bold(" does not meet minimum version of ")+ac.blue(minStr))
100
- }
101
- return ok;
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
+ }