@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
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/** Current `alice.json` schema version. Newer files are rejected, never rewritten. */
|
|
2
|
+
export declare const aliceRecordVersion = 1;
|
|
3
|
+
export interface AliceRecordApplication {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly framework: "Next.js" | "Hono" | "Expo";
|
|
7
|
+
}
|
|
8
|
+
export interface AliceRecordPackage {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly path: string;
|
|
11
|
+
readonly origin: "recipe" | "starter";
|
|
12
|
+
}
|
|
13
|
+
export interface AliceRecordIntegration {
|
|
14
|
+
/** Recipe identifier, for example `env` or `db`. */
|
|
15
|
+
readonly recipe: string;
|
|
16
|
+
/** Workspace package name of the application that was integrated. */
|
|
17
|
+
readonly application: string;
|
|
18
|
+
/** Workspace package name of the shared package that was integrated. */
|
|
19
|
+
readonly package: string;
|
|
20
|
+
}
|
|
21
|
+
export interface AliceRecord {
|
|
22
|
+
readonly schemaVersion: typeof aliceRecordVersion;
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly template: string;
|
|
25
|
+
readonly packageManager: {
|
|
26
|
+
readonly name: "pnpm";
|
|
27
|
+
readonly version: string;
|
|
28
|
+
};
|
|
29
|
+
readonly applications: readonly AliceRecordApplication[];
|
|
30
|
+
readonly packages: readonly AliceRecordPackage[];
|
|
31
|
+
readonly integrations: readonly AliceRecordIntegration[];
|
|
32
|
+
readonly reproducibleCommand: string;
|
|
33
|
+
}
|
|
34
|
+
/** Strict, non-executing parse. Unknown properties and newer schema versions are rejected. */
|
|
35
|
+
export declare function parseAliceRecord(source: string): AliceRecord;
|
|
36
|
+
/** Canonical, deterministic text: fixed key order, two-space indent, trailing newline. */
|
|
37
|
+
export declare function serialiseAliceRecord(record: AliceRecord): string;
|
|
38
|
+
/** JSON Schema describing `alice.json`; keep in step with `parseAliceRecord`. */
|
|
39
|
+
export declare const aliceRecordSchema: {
|
|
40
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
41
|
+
readonly additionalProperties: false;
|
|
42
|
+
readonly properties: {
|
|
43
|
+
readonly applications: {
|
|
44
|
+
readonly items: {
|
|
45
|
+
readonly additionalProperties: false;
|
|
46
|
+
readonly properties: {
|
|
47
|
+
readonly framework: {
|
|
48
|
+
readonly enum: readonly string[];
|
|
49
|
+
};
|
|
50
|
+
readonly name: {
|
|
51
|
+
readonly minLength: 1;
|
|
52
|
+
readonly type: "string";
|
|
53
|
+
};
|
|
54
|
+
readonly path: {
|
|
55
|
+
readonly minLength: 1;
|
|
56
|
+
readonly type: "string";
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
readonly required: readonly ["framework", "name", "path"];
|
|
60
|
+
readonly type: "object";
|
|
61
|
+
};
|
|
62
|
+
readonly type: "array";
|
|
63
|
+
};
|
|
64
|
+
readonly integrations: {
|
|
65
|
+
readonly items: {
|
|
66
|
+
readonly additionalProperties: false;
|
|
67
|
+
readonly properties: {
|
|
68
|
+
readonly application: {
|
|
69
|
+
readonly minLength: 1;
|
|
70
|
+
readonly type: "string";
|
|
71
|
+
};
|
|
72
|
+
readonly package: {
|
|
73
|
+
readonly minLength: 1;
|
|
74
|
+
readonly type: "string";
|
|
75
|
+
};
|
|
76
|
+
readonly recipe: {
|
|
77
|
+
readonly minLength: 1;
|
|
78
|
+
readonly type: "string";
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
readonly required: readonly ["application", "package", "recipe"];
|
|
82
|
+
readonly type: "object";
|
|
83
|
+
};
|
|
84
|
+
readonly type: "array";
|
|
85
|
+
};
|
|
86
|
+
readonly name: {
|
|
87
|
+
readonly minLength: 1;
|
|
88
|
+
readonly type: "string";
|
|
89
|
+
};
|
|
90
|
+
readonly packageManager: {
|
|
91
|
+
readonly additionalProperties: false;
|
|
92
|
+
readonly properties: {
|
|
93
|
+
readonly name: {
|
|
94
|
+
readonly const: "pnpm";
|
|
95
|
+
};
|
|
96
|
+
readonly version: {
|
|
97
|
+
readonly minLength: 1;
|
|
98
|
+
readonly type: "string";
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
readonly required: readonly ["name", "version"];
|
|
102
|
+
readonly type: "object";
|
|
103
|
+
};
|
|
104
|
+
readonly packages: {
|
|
105
|
+
readonly items: {
|
|
106
|
+
readonly additionalProperties: false;
|
|
107
|
+
readonly properties: {
|
|
108
|
+
readonly name: {
|
|
109
|
+
readonly minLength: 1;
|
|
110
|
+
readonly type: "string";
|
|
111
|
+
};
|
|
112
|
+
readonly origin: {
|
|
113
|
+
readonly enum: readonly string[];
|
|
114
|
+
};
|
|
115
|
+
readonly path: {
|
|
116
|
+
readonly minLength: 1;
|
|
117
|
+
readonly type: "string";
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
readonly required: readonly ["name", "origin", "path"];
|
|
121
|
+
readonly type: "object";
|
|
122
|
+
};
|
|
123
|
+
readonly type: "array";
|
|
124
|
+
};
|
|
125
|
+
readonly reproducibleCommand: {
|
|
126
|
+
readonly minLength: 1;
|
|
127
|
+
readonly type: "string";
|
|
128
|
+
};
|
|
129
|
+
readonly schemaVersion: {
|
|
130
|
+
readonly const: 1;
|
|
131
|
+
};
|
|
132
|
+
readonly template: {
|
|
133
|
+
readonly minLength: 1;
|
|
134
|
+
readonly type: "string";
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
readonly required: readonly ["applications", "integrations", "name", "packageManager", "packages", "reproducibleCommand", "schemaVersion", "template"];
|
|
138
|
+
readonly type: "object";
|
|
139
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/** Current `alice.json` schema version. Newer files are rejected, never rewritten. */
|
|
2
|
+
export const aliceRecordVersion = 1;
|
|
3
|
+
const maximumRecordBytes = 1_048_576;
|
|
4
|
+
const frameworks = new Set(["Next.js", "Hono", "Expo"]);
|
|
5
|
+
const origins = new Set(["recipe", "starter"]);
|
|
6
|
+
function fail(message) {
|
|
7
|
+
throw new Error(`Invalid alice.json: ${message}`);
|
|
8
|
+
}
|
|
9
|
+
function object(value, label) {
|
|
10
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
11
|
+
return fail(`${label} must be an object.`);
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function exactKeys(value, keys, label) {
|
|
16
|
+
const unknown = Object.keys(value).filter((key) => !keys.includes(key));
|
|
17
|
+
const missing = keys.filter((key) => !Object.hasOwn(value, key));
|
|
18
|
+
if (unknown.length > 0 || missing.length > 0) {
|
|
19
|
+
fail(`${label} must have exactly: ${keys.join(", ")}${unknown.length > 0 ? ` (unknown: ${unknown.join(", ")})` : ""}.`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function text(value, label) {
|
|
23
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
24
|
+
return fail(`${label} must be a non-empty string.`);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
function list(value, label) {
|
|
29
|
+
if (!Array.isArray(value)) {
|
|
30
|
+
return fail(`${label} must be an array.`);
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
/** Strict, non-executing parse. Unknown properties and newer schema versions are rejected. */
|
|
35
|
+
export function parseAliceRecord(source) {
|
|
36
|
+
if (Buffer.byteLength(source, "utf-8") > maximumRecordBytes) {
|
|
37
|
+
fail("file is larger than 1 MiB.");
|
|
38
|
+
}
|
|
39
|
+
let value;
|
|
40
|
+
try {
|
|
41
|
+
value = JSON.parse(source);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return fail("not valid JSON.");
|
|
45
|
+
}
|
|
46
|
+
const root = object(value, "the file");
|
|
47
|
+
if (typeof root.schemaVersion === "number" &&
|
|
48
|
+
root.schemaVersion > aliceRecordVersion) {
|
|
49
|
+
fail(`schemaVersion ${root.schemaVersion} is newer than this Alice supports (${aliceRecordVersion}). Upgrade Alice; the file was not changed.`);
|
|
50
|
+
}
|
|
51
|
+
if (root.schemaVersion !== aliceRecordVersion) {
|
|
52
|
+
fail(`schemaVersion must be ${aliceRecordVersion}.`);
|
|
53
|
+
}
|
|
54
|
+
exactKeys(root, [
|
|
55
|
+
"applications",
|
|
56
|
+
"integrations",
|
|
57
|
+
"name",
|
|
58
|
+
"packageManager",
|
|
59
|
+
"packages",
|
|
60
|
+
"reproducibleCommand",
|
|
61
|
+
"schemaVersion",
|
|
62
|
+
"template",
|
|
63
|
+
], "the file");
|
|
64
|
+
const manager = object(root.packageManager, "packageManager");
|
|
65
|
+
exactKeys(manager, ["name", "version"], "packageManager");
|
|
66
|
+
if (manager.name !== "pnpm") {
|
|
67
|
+
fail('packageManager.name must be "pnpm".');
|
|
68
|
+
}
|
|
69
|
+
const applications = list(root.applications, "applications").map((item, index) => {
|
|
70
|
+
const label = `applications[${index}]`;
|
|
71
|
+
const entry = object(item, label);
|
|
72
|
+
exactKeys(entry, ["framework", "name", "path"], label);
|
|
73
|
+
if (!frameworks.has(entry.framework)) {
|
|
74
|
+
fail(`${label}.framework is not a supported framework.`);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
framework: entry.framework,
|
|
78
|
+
name: text(entry.name, `${label}.name`),
|
|
79
|
+
path: text(entry.path, `${label}.path`),
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
const packages = list(root.packages, "packages").map((item, index) => {
|
|
83
|
+
const label = `packages[${index}]`;
|
|
84
|
+
const entry = object(item, label);
|
|
85
|
+
exactKeys(entry, ["name", "origin", "path"], label);
|
|
86
|
+
if (!origins.has(entry.origin)) {
|
|
87
|
+
fail(`${label}.origin must be "recipe" or "starter".`);
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
name: text(entry.name, `${label}.name`),
|
|
91
|
+
origin: entry.origin,
|
|
92
|
+
path: text(entry.path, `${label}.path`),
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
const integrations = list(root.integrations, "integrations").map((item, index) => {
|
|
96
|
+
const label = `integrations[${index}]`;
|
|
97
|
+
const entry = object(item, label);
|
|
98
|
+
exactKeys(entry, ["application", "package", "recipe"], label);
|
|
99
|
+
return {
|
|
100
|
+
application: text(entry.application, `${label}.application`),
|
|
101
|
+
package: text(entry.package, `${label}.package`),
|
|
102
|
+
recipe: text(entry.recipe, `${label}.recipe`),
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
applications,
|
|
107
|
+
integrations,
|
|
108
|
+
name: text(root.name, "name"),
|
|
109
|
+
packageManager: {
|
|
110
|
+
name: "pnpm",
|
|
111
|
+
version: text(manager.version, "packageManager.version"),
|
|
112
|
+
},
|
|
113
|
+
packages,
|
|
114
|
+
reproducibleCommand: text(root.reproducibleCommand, "reproducibleCommand"),
|
|
115
|
+
schemaVersion: aliceRecordVersion,
|
|
116
|
+
template: text(root.template, "template"),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** Canonical, deterministic text: fixed key order, two-space indent, trailing newline. */
|
|
120
|
+
export function serialiseAliceRecord(record) {
|
|
121
|
+
const canonical = {
|
|
122
|
+
applications: record.applications.map((item) => ({
|
|
123
|
+
framework: item.framework,
|
|
124
|
+
name: item.name,
|
|
125
|
+
path: item.path,
|
|
126
|
+
})),
|
|
127
|
+
integrations: record.integrations.map((item) => ({
|
|
128
|
+
application: item.application,
|
|
129
|
+
package: item.package,
|
|
130
|
+
recipe: item.recipe,
|
|
131
|
+
})),
|
|
132
|
+
name: record.name,
|
|
133
|
+
packageManager: {
|
|
134
|
+
name: record.packageManager.name,
|
|
135
|
+
version: record.packageManager.version,
|
|
136
|
+
},
|
|
137
|
+
packages: record.packages.map((item) => ({
|
|
138
|
+
name: item.name,
|
|
139
|
+
origin: item.origin,
|
|
140
|
+
path: item.path,
|
|
141
|
+
})),
|
|
142
|
+
reproducibleCommand: record.reproducibleCommand,
|
|
143
|
+
schemaVersion: record.schemaVersion,
|
|
144
|
+
template: record.template,
|
|
145
|
+
};
|
|
146
|
+
return `${JSON.stringify(canonical, null, 2)}\n`;
|
|
147
|
+
}
|
|
148
|
+
const nonEmpty = { minLength: 1, type: "string" };
|
|
149
|
+
/** JSON Schema describing `alice.json`; keep in step with `parseAliceRecord`. */
|
|
150
|
+
export const aliceRecordSchema = {
|
|
151
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
152
|
+
additionalProperties: false,
|
|
153
|
+
properties: {
|
|
154
|
+
applications: {
|
|
155
|
+
items: {
|
|
156
|
+
additionalProperties: false,
|
|
157
|
+
properties: {
|
|
158
|
+
framework: { enum: [...frameworks] },
|
|
159
|
+
name: nonEmpty,
|
|
160
|
+
path: nonEmpty,
|
|
161
|
+
},
|
|
162
|
+
required: ["framework", "name", "path"],
|
|
163
|
+
type: "object",
|
|
164
|
+
},
|
|
165
|
+
type: "array",
|
|
166
|
+
},
|
|
167
|
+
integrations: {
|
|
168
|
+
items: {
|
|
169
|
+
additionalProperties: false,
|
|
170
|
+
properties: {
|
|
171
|
+
application: nonEmpty,
|
|
172
|
+
package: nonEmpty,
|
|
173
|
+
recipe: nonEmpty,
|
|
174
|
+
},
|
|
175
|
+
required: ["application", "package", "recipe"],
|
|
176
|
+
type: "object",
|
|
177
|
+
},
|
|
178
|
+
type: "array",
|
|
179
|
+
},
|
|
180
|
+
name: nonEmpty,
|
|
181
|
+
packageManager: {
|
|
182
|
+
additionalProperties: false,
|
|
183
|
+
properties: { name: { const: "pnpm" }, version: nonEmpty },
|
|
184
|
+
required: ["name", "version"],
|
|
185
|
+
type: "object",
|
|
186
|
+
},
|
|
187
|
+
packages: {
|
|
188
|
+
items: {
|
|
189
|
+
additionalProperties: false,
|
|
190
|
+
properties: {
|
|
191
|
+
name: nonEmpty,
|
|
192
|
+
origin: { enum: [...origins] },
|
|
193
|
+
path: nonEmpty,
|
|
194
|
+
},
|
|
195
|
+
required: ["name", "origin", "path"],
|
|
196
|
+
type: "object",
|
|
197
|
+
},
|
|
198
|
+
type: "array",
|
|
199
|
+
},
|
|
200
|
+
reproducibleCommand: nonEmpty,
|
|
201
|
+
schemaVersion: { const: aliceRecordVersion },
|
|
202
|
+
template: nonEmpty,
|
|
203
|
+
},
|
|
204
|
+
required: [
|
|
205
|
+
"applications",
|
|
206
|
+
"integrations",
|
|
207
|
+
"name",
|
|
208
|
+
"packageManager",
|
|
209
|
+
"packages",
|
|
210
|
+
"reproducibleCommand",
|
|
211
|
+
"schemaVersion",
|
|
212
|
+
"template",
|
|
213
|
+
],
|
|
214
|
+
type: "object",
|
|
215
|
+
};
|
|
@@ -18,6 +18,10 @@ export declare const databaseRecipe: {
|
|
|
18
18
|
readonly default: "postgres";
|
|
19
19
|
readonly values: readonly ["postgres", "sqlite", "mysql"];
|
|
20
20
|
};
|
|
21
|
+
readonly localCompose: {
|
|
22
|
+
readonly default: "no";
|
|
23
|
+
readonly values: readonly ["no", "yes"];
|
|
24
|
+
};
|
|
21
25
|
};
|
|
22
26
|
readonly package: {
|
|
23
27
|
readonly dependencies: {
|
|
@@ -53,6 +57,14 @@ export declare const databaseTemplate: {
|
|
|
53
57
|
when: {
|
|
54
58
|
dialect: string;
|
|
55
59
|
};
|
|
60
|
+
} | {
|
|
61
|
+
destination: string;
|
|
62
|
+
mode: "copy";
|
|
63
|
+
source: string;
|
|
64
|
+
when: {
|
|
65
|
+
dialect: string;
|
|
66
|
+
localCompose: string;
|
|
67
|
+
};
|
|
56
68
|
})[];
|
|
57
69
|
readonly id: "database";
|
|
58
70
|
};
|
|
@@ -13,6 +13,8 @@ export const databaseRecipe = defineRecipe({
|
|
|
13
13
|
frameworkNeutral: true,
|
|
14
14
|
options: {
|
|
15
15
|
dialect: { default: "postgres", values: ["postgres", "sqlite", "mysql"] },
|
|
16
|
+
// Opt-in local container definition; SQLite is a file and never needs one.
|
|
17
|
+
localCompose: { default: "no", values: ["no", "yes"] },
|
|
16
18
|
},
|
|
17
19
|
package: databasePackage,
|
|
18
20
|
template: "database",
|
|
@@ -50,6 +52,12 @@ export const databaseTemplate = defineTemplate({
|
|
|
50
52
|
when: { dialect },
|
|
51
53
|
})),
|
|
52
54
|
]),
|
|
55
|
+
...["postgres", "mysql"].map((dialect) => ({
|
|
56
|
+
destination: "docker-compose.yml",
|
|
57
|
+
mode: "copy",
|
|
58
|
+
source: `${dialect}/docker-compose.yml`,
|
|
59
|
+
when: { dialect, localCompose: "yes" },
|
|
60
|
+
})),
|
|
53
61
|
],
|
|
54
62
|
id: "database",
|
|
55
63
|
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { aliceRecordSchema, aliceRecordVersion, parseAliceRecord, serialiseAliceRecord, } from "./alice-record.js";
|
|
2
|
+
export type { AliceRecord, AliceRecordApplication, AliceRecordIntegration, AliceRecordPackage, } from "./alice-record.js";
|
|
1
3
|
export type { AliceConfig } from "./configuration.js";
|
|
2
4
|
export { defineConfig } from "./configuration.js";
|
|
3
5
|
export { createApplicationManifestPlan } from "./application-manifest-plan.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { aliceRecordSchema, aliceRecordVersion, parseAliceRecord, serialiseAliceRecord, } from "./alice-record.js";
|
|
1
2
|
export { defineConfig } from "./configuration.js";
|
|
2
3
|
export { createApplicationManifestPlan } from "./application-manifest-plan.js";
|
|
3
4
|
export { applyApplicationManifestPlan } from "./application-manifest-writer.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { aliceRecordVersion, serialiseAliceRecord } from "./alice-record.js";
|
|
3
4
|
import { cacheRecipe, cacheTemplate } from "./cache-recipe.js";
|
|
4
5
|
import { databaseRecipe, databaseTemplate } from "./database-recipe.js";
|
|
5
6
|
import { environmentRecipe, environmentTemplate, } from "./environment-recipe.js";
|
|
@@ -71,6 +72,7 @@ export function validateProjectName(name) {
|
|
|
71
72
|
/** Every file the starter writes, relative to the project root. Recipe packages are separate. */
|
|
72
73
|
const starterDestinations = [
|
|
73
74
|
".gitattributes",
|
|
75
|
+
"alice.json",
|
|
74
76
|
".gitignore",
|
|
75
77
|
"README.md",
|
|
76
78
|
"apps/backend/README.md",
|
|
@@ -86,8 +88,13 @@ const starterDestinations = [
|
|
|
86
88
|
"apps/backend/tsconfig.json",
|
|
87
89
|
"apps/mobile/README.md",
|
|
88
90
|
"apps/mobile/app.json",
|
|
89
|
-
"apps/mobile/
|
|
90
|
-
"apps/mobile/
|
|
91
|
+
"apps/mobile/css.d.ts",
|
|
92
|
+
"apps/mobile/global.css",
|
|
93
|
+
"apps/mobile/metro.config.js",
|
|
94
|
+
"apps/mobile/nativewind-env.d.ts",
|
|
95
|
+
"apps/mobile/postcss.config.mjs",
|
|
96
|
+
"apps/mobile/src/app/_layout.tsx",
|
|
97
|
+
"apps/mobile/src/app/index.tsx",
|
|
91
98
|
"apps/mobile/assets/adaptive-icon.png",
|
|
92
99
|
"apps/mobile/assets/icon.png",
|
|
93
100
|
"apps/mobile/package.json",
|
|
@@ -190,6 +197,7 @@ const starterDestinations = [
|
|
|
190
197
|
"packages/user-interface/src/components/card.tsx",
|
|
191
198
|
"packages/user-interface/src/lib/utils.ts",
|
|
192
199
|
"packages/user-interface/src/styles/globals.css",
|
|
200
|
+
"packages/user-interface/src/styles/native.css",
|
|
193
201
|
"packages/user-interface/src/tokens.ts",
|
|
194
202
|
"packages/user-interface/tests/user-interface.test.tsx",
|
|
195
203
|
"packages/user-interface/tsconfig.json",
|
|
@@ -199,11 +207,12 @@ const starterDestinations = [
|
|
|
199
207
|
/** Files with `{{placeholders}}`; every other file is copied byte for byte. */
|
|
200
208
|
const renderedDestinations = new Set([
|
|
201
209
|
"README.md",
|
|
210
|
+
"alice.json",
|
|
202
211
|
"apps/backend/README.md",
|
|
203
212
|
"apps/backend/package.json",
|
|
204
213
|
"apps/mobile/README.md",
|
|
205
214
|
"apps/mobile/app.json",
|
|
206
|
-
"apps/mobile/app/index.tsx",
|
|
215
|
+
"apps/mobile/src/app/index.tsx",
|
|
207
216
|
"apps/mobile/package.json",
|
|
208
217
|
"apps/web/package.json",
|
|
209
218
|
"apps/web/src/app/layout.tsx",
|
|
@@ -276,7 +285,14 @@ function mobileScheme(name) {
|
|
|
276
285
|
const scheme = name.replaceAll(/[^a-z0-9.-]/gu, "-");
|
|
277
286
|
return /^[a-z]/u.test(scheme) ? scheme : `app-${scheme}`;
|
|
278
287
|
}
|
|
288
|
+
/** The generated record is written after every other file so it only exists for a complete project. */
|
|
289
|
+
function isRecord(file) {
|
|
290
|
+
return /^[^/]+\/alice\.json$/u.test(file.destination);
|
|
291
|
+
}
|
|
279
292
|
function compare(a, b) {
|
|
293
|
+
if (isRecord(a) !== isRecord(b)) {
|
|
294
|
+
return isRecord(a) ? 1 : -1;
|
|
295
|
+
}
|
|
280
296
|
if (a.destination < b.destination) {
|
|
281
297
|
return -1;
|
|
282
298
|
}
|
|
@@ -317,20 +333,33 @@ export function createProjectInitPlan(rawName) {
|
|
|
317
333
|
path: item.destination,
|
|
318
334
|
})));
|
|
319
335
|
const webPackageName = `@${name}/web`;
|
|
336
|
+
const applications = [
|
|
337
|
+
{ framework: "Next.js", name: webPackageName, path: "apps/web" },
|
|
338
|
+
{
|
|
339
|
+
framework: "Hono",
|
|
340
|
+
name: `@${name}/backend`,
|
|
341
|
+
path: "apps/backend",
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
framework: "Expo",
|
|
345
|
+
name: `@${name}/mobile`,
|
|
346
|
+
path: "apps/mobile",
|
|
347
|
+
},
|
|
348
|
+
];
|
|
349
|
+
const sortedPackages = [...starterPackages, ...recipePackages].toSorted((a, b) => (a.path < b.path ? -1 : 1));
|
|
350
|
+
// Deterministic by design: no timestamp and no machine-specific values.
|
|
351
|
+
const stackRecord = serialiseAliceRecord({
|
|
352
|
+
applications,
|
|
353
|
+
integrations: [],
|
|
354
|
+
name,
|
|
355
|
+
packageManager: { name: "pnpm", version: starterPnpmVersion },
|
|
356
|
+
packages: sortedPackages,
|
|
357
|
+
reproducibleCommand: `alice init ${name}`,
|
|
358
|
+
schemaVersion: aliceRecordVersion,
|
|
359
|
+
template: starterTemplateName,
|
|
360
|
+
});
|
|
320
361
|
return Object.freeze({
|
|
321
|
-
applications: Object.freeze(
|
|
322
|
-
{ framework: "Next.js", name: webPackageName, path: "apps/web" },
|
|
323
|
-
{
|
|
324
|
-
framework: "Hono",
|
|
325
|
-
name: `@${name}/backend`,
|
|
326
|
-
path: "apps/backend",
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
framework: "Expo",
|
|
330
|
-
name: `@${name}/mobile`,
|
|
331
|
-
path: "apps/mobile",
|
|
332
|
-
},
|
|
333
|
-
]),
|
|
362
|
+
applications: Object.freeze(applications),
|
|
334
363
|
filePlan: Object.freeze({
|
|
335
364
|
files: Object.freeze([...starterFiles, ...recipeFiles].toSorted(compare)),
|
|
336
365
|
packages: Object.freeze([
|
|
@@ -346,7 +375,7 @@ export function createProjectInitPlan(rawName) {
|
|
|
346
375
|
name: "pnpm",
|
|
347
376
|
version: starterPnpmVersion,
|
|
348
377
|
}),
|
|
349
|
-
packages: Object.freeze(
|
|
378
|
+
packages: Object.freeze(sortedPackages),
|
|
350
379
|
recipes: Object.freeze(recipes),
|
|
351
380
|
starterFiles: Object.freeze(starterFiles),
|
|
352
381
|
template: starterTemplateName,
|
|
@@ -356,6 +385,7 @@ export function createProjectInitPlan(rawName) {
|
|
|
356
385
|
mobileScheme: mobileScheme(name),
|
|
357
386
|
pnpmVersion: starterPnpmVersion,
|
|
358
387
|
projectName: name,
|
|
388
|
+
stackRecord,
|
|
359
389
|
webPackageName,
|
|
360
390
|
}),
|
|
361
391
|
webPackageName,
|
|
@@ -408,7 +438,12 @@ export async function renderProjectInit(input) {
|
|
|
408
438
|
const stats = await fs.lstat(path.join(templateRoot, file.source));
|
|
409
439
|
const bytes = await readSource(templateRoot, file.source, guards, stats);
|
|
410
440
|
let content = bytes;
|
|
411
|
-
if (
|
|
441
|
+
if (isRecord(file)) {
|
|
442
|
+
// Structured JSON cannot pass through the escaping-only template encodings, so the record is
|
|
443
|
+
// serialised from the plan; the template file only reserves the destination and fingerprint.
|
|
444
|
+
content = Buffer.from(input.plan.variables.stackRecord ?? "", "utf-8");
|
|
445
|
+
}
|
|
446
|
+
else if (mode === "render") {
|
|
412
447
|
let text;
|
|
413
448
|
try {
|
|
414
449
|
text = new TextDecoder("utf-8", {
|
package/package.json
CHANGED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { colors, radius, spacing } from "@alice/user-interface/tokens";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import {
|
|
4
|
-
Pressable,
|
|
5
|
-
StyleSheet,
|
|
6
|
-
Text,
|
|
7
|
-
useColorScheme,
|
|
8
|
-
View,
|
|
9
|
-
} from "react-native";
|
|
10
|
-
|
|
11
|
-
import { api } from "../src/api/client";
|
|
12
|
-
import { environment } from "../src/configuration/environment";
|
|
13
|
-
|
|
14
|
-
const projectName = {{json:projectName}};
|
|
15
|
-
|
|
16
|
-
type Status = "idle" | "checking" | "reachable" | "unreachable";
|
|
17
|
-
|
|
18
|
-
const styles = StyleSheet.create({
|
|
19
|
-
button: {
|
|
20
|
-
alignItems: "center",
|
|
21
|
-
alignSelf: "flex-start",
|
|
22
|
-
borderRadius: radius.md,
|
|
23
|
-
paddingHorizontal: spacing.md,
|
|
24
|
-
paddingVertical: spacing.sm + spacing.xs,
|
|
25
|
-
},
|
|
26
|
-
buttonLabel: { fontSize: 15, fontWeight: "600" },
|
|
27
|
-
screen: {
|
|
28
|
-
flex: 1,
|
|
29
|
-
gap: spacing.md,
|
|
30
|
-
justifyContent: "center",
|
|
31
|
-
padding: spacing.lg,
|
|
32
|
-
},
|
|
33
|
-
title: { fontSize: 32, fontWeight: "700" },
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const Home = () => {
|
|
37
|
-
const palette = colors[useColorScheme() === "dark" ? "dark" : "light"];
|
|
38
|
-
const [status, setStatus] = useState<Status>("idle");
|
|
39
|
-
|
|
40
|
-
const checkBackend = async () => {
|
|
41
|
-
setStatus("checking");
|
|
42
|
-
try {
|
|
43
|
-
await api.getJson("/health");
|
|
44
|
-
setStatus("reachable");
|
|
45
|
-
} catch {
|
|
46
|
-
setStatus("unreachable");
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const messages: Record<Status, string> = {
|
|
51
|
-
checking: "Checking…",
|
|
52
|
-
idle: `API: ${environment.EXPO_PUBLIC_API_URL}`,
|
|
53
|
-
reachable: "Backend reachable.",
|
|
54
|
-
unreachable:
|
|
55
|
-
"Backend not reachable. Start it with pnpm dev, and see the mobile README for device addresses.",
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const mutedStyle = { color: palette.mutedForeground };
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<View style={[styles.screen, { backgroundColor: palette.background }]}>
|
|
62
|
-
<Text
|
|
63
|
-
accessibilityRole="header"
|
|
64
|
-
style={[styles.title, { color: palette.foreground }]}
|
|
65
|
-
>
|
|
66
|
-
{projectName}
|
|
67
|
-
</Text>
|
|
68
|
-
<Text style={mutedStyle}>
|
|
69
|
-
Your Expo application was created by Alice. Edit app/index.tsx to begin.
|
|
70
|
-
</Text>
|
|
71
|
-
<Text accessibilityRole="text" style={mutedStyle}>
|
|
72
|
-
{messages[status]}
|
|
73
|
-
</Text>
|
|
74
|
-
<Pressable
|
|
75
|
-
accessibilityRole="button"
|
|
76
|
-
disabled={status === "checking"}
|
|
77
|
-
onPress={checkBackend}
|
|
78
|
-
style={[styles.button, { backgroundColor: palette.primary }]}
|
|
79
|
-
>
|
|
80
|
-
<Text
|
|
81
|
-
style={[styles.buttonLabel, { color: palette.primaryForeground }]}
|
|
82
|
-
>
|
|
83
|
-
Check backend
|
|
84
|
-
</Text>
|
|
85
|
-
</Pressable>
|
|
86
|
-
</View>
|
|
87
|
-
);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export default Home;
|