@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,70 +1,102 @@
1
- import {gatherFunctionDefinitions} from "../../lib/openAPI/ApiBuildCollector";
2
- import {buildOpenApi} from "../../lib/openAPI/openApiConstruction";
3
- import {whiteBright} from "ansi-colors";
4
- import {GetWebrootServePaths} from "../../lib/openAPI/WebrootFileSupport";
1
+ import { gatherFunctionDefinitions } from '../../lib/openAPI/ApiBuildCollector'
2
+ import { buildOpenApi } from '../../lib/openAPI/openApiConstruction'
3
+ import { GetWebrootServePaths } from '../../lib/openAPI/WebrootFileSupport'
5
4
 
6
5
  export async function MakePublicApiDoc
7
6
  (
8
- ):Promise<Uint8Array>
9
- {
10
- const defs = gatherFunctionDefinitions();
11
- return await buildOpenApi(defs)
7
+ ): Promise<Uint8Array> {
8
+ const defs = gatherFunctionDefinitions()
9
+ return await buildOpenApi(defs)
12
10
  }
13
11
 
14
12
  export async function MakeBuiltinApiDoc
15
13
  (
16
- yamlFile:string
14
+ yamlFile: string
17
15
 
18
- ):Promise<Uint8Array>
19
- {
20
- const defs = gatherFunctionDefinitions()
21
- addBuiltInDefinitions(defs)
22
- return await buildOpenApi(defs, false, yamlFile) //, true)
16
+ ): Promise<Uint8Array> {
17
+ const defs = gatherFunctionDefinitions()
18
+ addBuiltInDefinitions(defs)
19
+ return await buildOpenApi(defs, false, yamlFile) //, true)
23
20
  }
24
21
 
25
- export function addBuiltInDefinitions(defs:any[])
26
- {
27
- // console.warn("NOT ADDING ANY BUILTIN API INTEGRATIONS")
28
- // console.log("ADDING apiDef");
29
- defs.push(apiDef);
30
- // console.log("ADDING webrootDef");
31
- defs.push(webrootDef);
22
+ export function addBuiltInDefinitions (defs: any[]): void {
23
+ // console.warn("NOT ADDING ANY BUILTIN API INTEGRATIONS")
24
+ // console.log("ADDING apiDef");
25
+ defs.push(apiDef)
26
+ // console.log("ADDING webrootDef");
27
+ defs.push(webrootDef)
32
28
 
33
- // console.warn("Adding webroot literals");
34
- // do just /docs and see how that goes
35
- let fsdef = Object.assign({},fileServeDef); // copy
36
- fsdef.name = "fileserve_docs"
37
- fsdef.pathMap = "/docs/{path}"
38
- defs.push(fsdef);
39
- const roots = GetWebrootServePaths();
40
- // console.log("roots", roots)
41
- for(let root of roots)
42
- {
43
- if(root) {
44
- let rootName = root;
45
- while (rootName.indexOf("/") != -1) rootName = rootName.replace("/", "").toLowerCase().trim();
46
- let fileserve = Object.assign({}, fileServeDef); // copy
47
- fileserve.name = "fileserve_" + rootName
48
- fileserve.pathMap = `${root}/{path}`
49
- defs.push(fileserve);
50
- }
29
+ // console.warn("Adding webroot literals");
30
+ // do just /docs and see how that goes
31
+ const fsdef = Object.assign({}, fileServeDef) // copy
32
+ fsdef.name = 'fileserve_docs'
33
+ fsdef.pathMap = '/docs/{path}'
34
+ defs.push(fsdef)
35
+ const roots = GetWebrootServePaths()
36
+ // console.log("roots", roots)
37
+ for (const root of roots) {
38
+ if (root !== '') {
39
+ let rootName = root
40
+ while (rootName.includes('/')) rootName = rootName.replace('/', '').toLowerCase().trim()
41
+ const fileserve = Object.assign({}, fileServeDef) // copy
42
+ fileserve.name = 'fileserve_' + rootName
43
+ fileserve.pathMap = `${root}/{path}`
44
+ defs.push(fileserve)
51
45
  }
46
+ }
52
47
  }
53
48
 
54
- const apiDef = {"name": "API", "description": "", "version": "1.0.0", "pathMap": "/api", "allowedMethods": "GET",
55
- "logLevel": "Debug", "sessionRequired": false, "userRequired": false, "schemas": {}, "parameters": [],
56
- "returns": { "200": {"type": "empty", "description": "successful response."}, "500": {"type": "string",
57
- "description": "Error details"}}}
49
+ const apiDef = {
50
+ name: 'API',
51
+ description: '',
52
+ version: '1.0.0',
53
+ pathMap: '/api',
54
+ allowedMethods: 'GET',
55
+ logLevel: 'Debug',
56
+ sessionRequired: false,
57
+ userRequired: false,
58
+ schemas: {},
59
+ parameters: [],
60
+ returns: {
61
+ 200: { type: 'empty', description: 'successful response.' },
62
+ 500: {
63
+ type: 'string',
64
+ description: 'Error details'
65
+ }
66
+ }
67
+ }
58
68
 
59
- const fileServeDef = {"name": "FileServe", "description": "file service", "version":
60
- "1.0.0", "pathMap": "",
61
- "allowedMethods": "GET", "logLevel": "Debug", "sessionRequired": false, "userRequired": false,
62
- "schemas": {}, "parameters": [{"name": "path", "in": "path"}],
63
- "returns": {"200": {"type": "empty", "description": "successful response."},
64
- "500": {"type": "string", "description": "Error details"}}}
69
+ const fileServeDef = {
70
+ name: 'FileServe',
71
+ description: 'file service',
72
+ version:
73
+ '1.0.0',
74
+ pathMap: '',
75
+ allowedMethods: 'GET',
76
+ logLevel: 'Debug',
77
+ sessionRequired: false,
78
+ userRequired: false,
79
+ schemas: {},
80
+ parameters: [{ name: 'path', in: 'path' }],
81
+ returns: {
82
+ 200: { type: 'empty', description: 'successful response.' },
83
+ 500: { type: 'string', description: 'Error details' }
84
+ }
85
+ }
65
86
 
66
- const webrootDef = {"name": "Webroot", "description": "Serves files from the webroot /", "version": "1.0.0",
67
- "pathMap": "/{path}", "allowedMethods": "get", "logLevel": "Debug", "sessionRequired": false, "userRequired": false,
68
- "schemas": {}, "parameters": [{"name": "path", "in": "path"}],
69
- "returns": {"200": {"type": "empty", "description": "successful response."},
70
- "500": {"type": "string", "description": "Error details"}}}
87
+ const webrootDef = {
88
+ name: 'Webroot',
89
+ description: 'Serves files from the webroot /',
90
+ version: '1.0.0',
91
+ pathMap: '/{path}',
92
+ allowedMethods: 'get',
93
+ logLevel: 'Debug',
94
+ sessionRequired: false,
95
+ userRequired: false,
96
+ schemas: {},
97
+ parameters: [{ name: 'path', in: 'path' }],
98
+ returns: {
99
+ 200: { type: 'empty', description: 'successful response.' },
100
+ 500: { type: 'string', description: 'Error details' }
101
+ }
102
+ }
@@ -1,51 +1,47 @@
1
- import {StageWebrootZip} from "./StageWebrootZip";
2
- import {DeployBuiltInZip} from "./DeployBuiltInZip";
3
- import {GetWebrootServePaths} from "../../lib/openAPI/WebrootFileSupport";
1
+ import { StageWebrootZip } from './StageWebrootZip'
2
+ import { DeployBuiltInZip } from './DeployBuiltInZip'
3
+ import { GetWebrootServePaths } from '../../lib/openAPI/WebrootFileSupport'
4
4
 
5
5
  import fs from 'fs'
6
6
  import path from 'path'
7
7
 
8
-
9
8
  export async function DeployWebrootBuiltIn
10
9
  (
11
- )
12
- {
13
- const wrZip = await StageWebrootZip()
14
- // console.log("Deploy Webroot Builtin from "+wrZip)
15
- await DeployBuiltInZip("Webroot", wrZip)
16
- // remove temp zip when done
17
- fs.rmSync(wrZip, {recursive: true});
10
+ ): Promise<void> {
11
+ const wrZip = await StageWebrootZip()
12
+ // console.log("Deploy Webroot Builtin from "+wrZip)
13
+ await DeployBuiltInZip('Webroot', wrZip)
14
+ // remove temp zip when done
15
+ fs.rmSync(wrZip, { recursive: true })
18
16
  }
19
17
 
20
18
  export async function DeployRootFileserves
21
19
  (
22
- )
23
- {
24
- // console.log("Deploy Root Fileserves")
25
- // Get root paths
26
- const roots = GetWebrootServePaths();
27
- // for each, deploy under the name of each
28
- const fileserveZip = path.join(__dirname, 'prebuilt-zips', 'FileServe.zip')
29
- let all:Promise<any>[] = [];
30
- for(let root of roots) {
31
- root = root.trim()
32
- let name = "fileserve_" + root;
33
- while (name.indexOf("/") !== -1) {
34
- name = name.replace('/', '');
35
- }
36
- all.push(DeployBuiltInZip(name, fileserveZip))
20
+ ): Promise<void> {
21
+ // console.log("Deploy Root Fileserves")
22
+ // Get root paths
23
+ const roots = GetWebrootServePaths()
24
+ // for each, deploy under the name of each
25
+ const fileserveZip = path.join(__dirname, 'prebuilt-zips', 'FileServe.zip')
26
+ const all: Array<Promise<any>> = []
27
+ for (let root of roots) {
28
+ root = root.trim()
29
+ let name = 'fileserve_' + root
30
+ while (name.includes('/')) {
31
+ name = name.replace('/', '')
37
32
  }
38
- // console.log('wait all');
39
- await Promise.all(all);
40
- // console.log('all complete');
33
+ all.push(DeployBuiltInZip(name, fileserveZip))
34
+ }
35
+ // console.log('wait all');
36
+ await Promise.all(all)
37
+ // console.log('all complete');
41
38
  }
42
39
 
43
40
  export async function DeployApiBuiltin
44
41
  (
45
- ):Promise<any>
46
- {
47
- console.log("Deploy API Builtin")
48
- // get the prebuilt zip location
49
- const apiZip = path.join(__dirname, 'prebuilt-zips', 'API.zip')
50
- await DeployBuiltInZip("api", apiZip)
42
+ ): Promise<any> {
43
+ console.log('Deploy API Builtin')
44
+ // get the prebuilt zip location
45
+ const apiZip = path.join(__dirname, 'prebuilt-zips', 'API.zip')
46
+ await DeployBuiltInZip('api', apiZip)
51
47
  }
@@ -1,27 +1,25 @@
1
1
 
2
2
  import * as path from 'path'
3
- import {deployPackage} from '../deploy'
3
+ import { deployPackage } from '../deploy'
4
4
 
5
5
  export async function DeployBuiltInZip
6
6
  (
7
- name:string,
8
- zipPath:string
9
- )
10
- {
11
- // console.log(">> Deploying "+name)
12
- await deployPackage(name, zipPath);
7
+ name: string,
8
+ zipPath: string
9
+ ): Promise<void> {
10
+ // console.log(">> Deploying "+name)
11
+ await deployPackage(name, zipPath)
13
12
  }
14
13
 
15
14
  export async function DeployFileserve
16
15
  (
17
- root:string
18
- )
19
- {
20
- // rootName is without slash
21
- if(root) {
22
- let rootName = root.replace("/", "")
23
- let name = "fileserve_" + rootName
24
- let zipPath = path.join(__dirname, 'prebuilt-zips', 'FileServe.zip')
25
- await DeployBuiltInZip(name, zipPath)
26
- }
16
+ root: string
17
+ ): Promise<void> {
18
+ // rootName is without slash
19
+ if (root !== '') {
20
+ const rootName = root.replace('/', '')
21
+ const name = 'fileserve_' + rootName
22
+ const zipPath = path.join(__dirname, 'prebuilt-zips', 'FileServe.zip')
23
+ await DeployBuiltInZip(name, zipPath)
24
+ }
27
25
  }
@@ -1,39 +1,36 @@
1
- import {MakePublicApiDoc} from "./ApiDocMaker";
1
+ import { MakePublicApiDoc } from './ApiDocMaker'
2
2
 
3
- import * as ac from "ansi-colors"
4
3
  import * as path from 'path'
5
4
  import * as fs from 'fs'
6
- import {executeCommand} from "../../lib/executeCommand";
7
- import {resolvePaths} from "../../lib/pathResolve";
8
- import {recurseDirectory} from "../../lib/DirectoryUtils";
9
- import {FolderToZip, UnzipToFolder} from "../../lib/utils";
5
+ import { resolvePaths } from '../../lib/pathResolve'
6
+ import { recurseDirectory } from '../../lib/DirectoryUtils'
7
+ import { FolderToZip, UnzipToFolder } from '../../lib/utils'
10
8
 
11
9
  export async function StageWebrootZip
12
10
  (
13
- ):Promise<string>
14
- {
15
- // console.log(">> staging webroot to zip")
16
- const projectPaths = resolvePaths();
17
- // make a public yaml
18
- await MakePublicApiDoc(); // writes apidoc.yaml to docs
19
- const builtinPath = path.join(__dirname, 'prebuilt-zips', 'Webroot.zip')
20
- const exdir = path.join(projectPaths.basePath, '.package_temp');
21
- await UnzipToFolder(builtinPath, exdir)
22
- const webroot = path.join(projectPaths.basePath, 'webroot');
23
- const packageTemp = path.join(projectPaths.basePath, '.package_temp')
24
- const zipFilesPath = path.join(packageTemp, 'Webroot','__files__')
25
- await recurseDirectory(webroot, (filepath, stats) => {
26
- const relPath = filepath.substring(webroot.length)
27
- if(stats.isDirectory()) {
28
- fs.mkdirSync(zipFilesPath+relPath, {recursive: true})
29
- } else {
30
- fs.copyFileSync(filepath, zipFilesPath + relPath)
31
- }
32
- })
33
- const webrootZip = path.join(projectPaths.basePath, 'a.zip')
11
+ ): Promise<string> {
12
+ // console.log(">> staging webroot to zip")
13
+ const projectPaths = resolvePaths()
14
+ // make a public yaml
15
+ await MakePublicApiDoc() // writes apidoc.yaml to docs
16
+ const builtinPath = path.join(__dirname, 'prebuilt-zips', 'Webroot.zip')
17
+ const exdir = path.join(projectPaths.basePath, '.package_temp')
18
+ await UnzipToFolder(builtinPath, exdir)
19
+ const webroot = path.join(projectPaths.basePath, 'webroot')
20
+ const packageTemp = path.join(projectPaths.basePath, '.package_temp')
21
+ const zipFilesPath = path.join(packageTemp, 'Webroot', '__files__')
22
+ await recurseDirectory(webroot, (filepath, stats) => {
23
+ const relPath = filepath.substring(webroot.length)
24
+ if (stats.isDirectory()) {
25
+ fs.mkdirSync(zipFilesPath + relPath, { recursive: true })
26
+ } else {
27
+ fs.copyFileSync(filepath, zipFilesPath + relPath)
28
+ }
29
+ return false
30
+ })
31
+ const webrootZip = path.join(projectPaths.basePath, 'a.zip')
34
32
 
35
- await FolderToZip(path.join(packageTemp, 'Webroot'), webrootZip)
36
- // return path to this zip
37
- return webrootZip
38
-
39
- }
33
+ await FolderToZip(path.join(packageTemp, 'Webroot'), webrootZip)
34
+ // return path to this zip
35
+ return webrootZip
36
+ }
@@ -2,54 +2,47 @@
2
2
 
3
3
  import * as fs from 'fs'
4
4
  import * as path from 'path'
5
- import * as ac from "ansi-colors"
6
- import {resolvePaths} from "../lib/pathResolve";
7
- import {camelCase, pascalCase} from "../lib/CaseUtils"
8
- import {helpCreate} from "./help";
9
-
5
+ import * as ac from 'ansi-colors'
6
+ import { resolvePaths } from '../lib/pathResolve'
7
+ import { camelCase } from '../lib/CaseUtils'
8
+ import { helpCreate } from './help'
10
9
 
11
10
  /// Create command
12
- export function doCreate(
13
- funcName:string // name of function to create
14
- )
15
- {
16
- if(!funcName) {
17
- helpCreate()
18
- return
19
- } else {
20
-
21
- console.log(ac.green.bold("Creating new function named ")+funcName)
22
-
23
- const projectPaths = resolvePaths();
24
- const funcPath = path.join(projectPaths.functionPath, funcName);
25
- if(!fs.existsSync(funcPath)) fs.mkdirSync(funcPath)
26
- const dataDir = path.join(__dirname, '..', '..', 'templateData');
27
-
28
- const testdirname = camelCase(funcName) + '-tests';
29
- if(!fs.existsSync(path.join(funcPath, testdirname))) fs.mkdirSync(path.join(funcPath, testdirname))
30
- if(!fs.existsSync(path.join(funcPath, 'src'))) fs.mkdirSync(path.join(funcPath, 'src'))
31
-
32
- let localsrc = fs.readFileSync(path.join(dataDir, 'function-local-ts')).toString();
33
- while (localsrc.indexOf("$$FUNCTION_NAME$$") !== -1) {
34
- localsrc = localsrc.replace("$$FUNCTION_NAME$$", funcName);
35
- }
36
- fs.writeFileSync(path.join(funcPath, 'src', 'local.ts'), localsrc);
37
- let defsrc = fs.readFileSync(path.join(dataDir, 'function-definition-template')).toString();
38
- while(defsrc.indexOf("$$FUNCTION_NAME$$") !== -1) {
39
- defsrc = defsrc.replace("$$FUNCTION_NAME$$", funcName);
40
- }
41
- let defpathMap = "/"+funcName.toLowerCase();
42
- defsrc = defsrc.replace("$$PATHMAP$$", defpathMap)
43
- fs.writeFileSync(path.join(funcPath, 'src', 'definition.json'), defsrc);
44
- let mainsrc = fs.readFileSync(path.join(dataDir, 'function-main-ts')).toString();
45
- while(mainsrc.indexOf("$$TemplateName$$") !== -1) {
46
- mainsrc = mainsrc.replace("$$TemplateName$$", funcName);
47
- }
48
- fs.writeFileSync(path.join(funcPath, 'src', 'main.ts'), mainsrc);
49
- fs.copyFileSync(path.join(dataDir, 'function-test-template'), path.join(funcPath, testdirname, 'Sanity.test.ts'))
50
- fs.copyFileSync(path.join(dataDir, 'function-runmain-mjs'), path.join(funcPath, 'runmain.mjs'));
51
-
11
+ export function doCreate (
12
+ funcName?: string // name of function to create
13
+ ): void {
14
+ if (funcName === '' || funcName === undefined) {
15
+ helpCreate()
16
+ } else {
17
+ console.log(ac.green.bold('Creating new function named ') + funcName)
18
+
19
+ const projectPaths = resolvePaths()
20
+ const funcPath = path.join(projectPaths.functionPath, funcName)
21
+ if (!fs.existsSync(funcPath)) fs.mkdirSync(funcPath)
22
+ const dataDir = path.join(__dirname, '..', '..', 'templateData')
23
+
24
+ const testdirname = camelCase(funcName) + '-tests'
25
+ if (!fs.existsSync(path.join(funcPath, testdirname))) fs.mkdirSync(path.join(funcPath, testdirname))
26
+ if (!fs.existsSync(path.join(funcPath, 'src'))) fs.mkdirSync(path.join(funcPath, 'src'))
27
+
28
+ let localsrc = fs.readFileSync(path.join(dataDir, 'function-local-ts')).toString()
29
+ while (localsrc.includes('$$FUNCTION_NAME$$')) {
30
+ localsrc = localsrc.replace('$$FUNCTION_NAME$$', funcName)
52
31
  }
53
-
32
+ fs.writeFileSync(path.join(funcPath, 'src', 'local.ts'), localsrc)
33
+ let defsrc = fs.readFileSync(path.join(dataDir, 'function-definition-template')).toString()
34
+ while (defsrc.includes('$$FUNCTION_NAME$$')) {
35
+ defsrc = defsrc.replace('$$FUNCTION_NAME$$', funcName)
36
+ }
37
+ const defpathMap = '/' + funcName.toLowerCase()
38
+ defsrc = defsrc.replace('$$PATHMAP$$', defpathMap)
39
+ fs.writeFileSync(path.join(funcPath, 'src', 'definition.json'), defsrc)
40
+ let mainsrc = fs.readFileSync(path.join(dataDir, 'function-main-ts')).toString()
41
+ while (mainsrc.includes('$$TemplateName$$')) {
42
+ mainsrc = mainsrc.replace('$$TemplateName$$', funcName)
43
+ }
44
+ fs.writeFileSync(path.join(funcPath, 'src', 'main.ts'), mainsrc)
45
+ fs.copyFileSync(path.join(dataDir, 'function-test-template'), path.join(funcPath, testdirname, 'Sanity.test.ts'))
46
+ fs.copyFileSync(path.join(dataDir, 'function-runmain-mjs'), path.join(funcPath, 'runmain.mjs'))
47
+ }
54
48
  }
55
-