@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.
Files changed (107) hide show
  1. package/README.md +12 -0
  2. package/build/commands/actions/initQuestions.js +24 -22
  3. package/build/commands/actions/initQuestions.js.map +1 -1
  4. package/build/commands/actions/setupPackageJson.js +4 -4
  5. package/build/commands/actions/setupPackageJson.js.map +1 -1
  6. package/build/commands/build.js +31 -25
  7. package/build/commands/build.js.map +1 -1
  8. package/build/commands/builtin/ApiDocMaker.js +60 -23
  9. package/build/commands/builtin/ApiDocMaker.js.map +1 -1
  10. package/build/commands/builtin/BuiltInHandler.js +6 -6
  11. package/build/commands/builtin/BuiltInHandler.js.map +1 -1
  12. package/build/commands/builtin/DeployBuiltInZip.js +4 -4
  13. package/build/commands/builtin/DeployBuiltInZip.js.map +1 -1
  14. package/build/commands/builtin/StageWebrootZip.js +1 -0
  15. package/build/commands/builtin/StageWebrootZip.js.map +1 -1
  16. package/build/commands/create.js +10 -11
  17. package/build/commands/create.js.map +1 -1
  18. package/build/commands/deploy.js +38 -42
  19. package/build/commands/deploy.js.map +1 -1
  20. package/build/commands/doctor.js +38 -37
  21. package/build/commands/doctor.js.map +1 -1
  22. package/build/commands/help.js +93 -93
  23. package/build/commands/help.js.map +1 -1
  24. package/build/commands/init.js +7 -7
  25. package/build/commands/init.js.map +1 -1
  26. package/build/commands/package.js +50 -51
  27. package/build/commands/package.js.map +1 -1
  28. package/build/commands/publish.js +98 -102
  29. package/build/commands/publish.js.map +1 -1
  30. package/build/commands/settings.js +19 -18
  31. package/build/commands/settings.js.map +1 -1
  32. package/build/commands/start.js +4 -4
  33. package/build/commands/start.js.map +1 -1
  34. package/build/commands/test.js +3 -3
  35. package/build/commands/test.js.map +1 -1
  36. package/build/commands/user.js +1 -1
  37. package/build/commands/user.js.map +1 -1
  38. package/build/expressRoutes/all.js +27 -26
  39. package/build/expressRoutes/all.js.map +1 -1
  40. package/build/expressRoutes/api.js +9 -7
  41. package/build/expressRoutes/api.js.map +1 -1
  42. package/build/expressRoutes/functionBinder.js +38 -36
  43. package/build/expressRoutes/functionBinder.js.map +1 -1
  44. package/build/lib/CaseUtils.js +2 -2
  45. package/build/lib/CaseUtils.js.map +1 -1
  46. package/build/lib/DirectoryUtils.js +4 -3
  47. package/build/lib/DirectoryUtils.js.map +1 -1
  48. package/build/lib/LiftConfig.js +18 -20
  49. package/build/lib/LiftConfig.js.map +1 -1
  50. package/build/lib/LiftVersion.js +17 -12
  51. package/build/lib/LiftVersion.js.map +1 -1
  52. package/build/lib/Tests/fileCompare.test.js +11 -10
  53. package/build/lib/Tests/fileCompare.test.js.map +1 -1
  54. package/build/lib/askQuestion.js +3 -2
  55. package/build/lib/askQuestion.js.map +1 -1
  56. package/build/lib/executeCommand.js +46 -33
  57. package/build/lib/executeCommand.js.map +1 -1
  58. package/build/lib/fileCompare.js +9 -8
  59. package/build/lib/fileCompare.js.map +1 -1
  60. package/build/lib/openAPI/ApiBuildCollector.js +9 -8
  61. package/build/lib/openAPI/ApiBuildCollector.js.map +1 -1
  62. package/build/lib/openAPI/WebrootFileSupport.js +4 -3
  63. package/build/lib/openAPI/WebrootFileSupport.js.map +1 -1
  64. package/build/lib/openAPI/openApiConstruction.js +62 -61
  65. package/build/lib/openAPI/openApiConstruction.js.map +1 -1
  66. package/build/lib/pathResolve.js +4 -4
  67. package/build/lib/pathResolve.js.map +1 -1
  68. package/build/lib/utils.js +5 -4
  69. package/build/lib/utils.js.map +1 -1
  70. package/build/lift.js +14 -15
  71. package/build/lift.js.map +1 -1
  72. package/package.json +2 -1
  73. package/src/commands/actions/initQuestions.ts +112 -112
  74. package/src/commands/actions/setupPackageJson.ts +21 -25
  75. package/src/commands/build.ts +143 -146
  76. package/src/commands/builtin/ApiDocMaker.ts +86 -54
  77. package/src/commands/builtin/BuiltInHandler.ts +31 -35
  78. package/src/commands/builtin/DeployBuiltInZip.ts +15 -17
  79. package/src/commands/builtin/StageWebrootZip.ts +29 -32
  80. package/src/commands/create.ts +40 -47
  81. package/src/commands/deploy.ts +139 -152
  82. package/src/commands/doctor.ts +86 -82
  83. package/src/commands/help.ts +152 -153
  84. package/src/commands/init.ts +37 -39
  85. package/src/commands/package.ts +201 -204
  86. package/src/commands/publish.ts +277 -312
  87. package/src/commands/settings.ts +67 -70
  88. package/src/commands/start.ts +32 -37
  89. package/src/commands/test.ts +15 -16
  90. package/src/commands/user.ts +1 -1
  91. package/src/expressRoutes/all.ts +73 -78
  92. package/src/expressRoutes/api.ts +14 -16
  93. package/src/expressRoutes/functionBinder.ts +144 -151
  94. package/src/lib/CaseUtils.ts +49 -54
  95. package/src/lib/DirectoryUtils.ts +25 -27
  96. package/src/lib/LiftConfig.ts +46 -54
  97. package/src/lib/LiftVersion.ts +69 -77
  98. package/src/lib/Tests/fileCompare.test.ts +27 -26
  99. package/src/lib/askQuestion.ts +12 -13
  100. package/src/lib/executeCommand.ts +40 -33
  101. package/src/lib/fileCompare.ts +46 -37
  102. package/src/lib/openAPI/ApiBuildCollector.ts +36 -36
  103. package/src/lib/openAPI/WebrootFileSupport.ts +15 -17
  104. package/src/lib/openAPI/openApiConstruction.ts +169 -175
  105. package/src/lib/pathResolve.ts +22 -28
  106. package/src/lib/utils.ts +31 -33
  107. package/src/lift.ts +68 -67
@@ -1,95 +1,87 @@
1
1
 
2
2
  import * as path from 'path'
3
3
  import * as fs from 'fs'
4
- import {resolvePaths} from "./pathResolve";
4
+ import { resolvePaths } from './pathResolve'
5
5
 
6
- export class VersionInfo
7
- {
8
- public major:number = 0
9
- public minor:number = 0
10
- public revision:number = 0
11
- public suffix:string = "";
6
+ export class VersionInfo {
7
+ public major: number = 0
8
+ public minor: number = 0
9
+ public revision: number = 0
10
+ public suffix: string = ''
12
11
 
13
- constructor(vstr:string) {
14
- this.parse(vstr);
15
- }
12
+ constructor (vstr: string) {
13
+ this.parse(vstr)
14
+ }
16
15
 
17
- public toString = () => {
18
- return `${this.major}.${this.minor}.${this.revision}`+(this.suffix? "-"+this.suffix : "")
19
- }
20
- public parse = (vstr:string) => {
21
- let sn = vstr.indexOf('-');
22
- let suffix = ""
23
- if(sn !== -1) {
24
- suffix = vstr.substring(sn+1);
25
- vstr = vstr.substring(0,sn);
26
- }
27
- let parts = vstr.split('.');
28
- while(parts.length < 3) parts.push("0");
29
- this.major = parseInt(parts[0])
30
- this.minor = parseInt(parts[1]);
31
- this.revision = parseInt(parts[2]);
32
- if(!isFinite(this.major)) this.major = 0;
33
- if(!isFinite(this.minor)) this.minor = 0;
34
- if(!isFinite(this.revision)) this.revision = 0;
35
- this.suffix = suffix;
36
- }
37
- public equals(other: VersionInfo | string): boolean
38
- {
39
- // Note: not really a valid SemVer comparison
40
- if(typeof other === 'string') other = new VersionInfo(other);
41
- return this.major === other.major
42
- && this.minor === other.minor
43
- && this.revision === other.revision
44
- }
45
- public isGreaterThan(other:VersionInfo | string): boolean
46
- {
47
- // Note: not really a valid SemVer comparison
48
- if(typeof other === 'string') other = new VersionInfo(other);
49
- if(this.major > other.major) return true;
50
- if(this.major < other.major) return false;
51
- if(this.minor > other.minor) return true;
52
- if(this.minor < other.minor) return false;
53
- return (this.revision > other.revision);
16
+ public toString = (): string => {
17
+ let sfx = ''
18
+ if (this.suffix !== '') sfx = '-' + this.suffix
19
+ return `${this.major}.${this.minor}.${this.revision}${sfx}`
20
+ }
21
+
22
+ public parse = (vstr: string): VersionInfo => {
23
+ const sn = vstr.indexOf('-')
24
+ let suffix = ''
25
+ if (sn !== -1) {
26
+ suffix = vstr.substring(sn + 1)
27
+ vstr = vstr.substring(0, sn)
54
28
  }
29
+ const parts = vstr.split('.')
30
+ while (parts.length < 3) parts.push('0')
31
+ this.major = parseInt(parts[0])
32
+ this.minor = parseInt(parts[1])
33
+ this.revision = parseInt(parts[2])
34
+ if (!isFinite(this.major)) this.major = 0
35
+ if (!isFinite(this.minor)) this.minor = 0
36
+ if (!isFinite(this.revision)) this.revision = 0
37
+ this.suffix = suffix
38
+ return this
39
+ }
40
+
41
+ public equals (other: VersionInfo | string): boolean {
42
+ // Note: not really a valid SemVer comparison
43
+ if (typeof other === 'string') other = new VersionInfo(other)
44
+ return this.major === other.major &&
45
+ this.minor === other.minor &&
46
+ this.revision === other.revision
47
+ }
48
+
49
+ public isGreaterThan (other: VersionInfo | string): boolean {
50
+ // Note: not really a valid SemVer comparison
51
+ if (typeof other === 'string') other = new VersionInfo(other)
52
+ if (this.major > other.major) return true
53
+ if (this.major < other.major) return false
54
+ if (this.minor > other.minor) return true
55
+ if (this.minor < other.minor) return false
56
+ return (this.revision > other.revision)
57
+ }
55
58
  }
56
59
 
57
60
  // read version from Lift's package.json
58
- export function getLiftVersion()
59
- {
60
- let pkg = path.join(__dirname, '..', '..', 'package.json');
61
- return readPackageVersion(pkg);
62
-
61
+ export function getLiftVersion (): VersionInfo {
62
+ const pkg = path.join(__dirname, '..', '..', 'package.json')
63
+ return readPackageVersion(pkg)
63
64
  }
64
65
  // read version from project's package.json
65
- export function getProjectVersion()
66
- {
67
- const projectPaths = resolvePaths();
68
- return readPackageVersion(projectPaths.packagePath)
69
-
66
+ export function getProjectVersion (): VersionInfo {
67
+ const projectPaths = resolvePaths()
68
+ return readPackageVersion(projectPaths.packagePath)
70
69
  }
71
70
 
72
- export function getProjectName()
73
- {
74
- const projectPaths = resolvePaths();
75
- let pkgJson:{name?:string} = {}
76
- try {
77
- pkgJson = JSON.parse(fs.readFileSync(projectPaths.packagePath).toString())
78
- }
79
- catch(e) {}
80
- return pkgJson.name;
71
+ export function getProjectName (): string {
72
+ const projectPaths = resolvePaths()
73
+ let pkgJson: { name?: string } = {}
74
+ try {
75
+ pkgJson = JSON.parse(fs.readFileSync(projectPaths.packagePath).toString())
76
+ } catch (e) {}
77
+ return pkgJson.name ?? ''
81
78
  }
82
79
 
83
- function readPackageVersion(pkgPath:string):VersionInfo
84
- {
85
- let pkgJson:{version?:string} = {}
86
- try {
87
- pkgJson = JSON.parse(fs.readFileSync(pkgPath).toString())
88
- }
89
- catch(e) {}
90
-
91
- return new VersionInfo(pkgJson.version ?? "")
80
+ function readPackageVersion (pkgPath: string): VersionInfo {
81
+ let pkgJson: { version?: string } = {}
82
+ try {
83
+ pkgJson = JSON.parse(fs.readFileSync(pkgPath).toString())
84
+ } catch (e) {}
92
85
 
86
+ return new VersionInfo(pkgJson.version ?? '')
93
87
  }
94
-
95
-
@@ -1,34 +1,35 @@
1
1
 
2
- import Tap from "tap"
2
+ /* eslint @typescript-eslint/no-floating-promises: "off" */
3
3
 
4
- import * as path from 'path'
5
- import {isNewer, isNewerFile} from "../fileCompare";
4
+ import Tap from 'tap'
6
5
 
7
- function test(t:any) {
6
+ import * as path from 'path'
7
+ import { isNewerFile } from '../fileCompare'
8
8
 
9
+ function test (t: any): void {
9
10
  // ./dir1/file.1 551 < ./dir2/file.1 552
10
- // ./dir1/file.2 553 > ./dir2/file.1 552
11
- // ./dir1 553 > ./dir2 552
12
- // .dir1 (.1) 552 < ./dir2 552
13
-
14
- const dir1 = path.join(__dirname, "dir1");
15
- const dir2 = path.join(__dirname, "dir2");
16
- const dir1File1 = path.join(dir1, "file.1");
17
- const dir1File2 = path.join(dir1, "file.2");
18
- const dir2File1 = path.join(dir2, "file.1");
19
-
20
- let newer = isNewerFile(dir1File1, dir2File1)
21
- t.equal(newer, false, "./dir1/file.1 < ./dir2/file.1")
22
- newer = isNewerFile(dir1File2, dir2File1)
23
- t.equal(newer, true, "./dir1/file.2 > ./dir2/file.1")
24
- newer = isNewerFile(dir1, dir2);
25
- t.ok(newer, "dir1 > dir2");
26
- newer = isNewerFile(dir1, dir2, ".1");
27
- t.ok(!newer, "./dir1 (.1) < ./dir2")
28
-
29
-
30
- t.end()
11
+ // ./dir1/file.2 553 > ./dir2/file.1 552
12
+ // ./dir1 553 > ./dir2 552
13
+ // .dir1 (.1) 552 < ./dir2 552
14
+
15
+ const dir1 = path.join(__dirname, 'dir1')
16
+ const dir2 = path.join(__dirname, 'dir2')
17
+ const dir1File1 = path.join(dir1, 'file.1')
18
+ const dir1File2 = path.join(dir1, 'file.2')
19
+ const dir2File1 = path.join(dir2, 'file.1')
20
+
21
+ let newer = isNewerFile(dir1File1, dir2File1)
22
+ t.equal(newer, false, './dir1/file.1 < ./dir2/file.1')
23
+ newer = isNewerFile(dir1File2, dir2File1)
24
+ t.equal(newer, true, './dir1/file.2 > ./dir2/file.1')
25
+ newer = isNewerFile(dir1, dir2)
26
+ t.ok(newer, 'dir1 > dir2')
27
+ newer = isNewerFile(dir1, dir2, '.1')
28
+ t.ok(!newer, './dir1 (.1) < ./dir2')
29
+
30
+ t.end()
31
31
  }
32
+
32
33
  Tap.test('IsNewer', t => {
33
- test(t)
34
+ test(t)
34
35
  })
@@ -1,18 +1,17 @@
1
1
  /** handles interaction for asking a question */
2
2
 
3
- import * as ac from "ansi-colors"
4
- const readlineSync = require("readline-sync")
3
+ /* eslint @typescript-eslint/no-var-requires: "off" */
4
+ import * as ac from 'ansi-colors'
5
+ const readlineSync = require('readline-sync')
5
6
 
6
- export function ask(
7
- desc:string, // describes the context
8
- query:string, // asks the actual question
9
- def:string // default answer
7
+ export function ask (
8
+ desc: string, // describes the context
9
+ query: string, // asks the actual question
10
+ def: string // default answer
10
11
 
11
- ) :string // answer provided
12
- {
13
- console.log(ac.dim.blue.italic(desc))
14
- let answer = readlineSync.question(ac.bold.green(query) + ac.dim.grey(` [${def}] `)+ '? ')
15
- if(!answer) answer = def
16
- return answer
12
+ ): string { // answer provided
13
+ console.log(ac.dim.blue.italic(desc))
14
+ let answer = readlineSync.question(ac.bold.green(query) + ac.dim.grey(` [${def}] `) + '? ')
15
+ if (answer === '') answer = def
16
+ return answer
17
17
  }
18
-
@@ -1,38 +1,45 @@
1
1
 
2
- import {exec} from 'child_process'
3
- import * as path from 'path'
2
+ import { exec } from 'child_process'
4
3
 
5
- export function executeCommand(cmd:string, args:any[], cwd = '', consolePass = false, env:any = {}):Promise<any> {
6
- const out = {
7
- stdStr: '',
8
- errStr: '',
9
- retcode: 0
4
+ interface StringObject {
5
+ toString: () => string
6
+ }
7
+
8
+ export async function executeCommand (cmd: string, args: any[], cwd = '', consolePass = false, env: any = {}): Promise<any> {
9
+ const out = {
10
+ stdStr: '',
11
+ errStr: '',
12
+ retcode: 0
13
+ }
14
+ return await new Promise(resolve => {
15
+ const cmdstr = cmd + ' ' + args.join(' ')
16
+ // console.log('executing ', cmdstr, 'at', cwd)
17
+ const opts = {
18
+ cwd,
19
+ env: Object.assign(env, process.env)
20
+ }
21
+ const proc = exec(cmdstr, opts)
22
+ if (proc.stdout != null) {
23
+ proc.stdout.on('data', (data: StringObject) => {
24
+ out.stdStr += data.toString()
25
+ if (consolePass) process.stdout.write(data.toString())
26
+ })
10
27
  }
11
- return new Promise(resolve => {
12
- let cmdstr = cmd + ' ' + args.join(' ')
13
- // console.log('executing ', cmdstr, 'at', cwd)
14
- const opts = {
15
- cwd:cwd,
16
- env: Object.assign(env, process.env)
17
- }
18
- const proc = exec(cmdstr, opts)
19
- if(proc.stdout) proc.stdout.on('data', data => {
20
- out.stdStr += data.toString()
21
- if(consolePass) process.stdout.write(data.toString())
22
- })
23
- if(proc.stderr) proc.stderr.on('data', data => {
24
- out.errStr += data.toString()
25
- if(consolePass) process.stdout.write(data.toString())
26
- })
27
- proc.on('error', error => {
28
- console.error(error)
29
- if(!out.errStr) out.errStr = error.message
30
- out.retcode = -1
31
- resolve(out)
32
- })
33
- proc.on('close', code => {
34
- out.retcode = code === null ? -1 : code
35
- resolve(out)
36
- })
28
+ if (proc.stderr != null) {
29
+ proc.stderr.on('data', (data: StringObject) => {
30
+ out.errStr += data.toString()
31
+ if (consolePass) process.stdout.write(data.toString())
32
+ })
33
+ }
34
+ proc.on('error', error => {
35
+ console.error(error)
36
+ if (out.errStr === '') out.errStr = error.message
37
+ out.retcode = -1
38
+ resolve(out)
39
+ })
40
+ proc.on('close', code => {
41
+ out.retcode = code === null ? -1 : code
42
+ resolve(out)
37
43
  })
44
+ })
38
45
  }
@@ -1,46 +1,55 @@
1
- import path from "path";
2
- import fs from "fs";
3
- import {recurseDirectory} from "./DirectoryUtils";
1
+ import path from 'path'
2
+ import fs from 'fs'
3
+ import { recurseDirectory } from './DirectoryUtils'
4
4
 
5
5
  // true if filepath > mapped file in outDir (i.e. .ts > .js)
6
- export function isNewer(filepath:string, outDir:string, mappingObj:any = {".ts": ".js"})
7
- {
8
- let basename = path.basename(filepath);
9
- let ext = path.extname(filepath)
10
- basename = basename.substring(0, basename.lastIndexOf(ext));
11
- let newExt = "";
6
+ export function isNewer (
7
+ filepath: string,
8
+ outDir: string,
9
+ mappingObj: any = { '.ts': '.js' }
10
+ ): boolean {
11
+ let basename = path.basename(filepath)
12
+ const ext = path.extname(filepath)
13
+ basename = basename.substring(0, basename.lastIndexOf(ext))
14
+ let newExt = ''
12
15
 
13
- if(mappingObj[ext]) newExt = mappingObj[ext];
16
+ if (mappingObj[ext] !== undefined) newExt = mappingObj[ext]
14
17
 
15
- let outfile = path.join(outDir, basename+newExt);
16
- return isNewerFile(filepath, outfile);
18
+ const outfile = path.join(outDir, basename + newExt)
19
+ return isNewerFile(filepath, outfile)
17
20
  }
18
21
 
19
22
  // true if filepath is newer than destpath
20
- export function isNewerFile(filepath:string, destpath:string, srcFilter:string = "", dstFilter:string = "")
21
- {
22
- const sstat = fs.statSync(filepath);
23
- const srcTime = sstat.isDirectory() ? latestInDirectory(filepath, srcFilter) : fs.statSync(filepath).mtime;
24
- let destTime = new Date(0);
25
- if(fs.existsSync((destpath))) {
26
- const dstat = fs.statSync(destpath);
27
- destTime = dstat.isDirectory() ? latestInDirectory(destpath, dstFilter) : fs.statSync(destpath).mtime;
28
- }
29
- return (srcTime >= destTime)
23
+ export function isNewerFile (
24
+ filepath: string,
25
+ destpath: string,
26
+ srcFilter: string = '',
27
+ dstFilter: string = ''
28
+ ): boolean {
29
+ const sstat = fs.statSync(filepath)
30
+ const srcTime = sstat.isDirectory() ? latestInDirectory(filepath, srcFilter) : fs.statSync(filepath).mtime
31
+ let destTime = new Date(0)
32
+ if (fs.existsSync((destpath))) {
33
+ const dstat = fs.statSync(destpath)
34
+ destTime = dstat.isDirectory() ? latestInDirectory(destpath, dstFilter) : fs.statSync(destpath).mtime
35
+ }
36
+ return (srcTime >= destTime)
30
37
  }
31
- function latestInDirectory(dirPath:string, extFilter:string = "")
32
- {
33
- let newestTime = new Date(0);
34
- recurseDirectory(dirPath, (filepath, stats) => {
35
- if(stats.isFile()) {
36
- const ext = path.extname(filepath);
37
- if(!extFilter || ext === extFilter) {
38
- if(stats.mtime > newestTime) {
39
- newestTime = stats.mtime
40
- }
41
- }
38
+ function latestInDirectory (
39
+ dirPath: string,
40
+ extFilter: string = ''
41
+ ): Date {
42
+ let newestTime = new Date(0)
43
+ recurseDirectory(dirPath, (filepath, stats) => {
44
+ if (stats.isFile()) {
45
+ const ext = path.extname(filepath)
46
+ if ((extFilter ?? '') === '' || ext === extFilter) {
47
+ if (stats.mtime > newestTime) {
48
+ newestTime = stats.mtime
42
49
  }
43
- })
44
- return newestTime;
45
-
46
- }
50
+ }
51
+ }
52
+ return false
53
+ })
54
+ return newestTime
55
+ }
@@ -5,43 +5,43 @@
5
5
  */
6
6
  import fs from 'fs'
7
7
  import path from 'path'
8
- import {recurseDirectory} from "../DirectoryUtils";
9
- import {resolvePaths} from "../pathResolve";
8
+ import { recurseDirectory } from '../DirectoryUtils'
9
+ import { resolvePaths } from '../pathResolve'
10
10
 
11
-
12
- export function gatherFunctionDefinitions():any[] {
13
- const defs:any = []
14
- try {
15
- const projectPaths = resolvePaths();
16
- if(!projectPaths.verified) return [];
17
- const funcNames: string[] = [];
18
- if(!fs.existsSync(projectPaths.functionPath)) return [];
19
- let firstDepth = 0;
20
- recurseDirectory(projectPaths.functionPath, (filepath, stats) => {
21
- if (stats.isDirectory()) {
22
- let depth = filepath.split(path.sep).length
23
- if(!firstDepth) firstDepth = depth
24
- if(firstDepth == depth) {
25
- funcNames.push(path.basename(filepath));
26
- }
27
- }
28
- })
29
- if(projectPaths.functionPath.indexOf('functions') !== -1 ) {
30
- for (let name of funcNames) {
31
- let defPath = path.join(projectPaths.functionPath, name, 'src', 'definition.json')
32
- if (fs.existsSync(defPath)) {
33
- const content = fs.readFileSync(defPath).toString()
34
- let buildPath = path.join(projectPaths.buildPath, 'functions', name, 'src', 'definition.json')
35
- // fs.writeFileSync(buildPath, content); // use this opportunity to copy to build folder before we use it.
36
- defs.push(JSON.parse(content))
37
- } else {
38
- console.error(`Definition file not found at ${defPath}`);
39
- return [];
40
- }
41
- }
11
+ export function gatherFunctionDefinitions (): any[] {
12
+ const defs: any = []
13
+ try {
14
+ const projectPaths = resolvePaths()
15
+ if (!projectPaths.verified) return []
16
+ const funcNames: string[] = []
17
+ if (!fs.existsSync(projectPaths.functionPath)) return []
18
+ let firstDepth = 0
19
+ recurseDirectory(projectPaths.functionPath, (filepath, stats) => {
20
+ if (stats.isDirectory()) {
21
+ const depth = filepath.split(path.sep).length
22
+ if (firstDepth === 0) firstDepth = depth
23
+ if (firstDepth === depth) {
24
+ funcNames.push(path.basename(filepath))
25
+ }
26
+ }
27
+ return false
28
+ })
29
+ if (projectPaths.functionPath.includes('functions')) {
30
+ for (const name of funcNames) {
31
+ const defPath = path.join(projectPaths.functionPath, name, 'src', 'definition.json')
32
+ if (fs.existsSync(defPath)) {
33
+ const content = fs.readFileSync(defPath).toString()
34
+ // const buildPath = path.join(projectPaths.buildPath, 'functions', name, 'src', 'definition.json')
35
+ // fs.writeFileSync(buildPath, content); // use this opportunity to copy to build folder before we use it.
36
+ defs.push(JSON.parse(content))
37
+ } else {
38
+ console.error(`Definition file not found at ${defPath}`)
39
+ return []
42
40
  }
43
- } catch(e: any) {
44
- console.error("Exception in ApiBuildCollector", e)
41
+ }
45
42
  }
46
- return defs;
43
+ } catch (e: any) {
44
+ console.error('Exception in ApiBuildCollector', e)
45
+ }
46
+ return defs
47
47
  }
@@ -1,21 +1,19 @@
1
1
 
2
2
  import * as path from 'path'
3
- import {resolvePaths} from "../pathResolve";
4
- import {recurseDirectory} from "../DirectoryUtils";
3
+ import { resolvePaths } from '../pathResolve'
4
+ import { recurseDirectory } from '../DirectoryUtils'
5
5
 
6
+ export function GetWebrootServePaths (): string[] {
7
+ const projectPaths = resolvePaths()
8
+ const webroot = path.join(projectPaths.basePath, 'webroot')
6
9
 
7
- export function GetWebrootServePaths(): string[]
8
- {
9
- const projectPaths = resolvePaths();
10
- const webroot = path.join(projectPaths.basePath, "webroot")
11
-
12
- const list:string[] = [''];
13
- recurseDirectory(webroot, (filepath, stats) => {
14
- if(stats.isDirectory())
15
- {
16
- let relpath = filepath.substring(webroot.length);
17
- if(list.indexOf(relpath) === -1) list.push(relpath);
18
- }
19
- })
20
- return list;
21
- }
10
+ const list: string[] = ['']
11
+ recurseDirectory(webroot, (filepath, stats) => {
12
+ if (stats.isDirectory()) {
13
+ const relpath = filepath.substring(webroot.length)
14
+ if (!list.includes(relpath)) list.push(relpath)
15
+ }
16
+ return false
17
+ })
18
+ return list
19
+ }