@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/dist/index.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
|
-
import { inspectProject } from "@alice/core";
|
|
3
|
+
import { aliceRecordSchema, inspectProject } from "@alice/core";
|
|
4
4
|
import { Command, InvalidArgumentError, Option } from "commander";
|
|
5
5
|
import { addCache } from "./add-cache.js";
|
|
6
6
|
import { addDatabase } from "./add-db.js";
|
|
7
7
|
import { addEnvironment } from "./add-env.js";
|
|
8
|
+
import { addInputSchema, parseAddPayload } from "./add-input.js";
|
|
9
|
+
import { addFromPayload } from "./add-json.js";
|
|
8
10
|
import { addObservability } from "./add-observability.js";
|
|
11
|
+
import { describeAliceRecord } from "./alice-record-update.js";
|
|
12
|
+
import { initInputSchema, parseInitPayload } from "./init-input.js";
|
|
9
13
|
import { initProject } from "./init.js";
|
|
10
14
|
// Strip terminal controls from project-controlled text; never display script bodies.
|
|
11
15
|
function safe(value) {
|
|
@@ -46,6 +50,7 @@ program
|
|
|
46
50
|
lines.push(` ${member.name} ${member.framework} (${member.path})`, ` Scripts: ${Object.keys(member.scripts).toSorted().join(", ") || "none"}`);
|
|
47
51
|
}
|
|
48
52
|
}
|
|
53
|
+
lines.push(...(await describeAliceRecord(project.root)));
|
|
49
54
|
if (project.warnings.length) {
|
|
50
55
|
lines.push("", "Warnings", ...project.warnings.map((warning) => ` ${warning}`));
|
|
51
56
|
}
|
|
@@ -54,16 +59,54 @@ program
|
|
|
54
59
|
program
|
|
55
60
|
.command("init")
|
|
56
61
|
.description("Create a new Next.js + Turborepo workspace in a new directory beneath the current one")
|
|
57
|
-
.argument("
|
|
62
|
+
.argument("[name]", "Project name (also the new directory name)")
|
|
58
63
|
.option("--dry-run", "Preview the project without changing anything")
|
|
59
64
|
.option("--no-install", "Generate without installing dependencies")
|
|
60
65
|
.option("--no-git", "Do not initialise a Git repository")
|
|
66
|
+
.option("--json <payload>", "Read the name and options from a JSON object (see alice schema)")
|
|
61
67
|
.action(async (name, options) => {
|
|
62
|
-
|
|
68
|
+
if (options.json !== undefined) {
|
|
69
|
+
if (name !== undefined) {
|
|
70
|
+
throw new Error("Pass the name inside --json, not as an argument.");
|
|
71
|
+
}
|
|
72
|
+
const { name: payloadName, ...flags } = parseInitPayload(options.json);
|
|
73
|
+
process.exitCode = await initProject(payloadName, {
|
|
74
|
+
...flags,
|
|
75
|
+
json: true,
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (name === undefined) {
|
|
80
|
+
throw new Error("Missing project name. Run alice init <name>.");
|
|
81
|
+
}
|
|
82
|
+
const { json: _json, ...flags } = options;
|
|
83
|
+
process.exitCode = await initProject(name, flags);
|
|
84
|
+
});
|
|
85
|
+
program
|
|
86
|
+
.command("schema")
|
|
87
|
+
.description("Print the JSON input schemas for agent-driven commands")
|
|
88
|
+
.action(() => {
|
|
89
|
+
const schemas = {
|
|
90
|
+
commands: {
|
|
91
|
+
add: { input: addInputSchema },
|
|
92
|
+
init: { input: initInputSchema },
|
|
93
|
+
},
|
|
94
|
+
files: { "alice.json": aliceRecordSchema },
|
|
95
|
+
version: metadata.version,
|
|
96
|
+
};
|
|
97
|
+
process.stdout.write(`${JSON.stringify(schemas, null, 2)}\n`);
|
|
63
98
|
});
|
|
64
99
|
const add = program
|
|
65
100
|
.command("add")
|
|
66
|
-
.description("Generate environment, database, cache or observability packages and install dependencies")
|
|
101
|
+
.description("Generate environment, database, cache or observability packages and install dependencies")
|
|
102
|
+
.option("--json <payload>", "Run one add command from a JSON object and print one JSON result (see alice schema)")
|
|
103
|
+
.action(async (options) => {
|
|
104
|
+
if (options.json === undefined) {
|
|
105
|
+
add.help({ error: true });
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
process.exitCode = await addFromPayload(parseAddPayload(options.json));
|
|
109
|
+
});
|
|
67
110
|
add
|
|
68
111
|
.command("env")
|
|
69
112
|
.description("Generate @alice/environment in an existing pnpm workspace")
|
|
@@ -86,6 +129,7 @@ add
|
|
|
86
129
|
.option("--project <path>", "Workspace root or nested project directory")
|
|
87
130
|
.option("--dry-run", "Validate and preview without changing files or running pnpm")
|
|
88
131
|
.option("--no-install", "Generate without installing dependencies")
|
|
132
|
+
.option("--local-compose", "Also generate docker-compose.yml for a local PostgreSQL or MySQL container")
|
|
89
133
|
.addOption(new Option("--app <application>", "Integrate an existing database into an application; --dry-run previews changes"))
|
|
90
134
|
.action(async (options) => {
|
|
91
135
|
process.exitCode = await addDatabase(options);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { InitOptions } from "./init.js";
|
|
2
|
+
export interface InitInput extends InitOptions {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
}
|
|
5
|
+
/** JSON Schema for `alice init --json`; keep in step with `parseInitPayload`. */
|
|
6
|
+
export declare const initInputSchema: {
|
|
7
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
8
|
+
readonly additionalProperties: false;
|
|
9
|
+
readonly properties: {
|
|
10
|
+
readonly dryRun: {
|
|
11
|
+
readonly default: false;
|
|
12
|
+
readonly type: "boolean";
|
|
13
|
+
};
|
|
14
|
+
readonly git: {
|
|
15
|
+
readonly default: true;
|
|
16
|
+
readonly type: "boolean";
|
|
17
|
+
};
|
|
18
|
+
readonly install: {
|
|
19
|
+
readonly default: true;
|
|
20
|
+
readonly type: "boolean";
|
|
21
|
+
};
|
|
22
|
+
readonly name: {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
readonly required: readonly ["name"];
|
|
27
|
+
readonly type: "object";
|
|
28
|
+
};
|
|
29
|
+
/** Strict, non-executing parse. The name is validated again by the project planner. */
|
|
30
|
+
export declare function parseInitPayload(payload: string): InitInput;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** JSON Schema for `alice init --json`; keep in step with `parseInitPayload`. */
|
|
2
|
+
export const initInputSchema = {
|
|
3
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
4
|
+
additionalProperties: false,
|
|
5
|
+
properties: {
|
|
6
|
+
dryRun: { default: false, type: "boolean" },
|
|
7
|
+
git: { default: true, type: "boolean" },
|
|
8
|
+
install: { default: true, type: "boolean" },
|
|
9
|
+
name: { type: "string" },
|
|
10
|
+
},
|
|
11
|
+
required: ["name"],
|
|
12
|
+
type: "object",
|
|
13
|
+
};
|
|
14
|
+
const optionalFlags = ["dryRun", "git", "install"];
|
|
15
|
+
/** Strict, non-executing parse. The name is validated again by the project planner. */
|
|
16
|
+
export function parseInitPayload(payload) {
|
|
17
|
+
let value;
|
|
18
|
+
try {
|
|
19
|
+
value = JSON.parse(payload);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
throw new Error("--json payload is not valid JSON.");
|
|
23
|
+
}
|
|
24
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
25
|
+
throw new Error("--json payload must be a JSON object.");
|
|
26
|
+
}
|
|
27
|
+
const record = value;
|
|
28
|
+
const allowed = new Set(["name", ...optionalFlags]);
|
|
29
|
+
const unknown = Object.keys(record).filter((key) => !allowed.has(key));
|
|
30
|
+
if (unknown.length > 0) {
|
|
31
|
+
throw new Error(`--json payload has unknown ${unknown.length === 1 ? "property" : "properties"}: ${unknown.join(", ")}. Run alice schema for the accepted shape.`);
|
|
32
|
+
}
|
|
33
|
+
if (typeof record.name !== "string") {
|
|
34
|
+
throw new TypeError('--json payload requires a string "name".');
|
|
35
|
+
}
|
|
36
|
+
const flags = {};
|
|
37
|
+
for (const flag of optionalFlags) {
|
|
38
|
+
const flagValue = record[flag];
|
|
39
|
+
if (flagValue === undefined) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (typeof flagValue !== "boolean") {
|
|
43
|
+
throw new TypeError(`--json property "${flag}" must be a boolean.`);
|
|
44
|
+
}
|
|
45
|
+
flags[flag] = flagValue;
|
|
46
|
+
}
|
|
47
|
+
return { ...flags, name: record.name };
|
|
48
|
+
}
|
package/dist/init.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export interface InitOptions {
|
|
|
3
3
|
readonly dryRun?: boolean;
|
|
4
4
|
readonly install?: boolean;
|
|
5
5
|
readonly git?: boolean;
|
|
6
|
+
/** Emit one JSON result object on stdout instead of the human-readable report. */
|
|
7
|
+
readonly json?: boolean;
|
|
6
8
|
}
|
|
7
9
|
export interface InitEnvironment {
|
|
8
10
|
readonly cwd?: string;
|
package/dist/init.js
CHANGED
|
@@ -4,8 +4,15 @@ import { assertPackageDestinationAbsent, createProjectInitPlan, inspectProjectIn
|
|
|
4
4
|
import { initialiseGit } from "./git.js";
|
|
5
5
|
import { preparePnpm, processFailure, resolvePnpm, runProcess, } from "./pnpm.js";
|
|
6
6
|
const defaultTemplateRoot = fileURLToPath(new URL("templates/", import.meta.url));
|
|
7
|
+
// In JSON mode the report is collected instead of printed, so stdout carries one parseable object.
|
|
8
|
+
let collected = null;
|
|
7
9
|
function print(lines) {
|
|
8
|
-
|
|
10
|
+
const clean = lines.map((line) => line.replaceAll(/[\p{Cc}\p{Cf}]/gu, ""));
|
|
11
|
+
if (collected) {
|
|
12
|
+
collected.push(...clean);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
process.stdout.write(`${clean.join("\n")}\n`);
|
|
9
16
|
}
|
|
10
17
|
function tail(text, lines = 20) {
|
|
11
18
|
return text
|
|
@@ -155,6 +162,43 @@ async function installDependencies(context, command) {
|
|
|
155
162
|
* after a late failure.
|
|
156
163
|
*/
|
|
157
164
|
export async function initProject(name, options, environment = {}) {
|
|
165
|
+
if (!options.json) {
|
|
166
|
+
return await runInit(name, options, environment);
|
|
167
|
+
}
|
|
168
|
+
collected = [];
|
|
169
|
+
let exitCode = 1;
|
|
170
|
+
let failure;
|
|
171
|
+
try {
|
|
172
|
+
exitCode = await runInit(name, options, environment);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
failure = error instanceof Error ? error.message : "Initialisation failed.";
|
|
176
|
+
}
|
|
177
|
+
const report = collected;
|
|
178
|
+
collected = null;
|
|
179
|
+
let plan;
|
|
180
|
+
try {
|
|
181
|
+
plan = createProjectInitPlan(name);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
plan = undefined;
|
|
185
|
+
}
|
|
186
|
+
process.stdout.write(`${JSON.stringify({
|
|
187
|
+
...(failure === undefined
|
|
188
|
+
? {}
|
|
189
|
+
: { error: failure.replaceAll(/[\p{Cc}\p{Cf}]/gu, "") }),
|
|
190
|
+
applications: plan?.applications ?? [],
|
|
191
|
+
dryRun: options.dryRun ?? false,
|
|
192
|
+
exitCode,
|
|
193
|
+
name,
|
|
194
|
+
ok: exitCode === 0,
|
|
195
|
+
packages: plan?.packages ?? [],
|
|
196
|
+
report,
|
|
197
|
+
}, null, 2)}
|
|
198
|
+
`);
|
|
199
|
+
return exitCode;
|
|
200
|
+
}
|
|
201
|
+
async function runInit(name, options, environment) {
|
|
158
202
|
const plan = createProjectInitPlan(name);
|
|
159
203
|
const parent = await resolveProjectParent(environment.cwd ?? process.cwd());
|
|
160
204
|
const context = {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Local development database. Set DATABASE_PASSWORD in your shell before starting it.
|
|
2
|
+
services:
|
|
3
|
+
database:
|
|
4
|
+
image: mysql:8.4
|
|
5
|
+
ports:
|
|
6
|
+
- "3306:3306"
|
|
7
|
+
environment:
|
|
8
|
+
MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD:?Set DATABASE_PASSWORD before starting the database}
|
|
9
|
+
MYSQL_DATABASE: ${DATABASE_NAME:-alice}
|
|
10
|
+
volumes:
|
|
11
|
+
- database-data:/var/lib/mysql
|
|
12
|
+
healthcheck:
|
|
13
|
+
test:
|
|
14
|
+
["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -p$${MYSQL_ROOT_PASSWORD}"]
|
|
15
|
+
interval: 5s
|
|
16
|
+
timeout: 5s
|
|
17
|
+
retries: 10
|
|
18
|
+
|
|
19
|
+
volumes:
|
|
20
|
+
database-data:
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Local development database. Set DATABASE_PASSWORD in your shell before starting it.
|
|
2
|
+
services:
|
|
3
|
+
database:
|
|
4
|
+
image: postgres:17-alpine
|
|
5
|
+
ports:
|
|
6
|
+
- "5432:5432"
|
|
7
|
+
environment:
|
|
8
|
+
POSTGRES_USER: ${DATABASE_USER:-alice}
|
|
9
|
+
POSTGRES_PASSWORD: ${DATABASE_PASSWORD:?Set DATABASE_PASSWORD before starting the database}
|
|
10
|
+
POSTGRES_DB: ${DATABASE_NAME:-alice}
|
|
11
|
+
volumes:
|
|
12
|
+
- database-data:/var/lib/postgresql/data
|
|
13
|
+
healthcheck:
|
|
14
|
+
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
|
15
|
+
interval: 5s
|
|
16
|
+
timeout: 5s
|
|
17
|
+
retries: 10
|
|
18
|
+
|
|
19
|
+
volumes:
|
|
20
|
+
database-data:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -9,6 +9,14 @@ pnpm --filter {{raw:mobilePackageName}} ios # needs macOS with Xcode
|
|
|
9
9
|
pnpm --filter {{raw:mobilePackageName}} build # expo export for iOS and Android bundles
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
+
Screens live in `src/app` (Expo Router detects it automatically).
|
|
13
|
+
|
|
14
|
+
## Styling
|
|
15
|
+
|
|
16
|
+
Styling uses [Nativewind v5](https://www.nativewind.dev/v5) (Tailwind CSS v4 classes on React Native components). **Nativewind v5 is a release candidate**: `nativewind` and `react-native-css` are pinned to an exact RC pair, and `lightningcss` is pinned by the workspace `overrides`. Upgrade them together.
|
|
17
|
+
|
|
18
|
+
`global.css` imports `@alice/user-interface/native.css`, so classes such as `bg-background`, `text-muted-foreground` and `bg-primary` resolve to the same colours as the web app. Dark mode follows the system colour scheme. Keep `"userInterfaceStyle": "automatic"` in `app.json`.
|
|
19
|
+
|
|
12
20
|
`pnpm dev` at the workspace root starts this app together with the web and backend apps. Set `RCT_METRO_PORT` to change Metro's port.
|
|
13
21
|
|
|
14
22
|
## What is verified
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module "*.css";
|
|
@@ -20,15 +20,24 @@
|
|
|
20
20
|
"expo-linking": "58.0.14",
|
|
21
21
|
"expo-router": "58.0.25",
|
|
22
22
|
"expo-status-bar": "58.0.4",
|
|
23
|
+
"expo-system-ui": "58.0.6",
|
|
24
|
+
"nativewind": "5.0.0-rc.0",
|
|
23
25
|
"react": "19.3.0",
|
|
24
26
|
"react-native": "0.88.0",
|
|
27
|
+
"react-native-css": "3.1.0-rc.0",
|
|
28
|
+
"react-native-reanimated": "4.7.1",
|
|
25
29
|
"react-native-safe-area-context": "5.10.1",
|
|
26
30
|
"react-native-screens": "4.30.0",
|
|
31
|
+
"react-native-worklets": "0.13.0",
|
|
27
32
|
"zod": "4.6.7"
|
|
28
33
|
},
|
|
29
34
|
"devDependencies": {
|
|
30
35
|
"@alice/typescript": "workspace:*",
|
|
36
|
+
"@tailwindcss/postcss": "4.3.3",
|
|
31
37
|
"@types/react": "19.3.0",
|
|
38
|
+
"lightningcss": "1.30.1",
|
|
39
|
+
"postcss": "8.5.31",
|
|
40
|
+
"tailwindcss": "4.3.3",
|
|
32
41
|
"typescript": "6.0.3"
|
|
33
42
|
}
|
|
34
43
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { Pressable, Text, View } from "react-native";
|
|
3
|
+
|
|
4
|
+
import { api } from "../api/client";
|
|
5
|
+
import { environment } from "../configuration/environment";
|
|
6
|
+
|
|
7
|
+
const projectName = {{json:projectName}};
|
|
8
|
+
|
|
9
|
+
type Status = "idle" | "checking" | "reachable" | "unreachable";
|
|
10
|
+
|
|
11
|
+
const Home = () => {
|
|
12
|
+
const [status, setStatus] = useState<Status>("idle");
|
|
13
|
+
|
|
14
|
+
const checkBackend = async () => {
|
|
15
|
+
setStatus("checking");
|
|
16
|
+
try {
|
|
17
|
+
await api.getJson("/health");
|
|
18
|
+
setStatus("reachable");
|
|
19
|
+
} catch {
|
|
20
|
+
setStatus("unreachable");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const messages: Record<Status, string> = {
|
|
25
|
+
checking: "Checking…",
|
|
26
|
+
idle: `API: ${environment.EXPO_PUBLIC_API_URL}`,
|
|
27
|
+
reachable: "Backend reachable.",
|
|
28
|
+
unreachable:
|
|
29
|
+
"Backend not reachable. Start it with pnpm dev, and see the mobile README for device addresses.",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<View className="bg-background flex-1 justify-center gap-4 p-6">
|
|
34
|
+
<Text
|
|
35
|
+
accessibilityRole="header"
|
|
36
|
+
className="text-foreground text-3xl font-bold"
|
|
37
|
+
>
|
|
38
|
+
{projectName}
|
|
39
|
+
</Text>
|
|
40
|
+
<Text className="text-muted-foreground">
|
|
41
|
+
Your Expo application was created by Alice. Edit src/app/index.tsx to
|
|
42
|
+
begin.
|
|
43
|
+
</Text>
|
|
44
|
+
<Text accessibilityRole="text" className="text-muted-foreground">
|
|
45
|
+
{messages[status]}
|
|
46
|
+
</Text>
|
|
47
|
+
<Pressable
|
|
48
|
+
accessibilityRole="button"
|
|
49
|
+
className="bg-primary self-start rounded-md px-4 py-3"
|
|
50
|
+
disabled={status === "checking"}
|
|
51
|
+
onPress={checkBackend}
|
|
52
|
+
>
|
|
53
|
+
<Text className="text-primary-foreground text-center text-[15px] font-semibold">
|
|
54
|
+
Check backend
|
|
55
|
+
</Text>
|
|
56
|
+
</Pressable>
|
|
57
|
+
</View>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default Home;
|
|
@@ -10,6 +10,8 @@ export default defineConfig({
|
|
|
10
10
|
...(core.ignorePatterns ?? []),
|
|
11
11
|
"**/next-env.d.ts",
|
|
12
12
|
"**/expo-env.d.ts",
|
|
13
|
+
"**/nativewind-env.d.ts",
|
|
14
|
+
"**/metro.config.js",
|
|
13
15
|
"**/.expo/**",
|
|
14
16
|
// Written by the shadcn CLI, so they keep shadcn's own style and `shadcn add` produces no
|
|
15
17
|
// lint noise.
|
|
@@ -15,8 +15,9 @@ This package ships **source**, not a build. Next.js compiles it (`transpilePacka
|
|
|
15
15
|
- `./components/*` (`src/components/*.tsx`): shadcn components in the `radix-nova` style: `button` (`Button`, `buttonVariants`) and `card` (`Card`, `CardHeader`, `CardTitle`, `CardDescription`, `CardAction`, `CardContent`, `CardFooter`).
|
|
16
16
|
- `./lib/*` (`src/lib/*.ts`): `utils` exports `cn`, the class-name merger used by the components.
|
|
17
17
|
- `./globals.css`: Tailwind v4, `tw-animate-css`, shadcn's base styles and the neutral theme as CSS variables (light, and `.dark` for dark mode). Import it from an application's stylesheet.
|
|
18
|
+
- `./native.css`: the same theme for Nativewind in Expo: the colour variables (light, and dark through `prefers-color-scheme`) and fixed-pixel radii. Import it from the mobile application's `global.css`.
|
|
18
19
|
- `./postcss.config`: the shared PostCSS configuration (`@tailwindcss/postcss`).
|
|
19
|
-
- `./tokens` (`src/tokens.ts`): the same colours, radii and spacing as plain data, for React Native, which cannot read CSS variables. A test keeps them in sync with `globals.css`.
|
|
20
|
+
- `./tokens` (`src/tokens.ts`): the same colours, radii and spacing as plain data, for React Native, which cannot read CSS variables. A test keeps them in sync with `globals.css` and `native.css`.
|
|
20
21
|
- `./hooks/*`: reserved for hooks added by the shadcn CLI.
|
|
21
22
|
|
|
22
23
|
```tsx
|
|
@@ -41,7 +42,7 @@ pnpm dlx shadcn@latest add dialog # writes packages/user-interface/src/compone
|
|
|
41
42
|
|
|
42
43
|
The CLI may add dependencies to this package. Files in `src/components` and `src/hooks` are written by the CLI, so the formatter and linter leave them as shadcn wrote them. `Button` and `Card` come from the shadcn registry (MIT licensed).
|
|
43
44
|
|
|
44
|
-
Web and mobile do not share components: Expo uses React Native primitives with `./
|
|
45
|
+
Web and mobile do not share components: Expo uses React Native primitives styled with Nativewind classes (`bg-background`, `text-muted-foreground`, ...) generated from `./native.css`.
|
|
45
46
|
|
|
46
47
|
## Environment keys
|
|
47
48
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* The same neutral theme as globals.css, for Nativewind (React Native). Values mirror src/tokens.ts.
|
|
2
|
+
React Native has no `.dark` class or `calc()`, so dark mode follows the system colour scheme
|
|
3
|
+
and the radii are fixed pixel values. Import it from an Expo application's global.css. */
|
|
4
|
+
@theme inline {
|
|
5
|
+
--color-background: var(--background);
|
|
6
|
+
--color-foreground: var(--foreground);
|
|
7
|
+
--color-card: var(--card);
|
|
8
|
+
--color-card-foreground: var(--card-foreground);
|
|
9
|
+
--color-popover: var(--popover);
|
|
10
|
+
--color-popover-foreground: var(--popover-foreground);
|
|
11
|
+
--color-primary: var(--primary);
|
|
12
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
13
|
+
--color-secondary: var(--secondary);
|
|
14
|
+
--color-secondary-foreground: var(--secondary-foreground);
|
|
15
|
+
--color-muted: var(--muted);
|
|
16
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
17
|
+
--color-accent: var(--accent);
|
|
18
|
+
--color-accent-foreground: var(--accent-foreground);
|
|
19
|
+
--color-destructive: var(--destructive);
|
|
20
|
+
--color-border: var(--border);
|
|
21
|
+
--color-input: var(--input);
|
|
22
|
+
--color-ring: var(--ring);
|
|
23
|
+
|
|
24
|
+
--radius-sm: 6px;
|
|
25
|
+
--radius-md: 8px;
|
|
26
|
+
--radius-lg: 10px;
|
|
27
|
+
--radius-xl: 14px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
:root {
|
|
31
|
+
--accent: #f5f5f5;
|
|
32
|
+
--accent-foreground: #171717;
|
|
33
|
+
--background: #ffffff;
|
|
34
|
+
--border: #e5e5e5;
|
|
35
|
+
--card: #ffffff;
|
|
36
|
+
--card-foreground: #0a0a0a;
|
|
37
|
+
--destructive: #e7000b;
|
|
38
|
+
--foreground: #0a0a0a;
|
|
39
|
+
--input: #e5e5e5;
|
|
40
|
+
--muted: #f5f5f5;
|
|
41
|
+
--muted-foreground: #737373;
|
|
42
|
+
--popover: #ffffff;
|
|
43
|
+
--popover-foreground: #0a0a0a;
|
|
44
|
+
--primary: #171717;
|
|
45
|
+
--primary-foreground: #fafafa;
|
|
46
|
+
--ring: #a1a1a1;
|
|
47
|
+
--secondary: #f5f5f5;
|
|
48
|
+
--secondary-foreground: #171717;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@media (prefers-color-scheme: dark) {
|
|
52
|
+
:root {
|
|
53
|
+
--accent: #262626;
|
|
54
|
+
--accent-foreground: #fafafa;
|
|
55
|
+
--background: #0a0a0a;
|
|
56
|
+
--border: #ffffff1a;
|
|
57
|
+
--card: #171717;
|
|
58
|
+
--card-foreground: #fafafa;
|
|
59
|
+
--destructive: #ff6467;
|
|
60
|
+
--foreground: #fafafa;
|
|
61
|
+
--input: #ffffff26;
|
|
62
|
+
--muted: #262626;
|
|
63
|
+
--muted-foreground: #a1a1a1;
|
|
64
|
+
--popover: #171717;
|
|
65
|
+
--popover-foreground: #fafafa;
|
|
66
|
+
--primary: #e5e5e5;
|
|
67
|
+
--primary-foreground: #171717;
|
|
68
|
+
--ring: #737373;
|
|
69
|
+
--secondary: #262626;
|
|
70
|
+
--secondary-foreground: #fafafa;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -46,6 +46,20 @@ void test("tokens stay in sync with the CSS variables in globals.css", async ()
|
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
+
void test("tokens stay in sync with the CSS variables in native.css", async () => {
|
|
50
|
+
const css = await read("src/styles/native.css");
|
|
51
|
+
const dark = css.slice(css.indexOf("@media (prefers-color-scheme: dark)"));
|
|
52
|
+
for (const [scheme, source, selector] of [
|
|
53
|
+
["light", css, ":root"],
|
|
54
|
+
["dark", dark, " :root"],
|
|
55
|
+
] as const) {
|
|
56
|
+
const variables = declarations(source, selector);
|
|
57
|
+
for (const [token, value] of Object.entries(colors[scheme])) {
|
|
58
|
+
assert.equal(variables[kebab(token)], value, `${scheme} ${token}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
49
63
|
void test("Button renders the shadcn markup, variants and asChild", () => {
|
|
50
64
|
const primary = renderToStaticMarkup(<Button>Go</Button>);
|
|
51
65
|
assert.match(primary, /^<button /u);
|
|
@@ -6,6 +6,10 @@ packages:
|
|
|
6
6
|
allowBuilds:
|
|
7
7
|
esbuild: true
|
|
8
8
|
|
|
9
|
+
# Nativewind needs this exact lightningcss; other versions fail to deserialise global.css.
|
|
10
|
+
overrides:
|
|
11
|
+
lightningcss: 1.30.1
|
|
12
|
+
|
|
9
13
|
minimumReleaseAgeExclude:
|
|
10
14
|
- "@expo/cli@58.1.14"
|
|
11
15
|
- "@expo/config-plugins@58.0.10"
|