@decohere/create 0.0.1-dev.20261106.139 → 0.0.1-dev.20261106.146
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/README.md +38 -19
- package/es6/src/cli.js +2 -2
- package/es6/src/index.js +2 -1
- package/es6/src/resolve-launch.js +2 -2
- package/es6/src/runner.js +182 -64
- package/es6/src/tools.js +9 -0
- package/package.json +1 -1
- package/types/src/index.d.ts +2 -1
- package/types/src/resolve-launch.d.ts +2 -1
- package/types/src/runner.d.ts +9 -3
- package/types/src/tools.d.ts +5 -0
package/README.md
CHANGED
|
@@ -2,7 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Scaffold a new Decohere project — built with Forge, served with Flux.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Scaffolding always runs somewhere that already has its tools, so nothing gets installed on your machine.
|
|
6
|
+
|
|
7
|
+
| Where you run it | `create` | `add`, `auth0` |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| A Decohere Dev Container | Runs right there | Runs right there |
|
|
10
|
+
| Your machine, or another container with Docker access | Runs in the `ghcr.io/typesmiths/decohere/create` image, then copies the project out | Says to open the project's Dev Container |
|
|
11
|
+
| Another container with no Docker access | Says Docker is needed | Says to open the project's Dev Container |
|
|
12
|
+
|
|
13
|
+
The scaffolder image gets no folders from your machine, and it can't see `~/.npmrc` or your Auth0 login. It works in its own folder, and the project is copied out only if it succeeds, so a failed run or Ctrl-C leaves your folder as it was. The container is always removed. A new project needs an empty folder (a `.git` folder is fine). This works the same from your machine, from inside a container, and against a remote Docker.
|
|
14
|
+
|
|
15
|
+
Choosing Auth0 during `create` means logging in there. That login goes away with the container, so your first `auth0` command in the Dev Container asks you to log in once more.
|
|
6
16
|
|
|
7
17
|
## Usage
|
|
8
18
|
|
|
@@ -105,37 +115,45 @@ Each API is a separate deploy: package it (`pnpm run package:billing`) and build
|
|
|
105
115
|
|
|
106
116
|
### `auth0`
|
|
107
117
|
|
|
108
|
-
|
|
118
|
+
Run these in the project's Dev Container, which has the Auth0 CLI. Its login is kept in a Docker volume, so rebuilding the Dev Container doesn't log you out. Use this after a project exists, when a token expires, or when the login app needs to be created or updated.
|
|
109
119
|
|
|
110
120
|
```bash
|
|
111
121
|
# Device/URL login — open the printed URL in your browser
|
|
112
|
-
|
|
122
|
+
pnpm decohere auth0 login
|
|
113
123
|
|
|
114
|
-
# Update the Auth0 API and
|
|
115
|
-
|
|
116
|
-
npx @decohere/create auth0 configure -d my-app
|
|
124
|
+
# Update the Auth0 API, login app and token app for this workspace
|
|
125
|
+
pnpm decohere auth0 configure
|
|
117
126
|
|
|
118
|
-
#
|
|
119
|
-
decohere auth0
|
|
120
|
-
decohere auth0 configure
|
|
127
|
+
# Print a token for calling the API in development
|
|
128
|
+
pnpm decohere auth0 token
|
|
121
129
|
```
|
|
122
130
|
|
|
123
|
-
`configure` does **not** rewrite application source. It ensures a `<project> Dev` login app (written to `.env` as `AUTH0_CLIENT_ID`), scans `projects/*/src` for `@Authorize("action", "Subject")`, adds those permissions to the Auth0 API (keeping any already on the API) and assigns them to `AUTH0_ADMIN_USER_SUB` when set.
|
|
131
|
+
`configure` does **not** rewrite application source. It ensures a `<project> Dev` login app for your web app (written to `.env` as `AUTH0_CLIENT_ID`, and allowing `http://localhost:<port>` for each API), scans `projects/*/src` for `@Authorize("action", "Subject")`, adds those permissions to the Auth0 API (keeping any already on the API) and assigns them to `AUTH0_ADMIN_USER_SUB` when set.
|
|
124
132
|
|
|
125
133
|
#### Add Auth0 to an existing project
|
|
126
134
|
|
|
135
|
+
In the project's Dev Container:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
pnpm decohere add auth0
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
This logs in if needed, creates the Auth0 API and a `<project> Dev` login app, writes `AUTH0_ISSUER_BASE_URL`, `AUTH0_AUDIENCE` and `AUTH0_CLIENT_ID` to `.env`, adds the `auth` section to `config/config.yaml`, and adds `.withAuth()` to each API's `main.ts`. Running it again changes nothing. If a `main.ts` no longer has the generated shape, the command leaves it alone and prints the lines to add. It also creates a `<project> Token` machine app (written to `.env` as `AUTH0_TOKEN_CLIENT_ID`). It doesn't add the local user profile a new project with Postgres gets.
|
|
142
|
+
|
|
143
|
+
Once Auth0 is added, **every route needs a token** unless it has `@AllowAnonymous()`, because `withAuth()` is secure by default. To call one, in the Dev Container:
|
|
144
|
+
|
|
127
145
|
```bash
|
|
128
|
-
decohere
|
|
146
|
+
curl -H "Authorization: Bearer $(pnpm -s decohere auth0 token)" localhost:3000/hello/1
|
|
129
147
|
```
|
|
130
148
|
|
|
131
|
-
|
|
149
|
+
`auth0 token` prints a short-lived token from the machine app, with no browser, and it's allowed every permission on the API. Keep it to development. Your Auth0 login has to be current, because the Auth0 CLI fetches the token.
|
|
132
150
|
|
|
133
151
|
#### Keep Auth0 in sync with controllers
|
|
134
152
|
|
|
135
153
|
`@Authorize("read", "Invoice")` becomes Auth0 API permission `read:Invoice`. After adding a controller:
|
|
136
154
|
|
|
137
155
|
```bash
|
|
138
|
-
|
|
156
|
+
pnpm decohere auth0 configure
|
|
139
157
|
```
|
|
140
158
|
|
|
141
159
|
Then get a new access token so it includes the new permissions.
|
|
@@ -195,9 +213,9 @@ override `defineAbilitiesFor` for product CASL rules, and `mapPrincipal` for IdP
|
|
|
195
213
|
(including the `AUTH0_ADMIN_USER_SUB` admin bootstrap). `@decohere/http`'s default already maps
|
|
196
214
|
`admin` → `manage`/`all` and `action:Subject` scopes.
|
|
197
215
|
|
|
198
|
-
####
|
|
216
|
+
#### Try the API
|
|
199
217
|
|
|
200
|
-
While the API is running,
|
|
218
|
+
While the API is running, `http://localhost:3000/openapi.json` describes every route.
|
|
201
219
|
|
|
202
220
|
## Options
|
|
203
221
|
|
|
@@ -205,10 +223,11 @@ While the API is running, choose Import in Postman and paste `http://localhost:3
|
|
|
205
223
|
|---|---|---|
|
|
206
224
|
| `[directory]` / `-d <directory>` | `webapi` / global | Target directory (positional wins; default `.`) |
|
|
207
225
|
| `--name <slug>` | `webapi` | API directory under `projects/` (repeatable; default `api`) |
|
|
208
|
-
| `add api <name>` | `decohere add api`
|
|
209
|
-
| `add auth0` | `decohere add auth0`
|
|
210
|
-
| `auth0 login` | `decohere auth0`
|
|
211
|
-
| `auth0 configure` | `decohere auth0`
|
|
226
|
+
| `add api <name>` | `decohere add api` | Add an API to an existing Decohere workspace |
|
|
227
|
+
| `add auth0` | `decohere add auth0` | Add Auth0 to an existing workspace |
|
|
228
|
+
| `auth0 login` | `decohere auth0` | Device/URL login; keeps tokens in `~/.config/auth0` |
|
|
229
|
+
| `auth0 configure` | `decohere auth0` | Update the Auth0 API, login app and token app for an existing workspace |
|
|
230
|
+
| `auth0 token` | `decohere auth0` | Print an access token for calling the API in development |
|
|
212
231
|
| `--database <provider>` | `webapi` / `add` | `none` \| `postgres/typeorm` |
|
|
213
232
|
| `--auth <provider>` | `webapi` / `add` | `none` \| `auth0` |
|
|
214
233
|
| `-y, --yes` | `webapi` / `add` | Install dependencies without prompting |
|
package/es6/src/cli.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { launch } from "./runner.js";
|
|
3
|
+
await launch(process.argv.slice(2));
|
package/es6/src/index.js
CHANGED
|
@@ -62,7 +62,7 @@ export function containerArgvFromHost(argv) {
|
|
|
62
62
|
targetDir: cwd,
|
|
63
63
|
containerArgv: argv,
|
|
64
64
|
projectName: basename(cwd),
|
|
65
|
-
kind: "
|
|
65
|
+
kind: "create"
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
let directoryFlag;
|
|
@@ -97,6 +97,6 @@ export function containerArgvFromHost(argv) {
|
|
|
97
97
|
"."
|
|
98
98
|
],
|
|
99
99
|
projectName: basename(targetDir),
|
|
100
|
-
kind: product[0] === "auth0" ? "
|
|
100
|
+
kind: product[0] === "auth0" || isAdd ? "project" : "create"
|
|
101
101
|
};
|
|
102
102
|
}
|
package/es6/src/runner.js
CHANGED
|
@@ -1,18 +1,78 @@
|
|
|
1
|
-
import { execFileSync, spawnSync } from "node:child_process";
|
|
2
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readdirSync, renameSync, rmSync } from "node:fs";
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
4
|
+
import { join } from "node:path";
|
|
5
5
|
import { resolveLaunch } from "./resolve-launch.js";
|
|
6
|
+
import { hasDecohereTools, isInContainer, OPEN_DEV_CONTAINER_MESSAGE } from "./tools.js";
|
|
6
7
|
import { CREATE_IMAGE_REPOSITORY, CREATE_VERSION } from "./version.js";
|
|
7
8
|
const BUILDER_IMAGE = `${CREATE_IMAGE_REPOSITORY}:${CREATE_VERSION}`;
|
|
9
|
+
const SCAFFOLD_PACKAGE = `@decohere/scaffold@${CREATE_VERSION}`;
|
|
10
|
+
const WORKSPACE = "/workspace";
|
|
11
|
+
const SIGNAL_EXIT_CODES = {
|
|
12
|
+
SIGINT: 130,
|
|
13
|
+
SIGTERM: 143,
|
|
14
|
+
SIGHUP: 129
|
|
15
|
+
};
|
|
8
16
|
/**
|
|
9
|
-
*
|
|
10
|
-
* the
|
|
11
|
-
*/ export function
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
* Where a command runs: right here if this container has Decohere's tools, otherwise in
|
|
18
|
+
* the scaffolder image. Commands on an existing project need that project's Dev Container.
|
|
19
|
+
*/ export async function launch(argv) {
|
|
20
|
+
const plan = resolveLaunch(argv);
|
|
21
|
+
if (hasDecohereTools()) runHere(plan);
|
|
22
|
+
if (plan.kind === "project") {
|
|
23
|
+
console.error(OPEN_DEV_CONTAINER_MESSAGE);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
return runInBuilder(argv);
|
|
27
|
+
}
|
|
28
|
+
/** Help and version print and leave; nothing is written, so there's nothing to copy out. */ function writesProject({ containerArgv }) {
|
|
29
|
+
return !containerArgv.some((arg)=>[
|
|
30
|
+
"--help",
|
|
31
|
+
"-h",
|
|
32
|
+
"--version"
|
|
33
|
+
].includes(arg));
|
|
34
|
+
}
|
|
35
|
+
/** A new project only goes into an empty folder, so a copy can never overwrite someone's files. */ function refuseFolderWithFiles(targetDir) {
|
|
36
|
+
if (!existsSync(targetDir)) return;
|
|
37
|
+
const files = readdirSync(targetDir).filter((name)=>name !== ".git");
|
|
38
|
+
if (files.length === 0) return;
|
|
39
|
+
console.error(`\n ${targetDir} already has files in it.\n` + " Choose a new folder. To change an existing project, run `pnpm decohere add` in its Dev Container.\n");
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
function printNextSteps(targetDir) {
|
|
43
|
+
const open = isInContainer() ? ` cd ${targetDir}\n pnpm install\n pnpm dev\n` : ` code ${targetDir}\n\n Then reopen it in its Dev Container.\n`;
|
|
44
|
+
console.log(`\n Scaffold complete!\n\n Open your project:\n\n${open}`);
|
|
45
|
+
}
|
|
46
|
+
/** Run the scaffolder in this container, without starting another one. */ function runHere(plan) {
|
|
47
|
+
const { targetDir, containerArgv, projectName, kind } = plan;
|
|
48
|
+
const creating = kind === "create" && writesProject(plan);
|
|
49
|
+
if (creating) {
|
|
50
|
+
refuseFolderWithFiles(targetDir);
|
|
51
|
+
mkdirSync(targetDir, {
|
|
52
|
+
recursive: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const result = spawnSync("npx", [
|
|
56
|
+
"--yes",
|
|
57
|
+
SCAFFOLD_PACKAGE,
|
|
58
|
+
...containerArgv
|
|
59
|
+
], {
|
|
60
|
+
cwd: targetDir,
|
|
61
|
+
stdio: "inherit",
|
|
62
|
+
env: {
|
|
63
|
+
...process.env,
|
|
64
|
+
DECOHERE_BUILDER: "1",
|
|
65
|
+
DECOHERE_PROJECT_NAME: projectName
|
|
66
|
+
}
|
|
15
67
|
});
|
|
68
|
+
if (result.error != null) {
|
|
69
|
+
console.error(`\n Could not start the scaffolder: ${result.error.message}\n`);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
if (result.status === 0 && creating) printNextSteps(targetDir);
|
|
73
|
+
process.exit(result.status ?? 1);
|
|
74
|
+
}
|
|
75
|
+
function assertDockerAvailable() {
|
|
16
76
|
try {
|
|
17
77
|
execFileSync("docker", [
|
|
18
78
|
"info"
|
|
@@ -20,74 +80,132 @@ const BUILDER_IMAGE = `${CREATE_IMAGE_REPOSITORY}:${CREATE_VERSION}`;
|
|
|
20
80
|
stdio: "pipe"
|
|
21
81
|
});
|
|
22
82
|
} catch {
|
|
23
|
-
console.error("\n Docker is required to scaffold a Decohere project.\n" + " Install Docker Desktop: https://www.docker.com/products/docker-desktop\n");
|
|
83
|
+
console.error(isInContainer() ? "\n Docker is required to scaffold a Decohere project, and this container can't reach it.\n" + " Run this on your own machine, or give this container access to Docker.\n" : "\n Docker is required to scaffold a Decohere project.\n" + " Install Docker Desktop: https://www.docker.com/products/docker-desktop\n");
|
|
24
84
|
process.exit(1);
|
|
25
85
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
86
|
+
}
|
|
87
|
+
/** The container holds generated files and any Auth0 login until this runs. */ function removeContainer(name) {
|
|
88
|
+
const removed = spawnSync("docker", [
|
|
89
|
+
"rm",
|
|
90
|
+
"-f",
|
|
91
|
+
name
|
|
92
|
+
], {
|
|
93
|
+
stdio: "ignore"
|
|
32
94
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"-v",
|
|
36
|
-
`${targetDir}:/workspace`,
|
|
37
|
-
"-v",
|
|
38
|
-
`${npmCacheDir}:/npm-cache`
|
|
39
|
-
];
|
|
40
|
-
const envArgs = [
|
|
41
|
-
"-e",
|
|
42
|
-
"DECOHERE_BUILDER=1",
|
|
43
|
-
"-e",
|
|
44
|
-
`DECOHERE_PROJECT_NAME=${projectName}`,
|
|
45
|
-
"-e",
|
|
46
|
-
"NPM_CONFIG_CACHE=/npm-cache",
|
|
47
|
-
"-e",
|
|
48
|
-
"NPM_CONFIG_PREFER_OFFLINE=true",
|
|
49
|
-
"-e",
|
|
50
|
-
`HOME=${builderHome}`
|
|
51
|
-
];
|
|
52
|
-
const npmrcPath = resolve(homedir(), ".npmrc");
|
|
53
|
-
if (existsSync(npmrcPath)) {
|
|
54
|
-
volumes.push("-v", `${npmrcPath}:/tmp/host-npmrc:ro`);
|
|
55
|
-
envArgs.push("-e", "NPM_CONFIG_USERCONFIG=/tmp/host-npmrc");
|
|
95
|
+
if (removed.status !== 0) {
|
|
96
|
+
console.error(`\n Could not remove container ${name}. Remove it with: docker rm -f ${name}\n`);
|
|
56
97
|
}
|
|
57
|
-
|
|
58
|
-
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Copy the finished project out of the container. It lands in a temporary folder first, so a
|
|
101
|
+
* copy that fails partway leaves the target as it was.
|
|
102
|
+
*/ function copyProjectOut(name, targetDir) {
|
|
103
|
+
const createdTarget = !existsSync(targetDir);
|
|
104
|
+
mkdirSync(targetDir, {
|
|
59
105
|
recursive: true
|
|
60
106
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
107
|
+
const temp = mkdtempSync(join(targetDir, ".decohere-create-"));
|
|
108
|
+
try {
|
|
109
|
+
const copy = spawnSync("docker", [
|
|
110
|
+
"cp",
|
|
111
|
+
`${name}:${WORKSPACE}/.`,
|
|
112
|
+
temp
|
|
113
|
+
], {
|
|
114
|
+
stdio: [
|
|
115
|
+
"ignore",
|
|
116
|
+
"ignore",
|
|
117
|
+
"inherit"
|
|
118
|
+
]
|
|
119
|
+
});
|
|
120
|
+
if (copy.status !== 0) {
|
|
121
|
+
throw new Error(`docker cp failed with exit code ${copy.status}`);
|
|
122
|
+
}
|
|
123
|
+
for (const entry of readdirSync(temp)){
|
|
124
|
+
renameSync(join(temp, entry), join(targetDir, entry));
|
|
125
|
+
}
|
|
126
|
+
rmSync(temp, {
|
|
127
|
+
recursive: true,
|
|
128
|
+
force: true
|
|
129
|
+
});
|
|
130
|
+
} catch (reason) {
|
|
131
|
+
rmSync(createdTarget ? targetDir : temp, {
|
|
132
|
+
recursive: true,
|
|
133
|
+
force: true
|
|
134
|
+
});
|
|
135
|
+
throw reason;
|
|
68
136
|
}
|
|
69
|
-
|
|
137
|
+
}
|
|
138
|
+
function attach(name) {
|
|
139
|
+
return new Promise((resolve, reject)=>{
|
|
140
|
+
const child = spawn("docker", [
|
|
141
|
+
"start",
|
|
142
|
+
"--attach",
|
|
143
|
+
"--interactive",
|
|
144
|
+
name
|
|
145
|
+
], {
|
|
146
|
+
stdio: "inherit"
|
|
147
|
+
});
|
|
148
|
+
child.on("error", reject);
|
|
149
|
+
child.on("close", (code)=>resolve(code ?? 1));
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Run the scaffolder image with nothing shared from this machine, then copy the project out.
|
|
154
|
+
* Docker finds shared folders on the machine running Docker, which may not be this one, so
|
|
155
|
+
* this works the same from a host, a container, or against a remote Docker.
|
|
156
|
+
*/ export async function runInBuilder(argv) {
|
|
157
|
+
const plan = resolveLaunch(argv);
|
|
158
|
+
const { targetDir, containerArgv, projectName } = plan;
|
|
159
|
+
const copyOut = writesProject(plan);
|
|
160
|
+
if (copyOut) refuseFolderWithFiles(targetDir);
|
|
161
|
+
assertDockerAvailable();
|
|
162
|
+
const name = `decohere-create-${randomBytes(6).toString("hex")}`;
|
|
70
163
|
const ttyFlags = process.stdin.isTTY ? [
|
|
71
|
-
"
|
|
164
|
+
"--interactive",
|
|
165
|
+
"--tty"
|
|
72
166
|
] : [
|
|
73
|
-
"
|
|
167
|
+
"--interactive"
|
|
74
168
|
];
|
|
75
|
-
const
|
|
76
|
-
"
|
|
77
|
-
"--
|
|
169
|
+
const created = spawnSync("docker", [
|
|
170
|
+
"create",
|
|
171
|
+
"--name",
|
|
172
|
+
name,
|
|
78
173
|
...ttyFlags,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
"
|
|
174
|
+
"--env",
|
|
175
|
+
"DECOHERE_BUILDER=1",
|
|
176
|
+
"--env",
|
|
177
|
+
`DECOHERE_PROJECT_NAME=${projectName}`,
|
|
178
|
+
"--workdir",
|
|
179
|
+
WORKSPACE,
|
|
84
180
|
BUILDER_IMAGE,
|
|
85
181
|
...containerArgv
|
|
86
182
|
], {
|
|
87
|
-
stdio:
|
|
183
|
+
stdio: [
|
|
184
|
+
"ignore",
|
|
185
|
+
"ignore",
|
|
186
|
+
"inherit"
|
|
187
|
+
]
|
|
88
188
|
});
|
|
89
|
-
if (
|
|
90
|
-
|
|
189
|
+
if (created.status !== 0) process.exit(created.status ?? 1);
|
|
190
|
+
for (const [signal, code] of Object.entries(SIGNAL_EXIT_CODES)){
|
|
191
|
+
process.once(signal, ()=>{
|
|
192
|
+
removeContainer(name);
|
|
193
|
+
process.exit(code);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
console.log(" Running scaffolding in a sandboxed container...\n");
|
|
197
|
+
let exitCode = 1;
|
|
198
|
+
try {
|
|
199
|
+
exitCode = await attach(name);
|
|
200
|
+
if (exitCode === 0 && copyOut) {
|
|
201
|
+
copyProjectOut(name, targetDir);
|
|
202
|
+
printNextSteps(targetDir);
|
|
203
|
+
}
|
|
204
|
+
} catch (reason) {
|
|
205
|
+
exitCode = 1;
|
|
206
|
+
console.error(`\n Could not finish the scaffold: ${reason instanceof Error ? reason.message : String(reason)}\n`);
|
|
207
|
+
} finally{
|
|
208
|
+
removeContainer(name);
|
|
91
209
|
}
|
|
92
|
-
process.exit(
|
|
210
|
+
process.exit(exitCode);
|
|
93
211
|
}
|
package/es6/src/tools.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
/** Set by Decohere's Dev Container image, and by the images built from it. */ const TOOLS_ENV = "DECOHERE_TOOLS";
|
|
3
|
+
/** Whether this process runs somewhere that already has Decohere's scaffolding tools. */ export function hasDecohereTools(env = process.env) {
|
|
4
|
+
return env[TOOLS_ENV] === "1";
|
|
5
|
+
}
|
|
6
|
+
/** Whether this process runs in any container, where a project's own Dev Container can't open. */ export function isInContainer(env = process.env) {
|
|
7
|
+
return env.REMOTE_CONTAINERS === "true" || env.CODESPACES === "true" || existsSync("/.dockerenv") || existsSync("/run/.containerenv");
|
|
8
|
+
}
|
|
9
|
+
export const OPEN_DEV_CONTAINER_MESSAGE = "\n This command runs inside the project's Dev Container, which has the tools it needs.\n" + " Open the project in its Dev Container, then run it there, for example:\n\n" + " pnpm decohere add auth0\n";
|
package/package.json
CHANGED
package/types/src/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export type { LaunchKind, LaunchPlan } from "./resolve-launch.js";
|
|
2
2
|
export { containerArgvFromHost, resolveLaunch, toProductArgv } from "./resolve-launch.js";
|
|
3
|
-
export { runInBuilder } from "./runner.js";
|
|
3
|
+
export { launch, runInBuilder } from "./runner.js";
|
|
4
|
+
export { hasDecohereTools, OPEN_DEV_CONTAINER_MESSAGE } from "./tools.js";
|
package/types/src/runner.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* the
|
|
2
|
+
* Where a command runs: right here if this container has Decohere's tools, otherwise in
|
|
3
|
+
* the scaffolder image. Commands on an existing project need that project's Dev Container.
|
|
4
4
|
*/
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function launch(argv: string[]): Promise<never>;
|
|
6
|
+
/**
|
|
7
|
+
* Run the scaffolder image with nothing shared from this machine, then copy the project out.
|
|
8
|
+
* Docker finds shared folders on the machine running Docker, which may not be this one, so
|
|
9
|
+
* this works the same from a host, a container, or against a remote Docker.
|
|
10
|
+
*/
|
|
11
|
+
export declare function runInBuilder(argv: string[]): Promise<never>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Whether this process runs somewhere that already has Decohere's scaffolding tools. */
|
|
2
|
+
export declare function hasDecohereTools(env?: NodeJS.ProcessEnv): boolean;
|
|
3
|
+
/** Whether this process runs in any container, where a project's own Dev Container can't open. */
|
|
4
|
+
export declare function isInContainer(env?: NodeJS.ProcessEnv): boolean;
|
|
5
|
+
export declare const OPEN_DEV_CONTAINER_MESSAGE: string;
|