@decohere/create 0.0.1-dev.20261106.146 → 0.0.1-dev.20261106.175
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 +12 -2
- package/es6/src/runner.js +80 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@ Scaffolding always runs somewhere that already has its tools, so nothing gets in
|
|
|
12
12
|
|
|
13
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
14
|
|
|
15
|
+
With Auth0 and Postgres, `create` also makes an admin user with a generated password. The password isn't printed or kept in the project, and it's only for logging in. On Linux with a key store (GNOME Keyring or KWallet, through `secret-tool`), it's saved there, and `create` prints the command to read it. Anywhere else it goes in `~/.config/decohere/<project>.env`, readable only by you. Run inside a container, that file is in the container, so copy it if the container may be rebuilt.
|
|
16
|
+
|
|
15
17
|
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.
|
|
16
18
|
|
|
17
19
|
## Usage
|
|
@@ -40,7 +42,7 @@ Target directory is `webapi`'s optional argument or `-d` (default `.`). `npm cre
|
|
|
40
42
|
|
|
41
43
|
A first token that isn't a command (`webapi`, `create`, `add`, `auth0`, `help`) or a flag is the project's folder, so a mistyped command starts a project with that name.
|
|
42
44
|
|
|
43
|
-
The scaffolded Dev Container asks no questions. `gh` is installed in it: run `gh auth login` yourself if you want it, and the login persists in
|
|
45
|
+
The scaffolded Dev Container asks no questions. `gh` is installed in it: run `gh auth login` yourself if you want it, and the login persists in `~/.config/decohere/gh/<project>/`, outside the project and readable only by you. Each project has its own, so a project can use a different GitHub account. To use a token instead, put `GH_TOKEN=…` in `~/.config/decohere/gh/<project>.env`.
|
|
44
46
|
|
|
45
47
|
## Commands
|
|
46
48
|
|
|
@@ -89,6 +91,14 @@ Every API gets its own `projects/<name>/Dockerfile`; that folder is the Docker b
|
|
|
89
91
|
|
|
90
92
|
The app Dev Container is a thin `FROM ghcr.io/typesmiths/decohere/devcontainer:<version>` (pinned to the scaffolder version). Shared layers (bash history, pnpm, `gh`, js-debug bootloader fix) update via `docker pull` / Dev Container rebuild — Compose mounts and lifecycle scripts stay in the app repo. Rebuild with pull after upgrading `@decohere/create`.
|
|
91
93
|
|
|
94
|
+
The base image is `node:24-trixie-slim`, with no compilers. If an npm package has to compile on install because it has no prebuilt binary, add what it needs to your project's `.devcontainer/Dockerfile`:
|
|
95
|
+
|
|
96
|
+
```dockerfile
|
|
97
|
+
USER root
|
|
98
|
+
RUN apt-get update && apt-get install -y --no-install-recommends g++ make python3 && rm -rf /var/lib/apt/lists/*
|
|
99
|
+
USER node
|
|
100
|
+
```
|
|
101
|
+
|
|
92
102
|
#### Scripts
|
|
93
103
|
|
|
94
104
|
| Script | Command | When |
|
|
@@ -115,7 +125,7 @@ Each API is a separate deploy: package it (`pnpm run package:billing`) and build
|
|
|
115
125
|
|
|
116
126
|
### `auth0`
|
|
117
127
|
|
|
118
|
-
Run these in the project's Dev Container, which has the Auth0 CLI.
|
|
128
|
+
Run these in the project's Dev Container, which has the Auth0 CLI. Each project keeps its login in its own folder on your machine: `$XDG_RUNTIME_DIR/decohere-auth0/<project>` on Linux, which is held in memory and readable only by you, and `~/.config/decohere/decohere-auth0/<project>` elsewhere. Rebuilding the Dev Container doesn't log you out, but logging out of your machine or rebooting does on Linux. `configure` and `add auth0` stop if you're logged in to a different tenant from the one in `.env`. Use this after a project exists, when a token expires, or when the login app needs to be created or updated.
|
|
119
129
|
|
|
120
130
|
```bash
|
|
121
131
|
# Device/URL login — open the printed URL in your browser
|
package/es6/src/runner.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
2
|
-
import { existsSync, mkdirSync, mkdtempSync, readdirSync, renameSync, rmSync } from "node:fs";
|
|
2
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
3
4
|
import { randomBytes } from "node:crypto";
|
|
4
5
|
import { join } from "node:path";
|
|
5
6
|
import { resolveLaunch } from "./resolve-launch.js";
|
|
@@ -8,6 +9,7 @@ import { CREATE_IMAGE_REPOSITORY, CREATE_VERSION } from "./version.js";
|
|
|
8
9
|
const BUILDER_IMAGE = `${CREATE_IMAGE_REPOSITORY}:${CREATE_VERSION}`;
|
|
9
10
|
const SCAFFOLD_PACKAGE = `@decohere/scaffold@${CREATE_VERSION}`;
|
|
10
11
|
const WORKSPACE = "/workspace";
|
|
12
|
+
/** Passed by name only, so the value is never on a command line. */ const ADMIN_PASSWORD_ENV = "DECOHERE_ADMIN_PASSWORD";
|
|
11
13
|
const SIGNAL_EXIT_CODES = {
|
|
12
14
|
SIGINT: 130,
|
|
13
15
|
SIGTERM: 143,
|
|
@@ -39,6 +41,67 @@ const SIGNAL_EXIT_CODES = {
|
|
|
39
41
|
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
42
|
process.exit(1);
|
|
41
43
|
}
|
|
44
|
+
/** Meets Auth0's password rules whichever policy the tenant uses. */ function generateAdminPassword() {
|
|
45
|
+
return `${randomBytes(18).toString("base64url")}aA1!`;
|
|
46
|
+
}
|
|
47
|
+
/** Store it in the Linux key store, if there is one. The value goes over stdin, never in argv. */ function saveToKeyStore(projectName, password) {
|
|
48
|
+
if (process.platform !== "linux") return false;
|
|
49
|
+
const stored = spawnSync("secret-tool", [
|
|
50
|
+
"store",
|
|
51
|
+
`--label=Decohere ${projectName} Auth0 admin`,
|
|
52
|
+
...keyStoreAttributes(projectName)
|
|
53
|
+
], {
|
|
54
|
+
input: password,
|
|
55
|
+
stdio: [
|
|
56
|
+
"pipe",
|
|
57
|
+
"ignore",
|
|
58
|
+
"ignore"
|
|
59
|
+
]
|
|
60
|
+
});
|
|
61
|
+
return stored.error == null && stored.status === 0;
|
|
62
|
+
}
|
|
63
|
+
function keyStoreAttributes(projectName) {
|
|
64
|
+
return [
|
|
65
|
+
"service",
|
|
66
|
+
"decohere",
|
|
67
|
+
"project",
|
|
68
|
+
projectName,
|
|
69
|
+
"account",
|
|
70
|
+
"auth0-admin"
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* After a successful run, save the generated password: in the OS key store where there is one,
|
|
75
|
+
* otherwise in one private file outside the project. It's only for logging in, so nothing in
|
|
76
|
+
* the app reads it. Nothing is saved if no admin was made.
|
|
77
|
+
*/ function saveAdminPassword(targetDir, projectName, password) {
|
|
78
|
+
const env = join(targetDir, ".env");
|
|
79
|
+
const email = existsSync(env) ? readFileSync(env, "utf8").match(/^AUTH0_ADMIN_USER_EMAIL=(.+)$/m)?.[1] : undefined;
|
|
80
|
+
if (email == null) return;
|
|
81
|
+
const folder = join(homedir(), ".config", "decohere");
|
|
82
|
+
const file = join(folder, `${projectName}.env`);
|
|
83
|
+
if (saveToKeyStore(projectName, password)) {
|
|
84
|
+
// A file from an earlier run would hold a password that no longer works.
|
|
85
|
+
rmSync(file, {
|
|
86
|
+
force: true
|
|
87
|
+
});
|
|
88
|
+
console.log("\n Auth0 admin password saved in your key store. To read it:");
|
|
89
|
+
console.log(`\n secret-tool lookup ${keyStoreAttributes(projectName).join(" ")}`);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
mkdirSync(folder, {
|
|
93
|
+
recursive: true,
|
|
94
|
+
mode: 0o700
|
|
95
|
+
});
|
|
96
|
+
writeFileSync(file, `AUTH0_ADMIN_USER_EMAIL=${email}\nAUTH0_ADMIN_USER_PASSWORD=${password}\n`, {
|
|
97
|
+
mode: 0o600
|
|
98
|
+
});
|
|
99
|
+
chmodSync(file, 0o600);
|
|
100
|
+
console.log(`\n No key store found, so the Auth0 admin password is in a private file: ${file}`);
|
|
101
|
+
if (isInContainer()) {
|
|
102
|
+
console.log(" That's inside this container, so copy it if the container may be rebuilt.");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
42
105
|
function printNextSteps(targetDir) {
|
|
43
106
|
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
107
|
console.log(`\n Scaffold complete!\n\n Open your project:\n\n${open}`);
|
|
@@ -52,6 +115,7 @@ function printNextSteps(targetDir) {
|
|
|
52
115
|
recursive: true
|
|
53
116
|
});
|
|
54
117
|
}
|
|
118
|
+
const adminPassword = generateAdminPassword();
|
|
55
119
|
const result = spawnSync("npx", [
|
|
56
120
|
"--yes",
|
|
57
121
|
SCAFFOLD_PACKAGE,
|
|
@@ -62,14 +126,18 @@ function printNextSteps(targetDir) {
|
|
|
62
126
|
env: {
|
|
63
127
|
...process.env,
|
|
64
128
|
DECOHERE_BUILDER: "1",
|
|
65
|
-
DECOHERE_PROJECT_NAME: projectName
|
|
129
|
+
DECOHERE_PROJECT_NAME: projectName,
|
|
130
|
+
[ADMIN_PASSWORD_ENV]: adminPassword
|
|
66
131
|
}
|
|
67
132
|
});
|
|
68
133
|
if (result.error != null) {
|
|
69
134
|
console.error(`\n Could not start the scaffolder: ${result.error.message}\n`);
|
|
70
135
|
process.exit(1);
|
|
71
136
|
}
|
|
72
|
-
if (result.status === 0 && creating)
|
|
137
|
+
if (result.status === 0 && creating) {
|
|
138
|
+
saveAdminPassword(targetDir, projectName, adminPassword);
|
|
139
|
+
printNextSteps(targetDir);
|
|
140
|
+
}
|
|
73
141
|
process.exit(result.status ?? 1);
|
|
74
142
|
}
|
|
75
143
|
function assertDockerAvailable() {
|
|
@@ -160,6 +228,7 @@ function attach(name) {
|
|
|
160
228
|
if (copyOut) refuseFolderWithFiles(targetDir);
|
|
161
229
|
assertDockerAvailable();
|
|
162
230
|
const name = `decohere-create-${randomBytes(6).toString("hex")}`;
|
|
231
|
+
const adminPassword = generateAdminPassword();
|
|
163
232
|
const ttyFlags = process.stdin.isTTY ? [
|
|
164
233
|
"--interactive",
|
|
165
234
|
"--tty"
|
|
@@ -175,6 +244,8 @@ function attach(name) {
|
|
|
175
244
|
"DECOHERE_BUILDER=1",
|
|
176
245
|
"--env",
|
|
177
246
|
`DECOHERE_PROJECT_NAME=${projectName}`,
|
|
247
|
+
"--env",
|
|
248
|
+
ADMIN_PASSWORD_ENV,
|
|
178
249
|
"--workdir",
|
|
179
250
|
WORKSPACE,
|
|
180
251
|
BUILDER_IMAGE,
|
|
@@ -184,7 +255,11 @@ function attach(name) {
|
|
|
184
255
|
"ignore",
|
|
185
256
|
"ignore",
|
|
186
257
|
"inherit"
|
|
187
|
-
]
|
|
258
|
+
],
|
|
259
|
+
env: {
|
|
260
|
+
...process.env,
|
|
261
|
+
[ADMIN_PASSWORD_ENV]: adminPassword
|
|
262
|
+
}
|
|
188
263
|
});
|
|
189
264
|
if (created.status !== 0) process.exit(created.status ?? 1);
|
|
190
265
|
for (const [signal, code] of Object.entries(SIGNAL_EXIT_CODES)){
|
|
@@ -199,6 +274,7 @@ function attach(name) {
|
|
|
199
274
|
exitCode = await attach(name);
|
|
200
275
|
if (exitCode === 0 && copyOut) {
|
|
201
276
|
copyProjectOut(name, targetDir);
|
|
277
|
+
saveAdminPassword(targetDir, projectName, adminPassword);
|
|
202
278
|
printNextSteps(targetDir);
|
|
203
279
|
}
|
|
204
280
|
} catch (reason) {
|