@uns-kit/cli 0.0.34 → 0.0.36
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 +128 -128
- package/dist/index.js +181 -6
- package/package.json +2 -2
- package/templates/api/src/examples/api-example.ts +62 -61
- package/templates/azure-pipelines.yml +21 -21
- package/templates/codegen/codegen.ts +15 -15
- package/templates/codegen/src/uns/uns-tags.ts +1 -1
- package/templates/codegen/src/uns/uns-topics.ts +1 -1
- package/templates/config-files/config-docker.json +27 -0
- package/templates/config-files/config-localhost.json +27 -0
- package/templates/cron/src/examples/cron-example.ts +46 -45
- package/templates/default/README.md +30 -30
- package/templates/default/config.json +27 -27
- package/templates/default/gitignore +51 -48
- package/templates/default/package.json +19 -19
- package/templates/default/src/config/project.config.extension.example +23 -23
- package/templates/default/src/config/project.config.extension.ts +6 -6
- package/templates/default/src/examples/data-example.ts +68 -68
- package/templates/default/src/examples/load-test-data.ts +108 -108
- package/templates/default/src/examples/table-example.ts +66 -66
- package/templates/default/src/examples/uns-gateway-cli.ts +7 -7
- package/templates/default/src/index.ts +15 -15
- package/templates/default/src/uns/uns-tags.ts +2 -2
- package/templates/default/src/uns/uns-topics.ts +2 -2
- package/templates/default/tsconfig.json +16 -16
- package/templates/python/app/README.md +8 -0
- package/templates/python/app/__init__.py +0 -0
- package/templates/python/examples/README.md +134 -84
- package/templates/python/examples/__init__.py +0 -0
- package/templates/python/examples/api_handler.py +28 -101
- package/templates/python/examples/data_publish.py +11 -0
- package/templates/python/examples/data_subscribe.py +8 -124
- package/templates/python/examples/data_transformer.py +17 -147
- package/templates/python/examples/table_transformer.py +16 -163
- package/templates/python/gateway/__init__.py +0 -0
- package/templates/python/gateway/cli.py +75 -0
- package/templates/python/gateway/client.py +155 -0
- package/templates/python/gateway/manager.py +97 -0
- package/templates/python/gen/__init__.py +1 -0
- package/templates/python/gen/uns_gateway_pb2.py +70 -0
- package/templates/python/gen/uns_gateway_pb2_grpc.py +312 -0
- package/templates/python/main.py +1 -0
- package/templates/python/proto/uns-gateway.proto +102 -102
- package/templates/python/pyproject.toml +5 -0
- package/templates/python/scripts/setup.sh +87 -64
- package/templates/temporal/src/examples/temporal-example.ts +35 -34
- package/templates/vscode/.vscode/launch.json +164 -164
- package/templates/vscode/.vscode/settings.json +9 -9
- package/templates/vscode/uns-kit.code-workspace +13 -13
- package/templates/python/examples/api_register_and_serve.py +0 -159
- package/templates/python/examples/data_publish_once.py +0 -140
- package/templates/python/examples/data_publisher_loop.py +0 -142
- package/templates/python/gateway_client.py +0 -242
- package/templates/python/local/README.md +0 -8
- package/templates/python/local/__init__.py +0 -2
- package/templates/python/requirements.txt +0 -3
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Aljoša Vister
|
|
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) 2023 Aljoša Vister
|
|
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,128 +1,128 @@
|
|
|
1
|
-
# @uns-kit/cli
|
|
2
|
-
|
|
3
|
-
Command line scaffolding tool for the UNS toolkit. It bootstraps a new project with `@uns-kit/core` preconfigured and ready to extend with additional plugins.
|
|
4
|
-
|
|
5
|
-
## Prerequisites
|
|
6
|
-
|
|
7
|
-
- Node.js 18 or newer (ES2022 runtime features)
|
|
8
|
-
- A package manager such as `pnpm`, `npm`, or `yarn`
|
|
9
|
-
- `git` available on PATH (required for `configure-devops`, used to initialize new projects automatically)
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
pnpm --package=@uns-kit/cli dlx uns-kit create my-uns-app
|
|
15
|
-
# or with npx
|
|
16
|
-
npx @uns-kit/cli create my-uns-app
|
|
17
|
-
# or after installing globally
|
|
18
|
-
npm install -g @uns-kit/cli
|
|
19
|
-
uns-kit create my-uns-app
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
The command creates a new directory, copies the starter template, and pins `@uns-kit/core` to the currently published version. After the scaffold finishes:
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
cd my-uns-app
|
|
26
|
-
pnpm install
|
|
27
|
-
pnpm run dev
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
When `git` is available on your PATH the scaffold also initializes a fresh repository so you can commit immediately.
|
|
31
|
-
|
|
32
|
-
## Commands
|
|
33
|
-
|
|
34
|
-
- `uns-kit create <name>` – create a new UNS project in the specified directory.
|
|
35
|
-
- `uns-kit configure [path] [features...]` – run multiple configure templates in sequence (`--all` applies every template).
|
|
36
|
-
- `uns-kit configure-devops [path]` – add Azure DevOps tooling (dependencies, script, config) to an existing project.
|
|
37
|
-
- `uns-kit configure-vscode [path]` – copy VS Code launch/workspace files into an existing project.
|
|
38
|
-
- `uns-kit configure-codegen [path]` – scaffold GraphQL code generation and UNS refresh scripts.
|
|
39
|
-
- `uns-kit configure-api [path]` – copy UNS API examples and add `@uns-kit/api`.
|
|
40
|
-
- `uns-kit configure-cron [path]` – copy UNS cron examples and add `@uns-kit/cron`.
|
|
41
|
-
- `uns-kit configure-temporal [path]` – copy UNS Temporal examples and add `@uns-kit/temporal`.
|
|
42
|
-
- `uns-kit configure-python [path]` – copy Python gateway client scaffolding (no npm dependency required).
|
|
43
|
-
- `uns-kit help` – display usage information.
|
|
44
|
-
|
|
45
|
-
### Configure multiple features at once
|
|
46
|
-
|
|
47
|
-
Chain several add-ons without running each subcommand manually:
|
|
48
|
-
|
|
49
|
-
```bash
|
|
50
|
-
uns-kit configure --all
|
|
51
|
-
uns-kit configure ./apps/gateway devops vscode codegen
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Mix and match feature names after an optional target directory. Use `--all` to apply every available template in one shot.
|
|
55
|
-
|
|
56
|
-
### Configure Azure DevOps
|
|
57
|
-
|
|
58
|
-
Run inside a scaffolded project to add the Azure DevOps pull-request tooling:
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
uns-kit configure-devops
|
|
62
|
-
pnpm install
|
|
63
|
-
pnpm run pull-request
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
The command prompts for your Azure DevOps organization/project, ensures the remote repository exists, and updates `config.json` along with the necessary dev dependencies.
|
|
67
|
-
|
|
68
|
-
### Configure VS Code workspace
|
|
69
|
-
|
|
70
|
-
```bash
|
|
71
|
-
uns-kit configure-vscode
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Copies `.vscode/launch.json` plus a baseline workspace file into the project. Existing files are never overwritten, making it safe to re-run after hand edits.
|
|
75
|
-
|
|
76
|
-
### Configure GraphQL code generation
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
uns-kit configure-codegen
|
|
80
|
-
pnpm install
|
|
81
|
-
pnpm run codegen
|
|
82
|
-
pnpm run refresh-uns
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Adds `codegen.ts`, seeds `src/uns/` placeholder types, and wires the GraphQL Code Generator / `refresh-uns` script into `package.json`. After installing the new dev dependencies you can regenerate strongly-typed operations (`pnpm run codegen`) and rebuild UNS topics/tags from your environment (`pnpm run refresh-uns`).
|
|
86
|
-
|
|
87
|
-
### Add UNS API scaffolding
|
|
88
|
-
|
|
89
|
-
```bash
|
|
90
|
-
uns-kit configure-api
|
|
91
|
-
pnpm install
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
Copies API-oriented examples (under `src/examples/`) and adds `@uns-kit/api` to your project dependencies.
|
|
95
|
-
|
|
96
|
-
### Add cron-based scaffolding
|
|
97
|
-
|
|
98
|
-
```bash
|
|
99
|
-
uns-kit configure-cron
|
|
100
|
-
pnpm install
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Adds cron-oriented example stubs and installs `@uns-kit/cron`.
|
|
104
|
-
|
|
105
|
-
### Add Temporal scaffolding
|
|
106
|
-
|
|
107
|
-
```bash
|
|
108
|
-
uns-kit configure-temporal
|
|
109
|
-
pnpm install
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
Copies Temporal example placeholders and installs `@uns-kit/temporal`.
|
|
113
|
-
|
|
114
|
-
### Add Python gateway scaffolding
|
|
115
|
-
|
|
116
|
-
```bash
|
|
117
|
-
uns-kit configure-python
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
Copies the Python gateway client template (examples, scripts, requirements, proto) into your project so you can iterate on the gRPC gateway from Python alongside your TypeScript project.
|
|
121
|
-
|
|
122
|
-
### Extend the Config Schema
|
|
123
|
-
|
|
124
|
-
Edit `src/config/project.config.extension.ts` inside your generated project and run `pnpm run generate-config-schema`. This regenerates `config.schema.json` and `src/config/app-config.ts`, augmenting `@uns-kit/core`'s `AppConfig` so editors and runtime types stay in sync. If completions lag, reload the TypeScript server in your editor.
|
|
125
|
-
|
|
126
|
-
## License
|
|
127
|
-
|
|
128
|
-
MIT © Aljoša Vister
|
|
1
|
+
# @uns-kit/cli
|
|
2
|
+
|
|
3
|
+
Command line scaffolding tool for the UNS toolkit. It bootstraps a new project with `@uns-kit/core` preconfigured and ready to extend with additional plugins.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Node.js 18 or newer (ES2022 runtime features)
|
|
8
|
+
- A package manager such as `pnpm`, `npm`, or `yarn`
|
|
9
|
+
- `git` available on PATH (required for `configure-devops`, used to initialize new projects automatically)
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm --package=@uns-kit/cli dlx uns-kit create my-uns-app
|
|
15
|
+
# or with npx
|
|
16
|
+
npx @uns-kit/cli create my-uns-app
|
|
17
|
+
# or after installing globally
|
|
18
|
+
npm install -g @uns-kit/cli
|
|
19
|
+
uns-kit create my-uns-app
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The command creates a new directory, copies the starter template, and pins `@uns-kit/core` to the currently published version. After the scaffold finishes:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
cd my-uns-app
|
|
26
|
+
pnpm install
|
|
27
|
+
pnpm run dev
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
When `git` is available on your PATH the scaffold also initializes a fresh repository so you can commit immediately.
|
|
31
|
+
|
|
32
|
+
## Commands
|
|
33
|
+
|
|
34
|
+
- `uns-kit create <name>` – create a new UNS project in the specified directory.
|
|
35
|
+
- `uns-kit configure [path] [features...]` – run multiple configure templates in sequence (`--all` applies every template).
|
|
36
|
+
- `uns-kit configure-devops [path]` – add Azure DevOps tooling (dependencies, script, config) to an existing project.
|
|
37
|
+
- `uns-kit configure-vscode [path]` – copy VS Code launch/workspace files into an existing project.
|
|
38
|
+
- `uns-kit configure-codegen [path]` – scaffold GraphQL code generation and UNS refresh scripts.
|
|
39
|
+
- `uns-kit configure-api [path]` – copy UNS API examples and add `@uns-kit/api`.
|
|
40
|
+
- `uns-kit configure-cron [path]` – copy UNS cron examples and add `@uns-kit/cron`.
|
|
41
|
+
- `uns-kit configure-temporal [path]` – copy UNS Temporal examples and add `@uns-kit/temporal`.
|
|
42
|
+
- `uns-kit configure-python [path]` – copy Python gateway client scaffolding (no npm dependency required).
|
|
43
|
+
- `uns-kit help` – display usage information.
|
|
44
|
+
|
|
45
|
+
### Configure multiple features at once
|
|
46
|
+
|
|
47
|
+
Chain several add-ons without running each subcommand manually:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
uns-kit configure --all
|
|
51
|
+
uns-kit configure ./apps/gateway devops vscode codegen
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Mix and match feature names after an optional target directory. Use `--all` to apply every available template in one shot.
|
|
55
|
+
|
|
56
|
+
### Configure Azure DevOps
|
|
57
|
+
|
|
58
|
+
Run inside a scaffolded project to add the Azure DevOps pull-request tooling:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
uns-kit configure-devops
|
|
62
|
+
pnpm install
|
|
63
|
+
pnpm run pull-request
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The command prompts for your Azure DevOps organization/project, ensures the remote repository exists, and updates `config.json` along with the necessary dev dependencies.
|
|
67
|
+
|
|
68
|
+
### Configure VS Code workspace
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
uns-kit configure-vscode
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Copies `.vscode/launch.json` plus a baseline workspace file into the project. Existing files are never overwritten, making it safe to re-run after hand edits.
|
|
75
|
+
|
|
76
|
+
### Configure GraphQL code generation
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
uns-kit configure-codegen
|
|
80
|
+
pnpm install
|
|
81
|
+
pnpm run codegen
|
|
82
|
+
pnpm run refresh-uns
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Adds `codegen.ts`, seeds `src/uns/` placeholder types, and wires the GraphQL Code Generator / `refresh-uns` script into `package.json`. After installing the new dev dependencies you can regenerate strongly-typed operations (`pnpm run codegen`) and rebuild UNS topics/tags from your environment (`pnpm run refresh-uns`).
|
|
86
|
+
|
|
87
|
+
### Add UNS API scaffolding
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
uns-kit configure-api
|
|
91
|
+
pnpm install
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Copies API-oriented examples (under `src/examples/`) and adds `@uns-kit/api` to your project dependencies.
|
|
95
|
+
|
|
96
|
+
### Add cron-based scaffolding
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
uns-kit configure-cron
|
|
100
|
+
pnpm install
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Adds cron-oriented example stubs and installs `@uns-kit/cron`.
|
|
104
|
+
|
|
105
|
+
### Add Temporal scaffolding
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
uns-kit configure-temporal
|
|
109
|
+
pnpm install
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Copies Temporal example placeholders and installs `@uns-kit/temporal`.
|
|
113
|
+
|
|
114
|
+
### Add Python gateway scaffolding
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
uns-kit configure-python
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Copies the Python gateway client template (examples, scripts, requirements, proto) into your project so you can iterate on the gRPC gateway from Python alongside your TypeScript project.
|
|
121
|
+
|
|
122
|
+
### Extend the Config Schema
|
|
123
|
+
|
|
124
|
+
Edit `src/config/project.config.extension.ts` inside your generated project and run `pnpm run generate-config-schema`. This regenerates `config.schema.json` and `src/config/app-config.ts`, augmenting `@uns-kit/core`'s `AppConfig` so editors and runtime types stay in sync. If completions lag, reload the TypeScript server in your editor.
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
MIT © Aljoša Vister
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,17 @@ async function main() {
|
|
|
23
23
|
printHelp();
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
+
if (command === "configure-config") {
|
|
27
|
+
const targetPath = args[1];
|
|
28
|
+
try {
|
|
29
|
+
await configureConfigFiles(targetPath);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error(error.message);
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
26
37
|
if (command === "configure") {
|
|
27
38
|
const configureArgs = args.slice(1);
|
|
28
39
|
try {
|
|
@@ -137,6 +148,7 @@ function printHelp() {
|
|
|
137
148
|
"\nCommands:\n" +
|
|
138
149
|
" create <name> Scaffold a new UNS application\n" +
|
|
139
150
|
" configure [dir] [features...] Configure multiple templates (--all for everything)\n" +
|
|
151
|
+
" configure-config [dir] Copy configuration example files\n" +
|
|
140
152
|
" configure-devops [dir] Configure Azure DevOps tooling in an existing project\n" +
|
|
141
153
|
" configure-vscode [dir] Add VS Code workspace configuration files\n" +
|
|
142
154
|
" configure-codegen [dir] Copy GraphQL codegen template and dependencies\n" +
|
|
@@ -365,6 +377,53 @@ async function configureVscode(targetPath) {
|
|
|
365
377
|
console.log(" No files were found in the VS Code template directory.");
|
|
366
378
|
}
|
|
367
379
|
}
|
|
380
|
+
async function configureConfigFiles(targetPath) {
|
|
381
|
+
const targetDir = path.resolve(process.cwd(), targetPath ?? ".");
|
|
382
|
+
const templateDir = path.resolve(__dirname, "../templates/config-files");
|
|
383
|
+
try {
|
|
384
|
+
await access(templateDir);
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
throw new Error("Configuration template directory is missing. Please ensure templates/config-files is available.");
|
|
388
|
+
}
|
|
389
|
+
const { copied, skipped } = await copyTemplateDirectory(templateDir, targetDir, targetDir);
|
|
390
|
+
const configFilesToAdjust = copied.filter((file) => {
|
|
391
|
+
const filename = path.basename(file);
|
|
392
|
+
return filename.toLowerCase().startsWith("config") && filename.toLowerCase().endsWith(".json");
|
|
393
|
+
});
|
|
394
|
+
if (configFilesToAdjust.length) {
|
|
395
|
+
await applyConfigTemplatePlaceholders(targetDir, configFilesToAdjust);
|
|
396
|
+
}
|
|
397
|
+
console.log("\nConfiguration example files processed.");
|
|
398
|
+
if (copied.length) {
|
|
399
|
+
console.log(" Added:");
|
|
400
|
+
for (const file of copied) {
|
|
401
|
+
console.log(` ${file}`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (skipped.length) {
|
|
405
|
+
console.log(" Skipped (already exists):");
|
|
406
|
+
for (const file of skipped) {
|
|
407
|
+
console.log(` ${file}`);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (!copied.length && !skipped.length) {
|
|
411
|
+
console.log(" No configuration files were found in templates/config-files.");
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
async function applyConfigTemplatePlaceholders(targetDir, relativePaths) {
|
|
415
|
+
const packageName = await resolvePackageNameFromTarget(targetDir);
|
|
416
|
+
for (const relativePath of relativePaths) {
|
|
417
|
+
const absolutePath = path.join(targetDir, relativePath);
|
|
418
|
+
const replacements = {
|
|
419
|
+
__APP_CONFIG__: deriveConfigIdentifier(absolutePath),
|
|
420
|
+
};
|
|
421
|
+
if (packageName) {
|
|
422
|
+
replacements.__APP_NAME__ = packageName;
|
|
423
|
+
}
|
|
424
|
+
await replaceConfigTemplatePlaceholders(absolutePath, replacements, packageName);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
368
427
|
async function configureCodegen(targetPath) {
|
|
369
428
|
const targetDir = path.resolve(process.cwd(), targetPath ?? ".");
|
|
370
429
|
const templateDir = path.resolve(__dirname, "../templates/codegen");
|
|
@@ -476,6 +535,7 @@ async function configurePython(targetPath) {
|
|
|
476
535
|
const configureFeatureHandlers = {
|
|
477
536
|
devops: configureDevops,
|
|
478
537
|
vscode: configureVscode,
|
|
538
|
+
config: configureConfigFiles,
|
|
479
539
|
codegen: configureCodegen,
|
|
480
540
|
api: configureApi,
|
|
481
541
|
cron: configureCron,
|
|
@@ -486,6 +546,7 @@ const AVAILABLE_CONFIGURE_FEATURES = Object.keys(configureFeatureHandlers);
|
|
|
486
546
|
const configureFeatureLabels = {
|
|
487
547
|
devops: "Azure DevOps tooling",
|
|
488
548
|
vscode: "VS Code workspace",
|
|
549
|
+
config: "Configuration example files",
|
|
489
550
|
codegen: "GraphQL codegen tooling",
|
|
490
551
|
api: "UNS API resources",
|
|
491
552
|
cron: "UNS cron resources",
|
|
@@ -551,6 +612,8 @@ const configureFeatureAliases = {
|
|
|
551
612
|
"configure-devops": "devops",
|
|
552
613
|
vscode: "vscode",
|
|
553
614
|
"configure-vscode": "vscode",
|
|
615
|
+
config: "config",
|
|
616
|
+
"configure-config": "config",
|
|
554
617
|
codegen: "codegen",
|
|
555
618
|
"configure-codegen": "codegen",
|
|
556
619
|
api: "api",
|
|
@@ -983,22 +1046,28 @@ async function patchConfigJson(targetDir, packageName) {
|
|
|
983
1046
|
}
|
|
984
1047
|
}
|
|
985
1048
|
async function replacePlaceholders(targetDir, packageName) {
|
|
1049
|
+
const configFilePath = path.join(targetDir, "config.json");
|
|
986
1050
|
const replacements = {
|
|
987
|
-
__APP_NAME__: packageName
|
|
1051
|
+
__APP_NAME__: packageName,
|
|
1052
|
+
__APP_CONFIG__: deriveConfigIdentifier(configFilePath),
|
|
988
1053
|
};
|
|
989
1054
|
const filesToUpdate = [
|
|
990
1055
|
path.join(targetDir, "README.md"),
|
|
991
1056
|
path.join(targetDir, "src/index.ts"),
|
|
992
|
-
|
|
1057
|
+
configFilePath,
|
|
993
1058
|
];
|
|
994
1059
|
for (const file of filesToUpdate) {
|
|
995
1060
|
try {
|
|
996
1061
|
await access(file);
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1062
|
+
if (path.resolve(file) === path.resolve(configFilePath)) {
|
|
1063
|
+
await replaceConfigTemplatePlaceholders(file, replacements, packageName);
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
1066
|
+
const original = await readFile(file, "utf8");
|
|
1067
|
+
const updated = replaceInString(original, replacements);
|
|
1068
|
+
if (updated !== original) {
|
|
1069
|
+
await writeFile(file, updated, "utf8");
|
|
1000
1070
|
}
|
|
1001
|
-
await writeFile(file, content, "utf8");
|
|
1002
1071
|
}
|
|
1003
1072
|
catch (error) {
|
|
1004
1073
|
if (error.code !== "ENOENT") {
|
|
@@ -1007,6 +1076,112 @@ async function replacePlaceholders(targetDir, packageName) {
|
|
|
1007
1076
|
}
|
|
1008
1077
|
}
|
|
1009
1078
|
}
|
|
1079
|
+
async function resolvePackageNameFromTarget(targetDir) {
|
|
1080
|
+
const packagePath = path.join(targetDir, "package.json");
|
|
1081
|
+
try {
|
|
1082
|
+
const raw = await readFile(packagePath, "utf8");
|
|
1083
|
+
const pkg = JSON.parse(raw);
|
|
1084
|
+
const name = typeof pkg.name === "string" ? pkg.name.trim() : "";
|
|
1085
|
+
return name || undefined;
|
|
1086
|
+
}
|
|
1087
|
+
catch (error) {
|
|
1088
|
+
if (error.code === "ENOENT") {
|
|
1089
|
+
return undefined;
|
|
1090
|
+
}
|
|
1091
|
+
throw error;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
function deriveConfigIdentifier(filePath) {
|
|
1095
|
+
const baseName = path.basename(filePath, path.extname(filePath));
|
|
1096
|
+
if (baseName.startsWith("config-")) {
|
|
1097
|
+
const suffix = baseName.slice("config-".length);
|
|
1098
|
+
return suffix || "config";
|
|
1099
|
+
}
|
|
1100
|
+
return baseName || "config";
|
|
1101
|
+
}
|
|
1102
|
+
async function replaceConfigTemplatePlaceholders(filePath, replacements, packageName) {
|
|
1103
|
+
let raw;
|
|
1104
|
+
try {
|
|
1105
|
+
raw = await readFile(filePath, "utf8");
|
|
1106
|
+
}
|
|
1107
|
+
catch (error) {
|
|
1108
|
+
if (error.code === "ENOENT") {
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1111
|
+
throw error;
|
|
1112
|
+
}
|
|
1113
|
+
let parsed;
|
|
1114
|
+
try {
|
|
1115
|
+
parsed = JSON.parse(raw);
|
|
1116
|
+
}
|
|
1117
|
+
catch (error) {
|
|
1118
|
+
const updated = replaceInString(raw, replacements);
|
|
1119
|
+
if (updated !== raw) {
|
|
1120
|
+
await writeFile(filePath, updated, "utf8");
|
|
1121
|
+
}
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
let modified = applyJsonTemplateReplacements(parsed, replacements);
|
|
1125
|
+
if (packageName && parsed && typeof parsed === "object") {
|
|
1126
|
+
const root = parsed;
|
|
1127
|
+
const unsSection = root["uns"];
|
|
1128
|
+
if (unsSection && typeof unsSection === "object") {
|
|
1129
|
+
const unsRecord = unsSection;
|
|
1130
|
+
if (unsRecord["processName"] !== packageName) {
|
|
1131
|
+
unsRecord["processName"] = packageName;
|
|
1132
|
+
modified = true;
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
if (!modified) {
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1139
|
+
const formatted = JSON.stringify(parsed, null, 2) + "\n";
|
|
1140
|
+
await writeFile(filePath, formatted, "utf8");
|
|
1141
|
+
}
|
|
1142
|
+
function applyJsonTemplateReplacements(target, replacements) {
|
|
1143
|
+
let modified = false;
|
|
1144
|
+
const visit = (value) => {
|
|
1145
|
+
if (typeof value === "string") {
|
|
1146
|
+
const replaced = replaceInString(value, replacements);
|
|
1147
|
+
if (replaced !== value) {
|
|
1148
|
+
modified = true;
|
|
1149
|
+
}
|
|
1150
|
+
return replaced;
|
|
1151
|
+
}
|
|
1152
|
+
if (Array.isArray(value)) {
|
|
1153
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
1154
|
+
const next = visit(value[index]);
|
|
1155
|
+
if (next !== value[index]) {
|
|
1156
|
+
value[index] = next;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
return value;
|
|
1160
|
+
}
|
|
1161
|
+
if (value && typeof value === "object") {
|
|
1162
|
+
const record = value;
|
|
1163
|
+
for (const [key, child] of Object.entries(record)) {
|
|
1164
|
+
const next = visit(child);
|
|
1165
|
+
if (next !== child) {
|
|
1166
|
+
record[key] = next;
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
return record;
|
|
1170
|
+
}
|
|
1171
|
+
return value;
|
|
1172
|
+
};
|
|
1173
|
+
visit(target);
|
|
1174
|
+
return modified;
|
|
1175
|
+
}
|
|
1176
|
+
function replaceInString(input, replacements) {
|
|
1177
|
+
let result = input;
|
|
1178
|
+
for (const [needle, replacement] of Object.entries(replacements)) {
|
|
1179
|
+
if (needle && result.includes(needle)) {
|
|
1180
|
+
result = result.split(needle).join(replacement);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
return result;
|
|
1184
|
+
}
|
|
1010
1185
|
function normalizePackageName(input) {
|
|
1011
1186
|
const trimmed = input.trim();
|
|
1012
1187
|
if (trimmed.startsWith("@")) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uns-kit/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.36",
|
|
4
4
|
"description": "Command line scaffolding tool for UNS applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"azure-devops-node-api": "^15.1.1",
|
|
29
|
-
"@uns-kit/core": "0.0.
|
|
29
|
+
"@uns-kit/core": "0.0.36"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsc -p tsconfig.build.json",
|