@tremho/mist-lift 1.1.2 → 1.1.3-pre-release.1
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/LICENSE +21 -21
- package/README.md +65 -65
- package/build/lift.js +0 -0
- package/package.json +79 -75
- package/src/commands/actions/initQuestions.ts +133 -133
- package/src/commands/actions/setupPackageJson.ts +32 -32
- package/src/commands/build.ts +170 -170
- package/src/commands/builtin/ApiDocMaker.ts +102 -102
- package/src/commands/builtin/BuiltInHandler.ts +47 -47
- package/src/commands/builtin/DeployBuiltInZip.ts +25 -25
- package/src/commands/builtin/StageWebrootZip.ts +36 -36
- package/src/commands/create.ts +52 -52
- package/src/commands/deploy.ts +161 -161
- package/src/commands/doctor.ts +106 -106
- package/src/commands/help.ts +178 -178
- package/src/commands/info.ts +42 -42
- package/src/commands/init.ts +61 -61
- package/src/commands/package.ts +234 -234
- package/src/commands/publish.ts +330 -330
- package/src/commands/settings.ts +73 -73
- package/src/commands/start.ts +43 -43
- package/src/commands/test.ts +37 -37
- package/src/commands/user.ts +20 -20
- package/src/expressRoutes/all.ts +99 -99
- package/src/expressRoutes/api.ts +22 -22
- package/src/expressRoutes/functionBinder.ts +155 -155
- package/src/integration-tests/quickstart-scenario.test.ts +74 -74
- package/src/lib/CaseUtils.ts +63 -63
- package/src/lib/DirectoryUtils.ts +34 -34
- package/src/lib/LiftConfig.ts +74 -74
- package/src/lib/LiftVersion.ts +87 -87
- package/src/lib/Tests/fileCompare.test.ts +35 -35
- package/src/lib/askQuestion.ts +17 -17
- package/src/lib/executeCommand.ts +45 -45
- package/src/lib/fileCompare.ts +55 -55
- package/src/lib/openAPI/ApiBuildCollector.ts +47 -47
- package/src/lib/openAPI/WebrootFileSupport.ts +19 -19
- package/src/lib/openAPI/openApiConstruction.ts +196 -196
- package/src/lib/pathResolve.ts +26 -26
- package/src/lib/utils.ts +43 -43
- package/src/lift.ts +87 -87
- package/templateData/function-definition-template +20 -20
- package/templateData/function-local-ts +16 -16
- package/templateData/function-main-ts +16 -16
- package/templateData/function-runmain-mjs +6 -6
- package/templateData/function-test-template +11 -11
- package/templateData/swagger-ui-bundle.js +2 -2
- package/templateData/swagger-ui-standalone-preset.js +2 -2
- package/templateData/swagger-ui.css +2 -2
- package/tsconfig.json +28 -28
- /package/build/commands/builtin/{prebuilt-zips → prebult-zips}/API.zip +0 -0
- /package/build/commands/builtin/{prebuilt-zips → prebult-zips}/FileServe.zip +0 -0
- /package/build/commands/builtin/{prebuilt-zips → prebult-zips}/Webroot.zip +0 -0
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Steven Ohmert
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Steven Ohmert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
# MistLift
|
|
3
|
-
|
|
4
|
-
_CLI tools and structured project support for easy-access cloud development_
|
|
5
|
-
|
|
6
|
-
MistLift, aka [@tremho/mist-lift at npm](https://www.npmjs.com/package/@tremho/mist-lift) is an OpenSource project aimed at providing an easy and seamless platform for developers
|
|
7
|
-
to quickly develop cloud services locally and then migrating to cloud with a simple and
|
|
8
|
-
lightweight Command Line API that avoids some of the more intimidating aspects of
|
|
9
|
-
using larger frameworks for such purposes.
|
|
10
|
-
|
|
11
|
-
This provides a much lower barrier to entry to would-be cloud developers
|
|
12
|
-
and encourages a more open, distributed set of architectural choices from the
|
|
13
|
-
very beginnings of a new project.
|
|
14
|
-
|
|
15
|
-
The initial version of MistLift is complete with minimal viability
|
|
16
|
-
to represent its future potential. It focuses on a Typescript (JavaScript) oriented
|
|
17
|
-
NodeJS stack hosted on the Amazon Web Services (AWS) Cloud infrastructure.
|
|
18
|
-
|
|
19
|
-
In the future, other stacks will be supported, including DotNet and Python, and
|
|
20
|
-
other stacks supported by AWS.
|
|
21
|
-
Other cloud hosts, such as Azure, are also planned to be supported in future versions.
|
|
22
|
-
|
|
23
|
-
## Contributions Needed
|
|
24
|
-
|
|
25
|
-
MistLift is fully functional now, but there is much more planned in the
|
|
26
|
-
vision roadmap, and your help is needed!
|
|
27
|
-
|
|
28
|
-
[GitHub Repository](https://github.com/tremho/MistLift)
|
|
29
|
-
|
|
30
|
-
Any level of involvement or contribution is appreciated. Please see
|
|
31
|
-
the [Contribution Guidelines](https://github.com/tremho/MistLift/blob/main/CONTRIBUTING.md).
|
|
32
|
-
|
|
33
|
-
Also review the [Future States Plan](https://github.com/tremho/MistLift/blob/main/doc/Future%20State%20Planning.md)
|
|
34
|
-
and the [issues page](https://github.com/tremho/MistLift/issues) for future state plans and status.
|
|
35
|
-
|
|
36
|
-
## Getting Started
|
|
37
|
-
|
|
38
|
-
To get started using MistLift, please see the [QuickStart Guide](https://github.com/tremho/MistLift/blob/main/doc/MistLift%20Quick%20Start.md)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
## Changelog
|
|
42
|
-
|
|
43
|
-
### 1.1.1, 1.1.2 -- 7/1/24
|
|
44
|
-
|
|
45
|
-
- documentation updates
|
|
46
|
-
- insure commands issued at project root
|
|
47
|
-
- build if necessary before starting local server
|
|
48
|
-
- fix local request handling treatment of body
|
|
49
|
-
- fix package definition cross-over bug
|
|
50
|
-
- add lint and test targets
|
|
51
|
-
|
|
52
|
-
### 1.1.0 -- 6/28/24
|
|
53
|
-
- add `info` command
|
|
54
|
-
|
|
55
|
-
### 1.0.3 -- Initial Release 6/27/24
|
|
56
|
-
- Include missing template files in npm publish
|
|
57
|
-
|
|
58
|
-
### 1.0.0 - 1.0.2 -- Pre Release 6/26/24
|
|
59
|
-
- Basic functionality
|
|
60
|
-
- minor bug fixes
|
|
61
|
-
- documentation
|
|
62
|
-
- ts-standard linter adopted
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
1
|
+
|
|
2
|
+
# MistLift
|
|
3
|
+
|
|
4
|
+
_CLI tools and structured project support for easy-access cloud development_
|
|
5
|
+
|
|
6
|
+
MistLift, aka [@tremho/mist-lift at npm](https://www.npmjs.com/package/@tremho/mist-lift) is an OpenSource project aimed at providing an easy and seamless platform for developers
|
|
7
|
+
to quickly develop cloud services locally and then migrating to cloud with a simple and
|
|
8
|
+
lightweight Command Line API that avoids some of the more intimidating aspects of
|
|
9
|
+
using larger frameworks for such purposes.
|
|
10
|
+
|
|
11
|
+
This provides a much lower barrier to entry to would-be cloud developers
|
|
12
|
+
and encourages a more open, distributed set of architectural choices from the
|
|
13
|
+
very beginnings of a new project.
|
|
14
|
+
|
|
15
|
+
The initial version of MistLift is complete with minimal viability
|
|
16
|
+
to represent its future potential. It focuses on a Typescript (JavaScript) oriented
|
|
17
|
+
NodeJS stack hosted on the Amazon Web Services (AWS) Cloud infrastructure.
|
|
18
|
+
|
|
19
|
+
In the future, other stacks will be supported, including DotNet and Python, and
|
|
20
|
+
other stacks supported by AWS.
|
|
21
|
+
Other cloud hosts, such as Azure, are also planned to be supported in future versions.
|
|
22
|
+
|
|
23
|
+
## Contributions Needed
|
|
24
|
+
|
|
25
|
+
MistLift is fully functional now, but there is much more planned in the
|
|
26
|
+
vision roadmap, and your help is needed!
|
|
27
|
+
|
|
28
|
+
[GitHub Repository](https://github.com/tremho/MistLift)
|
|
29
|
+
|
|
30
|
+
Any level of involvement or contribution is appreciated. Please see
|
|
31
|
+
the [Contribution Guidelines](https://github.com/tremho/MistLift/blob/main/CONTRIBUTING.md).
|
|
32
|
+
|
|
33
|
+
Also review the [Future States Plan](https://github.com/tremho/MistLift/blob/main/doc/Future%20State%20Planning.md)
|
|
34
|
+
and the [issues page](https://github.com/tremho/MistLift/issues) for future state plans and status.
|
|
35
|
+
|
|
36
|
+
## Getting Started
|
|
37
|
+
|
|
38
|
+
To get started using MistLift, please see the [QuickStart Guide](https://github.com/tremho/MistLift/blob/main/doc/MistLift%20Quick%20Start.md)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Changelog
|
|
42
|
+
|
|
43
|
+
### 1.1.1, 1.1.2 -- 7/1/24
|
|
44
|
+
|
|
45
|
+
- documentation updates
|
|
46
|
+
- insure commands issued at project root
|
|
47
|
+
- build if necessary before starting local server
|
|
48
|
+
- fix local request handling treatment of body
|
|
49
|
+
- fix package definition cross-over bug
|
|
50
|
+
- add lint and test targets
|
|
51
|
+
|
|
52
|
+
### 1.1.0 -- 6/28/24
|
|
53
|
+
- add `info` command
|
|
54
|
+
|
|
55
|
+
### 1.0.3 -- Initial Release 6/27/24
|
|
56
|
+
- Include missing template files in npm publish
|
|
57
|
+
|
|
58
|
+
### 1.0.0 - 1.0.2 -- Pre Release 6/26/24
|
|
59
|
+
- Basic functionality
|
|
60
|
+
- minor bug fixes
|
|
61
|
+
- documentation
|
|
62
|
+
- ts-standard linter adopted
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
package/build/lift.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,75 +1,79 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@tremho/mist-lift",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "lift command line utility for MistLift development",
|
|
5
|
-
"main": "build/index.js",
|
|
6
|
-
"bin": {
|
|
7
|
-
"lift": "build/lift.js"
|
|
8
|
-
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
"prepublish": "
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"build
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"indev
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"build
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"@types/
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@tremho/mist-lift",
|
|
3
|
+
"version": "1.1.3-pre-release.1",
|
|
4
|
+
"description": "lift command line utility for MistLift development",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"lift": "build/lift.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"prepublish": "run-script-os",
|
|
11
|
+
"prepublish:nix": "npx rimraf build && npm run build && npm run indev",
|
|
12
|
+
"prepublish:windows": "npx rimraf build & npm run build & npm run indev",
|
|
13
|
+
"clean": "npx rimraf build ; npx rimraf node_modules ; npm install",
|
|
14
|
+
"build": "run-script-os",
|
|
15
|
+
"build:windows": "tsc & npm run postbuild",
|
|
16
|
+
"build:nix": "tsc && chmod +x build/lift.js && npm run postbuild",
|
|
17
|
+
"lint": "ts-standard --fix src",
|
|
18
|
+
"test": "npm run build && npm run unitTest && npm run integrationTest",
|
|
19
|
+
"unitTest": "tap --reporter=base --color --passes --disable-coverage src/lib/**/*.test.ts",
|
|
20
|
+
"integrationTest": "tap -t 150000 --reporter=base --color --passes --disable-coverage src/**/*.test.ts",
|
|
21
|
+
"indev": "run-script-os",
|
|
22
|
+
"indev:nix": "echo nix",
|
|
23
|
+
"indev:windows": "echo windows",
|
|
24
|
+
"postbuild" : "run-script-os",
|
|
25
|
+
"postbuild:nix": "cp -r src/commands/builtin/prebuilt-zips build/commands/builtin",
|
|
26
|
+
"postbuild:windows": "robocopy src/commands/builtin/prebuilt-zips build/commands/builtin/prebult-zips /e > NUL 2>&1",
|
|
27
|
+
"installCli": "npm run build && cp build/lift.js ~/.nvm/versions/node/`node --version`/bin/lift"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"build/**/*",
|
|
31
|
+
"src/**/*",
|
|
32
|
+
"templateData/*",
|
|
33
|
+
"index.d.ts",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE",
|
|
36
|
+
"tsconfig.json"
|
|
37
|
+
],
|
|
38
|
+
"keywords": [
|
|
39
|
+
"MistLift",
|
|
40
|
+
"Cloud",
|
|
41
|
+
"Lift",
|
|
42
|
+
"development",
|
|
43
|
+
"framework",
|
|
44
|
+
"cli",
|
|
45
|
+
"aws",
|
|
46
|
+
"express",
|
|
47
|
+
"node"
|
|
48
|
+
],
|
|
49
|
+
"author": "tremho",
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@aws-sdk/client-api-gateway": "^3.598.0",
|
|
53
|
+
"@aws-sdk/client-lambda": "^3.598.0",
|
|
54
|
+
"@aws-sdk/credential-providers": "^3.598.0",
|
|
55
|
+
"@tremho/inverse-y": "^1.1.0",
|
|
56
|
+
"ansi-colors": "^4.1.3",
|
|
57
|
+
"body-parser": "^1.20.2",
|
|
58
|
+
"clear-module": "^4.1.2",
|
|
59
|
+
"express": "^4.19.2",
|
|
60
|
+
"md5": "^2.3.0",
|
|
61
|
+
"openapi-ui": "^1.0.4",
|
|
62
|
+
"openapi3-ts": "^4.3.3",
|
|
63
|
+
"readline-sync": "^1.4.10",
|
|
64
|
+
"zip-dir": "^2.0.0"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@types/express": "^4.17.21",
|
|
68
|
+
"@types/md5": "^2.3.5",
|
|
69
|
+
"@types/node": "^20.14.2",
|
|
70
|
+
"@types/tap": "^15.0.11",
|
|
71
|
+
"@types/ws": "^8.5.10",
|
|
72
|
+
"axios": "^1.7.2",
|
|
73
|
+
"rimraf": "^5.0.7",
|
|
74
|
+
"run-script-os": "^1.1.6",
|
|
75
|
+
"tap": "^19.2.5",
|
|
76
|
+
"ts-standard": "^12.0.2",
|
|
77
|
+
"typescript": "^5.4.5"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
/** Handles the input the user must supply upon init
|
|
2
|
-
*/
|
|
3
|
-
|
|
4
|
-
import * as path from 'path'
|
|
5
|
-
import * as fs from 'fs'
|
|
6
|
-
import { executeCommand } from '../../lib/executeCommand'
|
|
7
|
-
import { ask } from '../../lib/askQuestion'
|
|
8
|
-
|
|
9
|
-
export async function interrogateUserForPackageJsonSettings (
|
|
10
|
-
projectPath: string,
|
|
11
|
-
defaults?: boolean
|
|
12
|
-
): Promise<void> {
|
|
13
|
-
// get existing package.json or {}
|
|
14
|
-
// name of project - module name, display name, short name
|
|
15
|
-
// description
|
|
16
|
-
// set version
|
|
17
|
-
// gitAuthor ?? Author
|
|
18
|
-
// create a repository under gitAuthor?
|
|
19
|
-
// copyright
|
|
20
|
-
// spdx licence
|
|
21
|
-
|
|
22
|
-
const gitAuthor = await findGitAuthor()
|
|
23
|
-
const pkgJson = existingPackageJson(projectPath)
|
|
24
|
-
let name = pkgJson.name ?? nameFromProjectPath(projectPath)
|
|
25
|
-
let version = pkgJson.version ?? '1.0.0-prerelease.1'
|
|
26
|
-
let description = pkgJson.description ?? ''
|
|
27
|
-
let author = pkgJson.author ?? gitAuthor
|
|
28
|
-
let copyright = pkgJson.copyright ?? defaultCopyright(author)
|
|
29
|
-
let spdx = pkgJson.license ?? 'MIT'
|
|
30
|
-
|
|
31
|
-
if (defaults !== true) {
|
|
32
|
-
let ok = false
|
|
33
|
-
while (!ok) {
|
|
34
|
-
name = ask('Module name of this project',
|
|
35
|
-
'module name',
|
|
36
|
-
name
|
|
37
|
-
)
|
|
38
|
-
ok = name !== undefined && name.indexOf(' ') === -1
|
|
39
|
-
}
|
|
40
|
-
ok = false
|
|
41
|
-
while (!ok) {
|
|
42
|
-
version = ask('Project version. Use prerelease suffix for development versions. Use Semantic Versioning (https://semver.org).',
|
|
43
|
-
'version',
|
|
44
|
-
version ?? '0.1.0-prerelease.1'
|
|
45
|
-
)
|
|
46
|
-
ok = version !== undefined && version.indexOf('.') !== -1
|
|
47
|
-
}
|
|
48
|
-
ok = false
|
|
49
|
-
while (!ok) {
|
|
50
|
-
description = ask('Give a brief description of what this project does / what it is for',
|
|
51
|
-
'description',
|
|
52
|
-
description ?? ''
|
|
53
|
-
)
|
|
54
|
-
ok = description !== ''
|
|
55
|
-
}
|
|
56
|
-
ok = false
|
|
57
|
-
while (!ok) {
|
|
58
|
-
author = ask('Identify yourself as the author of this project',
|
|
59
|
-
'name',
|
|
60
|
-
author
|
|
61
|
-
)
|
|
62
|
-
ok = author !== ''
|
|
63
|
-
}
|
|
64
|
-
ok = false
|
|
65
|
-
while (!ok) {
|
|
66
|
-
copyright = ask('Specify a displayable copyright notice',
|
|
67
|
-
'Copyright',
|
|
68
|
-
copyright
|
|
69
|
-
)
|
|
70
|
-
ok = copyright !== ''
|
|
71
|
-
}
|
|
72
|
-
ok = false
|
|
73
|
-
while (!ok) {
|
|
74
|
-
spdx = ask('Specify the appropriate SPDX license identifier for this project. See https://spdx.org/licenses/ for more info.',
|
|
75
|
-
'spdx identifier',
|
|
76
|
-
spdx
|
|
77
|
-
)
|
|
78
|
-
ok = spdx !== ''
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
pkgJson.name = name
|
|
82
|
-
pkgJson.version = version
|
|
83
|
-
pkgJson.description = description
|
|
84
|
-
pkgJson.author = author
|
|
85
|
-
pkgJson.copyright = copyright
|
|
86
|
-
pkgJson.license = spdx
|
|
87
|
-
|
|
88
|
-
const pkgPath = path.join(projectPath, 'package.json')
|
|
89
|
-
fs.writeFileSync(pkgPath,
|
|
90
|
-
JSON.stringify(pkgJson, null, 2))
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function findGitAuthor (
|
|
94
|
-
): Promise<string> {
|
|
95
|
-
return await executeCommand('git', ['config', '--get', 'user.name']).then((rt: any) => {
|
|
96
|
-
const rrt: { retcode: number | undefined, stdStr: string | undefined, errStr: string | undefined } = rt
|
|
97
|
-
let name: string | undefined = ''
|
|
98
|
-
if (rrt?.retcode !== 0) {
|
|
99
|
-
console.error(`Error ${rrt?.retcode ?? ''}`, rrt?.errStr)
|
|
100
|
-
} else {
|
|
101
|
-
name = rrt?.stdStr?.trim().toLowerCase()
|
|
102
|
-
}
|
|
103
|
-
return name ?? ''
|
|
104
|
-
})
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function defaultCopyright (
|
|
108
|
-
name: string
|
|
109
|
-
): string {
|
|
110
|
-
return `(C) ${new Date(Date.now()).getFullYear()} ${name}. All rights reserved.`
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function nameFromProjectPath (
|
|
114
|
-
refPath: string
|
|
115
|
-
): string {
|
|
116
|
-
const n = refPath.lastIndexOf('/') + 1
|
|
117
|
-
return refPath.substring(n)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function existingPackageJson (
|
|
121
|
-
refPath: string
|
|
122
|
-
): any {
|
|
123
|
-
let packageJson: any = {}
|
|
124
|
-
const pkgPath = path.join(refPath, 'package.json')
|
|
125
|
-
if (fs.existsSync((pkgPath))) {
|
|
126
|
-
try {
|
|
127
|
-
packageJson = JSON.parse(fs.readFileSync(pkgPath).toString())
|
|
128
|
-
} catch (e: any) {
|
|
129
|
-
// error in existing package.json. Please fix or remove and try again.
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return packageJson
|
|
133
|
-
}
|
|
1
|
+
/** Handles the input the user must supply upon init
|
|
2
|
+
*/
|
|
3
|
+
|
|
4
|
+
import * as path from 'path'
|
|
5
|
+
import * as fs from 'fs'
|
|
6
|
+
import { executeCommand } from '../../lib/executeCommand'
|
|
7
|
+
import { ask } from '../../lib/askQuestion'
|
|
8
|
+
|
|
9
|
+
export async function interrogateUserForPackageJsonSettings (
|
|
10
|
+
projectPath: string,
|
|
11
|
+
defaults?: boolean
|
|
12
|
+
): Promise<void> {
|
|
13
|
+
// get existing package.json or {}
|
|
14
|
+
// name of project - module name, display name, short name
|
|
15
|
+
// description
|
|
16
|
+
// set version
|
|
17
|
+
// gitAuthor ?? Author
|
|
18
|
+
// create a repository under gitAuthor?
|
|
19
|
+
// copyright
|
|
20
|
+
// spdx licence
|
|
21
|
+
|
|
22
|
+
const gitAuthor = await findGitAuthor()
|
|
23
|
+
const pkgJson = existingPackageJson(projectPath)
|
|
24
|
+
let name = pkgJson.name ?? nameFromProjectPath(projectPath)
|
|
25
|
+
let version = pkgJson.version ?? '1.0.0-prerelease.1'
|
|
26
|
+
let description = pkgJson.description ?? ''
|
|
27
|
+
let author = pkgJson.author ?? gitAuthor
|
|
28
|
+
let copyright = pkgJson.copyright ?? defaultCopyright(author)
|
|
29
|
+
let spdx = pkgJson.license ?? 'MIT'
|
|
30
|
+
|
|
31
|
+
if (defaults !== true) {
|
|
32
|
+
let ok = false
|
|
33
|
+
while (!ok) {
|
|
34
|
+
name = ask('Module name of this project',
|
|
35
|
+
'module name',
|
|
36
|
+
name
|
|
37
|
+
)
|
|
38
|
+
ok = name !== undefined && name.indexOf(' ') === -1
|
|
39
|
+
}
|
|
40
|
+
ok = false
|
|
41
|
+
while (!ok) {
|
|
42
|
+
version = ask('Project version. Use prerelease suffix for development versions. Use Semantic Versioning (https://semver.org).',
|
|
43
|
+
'version',
|
|
44
|
+
version ?? '0.1.0-prerelease.1'
|
|
45
|
+
)
|
|
46
|
+
ok = version !== undefined && version.indexOf('.') !== -1
|
|
47
|
+
}
|
|
48
|
+
ok = false
|
|
49
|
+
while (!ok) {
|
|
50
|
+
description = ask('Give a brief description of what this project does / what it is for',
|
|
51
|
+
'description',
|
|
52
|
+
description ?? ''
|
|
53
|
+
)
|
|
54
|
+
ok = description !== ''
|
|
55
|
+
}
|
|
56
|
+
ok = false
|
|
57
|
+
while (!ok) {
|
|
58
|
+
author = ask('Identify yourself as the author of this project',
|
|
59
|
+
'name',
|
|
60
|
+
author
|
|
61
|
+
)
|
|
62
|
+
ok = author !== ''
|
|
63
|
+
}
|
|
64
|
+
ok = false
|
|
65
|
+
while (!ok) {
|
|
66
|
+
copyright = ask('Specify a displayable copyright notice',
|
|
67
|
+
'Copyright',
|
|
68
|
+
copyright
|
|
69
|
+
)
|
|
70
|
+
ok = copyright !== ''
|
|
71
|
+
}
|
|
72
|
+
ok = false
|
|
73
|
+
while (!ok) {
|
|
74
|
+
spdx = ask('Specify the appropriate SPDX license identifier for this project. See https://spdx.org/licenses/ for more info.',
|
|
75
|
+
'spdx identifier',
|
|
76
|
+
spdx
|
|
77
|
+
)
|
|
78
|
+
ok = spdx !== ''
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
pkgJson.name = name
|
|
82
|
+
pkgJson.version = version
|
|
83
|
+
pkgJson.description = description
|
|
84
|
+
pkgJson.author = author
|
|
85
|
+
pkgJson.copyright = copyright
|
|
86
|
+
pkgJson.license = spdx
|
|
87
|
+
|
|
88
|
+
const pkgPath = path.join(projectPath, 'package.json')
|
|
89
|
+
fs.writeFileSync(pkgPath,
|
|
90
|
+
JSON.stringify(pkgJson, null, 2))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function findGitAuthor (
|
|
94
|
+
): Promise<string> {
|
|
95
|
+
return await executeCommand('git', ['config', '--get', 'user.name']).then((rt: any) => {
|
|
96
|
+
const rrt: { retcode: number | undefined, stdStr: string | undefined, errStr: string | undefined } = rt
|
|
97
|
+
let name: string | undefined = ''
|
|
98
|
+
if (rrt?.retcode !== 0) {
|
|
99
|
+
console.error(`Error ${rrt?.retcode ?? ''}`, rrt?.errStr)
|
|
100
|
+
} else {
|
|
101
|
+
name = rrt?.stdStr?.trim().toLowerCase()
|
|
102
|
+
}
|
|
103
|
+
return name ?? ''
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function defaultCopyright (
|
|
108
|
+
name: string
|
|
109
|
+
): string {
|
|
110
|
+
return `(C) ${new Date(Date.now()).getFullYear()} ${name}. All rights reserved.`
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function nameFromProjectPath (
|
|
114
|
+
refPath: string
|
|
115
|
+
): string {
|
|
116
|
+
const n = refPath.lastIndexOf('/') + 1
|
|
117
|
+
return refPath.substring(n)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function existingPackageJson (
|
|
121
|
+
refPath: string
|
|
122
|
+
): any {
|
|
123
|
+
let packageJson: any = {}
|
|
124
|
+
const pkgPath = path.join(refPath, 'package.json')
|
|
125
|
+
if (fs.existsSync((pkgPath))) {
|
|
126
|
+
try {
|
|
127
|
+
packageJson = JSON.parse(fs.readFileSync(pkgPath).toString())
|
|
128
|
+
} catch (e: any) {
|
|
129
|
+
// error in existing package.json. Please fix or remove and try again.
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return packageJson
|
|
133
|
+
}
|