@decohere/scaffold 0.0.1-dev.18 → 0.0.1-dev.20261105.54
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 +15 -0
- package/commonjs/src/add-api.action.js +37 -0
- package/commonjs/src/add-api.command.js +39 -0
- package/commonjs/src/add.command.js +22 -0
- package/commonjs/src/add.module.js +24 -0
- package/commonjs/src/auth0-configure.action.js +28 -0
- package/commonjs/src/auth0-configure.command.js +24 -0
- package/commonjs/src/auth0-login.action.js +28 -0
- package/commonjs/src/auth0-login.command.js +23 -0
- package/commonjs/src/auth0.command.js +22 -0
- package/commonjs/src/auth0.module.js +28 -0
- package/commonjs/src/cli.js +8 -0
- package/commonjs/src/create.command.js +22 -0
- package/commonjs/src/create.module.js +24 -0
- package/commonjs/src/domain/prompt.js +62 -0
- package/commonjs/src/index.js +48 -0
- package/commonjs/src/models/compose.model.js +258 -0
- package/commonjs/src/models/config-yaml.model.js +86 -0
- package/commonjs/src/models/const.js +30 -0
- package/commonjs/src/models/dev-container.model.js +172 -0
- package/commonjs/src/models/docker-image.model.js +277 -0
- package/commonjs/src/models/env-file.model.js +48 -0
- package/commonjs/src/models/gitignore.model.js +48 -0
- package/commonjs/src/models/launch-json.model.js +70 -0
- package/commonjs/src/models/package-json.model.js +157 -0
- package/commonjs/src/models/project.model.js +132 -0
- package/commonjs/src/models/source-file.js +4 -0
- package/commonjs/src/models/tsconfig.model.js +32 -0
- package/commonjs/src/models/vitest-config.model.js +33 -0
- package/commonjs/src/models/vscode-settings.model.js +29 -0
- package/commonjs/src/program.js +64 -0
- package/commonjs/src/resolve-target-dir.js +17 -0
- package/commonjs/src/services/scaffold.service.js +60 -0
- package/commonjs/src/version.js +55 -0
- package/commonjs/src/webapi/api-name.js +93 -0
- package/commonjs/src/webapi/auth0-commands.js +250 -0
- package/commonjs/src/webapi/authorize-scopes.js +79 -0
- package/commonjs/src/webapi/cli-options.js +99 -0
- package/commonjs/src/webapi/const.js +54 -0
- package/commonjs/src/webapi/create-api.js +275 -0
- package/commonjs/src/webapi/devcontainer/codebase-rag-mcp.js +164 -0
- package/commonjs/src/webapi/devcontainer/codebase-rag-mcp.ts +182 -0
- package/commonjs/src/webapi/devcontainer/host-scripts.js +50 -0
- package/commonjs/src/webapi/devcontainer/templates/codebase-rag.env.example +3 -0
- package/commonjs/src/webapi/devcontainer/templates/initialize.sh +169 -0
- package/commonjs/src/webapi/devcontainer/templates/post-create.sh +35 -0
- package/commonjs/src/webapi/devcontainer/templates/post-start.sh +65 -0
- package/commonjs/src/webapi/devcontainer/templates/tty-prompt.sh +38 -0
- package/commonjs/src/webapi/features/auth.feature.js +408 -0
- package/commonjs/src/webapi/features/auth0-cli.js +472 -0
- package/commonjs/src/webapi/features/biome-format.js +47 -0
- package/commonjs/src/webapi/features/database.feature.js +433 -0
- package/commonjs/src/webapi/features/finalize.feature.js +93 -0
- package/commonjs/src/webapi/features/postman.feature.js +322 -0
- package/commonjs/src/webapi/models/api-package-json.model.js +58 -0
- package/commonjs/src/webapi/models/auth-config.model.js +24 -0
- package/commonjs/src/webapi/models/controller-source-file.model.js +190 -0
- package/commonjs/src/webapi/models/github-ci.model.js +193 -0
- package/commonjs/src/webapi/models/main-source-file.model.js +165 -0
- package/commonjs/src/webapi/models/production-dockerfile.model.js +75 -0
- package/commonjs/src/webapi/models/sample-files.model.js +58 -0
- package/commonjs/src/webapi/models/webapi-image.model.js +25 -0
- package/commonjs/src/webapi/postman/hello-openapi.js +173 -0
- package/commonjs/src/webapi/postman/local-view.js +182 -0
- package/commonjs/src/webapi/postman/openapi-to-postman.js +238 -0
- package/commonjs/src/webapi/workspace-readme.js +109 -0
- package/commonjs/src/webapi.action.js +28 -0
- package/commonjs/src/webapi.command.js +43 -0
- package/es6/src/add-api.action.js +27 -0
- package/es6/src/add-api.command.js +29 -0
- package/es6/src/add.command.js +12 -0
- package/es6/src/add.module.js +14 -0
- package/es6/src/auth0-configure.action.js +18 -0
- package/es6/src/auth0-configure.command.js +14 -0
- package/es6/src/auth0-login.action.js +18 -0
- package/es6/src/auth0-login.command.js +13 -0
- package/es6/src/auth0.command.js +12 -0
- package/es6/src/auth0.module.js +18 -0
- package/es6/src/cli.js +4 -0
- package/es6/src/create.command.js +12 -0
- package/es6/src/create.module.js +14 -0
- package/es6/src/domain/prompt.js +41 -0
- package/es6/src/index.js +9 -0
- package/es6/src/models/compose.model.js +254 -0
- package/es6/src/models/config-yaml.model.js +74 -0
- package/es6/src/models/const.js +20 -0
- package/es6/src/models/dev-container.model.js +162 -0
- package/es6/src/models/docker-image.model.js +235 -0
- package/es6/src/models/env-file.model.js +44 -0
- package/es6/src/models/gitignore.model.js +38 -0
- package/es6/src/models/launch-json.model.js +60 -0
- package/es6/src/models/package-json.model.js +142 -0
- package/es6/src/models/project.model.js +117 -0
- package/es6/src/models/source-file.js +1 -0
- package/es6/src/models/tsconfig.model.js +22 -0
- package/es6/src/models/vitest-config.model.js +23 -0
- package/es6/src/models/vscode-settings.model.js +19 -0
- package/es6/src/program.js +50 -0
- package/es6/src/resolve-target-dir.js +7 -0
- package/es6/src/services/scaffold.service.js +50 -0
- package/es6/src/version.js +34 -0
- package/es6/src/webapi/api-name.js +57 -0
- package/es6/src/webapi/auth0-commands.js +185 -0
- package/es6/src/webapi/authorize-scopes.js +55 -0
- package/es6/src/webapi/cli-options.js +34 -0
- package/es6/src/webapi/const.js +21 -0
- package/es6/src/webapi/create-api.js +255 -0
- package/es6/src/webapi/devcontainer/codebase-rag-mcp.js +154 -0
- package/es6/src/webapi/devcontainer/codebase-rag-mcp.ts +182 -0
- package/es6/src/webapi/devcontainer/host-scripts.js +29 -0
- package/es6/src/webapi/devcontainer/templates/codebase-rag.env.example +3 -0
- package/es6/src/webapi/devcontainer/templates/initialize.sh +169 -0
- package/es6/src/webapi/devcontainer/templates/post-create.sh +35 -0
- package/es6/src/webapi/devcontainer/templates/post-start.sh +65 -0
- package/es6/src/webapi/devcontainer/templates/tty-prompt.sh +38 -0
- package/es6/src/webapi/features/auth.feature.js +357 -0
- package/es6/src/webapi/features/auth0-cli.js +406 -0
- package/es6/src/webapi/features/biome-format.js +40 -0
- package/es6/src/webapi/features/database.feature.js +423 -0
- package/es6/src/webapi/features/finalize.feature.js +83 -0
- package/es6/src/webapi/features/postman.feature.js +256 -0
- package/es6/src/webapi/models/api-package-json.model.js +53 -0
- package/es6/src/webapi/models/auth-config.model.js +20 -0
- package/es6/src/webapi/models/controller-source-file.model.js +181 -0
- package/{src/webapi/models/github-ci.model.ts → es6/src/webapi/models/github-ci.model.js} +27 -29
- package/es6/src/webapi/models/main-source-file.model.js +161 -0
- package/es6/src/webapi/models/production-dockerfile.model.js +66 -0
- package/es6/src/webapi/models/sample-files.model.js +40 -0
- package/es6/src/webapi/models/webapi-image.model.js +18 -0
- package/es6/src/webapi/postman/hello-openapi.js +166 -0
- package/es6/src/webapi/postman/local-view.js +167 -0
- package/es6/src/webapi/postman/openapi-to-postman.js +179 -0
- package/es6/src/webapi/workspace-readme.js +88 -0
- package/es6/src/webapi.action.js +18 -0
- package/es6/src/webapi.command.js +33 -0
- package/package.json +19 -9
- package/types/src/add-api.action.d.ts +13 -0
- package/types/src/add-api.command.d.ts +7 -0
- package/types/src/add.command.d.ts +6 -0
- package/types/src/add.module.d.ts +14 -0
- package/types/src/auth0-configure.action.d.ts +7 -0
- package/types/src/auth0-configure.command.d.ts +6 -0
- package/types/src/auth0-login.action.d.ts +4 -0
- package/types/src/auth0-login.command.d.ts +6 -0
- package/types/src/auth0.command.d.ts +6 -0
- package/types/src/auth0.module.d.ts +18 -0
- package/types/src/cli.d.ts +2 -0
- package/types/src/create.command.d.ts +6 -0
- package/types/src/create.module.d.ts +14 -0
- package/types/src/domain/prompt.d.ts +4 -0
- package/{src/index.ts → types/src/index.d.ts} +4 -0
- package/types/src/models/compose.model.d.ts +73 -0
- package/types/src/models/config-yaml.model.d.ts +27 -0
- package/types/src/models/const.d.ts +20 -0
- package/types/src/models/dev-container.model.d.ts +49 -0
- package/types/src/models/docker-image.model.d.ts +90 -0
- package/types/src/models/env-file.model.d.ts +16 -0
- package/types/src/models/gitignore.model.d.ts +9 -0
- package/types/src/models/launch-json.model.d.ts +7 -0
- package/types/src/models/package-json.model.d.ts +36 -0
- package/types/src/models/project.model.d.ts +60 -0
- package/{src/models/source-file.ts → types/src/models/source-file.d.ts} +4 -6
- package/types/src/models/tsconfig.model.d.ts +5 -0
- package/types/src/models/vitest-config.model.d.ts +5 -0
- package/types/src/models/vscode-settings.model.d.ts +7 -0
- package/types/src/program.d.ts +8 -0
- package/{src/resolve-target-dir.ts → types/src/resolve-target-dir.d.ts} +1 -4
- package/types/src/services/scaffold.service.d.ts +22 -0
- package/types/src/version.d.ts +6 -0
- package/types/src/webapi/api-name.d.ts +14 -0
- package/types/src/webapi/auth0-commands.d.ts +11 -0
- package/types/src/webapi/authorize-scopes.d.ts +7 -0
- package/types/src/webapi/cli-options.d.ts +6 -0
- package/{src/webapi/const.ts → types/src/webapi/const.d.ts} +9 -21
- package/types/src/webapi/create-api.d.ts +15 -0
- package/types/src/webapi/devcontainer/codebase-rag-mcp.d.ts +32 -0
- package/types/src/webapi/devcontainer/codebase-rag-mcp.ts +182 -0
- package/types/src/webapi/devcontainer/host-scripts.d.ts +7 -0
- package/types/src/webapi/devcontainer/templates/codebase-rag.env.example +3 -0
- package/types/src/webapi/devcontainer/templates/initialize.sh +169 -0
- package/types/src/webapi/devcontainer/templates/post-create.sh +35 -0
- package/types/src/webapi/devcontainer/templates/post-start.sh +65 -0
- package/types/src/webapi/devcontainer/templates/tty-prompt.sh +38 -0
- package/types/src/webapi/features/auth.feature.d.ts +10 -0
- package/types/src/webapi/features/auth0-cli.d.ts +84 -0
- package/types/src/webapi/features/biome-format.d.ts +5 -0
- package/types/src/webapi/features/database.feature.d.ts +7 -0
- package/types/src/webapi/features/finalize.feature.d.ts +2 -0
- package/types/src/webapi/features/postman.feature.d.ts +16 -0
- package/types/src/webapi/models/api-package-json.model.d.ts +18 -0
- package/types/src/webapi/models/auth-config.model.d.ts +26 -0
- package/types/src/webapi/models/controller-source-file.model.d.ts +46 -0
- package/types/src/webapi/models/github-ci.model.d.ts +9 -0
- package/types/src/webapi/models/main-source-file.model.d.ts +54 -0
- package/types/src/webapi/models/production-dockerfile.model.d.ts +18 -0
- package/types/src/webapi/models/sample-files.model.d.ts +7 -0
- package/types/src/webapi/models/webapi-image.model.d.ts +12 -0
- package/types/src/webapi/postman/hello-openapi.d.ts +19 -0
- package/types/src/webapi/postman/local-view.d.ts +17 -0
- package/types/src/webapi/postman/openapi-to-postman.d.ts +62 -0
- package/types/src/webapi/workspace-readme.d.ts +18 -0
- package/types/src/webapi.action.d.ts +14 -0
- package/types/src/webapi.command.d.ts +11 -0
- package/src/add-api.action.ts +0 -25
- package/src/add-api.command.ts +0 -31
- package/src/add.command.ts +0 -20
- package/src/add.module.ts +0 -11
- package/src/cli.ts +0 -4
- package/src/create.command.ts +0 -20
- package/src/create.module.ts +0 -11
- package/src/domain/prompt.ts +0 -50
- package/src/models/compose.model.ts +0 -205
- package/src/models/config-yaml.model.ts +0 -83
- package/src/models/const.ts +0 -20
- package/src/models/dev-container.model.ts +0 -136
- package/src/models/docker-image.model.ts +0 -343
- package/src/models/env-file.model.ts +0 -45
- package/src/models/gitignore.model.ts +0 -35
- package/src/models/launch-json.model.ts +0 -60
- package/src/models/package-json.model.ts +0 -169
- package/src/models/project.model.ts +0 -141
- package/src/models/tsconfig.model.ts +0 -29
- package/src/models/vitest-config.model.ts +0 -26
- package/src/models/vscode-settings.model.ts +0 -24
- package/src/program.ts +0 -63
- package/src/services/scaffold.service.ts +0 -89
- package/src/version.ts +0 -56
- package/src/webapi/api-name.ts +0 -73
- package/src/webapi/cli-options.ts +0 -56
- package/src/webapi/create-api.ts +0 -275
- package/src/webapi/devcontainer/host-scripts.ts +0 -35
- package/src/webapi/features/auth.feature.ts +0 -454
- package/src/webapi/features/auth0-cli.ts +0 -421
- package/src/webapi/features/biome-format.ts +0 -34
- package/src/webapi/features/database.feature.ts +0 -522
- package/src/webapi/features/finalize.feature.ts +0 -112
- package/src/webapi/features/postman.feature.ts +0 -287
- package/src/webapi/models/api-package-json.model.ts +0 -60
- package/src/webapi/models/auth-config.model.ts +0 -36
- package/src/webapi/models/controller-source-file.model.ts +0 -232
- package/src/webapi/models/main-source-file.model.ts +0 -208
- package/src/webapi/models/production-dockerfile.model.ts +0 -162
- package/src/webapi/models/sample-files.model.ts +0 -45
- package/src/webapi/models/webapi-image.model.ts +0 -21
- package/src/webapi/postman/hello-openapi.ts +0 -92
- package/src/webapi/postman/local-view.ts +0 -195
- package/src/webapi/postman/openapi-to-postman.ts +0 -208
- package/src/webapi/workspace-readme.ts +0 -192
- package/src/webapi.action.ts +0 -22
- package/src/webapi.command.ts +0 -41
- package/tests/auth-postman.wiring.spec.ts +0 -263
- package/tests/auth0-cli.spec.ts +0 -232
- package/tests/biome-format.spec.ts +0 -49
- package/tests/cli.integration.spec.ts +0 -658
- package/tests/compose.model.spec.ts +0 -51
- package/tests/container-image.model.spec.ts +0 -162
- package/tests/dev-container.model.spec.ts +0 -29
- package/tests/devcontainer-base-image.spec.ts +0 -32
- package/tests/hello-di-inject.scaffold.spec.ts +0 -18
- package/tests/hello-route.contract.spec.ts +0 -94
- package/tests/package-json.order.spec.ts +0 -59
- package/tests/postman-from-openapi.spec.ts +0 -197
- package/tests/seed-devcontainer-templates.ts +0 -40
- package/tests/webapi/devcontainer/codebase-rag-mcp.spec.ts +0 -96
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "DockerCompose", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return DockerCompose;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nodefs = require("node:fs");
|
|
12
|
+
const _yaml = require("yaml");
|
|
13
|
+
const _const = require("./const.js");
|
|
14
|
+
class DockerCompose {
|
|
15
|
+
key = _const.WELL_KNOWN_FILES.DOCKER_COMPOSE;
|
|
16
|
+
_projectName;
|
|
17
|
+
_headerComments = [];
|
|
18
|
+
_services = new Map();
|
|
19
|
+
_volumes = new Set();
|
|
20
|
+
_networks = new Map();
|
|
21
|
+
_envFiles = [];
|
|
22
|
+
_existing;
|
|
23
|
+
/** Load an existing compose file so `decohere add api` can merge into it. */ static fromFile(absolutePath) {
|
|
24
|
+
const compose = new DockerCompose();
|
|
25
|
+
compose._existing = (0, _yaml.parseDocument)((0, _nodefs.readFileSync)(absolutePath, "utf8"));
|
|
26
|
+
return compose;
|
|
27
|
+
}
|
|
28
|
+
/** True when the service is defined (in the loaded file or added since). */ hasService(name) {
|
|
29
|
+
return this._services.has(name) || this._existing?.hasIn([
|
|
30
|
+
"services",
|
|
31
|
+
name
|
|
32
|
+
]) === true;
|
|
33
|
+
}
|
|
34
|
+
/** Compose project name (`name:` top-level) — isolates containers/volumes. */ setProjectName(name) {
|
|
35
|
+
this._projectName = name;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
/** File-level `#` comments rendered above `name:` / `services:`. */ addHeaderComment(...lines) {
|
|
39
|
+
this._headerComments.push(...lines);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
addService(name, config) {
|
|
43
|
+
this._services.set(name, config);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
files() {
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
filePath: ".devcontainer/docker-compose.yml",
|
|
50
|
+
content: this.getContent()
|
|
51
|
+
}
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
addVolume(name) {
|
|
55
|
+
this._volumes.add(name);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
addNetwork(key, network) {
|
|
59
|
+
this._networks.set(key, network);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
/** Append an env_file path to an existing service. */ addEnvFile(serviceName, filePath) {
|
|
63
|
+
// A service already in the loaded file wins over an `addService` of the same name.
|
|
64
|
+
const svc = this._existing?.hasIn([
|
|
65
|
+
"services",
|
|
66
|
+
serviceName
|
|
67
|
+
]) ? undefined : this._services.get(serviceName);
|
|
68
|
+
if (svc) svc.env_file = [
|
|
69
|
+
...svc.env_file ?? [],
|
|
70
|
+
filePath
|
|
71
|
+
];
|
|
72
|
+
else this._envFiles.push([
|
|
73
|
+
serviceName,
|
|
74
|
+
filePath
|
|
75
|
+
]);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
getContent() {
|
|
79
|
+
if (this._existing) return this.mergeIntoExisting(this._existing);
|
|
80
|
+
const lines = [];
|
|
81
|
+
for (const comment of this._headerComments){
|
|
82
|
+
lines.push(comment.startsWith("#") ? comment : `# ${comment}`);
|
|
83
|
+
}
|
|
84
|
+
if (this._headerComments.length > 0) {
|
|
85
|
+
lines.push("");
|
|
86
|
+
}
|
|
87
|
+
if (this._projectName) {
|
|
88
|
+
lines.push(`name: ${this._projectName}`, "");
|
|
89
|
+
}
|
|
90
|
+
lines.push("services:");
|
|
91
|
+
for (const [name, svc] of this._services){
|
|
92
|
+
lines.push(` ${name}:`);
|
|
93
|
+
if (svc.build) lines.push(` build: ${svc.build}`);
|
|
94
|
+
if (svc.image) lines.push(` image: ${svc.image}`);
|
|
95
|
+
if (svc.container_name) lines.push(` container_name: ${svc.container_name}`);
|
|
96
|
+
if (svc.command) lines.push(` command: ${svc.command}`);
|
|
97
|
+
if (svc.user) lines.push(` user: "${svc.user}"`);
|
|
98
|
+
if (svc.restart) lines.push(` restart: ${svc.restart}`);
|
|
99
|
+
if (svc.profiles && svc.profiles.length > 0) {
|
|
100
|
+
lines.push(" profiles:");
|
|
101
|
+
for (const p of svc.profiles)lines.push(` - ${p}`);
|
|
102
|
+
}
|
|
103
|
+
if (svc.env_file && svc.env_file.length > 0) {
|
|
104
|
+
lines.push(" env_file:");
|
|
105
|
+
for (const f of svc.env_file)lines.push(` - ${f}`);
|
|
106
|
+
}
|
|
107
|
+
if (svc.environment && Object.keys(svc.environment).length > 0) {
|
|
108
|
+
lines.push(" environment:");
|
|
109
|
+
for (const [k, v] of Object.entries(svc.environment)){
|
|
110
|
+
lines.push(` ${k}: ${v}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (svc.ports && svc.ports.length > 0) {
|
|
114
|
+
lines.push(" ports:");
|
|
115
|
+
for (const p of svc.ports)lines.push(` - "${p}"`);
|
|
116
|
+
}
|
|
117
|
+
if (svc.volumes && svc.volumes.length > 0) {
|
|
118
|
+
lines.push(" volumes:");
|
|
119
|
+
for (const v of svc.volumes)lines.push(` - ${v}`);
|
|
120
|
+
}
|
|
121
|
+
if (svc.networks && svc.networks.length > 0) {
|
|
122
|
+
const onlyStrings = svc.networks.every((n)=>typeof n === "string");
|
|
123
|
+
if (onlyStrings) {
|
|
124
|
+
lines.push(" networks:");
|
|
125
|
+
for (const n of svc.networks)lines.push(` - ${n}`);
|
|
126
|
+
} else {
|
|
127
|
+
lines.push(" networks:");
|
|
128
|
+
for (const n of svc.networks){
|
|
129
|
+
if (typeof n === "string") {
|
|
130
|
+
lines.push(` ${n}:`);
|
|
131
|
+
} else {
|
|
132
|
+
for (const [netKey, cfg] of Object.entries(n)){
|
|
133
|
+
lines.push(` ${netKey}:`);
|
|
134
|
+
if (cfg.aliases && cfg.aliases.length > 0) {
|
|
135
|
+
lines.push(" aliases:");
|
|
136
|
+
for (const a of cfg.aliases)lines.push(` - ${a}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (svc.depends_on && svc.depends_on.length > 0) {
|
|
144
|
+
lines.push(" depends_on:");
|
|
145
|
+
for (const d of svc.depends_on)lines.push(` - ${d}`);
|
|
146
|
+
}
|
|
147
|
+
if (svc.healthcheck) {
|
|
148
|
+
const hc = svc.healthcheck;
|
|
149
|
+
lines.push(" healthcheck:");
|
|
150
|
+
lines.push(` test: ${JSON.stringify(hc.test)}`);
|
|
151
|
+
if (hc.interval) lines.push(` interval: ${hc.interval}`);
|
|
152
|
+
if (hc.timeout) lines.push(` timeout: ${hc.timeout}`);
|
|
153
|
+
if (hc.retries != null) lines.push(` retries: ${hc.retries}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (this._networks.size > 0) {
|
|
157
|
+
lines.push("");
|
|
158
|
+
lines.push("networks:");
|
|
159
|
+
for (const [key, net] of this._networks){
|
|
160
|
+
lines.push(` ${key}:`);
|
|
161
|
+
lines.push(` name: ${net.name}`);
|
|
162
|
+
if (net.external) lines.push(" external: true");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (this._volumes.size > 0) {
|
|
166
|
+
lines.push("");
|
|
167
|
+
lines.push("volumes:");
|
|
168
|
+
for (const v of this._volumes)lines.push(` ${v}:`);
|
|
169
|
+
}
|
|
170
|
+
return `${lines.join("\n")}\n`;
|
|
171
|
+
}
|
|
172
|
+
mergeIntoExisting(doc) {
|
|
173
|
+
if (!(0, _yaml.isMap)(doc.contents)) throw new Error("docker-compose.yml is not a YAML mapping");
|
|
174
|
+
for (const line of this._headerComments){
|
|
175
|
+
const text = line.replace(/^#\s?/, "");
|
|
176
|
+
const before = doc.commentBefore ?? "";
|
|
177
|
+
if (!before.includes(text)) doc.commentBefore = before ? `${before}\n ${text}` : ` ${text}`;
|
|
178
|
+
}
|
|
179
|
+
for (const [name, svc] of this._services){
|
|
180
|
+
if (!doc.hasIn([
|
|
181
|
+
"services",
|
|
182
|
+
name
|
|
183
|
+
])) doc.setIn([
|
|
184
|
+
"services",
|
|
185
|
+
name
|
|
186
|
+
], doc.createNode(toComposeYaml(svc)));
|
|
187
|
+
}
|
|
188
|
+
for (const [service, path] of this._envFiles){
|
|
189
|
+
if (!doc.hasIn([
|
|
190
|
+
"services",
|
|
191
|
+
service
|
|
192
|
+
])) continue;
|
|
193
|
+
const envFiles = doc.getIn([
|
|
194
|
+
"services",
|
|
195
|
+
service,
|
|
196
|
+
"env_file"
|
|
197
|
+
]);
|
|
198
|
+
if ((0, _yaml.isSeq)(envFiles)) {
|
|
199
|
+
if (!envFiles.items.some((item)=>String(item) === path)) envFiles.add(path);
|
|
200
|
+
} else if (envFiles == null) {
|
|
201
|
+
doc.setIn([
|
|
202
|
+
"services",
|
|
203
|
+
service,
|
|
204
|
+
"env_file"
|
|
205
|
+
], doc.createNode([
|
|
206
|
+
path
|
|
207
|
+
]));
|
|
208
|
+
} else if (String(envFiles) !== path) {
|
|
209
|
+
doc.setIn([
|
|
210
|
+
"services",
|
|
211
|
+
service,
|
|
212
|
+
"env_file"
|
|
213
|
+
], doc.createNode([
|
|
214
|
+
String(envFiles),
|
|
215
|
+
path
|
|
216
|
+
]));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
for (const [key, network] of this._networks){
|
|
220
|
+
if (!doc.hasIn([
|
|
221
|
+
"networks",
|
|
222
|
+
key
|
|
223
|
+
])) doc.setIn([
|
|
224
|
+
"networks",
|
|
225
|
+
key
|
|
226
|
+
], doc.createNode(network));
|
|
227
|
+
}
|
|
228
|
+
for (const volume of this._volumes){
|
|
229
|
+
if (!doc.hasIn([
|
|
230
|
+
"volumes",
|
|
231
|
+
volume
|
|
232
|
+
])) doc.setIn([
|
|
233
|
+
"volumes",
|
|
234
|
+
volume
|
|
235
|
+
], null);
|
|
236
|
+
}
|
|
237
|
+
return doc.toString({
|
|
238
|
+
lineWidth: 0
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/** Plain compose YAML shape for a service (networks with aliases become a map). */ function toComposeYaml(svc) {
|
|
243
|
+
const { networks, ...rest } = svc;
|
|
244
|
+
if (!networks || networks.length === 0) return rest;
|
|
245
|
+
if (networks.every((n)=>typeof n === "string")) return {
|
|
246
|
+
...rest,
|
|
247
|
+
networks
|
|
248
|
+
};
|
|
249
|
+
const networkMap = {};
|
|
250
|
+
for (const network of networks){
|
|
251
|
+
if (typeof network === "string") networkMap[network] = null;
|
|
252
|
+
else Object.assign(networkMap, network);
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
...rest,
|
|
256
|
+
networks: networkMap
|
|
257
|
+
};
|
|
258
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get ConfigYaml () {
|
|
13
|
+
return ConfigYaml;
|
|
14
|
+
},
|
|
15
|
+
get injectYamlDataSource () {
|
|
16
|
+
return injectYamlDataSource;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _nodefs = require("node:fs");
|
|
20
|
+
class ConfigYaml {
|
|
21
|
+
key;
|
|
22
|
+
filePath;
|
|
23
|
+
_sections = [];
|
|
24
|
+
constructor(key, filePath, baseContent){
|
|
25
|
+
this.key = key;
|
|
26
|
+
this.filePath = filePath;
|
|
27
|
+
this._sections.push(baseContent);
|
|
28
|
+
}
|
|
29
|
+
addSection(yaml) {
|
|
30
|
+
this._sections.push(yaml);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/** True when a datasource with this `name:` already appears in the file. */ hasDataSource(name) {
|
|
34
|
+
return this._sections.join("\n").includes(`name: ${name}\n`);
|
|
35
|
+
}
|
|
36
|
+
hasDataSources() {
|
|
37
|
+
return this._sections.join("\n").includes("dataSources:");
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Insert a `dataSources` list item. Used by `webapi add` so we do not write a
|
|
41
|
+
* second top-level `database:` key (YAML last-key-wins).
|
|
42
|
+
*/ appendDataSource(item) {
|
|
43
|
+
const current = this._sections.join("\n");
|
|
44
|
+
this._sections.length = 0;
|
|
45
|
+
this._sections.push(injectYamlDataSource(current, item));
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
static fromFile(key, relativePath, absolutePath) {
|
|
49
|
+
const content = (0, _nodefs.readFileSync)(absolutePath, "utf8");
|
|
50
|
+
return new ConfigYaml(key, relativePath, content);
|
|
51
|
+
}
|
|
52
|
+
files() {
|
|
53
|
+
return [
|
|
54
|
+
{
|
|
55
|
+
filePath: this.filePath,
|
|
56
|
+
content: this._sections.join("\n")
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function injectYamlDataSource(yaml, item) {
|
|
62
|
+
const block = item.replace(/\n$/, "");
|
|
63
|
+
if (!yaml.includes("dataSources:")) {
|
|
64
|
+
const prefix = yaml.trimEnd();
|
|
65
|
+
const section = `database:\n dataSources:\n${block}\n`;
|
|
66
|
+
return prefix.length > 0 ? `${prefix}\n\n${section}` : section;
|
|
67
|
+
}
|
|
68
|
+
const lines = yaml.split("\n");
|
|
69
|
+
const dsIndex = lines.findIndex((line)=>/^\s*dataSources:\s*$/.test(line));
|
|
70
|
+
if (dsIndex < 0) {
|
|
71
|
+
return `${yaml.trimEnd()}\n\ndatabase:\n dataSources:\n${block}\n`;
|
|
72
|
+
}
|
|
73
|
+
let insertAt = lines.length;
|
|
74
|
+
for(let i = dsIndex + 1; i < lines.length; i++){
|
|
75
|
+
if (/^[A-Za-z]/.test(lines[i] ?? "")) {
|
|
76
|
+
insertAt = i;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const insertLines = block.split("\n");
|
|
81
|
+
if (insertAt < lines.length && lines[insertAt - 1] !== "") {
|
|
82
|
+
insertLines.push("");
|
|
83
|
+
}
|
|
84
|
+
lines.splice(insertAt, 0, ...insertLines);
|
|
85
|
+
return lines.join("\n");
|
|
86
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "WELL_KNOWN_FILES", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return WELL_KNOWN_FILES;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const WELL_KNOWN_FILES = {
|
|
12
|
+
VSCODE_SETTINGS: "VSCODE_SETTINGS",
|
|
13
|
+
LAUNCH_JSON: "LAUNCH_JSON",
|
|
14
|
+
DOCKER_COMPOSE: "DOCKER_COMPOSE",
|
|
15
|
+
DEVCONTAINER_JSON: "DEVCONTAINER_JSON",
|
|
16
|
+
DOCKERFILE: "DOCKERFILE",
|
|
17
|
+
PRODUCTION_DOCKERFILE: "PRODUCTION_DOCKERFILE",
|
|
18
|
+
GITHUB_CI: "GITHUB_CI",
|
|
19
|
+
PACKAGE_JSON: "PACKAGE_JSON",
|
|
20
|
+
API_PACKAGE_JSON: "API_PACKAGE_JSON",
|
|
21
|
+
TSCONFIG: "TSCONFIG",
|
|
22
|
+
VITEST_CONFIG: "VITEST_CONFIG",
|
|
23
|
+
MAIN_TS: "MAIN_TS",
|
|
24
|
+
CONTROLLER_TS: "CONTROLLER_TS",
|
|
25
|
+
CONFIG_YAML: "CONFIG_YAML",
|
|
26
|
+
CONFIG_DEV_YAML: "CONFIG_DEV_YAML",
|
|
27
|
+
GITIGNORE: "GITIGNORE",
|
|
28
|
+
AUTH_CONFIG: "AUTH_CONFIG",
|
|
29
|
+
ENV_FILE: "ENV_FILE"
|
|
30
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "DevContainer", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return DevContainer;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nodefs = require("node:fs");
|
|
12
|
+
const _const = require("./const.js");
|
|
13
|
+
class DevContainer {
|
|
14
|
+
key = _const.WELL_KNOWN_FILES.DEVCONTAINER_JSON;
|
|
15
|
+
_extensions = [];
|
|
16
|
+
_ports = [];
|
|
17
|
+
_portAttributes = new Map();
|
|
18
|
+
_mounts;
|
|
19
|
+
_workspaceFolder = "/workspace";
|
|
20
|
+
_postCreateCommand;
|
|
21
|
+
_updateContentCommand;
|
|
22
|
+
_postStartCommand;
|
|
23
|
+
_initializeCommand;
|
|
24
|
+
_remoteUser = "node";
|
|
25
|
+
_useCompose = false;
|
|
26
|
+
_existing;
|
|
27
|
+
/**
|
|
28
|
+
* Load an existing devcontainer.json so `decohere add api` can merge into it.
|
|
29
|
+
* Only extensions, forwarded ports and port attributes are merged; everything else is kept.
|
|
30
|
+
*/ static fromFile(absolutePath) {
|
|
31
|
+
const devContainer = new DevContainer();
|
|
32
|
+
try {
|
|
33
|
+
devContainer._existing = JSON.parse((0, _nodefs.readFileSync)(absolutePath, "utf8"));
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new Error(`Can't update ${absolutePath}: it isn't plain JSON (${error.message}). Remove any comments or trailing commas and try again.`);
|
|
36
|
+
}
|
|
37
|
+
return devContainer;
|
|
38
|
+
}
|
|
39
|
+
constructor(){
|
|
40
|
+
this._mounts = [
|
|
41
|
+
this.bindMount(this._workspaceFolder)
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
/** In-container path Cursor/VS Code opens (Agents window uses the basename). */ setWorkspaceFolder(folder) {
|
|
45
|
+
this._workspaceFolder = folder;
|
|
46
|
+
this._mounts = [
|
|
47
|
+
this.bindMount(folder)
|
|
48
|
+
];
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
bindMount(target) {
|
|
52
|
+
return `source=..,target=${target},type=bind,consistency=cached`;
|
|
53
|
+
}
|
|
54
|
+
addExtension(...ids) {
|
|
55
|
+
this._extensions.push(...ids);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
forwardPort(...ports) {
|
|
59
|
+
this._ports.push(...ports);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
setPortAttributes(port, attrs) {
|
|
63
|
+
this._portAttributes.set(port, attrs);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
setPostCreateCommand(cmd) {
|
|
67
|
+
this._postCreateCommand = cmd;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
setUpdateContentCommand(cmd) {
|
|
71
|
+
this._updateContentCommand = cmd;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
setPostStartCommand(cmd) {
|
|
75
|
+
this._postStartCommand = cmd;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
setInitializeCommand(cmd) {
|
|
79
|
+
this._initializeCommand = cmd;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
setRemoteUser(user) {
|
|
83
|
+
this._remoteUser = user;
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
useCompose() {
|
|
87
|
+
this._useCompose = true;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
files() {
|
|
91
|
+
const config = this._existing ? this.mergeIntoExisting(this._existing) : this.build();
|
|
92
|
+
return [
|
|
93
|
+
{
|
|
94
|
+
filePath: ".devcontainer/devcontainer.json",
|
|
95
|
+
content: JSON.stringify(config, null, 2)
|
|
96
|
+
}
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
mergeIntoExisting(existing) {
|
|
100
|
+
const config = structuredClone(existing);
|
|
101
|
+
if (this._extensions.length > 0) {
|
|
102
|
+
const customizations = objectAt(config, "customizations");
|
|
103
|
+
const vscode = objectAt(customizations, "vscode");
|
|
104
|
+
vscode.extensions = union(vscode.extensions, this._extensions);
|
|
105
|
+
}
|
|
106
|
+
if (this._ports.length > 0) {
|
|
107
|
+
config.forwardPorts = union(config.forwardPorts, this._ports);
|
|
108
|
+
}
|
|
109
|
+
if (this._portAttributes.size > 0) {
|
|
110
|
+
const attributes = objectAt(config, "portsAttributes");
|
|
111
|
+
for (const [port, attrs] of this._portAttributes){
|
|
112
|
+
attributes[String(port)] ??= attrs;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return config;
|
|
116
|
+
}
|
|
117
|
+
build() {
|
|
118
|
+
const config = {};
|
|
119
|
+
if (this._useCompose) {
|
|
120
|
+
config.dockerComposeFile = "docker-compose.yml";
|
|
121
|
+
config.service = "devcontainer";
|
|
122
|
+
config.workspaceFolder = this._workspaceFolder;
|
|
123
|
+
}
|
|
124
|
+
if (this._initializeCommand) {
|
|
125
|
+
config.initializeCommand = this._initializeCommand;
|
|
126
|
+
}
|
|
127
|
+
if (this._mounts) {
|
|
128
|
+
config.mounts = this._mounts;
|
|
129
|
+
}
|
|
130
|
+
if (this._extensions.length > 0) {
|
|
131
|
+
config.customizations = {
|
|
132
|
+
vscode: {
|
|
133
|
+
extensions: this._extensions
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (this._ports.length > 0) {
|
|
138
|
+
config.forwardPorts = this._ports;
|
|
139
|
+
}
|
|
140
|
+
if (this._portAttributes.size > 0) {
|
|
141
|
+
const portsAttributes = {};
|
|
142
|
+
for (const [port, attrs] of this._portAttributes){
|
|
143
|
+
portsAttributes[String(port)] = attrs;
|
|
144
|
+
}
|
|
145
|
+
config.portsAttributes = portsAttributes;
|
|
146
|
+
}
|
|
147
|
+
if (this._postCreateCommand) {
|
|
148
|
+
config.postCreateCommand = this._postCreateCommand;
|
|
149
|
+
}
|
|
150
|
+
if (this._updateContentCommand) {
|
|
151
|
+
config.updateContentCommand = this._updateContentCommand;
|
|
152
|
+
}
|
|
153
|
+
if (this._postStartCommand) {
|
|
154
|
+
config.postStartCommand = this._postStartCommand;
|
|
155
|
+
}
|
|
156
|
+
if (this._remoteUser) {
|
|
157
|
+
config.remoteUser = this._remoteUser;
|
|
158
|
+
}
|
|
159
|
+
return config;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** The object at `parent[key]`, created when missing. */ function objectAt(parent, key) {
|
|
163
|
+
parent[key] ??= {};
|
|
164
|
+
return parent[key];
|
|
165
|
+
}
|
|
166
|
+
function union(existing, additions) {
|
|
167
|
+
const items = Array.isArray(existing) ? [
|
|
168
|
+
...existing
|
|
169
|
+
] : [];
|
|
170
|
+
for (const item of additions)if (!items.includes(item)) items.push(item);
|
|
171
|
+
return items;
|
|
172
|
+
}
|