@skathi-native/cli 0.1.0-beta.1 → 0.1.0-beta.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.
Files changed (53) hide show
  1. package/aot/host-globals.json +105 -0
  2. package/aot/native.ts +142 -0
  3. package/aot/pin.ts +67 -0
  4. package/aot/toolchain.lock.json +17 -0
  5. package/aot/transform.ts +69 -0
  6. package/cli/aot-build.ts +189 -0
  7. package/cli/build-app.ts +67 -25
  8. package/cli/config.ts +44 -101
  9. package/cli/create.ts +107 -234
  10. package/cli/help.ts +159 -0
  11. package/cli/host-fetch.ts +87 -48
  12. package/cli/host.ts +18 -8
  13. package/cli/sk.ts +35 -110
  14. package/cli/skpk.ts +4 -0
  15. package/package.json +4 -2
  16. package/templates/icon.png +0 -0
  17. package/templates/minimal/.vscode/settings.json +3 -0
  18. package/templates/minimal/assets/hello.txt +1 -0
  19. package/templates/minimal/src/App.vue +142 -0
  20. package/templates/minimal/src/main.ts +4 -0
  21. package/templates/showcase/.vscode/settings.json +3 -0
  22. package/templates/showcase/assets/hello.txt +1 -0
  23. package/templates/showcase/assets/media/aurora.png +0 -0
  24. package/templates/showcase/assets/media/clip.mp4 +0 -0
  25. package/templates/showcase/assets/media/sticker.tgs +0 -0
  26. package/templates/showcase/src/App.vue +128 -0
  27. package/templates/showcase/src/components/Card.vue +41 -0
  28. package/templates/showcase/src/components/Icon.vue +29 -0
  29. package/templates/showcase/src/components/Page.vue +41 -0
  30. package/templates/showcase/src/components/Titlebar.vue +132 -0
  31. package/templates/showcase/src/engine.ts +10 -0
  32. package/templates/showcase/src/icons.ts +22 -0
  33. package/templates/showcase/src/main.ts +7 -0
  34. package/templates/showcase/src/pages/AudioPage.vue +121 -0
  35. package/templates/showcase/src/pages/FilesPage.vue +87 -0
  36. package/templates/showcase/src/pages/FormsPage.vue +138 -0
  37. package/templates/showcase/src/pages/GraphicsPage.vue +154 -0
  38. package/templates/showcase/src/pages/HomePage.vue +140 -0
  39. package/templates/showcase/src/pages/LocalePage.vue +71 -0
  40. package/templates/showcase/src/pages/MediaPage.vue +85 -0
  41. package/templates/showcase/src/pages/MotionPage.vue +199 -0
  42. package/templates/showcase/src/pages/NetworkPage.vue +104 -0
  43. package/templates/showcase/src/pages/PermissionsPage.vue +80 -0
  44. package/templates/showcase/src/pages/StoragePage.vue +104 -0
  45. package/templates/showcase/src/pages/StylesPage.vue +199 -0
  46. package/templates/showcase/src/pages/SystemPage.vue +89 -0
  47. package/templates/showcase/src/pages/TrayPage.vue +66 -0
  48. package/templates/showcase/src/pages/WindowPage.vue +128 -0
  49. package/templates/showcase/src/product.ts +2 -0
  50. package/templates/showcase/src/router.ts +149 -0
  51. package/templates/showcase/src/stores/counter.ts +9 -0
  52. package/templates/showcase/src/stores/desktop.ts +115 -0
  53. package/templates/showcase/src/styles.css +140 -0
package/cli/create.ts CHANGED
@@ -1,42 +1,65 @@
1
1
  // `sk create [dir]`: a new app. In a terminal it asks for what the flags do not say: the directory, the
2
- // name, the OSes to package for, the engine parts, whether published builds keep devtools, vue-router
3
- // and pinia, and the package manager. `--yes` (or no terminal) takes the defaults.
2
+ // name, the template, the OSes to package for, whether published builds keep devtools,
3
+ // and the package manager. `--yes` (or no terminal) takes the defaults.
4
4
  //
5
- // It writes package.json (the app root the builders resolve npm dependencies from), sk.config.json,
6
- // src/, assets/, a generated 256² icon.png and a tsconfig.json that type-checks against the runtime.
5
+ // It copies templates/<template>/ (src/, assets/) with the placeholders filled in, and writes
6
+ // package.json (the app root the builders resolve npm dependencies from), sk.config.json, the Skathi
7
+ // icon as icon.png and a tsconfig.json that type-checks against the runtime.
7
8
  // Nothing is overwritten: an existing file is an error, not a merge.
8
9
 
9
- import { existsSync, mkdirSync, writeFileSync } from "node:fs";
10
- import { basename, dirname, join, relative, resolve, sep } from "node:path";
10
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
11
+ import { basename, extname, join, relative, resolve } from "node:path";
11
12
  import * as p from "@clack/prompts";
12
- import { RUNTIME_DIR, RUNTIME_SRC_DIR, runtimeRequire } from "../runtime-path";
13
- import { ConfigError, OPTIONAL, parseParts, sanitizeExeName, type Part } from "./config";
14
- import { encodePng } from "./icon";
13
+ import { runtimeRequire } from "../runtime-path";
14
+ import { ConfigError, sanitizeExeName } from "./config";
15
+ import { CLI_VERSION } from "./host";
15
16
  import { currentPlatform, parsePlatform, type Platform } from "./platform";
16
17
  import { colorEnabled, paint } from "./term";
17
18
 
18
19
  export const PACKAGE_MANAGERS = ["bun", "npm", "pnpm", "yarn"] as const;
19
20
  export type PackageManager = (typeof PACKAGE_MANAGERS)[number];
20
21
 
22
+ export const TEMPLATES = ["showcase", "minimal"] as const;
23
+ export type Template = (typeof TEMPLATES)[number];
24
+
25
+ interface TemplateInfo {
26
+ hint: string;
27
+ /** Taken at the versions the runtime itself depends on. */
28
+ dependencies: string[];
29
+ window: Record<string, unknown>;
30
+ packs?: { name: string; match?: string[] }[];
31
+ }
32
+
33
+ const TEMPLATE_INFO: Record<Template, TemplateInfo> = {
34
+ showcase: {
35
+ hint: "every Skathi feature, one page each",
36
+ dependencies: ["pinia", "vue-router"],
37
+ window: { width: 1100, height: 720, minWidth: 480, minHeight: 360, titleBarStyle: "hidden", titleBarHeight: 40 },
38
+ packs: [{ name: "media", match: ["assets/media/**"] }],
39
+ },
40
+ minimal: {
41
+ hint: "one window, one component",
42
+ dependencies: [],
43
+ window: { width: 760, height: 520, titleBarStyle: "default" },
44
+ },
45
+ };
46
+
47
+ export const TEMPLATES_DIR = resolve(import.meta.dir, "..", "templates");
48
+
49
+ export const CONFIG_SCHEMA = "./node_modules/@skathi-native/runtime/sk.config.schema.json";
50
+
51
+ /** Files whose text has its `{{key}}` placeholders filled in; anything else is copied byte for byte. */
52
+ const TEXT_FILES = new Set([".vue", ".ts", ".css", ".txt", ".json", ".html", ".svg"]);
53
+
21
54
  export interface CreateOptions {
22
55
  name?: string | undefined;
56
+ template?: Template | undefined;
23
57
  platforms?: Platform[] | undefined;
24
- /** Engine parts left out of every build; devtools is {@link CreateOptions.keepDevtools}'s. */
25
- without?: Part[] | undefined;
26
58
  /** Whether `sk publish` keeps devtools (`sk build` always has them). */
27
59
  keepDevtools?: boolean | undefined;
28
- router?: boolean | undefined;
29
60
  packageManager?: PackageManager | undefined;
30
61
  }
31
62
 
32
- const ENGINE_PARTS: { value: Exclude<Part, "devtools">; label: string; hint: string }[] = [
33
- { value: "audio", label: "Audio", hint: "Web Audio, <audio>, sound from <video>" },
34
- { value: "clipboard", label: "Clipboard", hint: "navigator.clipboard" },
35
- { value: "storages", label: "Storage on disk", hint: "localStorage and IndexedDB that survive a restart" },
36
- { value: "indexeddb", label: "IndexedDB", hint: "indexedDB" },
37
- { value: "webgpu", label: "WebGPU", hint: "navigator.gpu" },
38
- ];
39
-
40
63
  /** The package manager this was started from (`npm_config_user_agent`), else bun. */
41
64
  export function detectPackageManager(agent = process.env.npm_config_user_agent ?? ""): PackageManager {
42
65
  return PACKAGE_MANAGERS.find((pm) => agent.startsWith(`${pm}/`)) ?? "bun";
@@ -45,167 +68,33 @@ export function detectPackageManager(agent = process.env.npm_config_user_agent ?
45
68
  export const runScript = (pm: PackageManager, script: string) =>
46
69
  pm === "npm" || pm === "bun" ? `${pm} run ${script}` : `${pm} ${script}`;
47
70
 
48
- function icon(): Uint8Array {
49
- const size = 256;
50
- const data = new Uint8Array(size * size * 4);
51
- const r = 56;
52
- for (let y = 0; y < size; y++) {
53
- for (let x = 0; x < size; x++) {
54
- const dx = Math.max(0, Math.abs(x - 127.5) - (128 - r));
55
- const dy = Math.max(0, Math.abs(y - 127.5) - (128 - r));
56
- const inside = dx * dx + dy * dy <= r * r;
57
- const t = (x + y) / (2 * size);
58
- const o = (y * size + x) * 4;
59
- data[o] = Math.round(0x42 + (0x2f - 0x42) * t);
60
- data[o + 1] = Math.round(0xb8 + (0x6f - 0xb8) * t);
61
- data[o + 2] = Math.round(0x83 + (0xd8 - 0x83) * t);
62
- data[o + 3] = inside ? 255 : 0;
63
- }
64
- }
65
- return encodePng({ width: size, height: size, data });
66
- }
67
-
68
71
  const json = (v: unknown) => JSON.stringify(v, null, 2) + "\n";
69
72
 
70
- const STYLE = `
71
- .root {
72
- display: flex;
73
- flex-direction: column;
74
- gap: 12px;
75
- padding: 24px;
76
- color: white;
77
- }
78
- .title {
79
- font-size: 22px;
80
- font-weight: 600;
73
+ function listFiles(dir: string, prefix = ""): string[] {
74
+ return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
75
+ const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
76
+ return entry.isDirectory() ? listFiles(join(dir, entry.name), rel) : [rel];
77
+ });
81
78
  }
82
- .btn {
83
- align-self: flex-start;
84
- padding: 6px 14px;
85
- border-radius: 8px;
86
- background: #ffffff22;
87
- }`;
88
-
89
- function sources(productName: string, router: boolean): Record<string, string> {
90
- if (!router) {
91
- return {
92
- "src/main.ts": `import { createApp } from "vue";
93
- import App from "./App.vue";
94
-
95
- createApp(App).mount();
96
- `,
97
- "src/App.vue": `<script setup lang="ts">
98
- import { onMounted, ref } from "vue";
99
79
 
100
- const count = ref(0);
101
- // A relative URL resolves against the app root in dev and against the payload once packaged.
102
- const greeting = ref("…");
103
- onMounted(async () => {
104
- const res = await fetch?.("assets/hello.txt");
105
- const text = res?.ok ? await res.text?.() : undefined;
106
- greeting.value = text?.trim() ?? "assets/hello.txt did not load";
107
- });
108
- </script>
109
-
110
- <template>
111
- <div class="root">
112
- <div class="title">${productName}</div>
113
- <div class="line">{{ greeting }}</div>
114
- <div class="btn" @click="count++">clicked {{ count }}×</div>
115
- </div>
116
- </template>
117
-
118
- <style scoped>${STYLE}
119
- </style>
120
- `,
121
- };
80
+ /** The template's files, keyed by app-relative path; `{{key}}` is replaced in text files, escaped for a string literal except in .txt. */
81
+ export function templateFiles(template: Template, values: Record<string, string>): Record<string, string | Uint8Array> {
82
+ const dir = join(TEMPLATES_DIR, template);
83
+ const out: Record<string, string | Uint8Array> = {};
84
+ for (const rel of listFiles(dir)) {
85
+ const bytes = readFileSync(join(dir, rel));
86
+ const ext = extname(rel);
87
+ if (!TEXT_FILES.has(ext)) {
88
+ out[rel] = bytes;
89
+ continue;
90
+ }
91
+ out[rel] = bytes.toString("utf8").replace(/\{\{(\w+)\}\}/g, (whole, key: string) => {
92
+ const value = values[key];
93
+ if (value === undefined) return whole;
94
+ return ext === ".txt" ? value : JSON.stringify(value).slice(1, -1);
95
+ });
122
96
  }
123
- return {
124
- "src/main.ts": `import { createApp } from "vue";
125
- import { createPinia } from "pinia";
126
- import App from "./App.vue";
127
- import { router } from "./router";
128
-
129
- createApp(App).use(createPinia()).use(router).mount();
130
- `,
131
- "src/router.ts": `import { createMemoryHistory, createRouter } from "vue-router";
132
- import Home from "./views/Home.vue";
133
- import About from "./views/About.vue";
134
-
135
- export const router = createRouter({
136
- history: createMemoryHistory(),
137
- routes: [
138
- { path: "/", component: Home },
139
- { path: "/about", component: About },
140
- ],
141
- });
142
- `,
143
- "src/stores/counter.ts": `import { defineStore } from "pinia";
144
- import { ref } from "vue";
145
-
146
- export const useCounter = defineStore("counter", () => {
147
- const count = ref(0);
148
- const increment = () => count.value++;
149
- return { count, increment };
150
- });
151
- `,
152
- "src/App.vue": `<template>
153
- <div class="root">
154
- <div class="title">${productName}</div>
155
- <div class="nav">
156
- <RouterLink class="btn" to="/">Home</RouterLink>
157
- <RouterLink class="btn" to="/about">About</RouterLink>
158
- </div>
159
- <RouterView />
160
- </div>
161
- </template>
162
-
163
- <style scoped>${STYLE}
164
- .nav {
165
- display: flex;
166
- gap: 8px;
167
- }
168
- </style>
169
- `,
170
- "src/views/Home.vue": `<script setup lang="ts">
171
- import { onMounted, ref } from "vue";
172
- import { useCounter } from "../stores/counter";
173
-
174
- const counter = useCounter();
175
- // A relative URL resolves against the app root in dev and against the payload once packaged.
176
- const greeting = ref("…");
177
- onMounted(async () => {
178
- const res = await fetch?.("assets/hello.txt");
179
- const text = res?.ok ? await res.text?.() : undefined;
180
- greeting.value = text?.trim() ?? "assets/hello.txt did not load";
181
- });
182
- </script>
183
-
184
- <template>
185
- <div>{{ greeting }}</div>
186
- <div class="btn" @click="counter.increment()">clicked {{ counter.count }}×</div>
187
- </template>
188
-
189
- <style scoped>
190
- .btn {
191
- align-self: flex-start;
192
- padding: 6px 14px;
193
- border-radius: 8px;
194
- background: #ffffff22;
195
- }
196
- </style>
197
- `,
198
- "src/views/About.vue": `<script setup lang="ts">
199
- import { useCounter } from "../stores/counter";
200
-
201
- const counter = useCounter();
202
- </script>
203
-
204
- <template>
205
- <div>The counter lives in a pinia store: {{ counter.count }}, here too.</div>
206
- </template>
207
- `,
208
- };
97
+ return out;
209
98
  }
210
99
 
211
100
  /** Writes the app; every option has a default. Returns the files written. */
@@ -222,66 +111,51 @@ export function create(target: string, options: CreateOptions = {}): string[] {
222
111
  .toLowerCase()
223
112
  .replace(/[^a-z0-9]+/g, "-")
224
113
  .replace(/^-|-$/g, "") || "app";
114
+ const template = options.template ?? "showcase";
115
+ const info = TEMPLATE_INFO[template];
225
116
  const platforms = options.platforms?.length ? options.platforms : [currentPlatform()];
226
- const without: Part[] = OPTIONAL.filter((part) =>
227
- part === "devtools" ? !options.keepDevtools : (options.without ?? []).includes(part),
228
- );
229
- const rel = (to: string) => relative(dir, to).split(sep).join("/");
230
- const runtime = rel(RUNTIME_SRC_DIR);
231
- const pkg = (name: string) => rel(dirname(runtimeRequire.resolve(`${name}/package.json`)));
117
+ const runtimeDeps = (runtimeRequire("./package.json") as { dependencies: Record<string, string> }).dependencies;
118
+ const sdk = `^${CLI_VERSION}`;
232
119
 
233
120
  const files: Record<string, string | Uint8Array> = {
121
+ ...templateFiles(template, { name, productName }),
234
122
  "package.json": json({
235
123
  name: slug,
236
124
  version: "0.1.0",
237
125
  private: true,
238
126
  type: "module",
239
- scripts: { dev: "sk dev", build: "sk build", publish: "sk publish" },
127
+ scripts: {
128
+ dev: "sk dev",
129
+ build: "sk build",
130
+ publish: "sk publish",
131
+ check: "sk check",
132
+ typecheck: "vue-tsc --noEmit",
133
+ },
134
+ dependencies: {
135
+ "@skathi-native/runtime": sdk,
136
+ ...Object.fromEntries(info.dependencies.map((dep) => [dep, runtimeDeps[dep]])),
137
+ },
138
+ devDependencies: { "@skathi-native/cli": sdk, typescript: "^5", "vue-tsc": "^3" },
240
139
  }),
241
140
  "sk.config.json": json({
141
+ $schema: CONFIG_SCHEMA,
242
142
  name,
243
143
  productName,
244
144
  version: "0.1.0",
245
145
  platforms,
246
- window: { title: productName, width: 900, height: 640, backdrop: "mica" },
146
+ publishDevtools: options.keepDevtools === true,
147
+ window: { title: productName, ...info.window, backdrop: "mica" },
247
148
  assets: ["assets"],
248
- windows: { exeName, icon: "icon.png", without },
149
+ ...(info.packs ? { packs: info.packs } : {}),
150
+ windows: { exeName, icon: "icon.png" },
249
151
  ...(platforms.includes("macos") ? { macos: { bundleId: `com.example.${slug}` } } : {}),
250
152
  }),
251
- ...sources(productName, options.router ?? false),
252
- "assets/hello.txt": `hello from ${name}'s assets\n`,
253
- "icon.png": icon(),
153
+ "icon.png": readFileSync(join(TEMPLATES_DIR, "icon.png")),
254
154
  "tsconfig.json": json({
255
- compilerOptions: {
256
- target: "ESNext",
257
- module: "ESNext",
258
- moduleResolution: "bundler",
259
- lib: ["ESNext"],
260
- strict: true,
261
- noEmit: true,
262
- skipLibCheck: true,
263
- useDefineForClassFields: false,
264
- isolatedModules: true,
265
- types: [],
266
- baseUrl: ".",
267
- paths: {
268
- vue: [`${runtime}/runtime.ts`],
269
- "@skathi-native/runtime": [`${runtime}/runtime.ts`],
270
- "vue-router": [pkg("vue-router")],
271
- pinia: [pkg("pinia")],
272
- },
273
- },
274
- // Template types from the runtime: an installed `vue` package brings DOM typings the engine does not have.
275
- vueCompilerOptions: { lib: "@skathi-native/runtime" },
276
- include: [
277
- `${runtime}/engine.d.ts`,
278
- `${runtime}/protocol.d.ts`,
279
- `${runtime}/indexeddb.d.ts`,
280
- `${rel(RUNTIME_DIR)}/env.d.ts`,
281
- "src/**/*.ts",
282
- "src/**/*.vue",
283
- ],
155
+ extends: "@skathi-native/runtime/tsconfig.app.json",
156
+ include: ["src/**/*.ts", "src/**/*.vue"],
284
157
  }),
158
+ ".gitignore": "node_modules/\ndist/\n",
285
159
  };
286
160
 
287
161
  for (const rel of Object.keys(files)) {
@@ -300,10 +174,9 @@ export function create(target: string, options: CreateOptions = {}): string[] {
300
174
 
301
175
  export interface CreateFlags {
302
176
  name?: string | undefined;
177
+ template?: string | undefined;
303
178
  os?: string | undefined;
304
- without?: string | undefined;
305
179
  devtools?: boolean | undefined;
306
- router?: boolean | undefined;
307
180
  pm?: string | undefined;
308
181
  yes?: boolean | undefined;
309
182
  }
@@ -314,6 +187,12 @@ function parsePm(v: string): PackageManager {
314
187
  return pm;
315
188
  }
316
189
 
190
+ export function parseTemplate(v: string): Template {
191
+ const template = TEMPLATES.find((t) => t === v.trim().toLowerCase());
192
+ if (!template) throw new ConfigError(`--template ${JSON.stringify(v)}: expected one of ${TEMPLATES.join(", ")}`);
193
+ return template;
194
+ }
195
+
317
196
  function answered<T>(value: T): Exclude<T, symbol> {
318
197
  if (p.isCancel(value) || typeof value === "symbol") {
319
198
  p.cancel("Nothing was created.");
@@ -327,13 +206,12 @@ export async function createCommand(target: string | undefined, flags: CreateFla
327
206
  const ask = !flags.yes && process.stdin.isTTY === true && process.stdout.isTTY === true;
328
207
  const options: CreateOptions = {
329
208
  name: flags.name,
209
+ template: flags.template !== undefined ? parseTemplate(flags.template) : undefined,
330
210
  platforms: flags.os
331
211
  ?.split(/[\s,]+/)
332
212
  .filter(Boolean)
333
213
  .map(parsePlatform),
334
- without: flags.without !== undefined ? parseParts(flags.without, "--without") : undefined,
335
214
  keepDevtools: flags.devtools,
336
- router: flags.router,
337
215
  packageManager: flags.pm !== undefined ? parsePm(flags.pm) : undefined,
338
216
  };
339
217
  let dir = target;
@@ -356,6 +234,13 @@ export async function createCommand(target: string | undefined, flags: CreateFla
356
234
  validate: (v) => (v?.trim() ? undefined : "it needs a name"),
357
235
  }),
358
236
  );
237
+ options.template ??= answered(
238
+ await p.select<Template>({
239
+ message: "Template",
240
+ options: TEMPLATES.map((t) => ({ value: t, label: t, hint: TEMPLATE_INFO[t].hint })),
241
+ initialValue: "showcase",
242
+ }),
243
+ );
359
244
  options.platforms ??= answered(
360
245
  await p.multiselect<Platform>({
361
246
  message: "Package it for",
@@ -368,24 +253,12 @@ export async function createCommand(target: string | undefined, flags: CreateFla
368
253
  required: true,
369
254
  }),
370
255
  );
371
- if (!options.without) {
372
- const kept = answered(
373
- await p.multiselect<Exclude<Part, "devtools">>({
374
- message: "Engine parts (leaving one out makes the exe smaller)",
375
- options: ENGINE_PARTS,
376
- initialValues: ENGINE_PARTS.map((e) => e.value),
377
- required: false,
378
- }),
379
- );
380
- options.without = ENGINE_PARTS.map((e) => e.value).filter((v) => !kept.includes(v));
381
- }
382
256
  options.keepDevtools ??= answered(
383
257
  await p.confirm({
384
258
  message: "Keep devtools (F12) in published builds? sk build always has them",
385
259
  initialValue: false,
386
260
  }),
387
261
  );
388
- options.router ??= answered(await p.confirm({ message: "Add vue-router and pinia?", initialValue: true }));
389
262
  options.packageManager ??= answered(
390
263
  await p.select<PackageManager>({
391
264
  message: "Package manager",
@@ -399,7 +272,7 @@ export async function createCommand(target: string | undefined, flags: CreateFla
399
272
  const pm = options.packageManager ?? detectPackageManager();
400
273
  create(dir, options);
401
274
  const where = relative(process.cwd(), resolve(dir)) || ".";
402
- const next = [...(where === "." ? [] : [`cd ${where}`]), runScript(pm, "dev")].join("\n");
275
+ const next = [...(where === "." ? [] : [`cd ${where}`]), `${pm} install`, runScript(pm, "dev")].join("\n");
403
276
  if (ask) {
404
277
  p.note(next, "Next");
405
278
  p.outro(`${options.name ?? basename(resolve(dir))} is ready`);
package/cli/help.ts ADDED
@@ -0,0 +1,159 @@
1
+ import { CLI_VERSION } from "./host";
2
+ import { paint, type Paint } from "./term";
3
+
4
+ type Row = [string, string];
5
+ type Section = { title: string; rows: Row[] };
6
+
7
+ const COMMANDS: Row[] = [
8
+ ["create [dir]", "Start a new app"],
9
+ ["dev [app]", "Run the app with hot reload"],
10
+ ["build [app]", "Debug build: devtools on, not minified"],
11
+ ["publish [app]", "Release build to ship"],
12
+ ["run [app]", "Build, then start the app"],
13
+ ["check [app]", "What breaks under AOT, and how well the code is typed"],
14
+ ["explain <code>", "What a check code means and how to fix it"],
15
+ ["host <command>", "Manage the prebuilt engine hosts"],
16
+ ];
17
+
18
+ const BUILD: Section[] = [
19
+ {
20
+ title: "Options",
21
+ rows: [
22
+ ["--platform <os>", "windows, macos or linux (default: this OS)"],
23
+ ["--out <dir>", "Output directory (default: <app>/dist/debug or dist/release)"],
24
+ ["--define K=V", "A Vite-style define; repeatable"],
25
+ ["--config <path>", "An sk.config.json outside the app"],
26
+ ["--sign <identity>", "macOS: codesign identity (- for ad hoc)"],
27
+ ["--no-sign", "macOS: leave the bundle unsigned"],
28
+ ["--console", "Windows: keep the console window"],
29
+ ["--aot", "Windows x64: compile the app to a native image (--no-aot: don't)"],
30
+ ["--json", "Print the result as JSON"],
31
+ ],
32
+ },
33
+ {
34
+ title: "Advanced",
35
+ rows: [
36
+ ["--host <exe>", "Stamp this host instead of the cached one"],
37
+ ["--payload-only", "Write dist/.sk/app.skpk and stop"],
38
+ ["--aot-inputs", "Keep the typed sources for a later AOT compile"],
39
+ ["--aot-compiler <exe>", "Compile native images with this sk-aot.exe (or SK_AOT_COMPILER)"],
40
+ ],
41
+ },
42
+ ];
43
+
44
+ const HELP: Record<string, { usage: string; about: string; sections: Section[] }> = {
45
+ create: {
46
+ usage: "sk create [dir] [options]",
47
+ about: "Start a new app. In a terminal it asks for whatever the options leave open.",
48
+ sections: [
49
+ {
50
+ title: "Options",
51
+ rows: [
52
+ ["--name <name>", "The app's name (default: the directory's)"],
53
+ ["--template <name>", "showcase (every feature) or minimal"],
54
+ ["--os <list>", "What to package for: windows, macos, linux"],
55
+ ["--devtools", "Keep devtools (F12) in published builds"],
56
+ ["--pm <name>", "bun, npm, pnpm or yarn"],
57
+ ["-y, --yes", "Ask nothing, take the defaults"],
58
+ ],
59
+ },
60
+ ],
61
+ },
62
+ dev: {
63
+ usage: "sk dev [app] [options]",
64
+ about: "Run the app with hot reload: edits to .vue, .ts and .css apply without a restart.",
65
+ sections: [{ title: "Options", rows: [["--exe <host>", "Run this dev host instead of the cached one"]] }],
66
+ },
67
+ build: {
68
+ usage: "sk build [app] [options]",
69
+ about: "A debug build in <app>/dist/debug: devtools (F12) on, the bundle not minified.",
70
+ sections: BUILD,
71
+ },
72
+ publish: {
73
+ usage: "sk publish [app] [options]",
74
+ about:
75
+ 'The release build in <app>/dist/release: minified, devtools only with "publishDevtools": true in sk.config.json.',
76
+ sections: BUILD,
77
+ },
78
+ run: {
79
+ usage: "sk run [app] [options] [-- app args]",
80
+ about: "sk build, then start the app with its output in this terminal.",
81
+ sections: BUILD,
82
+ },
83
+ check: {
84
+ usage: "sk check [app] [options]",
85
+ about: "What in the bundle, app code and node_modules, breaks or slows down under AOT, and how well it is typed.",
86
+ sections: [
87
+ {
88
+ title: "Options",
89
+ rows: [
90
+ ["--format json", "One JSON report on stdout (schema skathi.check)"],
91
+ ["--deny-warnings", "Fail on warnings too"],
92
+ ["--no-deps", "Only the app's own code"],
93
+ ["--config <path>", "An sk.config.json outside the app"],
94
+ ],
95
+ },
96
+ {
97
+ title: "Exit codes",
98
+ rows: [
99
+ ["0", "Clean"],
100
+ ["1", "Errors (or warnings with --deny-warnings)"],
101
+ ["2", "Bad usage or config, or the check failed"],
102
+ ],
103
+ },
104
+ ],
105
+ },
106
+ explain: {
107
+ usage: "sk explain <code> | --list",
108
+ about: "What a check code means, an example, and how to fix it.",
109
+ sections: [{ title: "Options", rows: [["--list", "Every code"]] }],
110
+ },
111
+ host: {
112
+ usage: "sk host <command>",
113
+ about: "The engine host is the prebuilt executable an app is packed into. sk build fetches it on demand.",
114
+ sections: [
115
+ {
116
+ title: "Commands",
117
+ rows: [
118
+ ["fetch", "Download this version's hosts into the local cache"],
119
+ ["path", "Which host sk build would use"],
120
+ ["info [exe]", "What a host says about itself"],
121
+ ["add <exe>", "Verify a host and add it to the cache"],
122
+ ["build", "In a Skathi checkout: build the hosts with cargo"],
123
+ ],
124
+ },
125
+ ],
126
+ },
127
+ };
128
+
129
+ function rows(p: Paint, list: Row[]): string[] {
130
+ const width = Math.max(...list.map(([name]) => name.length));
131
+ return list.map(([name, text]) => ` ${p.cyan(name.padEnd(width))} ${text}`);
132
+ }
133
+
134
+ function sections(p: Paint, list: Section[]): string[] {
135
+ return list.flatMap((s) => ["", p.bold(s.title), ...rows(p, s.rows)]);
136
+ }
137
+
138
+ const head = (p: Paint) => `${p.bold("sk")} ${p.dim(CLI_VERSION)} Skathi apps for Windows, macOS and Linux`;
139
+
140
+ export function topHelp(color: boolean): string {
141
+ const p = paint(color);
142
+ return [
143
+ head(p),
144
+ "",
145
+ `${p.bold("Usage")} sk <command> [app] [options]`,
146
+ "",
147
+ p.bold("Commands"),
148
+ ...rows(p, COMMANDS),
149
+ "",
150
+ p.dim("Run sk <command> --help for its options. [app] is a directory (default: .)."),
151
+ ].join("\n");
152
+ }
153
+
154
+ export function commandHelp(command: string, color: boolean): string | null {
155
+ const help = HELP[command];
156
+ if (!help) return null;
157
+ const p = paint(color);
158
+ return [`${p.bold("Usage")} ${help.usage}`, "", help.about, ...sections(p, help.sections)].join("\n");
159
+ }