@alicesystems/cli 0.1.0-alpha.2 → 0.1.0-alpha.3
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 +6 -0
- package/dist/add-db.d.ts +1 -0
- package/dist/add-db.js +12 -2
- package/dist/add-input.d.ts +117 -0
- package/dist/add-input.js +137 -0
- package/dist/add-json.d.ts +3 -0
- package/dist/add-json.js +61 -0
- package/dist/add-shared-package.js +16 -2
- package/dist/alice-record-update.d.ts +20 -0
- package/dist/alice-record-update.js +127 -0
- package/dist/application-integration.js +22 -4
- package/dist/index.js +48 -4
- package/dist/init-input.d.ts +30 -0
- package/dist/init-input.js +48 -0
- package/dist/init.d.ts +2 -0
- package/dist/init.js +45 -1
- package/dist/templates/database/mysql/docker-compose.yml +20 -0
- package/dist/templates/database/postgres/docker-compose.yml +20 -0
- package/dist/templates/project/alice.json.tpl +1 -0
- package/dist/templates/project/apps/mobile/README.md.tpl +8 -0
- package/dist/templates/project/apps/mobile/css.d.ts +1 -0
- package/dist/templates/project/apps/mobile/global.css +6 -0
- package/dist/templates/project/apps/mobile/metro.config.js +4 -0
- package/dist/templates/project/apps/mobile/nativewind-env.d.ts +3 -0
- package/dist/templates/project/apps/mobile/package.json.tpl +9 -0
- package/dist/templates/project/apps/mobile/postcss.config.mjs +5 -0
- package/dist/templates/project/apps/mobile/{app → src/app}/_layout.tsx +1 -0
- package/dist/templates/project/apps/mobile/src/app/index.tsx.tpl +61 -0
- package/dist/templates/project/apps/mobile/tsconfig.json.tpl +1 -1
- package/dist/templates/project/oxlint.config.mts.tpl +2 -0
- package/dist/templates/project/packages/user-interface/README.md.tpl +3 -2
- package/dist/templates/project/packages/user-interface/package.json.tpl +1 -0
- package/dist/templates/project/packages/user-interface/src/styles/native.css +72 -0
- package/dist/templates/project/packages/user-interface/tests/user-interface.test.tsx +14 -0
- package/dist/templates/project/pnpm-workspace.yaml.tpl +4 -0
- package/node_modules/@alice/core/dist/alice-record.d.ts +139 -0
- package/node_modules/@alice/core/dist/alice-record.js +215 -0
- package/node_modules/@alice/core/dist/database-recipe.d.ts +12 -0
- package/node_modules/@alice/core/dist/database-recipe.js +8 -0
- package/node_modules/@alice/core/dist/index.d.ts +2 -0
- package/node_modules/@alice/core/dist/index.js +1 -0
- package/node_modules/@alice/core/dist/project-init.js +53 -18
- package/package.json +1 -1
- package/dist/templates/project/apps/mobile/app/index.tsx.tpl +0 -90
- package/dist/templates/project/packages/cache/README.md.tpl +0 -42
- package/dist/templates/project/packages/cache/package.json.tpl +0 -26
- package/dist/templates/project/packages/cache/src/cache.ts +0 -50
- package/dist/templates/project/packages/cache/src/create-cache.ts +0 -16
- package/dist/templates/project/packages/cache/src/index.ts +0 -4
- package/dist/templates/project/packages/cache/src/memory-cache.ts +0 -147
- package/dist/templates/project/packages/cache/tests/cache.test.mjs +0 -83
- package/dist/templates/project/packages/cache/tsconfig.json.tpl +0 -1
- package/dist/templates/project/packages/errors/src/app-error.ts +0 -31
- package/dist/templates/project/packages/errors/src/codes.ts +0 -29
- package/dist/templates/project/packages/errors/src/response.ts +0 -46
- package/dist/templates/project/packages/observability/README.md.tpl +0 -30
- package/dist/templates/project/packages/observability/package.json.tpl +0 -26
- package/dist/templates/project/packages/observability/src/error-reporting.ts +0 -23
- package/dist/templates/project/packages/observability/src/index.ts +0 -13
- package/dist/templates/project/packages/observability/src/logger.ts +0 -123
- package/dist/templates/project/packages/observability/src/tracing.ts +0 -41
- package/dist/templates/project/packages/observability/tests/observability.test.mjs +0 -92
- package/dist/templates/project/packages/observability/tsconfig.json.tpl +0 -1
- package/dist/templates/project/packages/user-interface/src/index.ts +0 -2
- package/dist/templates/project/packages/user-interface/src/web/button.tsx +0 -33
- package/dist/templates/project/packages/user-interface/src/web/card.tsx +0 -13
- package/dist/templates/project/packages/user-interface/src/web/cn.ts +0 -6
- package/dist/templates/project/packages/user-interface/src/web/index.ts +0 -4
- package/dist/templates/project/packages/user-interface/tests/user-interface.test.mjs +0 -49
- package/dist/templates/project/packages/user-interface/theme.css +0 -37
package/README.md
CHANGED
|
@@ -35,12 +35,18 @@ alice add env --dry-run
|
|
|
35
35
|
alice add db --dialect postgres --dry-run
|
|
36
36
|
alice add cache --adapter redis --dry-run
|
|
37
37
|
alice add observability --adapter pino --dry-run
|
|
38
|
+
alice add db --dialect mysql --local-compose --dry-run
|
|
39
|
+
alice init --json '{"name":"demo","dryRun":true}'
|
|
40
|
+
alice add --json '{"recipe":"env","dryRun":true}'
|
|
41
|
+
alice schema
|
|
38
42
|
```
|
|
39
43
|
|
|
40
44
|
Run `add` from an existing pnpm workspace or pass `--project <path>`. Omit `--dry-run` to generate and install. Database dialects are `postgres` (default, Neon HTTP), `sqlite` and `mysql`; cache adapters are `memory` (default) and `redis`; logger adapters are `console` (default) and `pino`. Redis generation requires an existing environment package.
|
|
41
45
|
|
|
42
46
|
`alice add env --app <application>` and `alice add db --app <application>` create integration modules for existing Hono, Next.js and NestJS applications. Database integration requires the shared database package to be built. Application startup/module wiring remains manual. Next.js environment integration is public-client-only; database integration is server-only.
|
|
43
47
|
|
|
48
|
+
`alice init` writes `alice.json`, a deterministic record of the project, and `alice add` updates it last (a missing, invalid or newer file is never created or overwritten). `--json` takes a strict payload and prints one JSON result object; `alice schema` prints the accepted shapes. `--local-compose` (PostgreSQL and MySQL) adds a `docker-compose.yml` whose password comes from `DATABASE_PASSWORD`.
|
|
49
|
+
|
|
44
50
|
Existing packages and developer files are protected from overwrites. Failed setup preserves generated files and reports recovery steps. Generation does not provision services or deploy applications.
|
|
45
51
|
|
|
46
52
|
## Alpha limitations
|
package/dist/add-db.d.ts
CHANGED
package/dist/add-db.js
CHANGED
|
@@ -13,8 +13,18 @@ export async function addDatabase(options, runner = runProcess) {
|
|
|
13
13
|
}
|
|
14
14
|
return integrateDatabase({ ...options, app: options.app }, runner);
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
if (options.localCompose && options.dialect === "sqlite") {
|
|
17
|
+
throw new Error("--local-compose does not apply to SQLite, which is a local file. Use --dialect postgres or mysql.");
|
|
18
|
+
}
|
|
19
|
+
const code = await addSharedPackage("db", {
|
|
17
20
|
...options,
|
|
18
|
-
recipeOptions:
|
|
21
|
+
recipeOptions: {
|
|
22
|
+
...(options.dialect === undefined ? {} : { dialect: options.dialect }),
|
|
23
|
+
...(options.localCompose ? { localCompose: "yes" } : {}),
|
|
24
|
+
},
|
|
19
25
|
}, runner);
|
|
26
|
+
if (code === 0 && options.localCompose && !options.dryRun) {
|
|
27
|
+
process.stdout.write("Local database: set DATABASE_PASSWORD in your shell, then run docker compose -f packages/database/docker-compose.yml up -d\n");
|
|
28
|
+
}
|
|
29
|
+
return code;
|
|
20
30
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export type AddRecipe = "env" | "db" | "cache" | "observability";
|
|
2
|
+
export interface AddInput {
|
|
3
|
+
readonly recipe: AddRecipe;
|
|
4
|
+
readonly project?: string;
|
|
5
|
+
readonly dryRun?: boolean;
|
|
6
|
+
readonly install?: boolean;
|
|
7
|
+
readonly app?: string;
|
|
8
|
+
readonly dialect?: string;
|
|
9
|
+
readonly adapter?: string;
|
|
10
|
+
readonly localCompose?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** JSON Schema for `alice add --json`; keep in step with `parseAddPayload`. */
|
|
13
|
+
export declare const addInputSchema: {
|
|
14
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
15
|
+
readonly oneOf: readonly [{
|
|
16
|
+
readonly additionalProperties: false;
|
|
17
|
+
readonly properties: {
|
|
18
|
+
readonly app: {
|
|
19
|
+
readonly type: "string";
|
|
20
|
+
};
|
|
21
|
+
readonly recipe: {
|
|
22
|
+
readonly const: "env";
|
|
23
|
+
};
|
|
24
|
+
readonly dryRun: {
|
|
25
|
+
readonly default: false;
|
|
26
|
+
readonly type: "boolean";
|
|
27
|
+
};
|
|
28
|
+
readonly install: {
|
|
29
|
+
readonly default: true;
|
|
30
|
+
readonly type: "boolean";
|
|
31
|
+
};
|
|
32
|
+
readonly project: {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
readonly required: readonly ["recipe"];
|
|
37
|
+
readonly type: "object";
|
|
38
|
+
}, {
|
|
39
|
+
readonly additionalProperties: false;
|
|
40
|
+
readonly properties: {
|
|
41
|
+
readonly app: {
|
|
42
|
+
readonly type: "string";
|
|
43
|
+
};
|
|
44
|
+
readonly dialect: {
|
|
45
|
+
readonly enum: readonly ["postgres", "sqlite", "mysql"];
|
|
46
|
+
};
|
|
47
|
+
readonly localCompose: {
|
|
48
|
+
readonly default: false;
|
|
49
|
+
readonly type: "boolean";
|
|
50
|
+
};
|
|
51
|
+
readonly recipe: {
|
|
52
|
+
readonly const: "db";
|
|
53
|
+
};
|
|
54
|
+
readonly dryRun: {
|
|
55
|
+
readonly default: false;
|
|
56
|
+
readonly type: "boolean";
|
|
57
|
+
};
|
|
58
|
+
readonly install: {
|
|
59
|
+
readonly default: true;
|
|
60
|
+
readonly type: "boolean";
|
|
61
|
+
};
|
|
62
|
+
readonly project: {
|
|
63
|
+
readonly type: "string";
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
readonly required: readonly ["recipe"];
|
|
67
|
+
readonly type: "object";
|
|
68
|
+
}, {
|
|
69
|
+
readonly additionalProperties: false;
|
|
70
|
+
readonly properties: {
|
|
71
|
+
readonly adapter: {
|
|
72
|
+
readonly enum: readonly ["memory", "redis"];
|
|
73
|
+
};
|
|
74
|
+
readonly recipe: {
|
|
75
|
+
readonly const: "cache";
|
|
76
|
+
};
|
|
77
|
+
readonly dryRun: {
|
|
78
|
+
readonly default: false;
|
|
79
|
+
readonly type: "boolean";
|
|
80
|
+
};
|
|
81
|
+
readonly install: {
|
|
82
|
+
readonly default: true;
|
|
83
|
+
readonly type: "boolean";
|
|
84
|
+
};
|
|
85
|
+
readonly project: {
|
|
86
|
+
readonly type: "string";
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
readonly required: readonly ["recipe"];
|
|
90
|
+
readonly type: "object";
|
|
91
|
+
}, {
|
|
92
|
+
readonly additionalProperties: false;
|
|
93
|
+
readonly properties: {
|
|
94
|
+
readonly adapter: {
|
|
95
|
+
readonly enum: readonly ["console", "pino"];
|
|
96
|
+
};
|
|
97
|
+
readonly recipe: {
|
|
98
|
+
readonly const: "observability";
|
|
99
|
+
};
|
|
100
|
+
readonly dryRun: {
|
|
101
|
+
readonly default: false;
|
|
102
|
+
readonly type: "boolean";
|
|
103
|
+
};
|
|
104
|
+
readonly install: {
|
|
105
|
+
readonly default: true;
|
|
106
|
+
readonly type: "boolean";
|
|
107
|
+
};
|
|
108
|
+
readonly project: {
|
|
109
|
+
readonly type: "string";
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
readonly required: readonly ["recipe"];
|
|
113
|
+
readonly type: "object";
|
|
114
|
+
}];
|
|
115
|
+
};
|
|
116
|
+
/** Strict, non-executing parse. Option values are validated again by the recipes. */
|
|
117
|
+
export declare function parseAddPayload(payload: string): AddInput;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const dialects = ["postgres", "sqlite", "mysql"];
|
|
2
|
+
const adapters = {
|
|
3
|
+
cache: ["memory", "redis"],
|
|
4
|
+
observability: ["console", "pino"],
|
|
5
|
+
};
|
|
6
|
+
const common = {
|
|
7
|
+
dryRun: { default: false, type: "boolean" },
|
|
8
|
+
install: { default: true, type: "boolean" },
|
|
9
|
+
project: { type: "string" },
|
|
10
|
+
};
|
|
11
|
+
/** JSON Schema for `alice add --json`; keep in step with `parseAddPayload`. */
|
|
12
|
+
export const addInputSchema = {
|
|
13
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
14
|
+
oneOf: [
|
|
15
|
+
{
|
|
16
|
+
additionalProperties: false,
|
|
17
|
+
properties: {
|
|
18
|
+
...common,
|
|
19
|
+
app: { type: "string" },
|
|
20
|
+
recipe: { const: "env" },
|
|
21
|
+
},
|
|
22
|
+
required: ["recipe"],
|
|
23
|
+
type: "object",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
properties: {
|
|
28
|
+
...common,
|
|
29
|
+
app: { type: "string" },
|
|
30
|
+
dialect: { enum: dialects },
|
|
31
|
+
localCompose: { default: false, type: "boolean" },
|
|
32
|
+
recipe: { const: "db" },
|
|
33
|
+
},
|
|
34
|
+
required: ["recipe"],
|
|
35
|
+
type: "object",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
properties: {
|
|
40
|
+
...common,
|
|
41
|
+
adapter: { enum: adapters.cache },
|
|
42
|
+
recipe: { const: "cache" },
|
|
43
|
+
},
|
|
44
|
+
required: ["recipe"],
|
|
45
|
+
type: "object",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
additionalProperties: false,
|
|
49
|
+
properties: {
|
|
50
|
+
...common,
|
|
51
|
+
adapter: { enum: adapters.observability },
|
|
52
|
+
recipe: { const: "observability" },
|
|
53
|
+
},
|
|
54
|
+
required: ["recipe"],
|
|
55
|
+
type: "object",
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
const allowedByRecipe = {
|
|
60
|
+
cache: ["adapter"],
|
|
61
|
+
db: ["app", "dialect", "localCompose"],
|
|
62
|
+
env: ["app"],
|
|
63
|
+
observability: ["adapter"],
|
|
64
|
+
};
|
|
65
|
+
const stringKeys = ["app", "dialect", "adapter", "project"];
|
|
66
|
+
const booleanKeys = ["dryRun", "install", "localCompose"];
|
|
67
|
+
const commonBooleans = ["dryRun", "install"];
|
|
68
|
+
function isRecipe(value) {
|
|
69
|
+
return typeof value === "string" && Object.hasOwn(allowedByRecipe, value);
|
|
70
|
+
}
|
|
71
|
+
/** Strict, non-executing parse. Option values are validated again by the recipes. */
|
|
72
|
+
export function parseAddPayload(payload) {
|
|
73
|
+
let value;
|
|
74
|
+
try {
|
|
75
|
+
value = JSON.parse(payload);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
throw new Error("--json payload is not valid JSON.");
|
|
79
|
+
}
|
|
80
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
81
|
+
throw new Error("--json payload must be a JSON object.");
|
|
82
|
+
}
|
|
83
|
+
const record = value;
|
|
84
|
+
if (!isRecipe(record.recipe)) {
|
|
85
|
+
throw new Error('--json payload requires "recipe": env, db, cache or observability.');
|
|
86
|
+
}
|
|
87
|
+
const { recipe } = record;
|
|
88
|
+
const allowed = new Set([
|
|
89
|
+
"recipe",
|
|
90
|
+
"project",
|
|
91
|
+
...commonBooleans,
|
|
92
|
+
...allowedByRecipe[recipe],
|
|
93
|
+
]);
|
|
94
|
+
const unknown = Object.keys(record).filter((key) => !allowed.has(key));
|
|
95
|
+
if (unknown.length > 0) {
|
|
96
|
+
throw new Error(`--json payload has ${unknown.length === 1 ? "a property" : "properties"} not accepted for "${recipe}": ${unknown.join(", ")}. Run alice schema for the accepted shape.`);
|
|
97
|
+
}
|
|
98
|
+
const result = readValues(record, recipe);
|
|
99
|
+
checkEnums(result);
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
function readValues(record, recipe) {
|
|
103
|
+
const result = { recipe };
|
|
104
|
+
for (const key of stringKeys) {
|
|
105
|
+
const entry = record[key];
|
|
106
|
+
if (entry === undefined) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (typeof entry !== "string" || entry.length === 0) {
|
|
110
|
+
throw new TypeError(`--json property "${key}" must be a non-empty string.`);
|
|
111
|
+
}
|
|
112
|
+
result[key] = entry;
|
|
113
|
+
}
|
|
114
|
+
for (const key of booleanKeys) {
|
|
115
|
+
const entry = record[key];
|
|
116
|
+
if (entry === undefined) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (typeof entry !== "boolean") {
|
|
120
|
+
throw new TypeError(`--json property "${key}" must be a boolean.`);
|
|
121
|
+
}
|
|
122
|
+
result[key] = entry;
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
function checkEnums(input) {
|
|
127
|
+
const { adapter, dialect, recipe } = input;
|
|
128
|
+
if (dialect !== undefined &&
|
|
129
|
+
!dialects.includes(dialect)) {
|
|
130
|
+
throw new Error(`--json "dialect" must be one of: ${dialects.join(", ")}.`);
|
|
131
|
+
}
|
|
132
|
+
if (adapter !== undefined &&
|
|
133
|
+
(recipe === "cache" || recipe === "observability") &&
|
|
134
|
+
!adapters[recipe].includes(adapter)) {
|
|
135
|
+
throw new Error(`--json "adapter" for ${recipe} must be one of: ${adapters[recipe].join(", ")}.`);
|
|
136
|
+
}
|
|
137
|
+
}
|
package/dist/add-json.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { addCache } from "./add-cache.js";
|
|
2
|
+
import { addDatabase } from "./add-db.js";
|
|
3
|
+
import { addEnvironment } from "./add-env.js";
|
|
4
|
+
import { addObservability } from "./add-observability.js";
|
|
5
|
+
function stripControls(value) {
|
|
6
|
+
return value.replaceAll(/[\p{Cc}\p{Cf}]/gu, "");
|
|
7
|
+
}
|
|
8
|
+
/** Runs the existing command and collects what it prints, so stdout can carry one JSON object. */
|
|
9
|
+
async function capture(run) {
|
|
10
|
+
const lines = [];
|
|
11
|
+
const original = process.stdout.write.bind(process.stdout);
|
|
12
|
+
process.stdout.write = ((chunk) => {
|
|
13
|
+
const text = typeof chunk === "string" ? chunk : Buffer.from(chunk).toString();
|
|
14
|
+
lines.push(...text.split(/\r?\n/u));
|
|
15
|
+
return true;
|
|
16
|
+
});
|
|
17
|
+
try {
|
|
18
|
+
const exitCode = await run();
|
|
19
|
+
return { exitCode, report: lines.filter(Boolean).map(stripControls) };
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return {
|
|
23
|
+
error: stripControls(error instanceof Error ? error.message : "Add failed."),
|
|
24
|
+
exitCode: 1,
|
|
25
|
+
report: lines.filter(Boolean).map(stripControls),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
process.stdout.write = original;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function dispatch(input) {
|
|
33
|
+
const { recipe, ...options } = input;
|
|
34
|
+
switch (recipe) {
|
|
35
|
+
case "env": {
|
|
36
|
+
return addEnvironment(options);
|
|
37
|
+
}
|
|
38
|
+
case "db": {
|
|
39
|
+
return addDatabase(options);
|
|
40
|
+
}
|
|
41
|
+
case "cache": {
|
|
42
|
+
return addCache(options);
|
|
43
|
+
}
|
|
44
|
+
default: {
|
|
45
|
+
return addObservability(options);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** One JSON result object on stdout; the exit code mirrors the flag-based command. */
|
|
50
|
+
export async function addFromPayload(input) {
|
|
51
|
+
const result = await capture(() => dispatch(input));
|
|
52
|
+
process.stdout.write(`${JSON.stringify({
|
|
53
|
+
dryRun: input.dryRun ?? false,
|
|
54
|
+
...(result.error === undefined ? {} : { error: result.error }),
|
|
55
|
+
exitCode: result.exitCode,
|
|
56
|
+
ok: result.exitCode === 0,
|
|
57
|
+
recipe: input.recipe,
|
|
58
|
+
report: result.report,
|
|
59
|
+
}, null, 2)}\n`);
|
|
60
|
+
return result.exitCode;
|
|
61
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
2
|
import { assertPackageDestinationAbsent, createFilePlan, createInstallationPlan, createRecipeRegistry, cacheRecipe, cacheTemplate, databaseRecipe, databaseTemplate, environmentRecipe, environmentTemplate, inspectFilePlan, inspectProject, observabilityRecipe, observabilityTemplate, renderFilePlan, validateWorkspaceDestination, writeRenderedFilePlan, } from "@alice/core";
|
|
3
|
+
import { updateAliceRecord } from "./alice-record-update.js";
|
|
3
4
|
import { preparePnpm, processFailure, runProcess } from "./pnpm.js";
|
|
4
5
|
// Explicit built-ins only. Assets are staged beside the compiled CLI during build.
|
|
5
6
|
const registry = createRecipeRegistry([
|
|
@@ -163,10 +164,23 @@ export async function addSharedPackage(recipeId, options, runner = runProcess) {
|
|
|
163
164
|
: "Dependency installation: Skipped (--no-install)",
|
|
164
165
|
]);
|
|
165
166
|
}
|
|
166
|
-
|
|
167
|
+
const recordChange = {
|
|
168
|
+
kind: "package",
|
|
169
|
+
name: contract.name,
|
|
170
|
+
path: contract.destination,
|
|
171
|
+
};
|
|
172
|
+
if (result.status === "dry-run") {
|
|
173
|
+
print(await updateAliceRecord(project.root, recordChange, { dryRun: true }));
|
|
174
|
+
}
|
|
175
|
+
if (code !== 0 || result.status !== "success") {
|
|
167
176
|
return code;
|
|
168
177
|
}
|
|
169
|
-
|
|
178
|
+
const installed = command
|
|
179
|
+
? await installDependencies(command, runner, contract.name)
|
|
180
|
+
: 0;
|
|
181
|
+
// The record is updated last, once the files exist, whether or not installation succeeded.
|
|
182
|
+
print(await updateAliceRecord(project.root, recordChange));
|
|
183
|
+
return installed;
|
|
170
184
|
}
|
|
171
185
|
async function installDependencies(command, runner, packageName) {
|
|
172
186
|
print(["Dependency installation started: pnpm install"]);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type AliceRecordChange = {
|
|
2
|
+
readonly kind: "package";
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly path: string;
|
|
5
|
+
} | {
|
|
6
|
+
readonly kind: "integration";
|
|
7
|
+
readonly recipe: string;
|
|
8
|
+
readonly application: string;
|
|
9
|
+
readonly package: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Records a completed change in `alice.json`. This runs last and never fails the command: the
|
|
13
|
+
* generated files already exist, so every problem becomes a report line and the file is left alone.
|
|
14
|
+
* A missing file is not created (older projects have none), and an invalid or newer file is refused.
|
|
15
|
+
*/
|
|
16
|
+
export declare function updateAliceRecord(root: string, change: AliceRecordChange, options?: {
|
|
17
|
+
readonly dryRun?: boolean;
|
|
18
|
+
}): Promise<string[]>;
|
|
19
|
+
/** Read-only summary for `alice inspect`. Nothing is printed when the project has no record. */
|
|
20
|
+
export declare function describeAliceRecord(root: string): Promise<string[]>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parseAliceRecord, serialiseAliceRecord } from "@alice/core";
|
|
4
|
+
const recordFile = "alice.json";
|
|
5
|
+
function describe(change) {
|
|
6
|
+
return change.kind === "package"
|
|
7
|
+
? `package ${change.name}`
|
|
8
|
+
: `${change.recipe} integration in ${change.application}`;
|
|
9
|
+
}
|
|
10
|
+
/** Idempotent: returns the same record when the change is already present. */
|
|
11
|
+
function apply(record, change) {
|
|
12
|
+
if (change.kind === "package") {
|
|
13
|
+
if (record.packages.some((item) => item.name === change.name)) {
|
|
14
|
+
return record;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
...record,
|
|
18
|
+
packages: [
|
|
19
|
+
...record.packages,
|
|
20
|
+
{ name: change.name, origin: "recipe", path: change.path },
|
|
21
|
+
].toSorted((a, b) => (a.path < b.path ? -1 : 1)),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (record.integrations.some((item) => item.recipe === change.recipe &&
|
|
25
|
+
item.application === change.application &&
|
|
26
|
+
item.package === change.package)) {
|
|
27
|
+
return record;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
...record,
|
|
31
|
+
integrations: [
|
|
32
|
+
...record.integrations,
|
|
33
|
+
{
|
|
34
|
+
application: change.application,
|
|
35
|
+
package: change.package,
|
|
36
|
+
recipe: change.recipe,
|
|
37
|
+
},
|
|
38
|
+
].toSorted((a, b) => `${a.recipe}/${a.application}` < `${b.recipe}/${b.application}` ? -1 : 1),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Records a completed change in `alice.json`. This runs last and never fails the command: the
|
|
43
|
+
* generated files already exist, so every problem becomes a report line and the file is left alone.
|
|
44
|
+
* A missing file is not created (older projects have none), and an invalid or newer file is refused.
|
|
45
|
+
*/
|
|
46
|
+
export async function updateAliceRecord(root, change, options = {}) {
|
|
47
|
+
const file = path.join(root, recordFile);
|
|
48
|
+
let before;
|
|
49
|
+
try {
|
|
50
|
+
before = await fs.readFile(file, "utf-8");
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error.code === "ENOENT") {
|
|
54
|
+
return [
|
|
55
|
+
`${recordFile}: not found, so nothing was recorded (projects created before ${recordFile} existed have none).`,
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
return [`${recordFile}: could not be read, so it was not updated.`];
|
|
59
|
+
}
|
|
60
|
+
let record;
|
|
61
|
+
try {
|
|
62
|
+
record = parseAliceRecord(before);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return [
|
|
66
|
+
`${error instanceof Error ? error.message : `${recordFile} is invalid.`} It was not updated.`,
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
const next = apply(record, change);
|
|
70
|
+
if (next === record) {
|
|
71
|
+
return [`${recordFile}: already records the ${describe(change)}.`];
|
|
72
|
+
}
|
|
73
|
+
if (options.dryRun) {
|
|
74
|
+
return [`${recordFile}: would record the ${describe(change)}.`];
|
|
75
|
+
}
|
|
76
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
77
|
+
try {
|
|
78
|
+
await fs.writeFile(temporary, serialiseAliceRecord(next), {
|
|
79
|
+
encoding: "utf-8",
|
|
80
|
+
flag: "wx",
|
|
81
|
+
});
|
|
82
|
+
// Refuse if it was edited while this command ran; the developer's version wins.
|
|
83
|
+
if ((await fs.readFile(file, "utf-8")) !== before) {
|
|
84
|
+
await fs.rm(temporary, { force: true });
|
|
85
|
+
return [
|
|
86
|
+
`${recordFile}: changed while Alice was running, so it was not updated.`,
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
await fs.rename(temporary, file);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
await fs.rm(temporary, { force: true }).catch((error) => error);
|
|
93
|
+
return [`${recordFile}: could not be written, so it was not updated.`];
|
|
94
|
+
}
|
|
95
|
+
return [`${recordFile}: recorded the ${describe(change)}.`];
|
|
96
|
+
}
|
|
97
|
+
/** Read-only summary for `alice inspect`. Nothing is printed when the project has no record. */
|
|
98
|
+
export async function describeAliceRecord(root) {
|
|
99
|
+
let source;
|
|
100
|
+
try {
|
|
101
|
+
source = await fs.readFile(path.join(root, recordFile), "utf-8");
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const record = parseAliceRecord(source);
|
|
108
|
+
return [
|
|
109
|
+
"",
|
|
110
|
+
`Alice Record (${recordFile})`,
|
|
111
|
+
` Template: ${record.template}`,
|
|
112
|
+
` Created with: ${record.reproducibleCommand}`,
|
|
113
|
+
` Integrations: ${record.integrations.length === 0
|
|
114
|
+
? "none recorded"
|
|
115
|
+
: record.integrations
|
|
116
|
+
.map((item) => `${item.recipe} in ${item.application}`)
|
|
117
|
+
.join(", ")}`,
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
return [
|
|
122
|
+
"",
|
|
123
|
+
`Alice Record (${recordFile})`,
|
|
124
|
+
` ${error instanceof Error ? error.message : "Invalid record."}`,
|
|
125
|
+
];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
2
|
import { applyApplicationManifestPlan, createApplicationIntegrationPlan, createDatabaseApplicationIntegrationPlan, createDatabaseIntegrationFilePlan, databaseRecipe, verifyDatabasePackage, verifyDatabaseIntegrationFiles, createApplicationManifestPlan, createEnvironmentIntegrationFilePlan, createRecipeRegistry, environmentIntegrations, environmentRecipe, inspectFilePlan, inspectProject, validateWorkspaceDestination, verifyEnvironmentPackage, writeFilePlan, prepareDatabaseIntegrationFiles, writeRenderedFilePlan, } from "@alice/core";
|
|
3
|
+
import { updateAliceRecord } from "./alice-record-update.js";
|
|
3
4
|
import { preparePnpm, processFailure, runProcess } from "./pnpm.js";
|
|
4
5
|
const registry = createRecipeRegistry([environmentRecipe, databaseRecipe]);
|
|
5
6
|
const environmentStrategy = {
|
|
@@ -132,6 +133,12 @@ async function applyIntegration(options, strategy, runner) {
|
|
|
132
133
|
]);
|
|
133
134
|
return 0;
|
|
134
135
|
}
|
|
136
|
+
print(await updateAliceRecord(project.root, {
|
|
137
|
+
application: plan.application.name,
|
|
138
|
+
kind: "integration",
|
|
139
|
+
package: recordedPackage(strategy),
|
|
140
|
+
recipe: strategy.recipeId,
|
|
141
|
+
}, { dryRun: true }));
|
|
135
142
|
print([
|
|
136
143
|
`Manifest validation: ${validation.status}`,
|
|
137
144
|
...validation.errors,
|
|
@@ -184,11 +191,9 @@ async function applyIntegration(options, strategy, runner) {
|
|
|
184
191
|
if (!(await updateManifest(prepared, options.app))) {
|
|
185
192
|
return 1;
|
|
186
193
|
}
|
|
194
|
+
let installCode = 0;
|
|
187
195
|
if (command) {
|
|
188
|
-
|
|
189
|
-
if (code !== 0) {
|
|
190
|
-
return code;
|
|
191
|
-
}
|
|
196
|
+
installCode = await installDependencies(command, runner);
|
|
192
197
|
}
|
|
193
198
|
else {
|
|
194
199
|
print([
|
|
@@ -196,9 +201,22 @@ async function applyIntegration(options, strategy, runner) {
|
|
|
196
201
|
`Next step from ${project.root}: pnpm install`,
|
|
197
202
|
]);
|
|
198
203
|
}
|
|
204
|
+
// The record is updated last, once files and manifest exist, whether or not installation succeeded.
|
|
205
|
+
print(await updateAliceRecord(project.root, {
|
|
206
|
+
application: plan.application.name,
|
|
207
|
+
kind: "integration",
|
|
208
|
+
package: recordedPackage(strategy),
|
|
209
|
+
recipe: strategy.recipeId,
|
|
210
|
+
}));
|
|
211
|
+
if (installCode !== 0) {
|
|
212
|
+
return installCode;
|
|
213
|
+
}
|
|
199
214
|
reportCompletion(plan, strategy, options.install !== false);
|
|
200
215
|
return 0;
|
|
201
216
|
}
|
|
217
|
+
function recordedPackage(strategy) {
|
|
218
|
+
return registry.get(strategy.recipeId)?.package.name ?? strategy.recipeId;
|
|
219
|
+
}
|
|
202
220
|
async function updateManifest(prepared, app) {
|
|
203
221
|
const { project, plan, manifest, strategy } = prepared;
|
|
204
222
|
// Revalidate configuration and identity again after creation, before the guarded manifest update.
|