@skathi-native/cli 0.1.0-beta.2 → 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 (33) 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 +10 -53
  10. package/cli/help.ts +4 -5
  11. package/cli/host-fetch.ts +87 -48
  12. package/cli/host.ts +18 -8
  13. package/cli/sk.ts +16 -25
  14. package/cli/skpk.ts +4 -0
  15. package/package.json +3 -2
  16. package/templates/icon.png +0 -0
  17. package/templates/minimal/.vscode/settings.json +3 -0
  18. package/templates/showcase/.vscode/settings.json +3 -0
  19. package/templates/showcase/src/components/Titlebar.vue +7 -3
  20. package/templates/showcase/src/engine.ts +3 -26
  21. package/templates/showcase/src/pages/AudioPage.vue +6 -9
  22. package/templates/showcase/src/pages/FilesPage.vue +11 -15
  23. package/templates/showcase/src/pages/FormsPage.vue +2 -3
  24. package/templates/showcase/src/pages/GraphicsPage.vue +13 -15
  25. package/templates/showcase/src/pages/HomePage.vue +1 -2
  26. package/templates/showcase/src/pages/LocalePage.vue +2 -2
  27. package/templates/showcase/src/pages/MediaPage.vue +1 -1
  28. package/templates/showcase/src/pages/MotionPage.vue +1 -1
  29. package/templates/showcase/src/pages/NetworkPage.vue +6 -5
  30. package/templates/showcase/src/pages/PermissionsPage.vue +2 -2
  31. package/templates/showcase/src/pages/StoragePage.vue +23 -36
  32. package/templates/showcase/src/pages/SystemPage.vue +3 -3
  33. package/templates/showcase/src/components/Missing.vue +0 -26
package/cli/build-app.ts CHANGED
@@ -8,21 +8,15 @@
8
8
  // without a re-stamp. On macOS (or `--platform macos` with `--host <mac sk-app>`) the last step is
9
9
  // macos-bundle.ts: the host is copied into `<exeName>.app`, the SKPK goes in Contents/Resources,
10
10
  // and the bundle is signed (ad hoc unless an identity is given). On Linux the SKPK is appended to a
11
- // copy of the host ELF (elf.ts). `PACKAGERS` holds the three.
11
+ // copy of the host ELF (elf.ts). `PACKAGERS` holds the three. With `--aot` (Windows x64), aot-build.ts adds
12
+ // the app's native image to the SKPK.
12
13
 
13
14
  import { createHash } from "node:crypto";
14
15
  import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
15
16
  import { join, relative, resolve, sep } from "node:path";
17
+ import { aotCheck, aotPlatformProblem, buildNative, hostAot, type NativeBuild } from "./aot-build";
16
18
  import { collectAssets, type AssetFile } from "./assets";
17
- import {
18
- loadAppConfig,
19
- partsLeftOut,
20
- variantFor,
21
- variantWarnings,
22
- type AppConfig,
23
- type PackConfig,
24
- type Variant,
25
- } from "./config";
19
+ import { ConfigError, loadAppConfig, parseVariant, type AppConfig, type PackConfig, type Variant } from "./config";
26
20
  import { stampElf, type ElfStampResult } from "./elf";
27
21
  import { CLI_VERSION, PKG_DIR, type ResolvedHost } from "./host";
28
22
  import { resolveOrFetchHost } from "./host-fetch";
@@ -55,20 +49,26 @@ export interface BuildOptions {
55
49
  configPath?: string | undefined;
56
50
  out?: string | undefined;
57
51
  host?: string | undefined;
58
- /** The host variant; overrides sk.config.json's `windows` selection. */
52
+ /** The host variant (standard or no-devtools); overrides the mode's. */
59
53
  variant?: Variant | undefined;
60
54
  console?: boolean;
61
55
  payloadOnly?: boolean;
62
56
  allowHostMismatch?: boolean;
63
57
  defines?: string[] | undefined;
64
58
  aotInputs?: boolean;
59
+ /** Compile the app to a native image (over sk.config.json "aot"). */
60
+ aot?: boolean | undefined;
61
+ /** The sk-aot to use instead of the checkout's or the release's. */
62
+ aotCompiler?: string | undefined;
63
+ /** Colors in a report that refuses the build. */
64
+ color?: boolean;
65
65
  platform?: Platform | undefined;
66
66
  /** macOS: a codesign identity (`-` = ad hoc), or false for none; over `macos.sign`. */
67
67
  sign?: string | false | undefined;
68
68
  /**
69
69
  * `sk build` is "debug": devtools always in, the bundle not minified, <app>/dist/debug. `sk publish` is
70
- * "release": sk.config.json's engine selection, and without one, no devtools; <app>/dist/release. Unset:
71
- * the config's selection into <app>/dist, as the API always did.
70
+ * "release": no devtools unless sk.config.json has "publishDevtools": true; <app>/dist/release. Unset:
71
+ * the standard host into <app>/dist.
72
72
  */
73
73
  mode?: "debug" | "release" | undefined;
74
74
  /** Plain lines instead of the default progress on stderr. */
@@ -76,12 +76,9 @@ export interface BuildOptions {
76
76
  progress?: Progress;
77
77
  }
78
78
 
79
- /** The variant a mode builds when neither `--variant` nor a selection flag names one. */
79
+ /** The variant a mode builds when `--variant` names none. */
80
80
  export function modeVariant(config: AppConfig, mode: BuildOptions["mode"]): Variant {
81
- const selected = config.windows.variant;
82
- if (mode === "debug") return variantFor(partsLeftOut(selected).filter((p) => p !== "devtools"));
83
- if (mode === "release" && !config.windows.selected) return "no-devtools";
84
- return selected;
81
+ return mode === "release" && !config.publishDevtools ? "no-devtools" : "standard";
85
82
  }
86
83
 
87
84
  interface BuilderAsset {
@@ -122,6 +119,14 @@ export interface BuildResult {
122
119
  payloadBytes: number;
123
120
  packs: { name: string; path: string; bytes: number; assets: number }[];
124
121
  aotInputs: string | null;
122
+ native: {
123
+ manifest: string;
124
+ imageBytes: number;
125
+ compressedBytes: number;
126
+ entry: number;
127
+ compiler: string;
128
+ ms: number;
129
+ } | null;
125
130
  warnings: string[];
126
131
  ms: { bundle: number; assets: number; stamp: number; total: number };
127
132
  }
@@ -354,9 +359,15 @@ async function build(options: BuildOptions, progress: Progress): Promise<BuildRe
354
359
  const platform = options.platform ?? currentPlatform();
355
360
  const config = loadAppConfig(options.target, { configPath: options.configPath, platform });
356
361
  const warnings = [...config.warnings];
357
- const asked: Variant = options.variant ?? modeVariant(config, options.mode);
358
- partsLeftOut(asked);
359
- warnings.push(...variantWarnings(asked));
362
+ const variant: Variant =
363
+ options.variant === undefined ? modeVariant(config, options.mode) : parseVariant(options.variant, "--variant");
364
+ const aot = options.aot ?? config.aot;
365
+ if (aot) {
366
+ const problem = aotPlatformProblem(platform);
367
+ if (problem) throw new ConfigError(problem);
368
+ if (options.payloadOnly)
369
+ throw new ConfigError("--aot compiles against the host it stamps, so it cannot be combined with --payload-only");
370
+ }
360
371
  const outDir = resolve(options.out ?? join(config.appRoot, "dist", ...(options.mode ? [options.mode] : [])));
361
372
  const work = join(outDir, ".sk");
362
373
  mkdirSync(work, { recursive: true });
@@ -367,7 +378,7 @@ async function build(options: BuildOptions, progress: Progress): Promise<BuildRe
367
378
  ? null
368
379
  : await resolveOrFetchHost({
369
380
  host: options.host,
370
- variant: asked,
381
+ variant,
371
382
  allowMismatch: options.allowHostMismatch,
372
383
  platform,
373
384
  log,
@@ -375,10 +386,8 @@ async function build(options: BuildOptions, progress: Progress): Promise<BuildRe
375
386
  if (host) {
376
387
  progress.detail(`${host.info.variant} · Skathi ${host.info.skathi} ${host.info.profile} · ${host.source}`);
377
388
  if (host.unverified) warnings.push(host.unverified);
378
- if (host.substitute) warnings.push(host.substitute);
379
389
  }
380
- // The payload names the host it runs on, which a stand-in changes.
381
- const variant: Variant = host?.substitute ? host.info.variant : asked;
390
+ const hostNative = aot && host ? hostAot(host) : null;
382
391
 
383
392
  const jsOut = join(work, "app.prod.js");
384
393
  const assetsJson = join(work, "assets.json");
@@ -417,6 +426,7 @@ async function build(options: BuildOptions, progress: Progress): Promise<BuildRe
417
426
  const script = readFileSync(jsOut);
418
427
  const windowJson = readFileSync(join(work, "window.json"));
419
428
  const msBundle = performance.now() - tb;
429
+ if (aot) await aotCheck(options.target, options.configPath, progress, options.color ?? false);
420
430
 
421
431
  progress.step("assets");
422
432
  const ta = performance.now();
@@ -477,6 +487,21 @@ async function build(options: BuildOptions, progress: Progress): Promise<BuildRe
477
487
  for (const p of packs) writeFileSync(join(work, p.file), p.blob);
478
488
  progress.detail(`${collected.files.length} files · ${kib(collected.totalBytes)}`);
479
489
 
490
+ let native: NativeBuild | null = null;
491
+ const tn = performance.now();
492
+ if (hostNative) {
493
+ native = await buildNative({
494
+ source: script,
495
+ aot: hostNative,
496
+ compilerPath: options.aotCompiler,
497
+ work: join(work, "aot"),
498
+ progress,
499
+ log,
500
+ });
501
+ inputs.push(...native.inputs);
502
+ }
503
+ const msNative = performance.now() - tn;
504
+
480
505
  let packaged: Packaged | null = null;
481
506
  const ts = performance.now();
482
507
  progress.step(options.payloadOnly || !host ? "payload" : platform === "macos" ? "app bundle" : "exe");
@@ -510,6 +535,14 @@ async function build(options: BuildOptions, progress: Progress): Promise<BuildRe
510
535
  assets: collected.files,
511
536
  bundleBytes: script.length,
512
537
  aotInputs: options.aotInputs ? join(work, "aot-inputs", "manifest.json") : null,
538
+ native: native && {
539
+ manifest: native.manifestPath,
540
+ imageBytes: native.imageBytes,
541
+ compressedBytes: native.compressedBytes,
542
+ entry: native.entry,
543
+ compiler: native.compiler.path,
544
+ ms: Math.round(msNative),
545
+ },
513
546
  payloadBytes: packaged?.payload.length ?? readFileSync(skpk).length,
514
547
  packs: packs.map((p) => ({
515
548
  name: p.name,
@@ -580,6 +613,15 @@ export function summary(r: BuildResult, color = false): string {
580
613
  ),
581
614
  row("payload", `${kib(r.payloadBytes)} ${p.dim(r.skpk)}`),
582
615
  );
616
+ if (r.native) {
617
+ lines.push(
618
+ row(
619
+ "native",
620
+ `${mib(r.native.imageBytes)} image (${mib(r.native.compressedBytes)} in the payload), entry ${r.native.entry} ` +
621
+ p.dim(r.native.manifest),
622
+ ),
623
+ );
624
+ }
583
625
  for (const pk of r.packs)
584
626
  lines.push(row("pack", `${pk.name}: ${pk.assets} asset(s), ${kib(pk.bytes)} ${p.dim(pk.path)}`));
585
627
  lines.push(`${p.green("done")} in ${seconds(r.ms.total)}`);
package/cli/config.ts CHANGED
@@ -8,8 +8,9 @@
8
8
  // "packs": [{ "name": "fonts", "match": ["**/*.woff2"] }, { "name": "assets" }]
9
9
  // assets in their own .skpk files, in order; no "match" takes the rest
10
10
  // "define", "aliases" Vite's `define`; a bare module name -> the app's own stand-in file
11
- // "windows": { exeName, icon, company, copyright, description, console,
12
- // without | features | host } engine parts left out / taken / a whole variant by name
11
+ // "publishDevtools": true sk publish keeps devtools (the standard host instead of no-devtools)
12
+ // "aot": true sk build and sk publish compile the app to a native image (Windows x64)
13
+ // "windows": { exeName, icon, company, copyright, description, console }
13
14
  // "macos": { bundleId, exeName, icon, category, minimumSystemVersion, copyright,
14
15
  // microphoneUsageDescription, cameraUsageDescription, sign }
15
16
  //
@@ -21,82 +22,26 @@ import { basename, dirname, isAbsolute, join, resolve, sep } from "node:path";
21
22
  import type { Platform } from "./platform";
22
23
  import { numericVersion } from "./versioninfo";
23
24
 
24
- /**
25
- * The parts of the engine a host can be built WITHOUT: the same list and order as `OPTIONAL` in
26
- * crates/sk-app/src/payload.rs. `devtools` is the listener, inspector and F12; the rest are cargo features of sk-app.
27
- */
28
- export const OPTIONAL = ["devtools", "audio", "clipboard", "storages", "indexeddb", "webgpu"] as const;
29
- export type Part = (typeof OPTIONAL)[number];
30
-
31
- /** A host's name: `standard`, else the parts left out as `no-<part>` joined by `+` in {@link OPTIONAL}'s order. The host cache is keyed by it. */
25
+ /** A prod host's name, the key the host cache and the release find it by: the whole engine, with or without devtools. */
32
26
  export type Variant = string;
33
- export const VARIANTS: Variant[] = ["standard", "no-devtools"];
34
-
35
- const isPart = (p: unknown): p is Part => typeof p === "string" && (OPTIONAL as readonly string[]).includes(p);
36
-
37
- export function variantFor(without: Iterable<Part>): Variant {
38
- const off = new Set(without);
39
- const names = OPTIONAL.filter((p) => off.has(p)).map((p) => `no-${p}`);
40
- return names.length ? names.join("+") : "standard";
41
- }
42
-
43
- export function partsLeftOut(variant: Variant): Part[] {
44
- if (variant === "standard") return [];
45
- const off = new Set<Part>();
46
- for (const name of variant.split("+")) {
47
- const p = name.startsWith("no-") ? name.slice(3) : "";
48
- if (!isPart(p)) {
49
- throw new ConfigError(
50
- `${JSON.stringify(variant)} is not a host variant — "standard", or the parts left out as no-<part> joined by "+" ` +
51
- `(parts: ${OPTIONAL.join(", ")})`,
52
- );
53
- }
54
- off.add(p);
55
- }
56
- return OPTIONAL.filter((p) => off.has(p));
57
- }
27
+ export const VARIANTS: readonly Variant[] = ["standard", "no-devtools"];
58
28
 
59
- /** A list of part names: `"audio,clipboard"` or an array; spaces separate too (PowerShell passes an unquoted `audio,clipboard` as `"audio clipboard"`). */
60
- export function parseParts(list: unknown, where: string): Part[] {
61
- const items = typeof list === "string" ? list.split(/[\s,]+/).filter(Boolean) : list;
62
- if (!Array.isArray(items)) throw new ConfigError(`${where} must be a list of parts (${OPTIONAL.join(", ")})`);
63
- const out = new Set<Part>();
64
- for (const p of items) {
65
- if (!isPart(p))
66
- throw new ConfigError(`${where}: ${JSON.stringify(p)} is not a part — known parts are ${OPTIONAL.join(", ")}`);
67
- out.add(p);
68
- }
69
- return OPTIONAL.filter((p) => out.has(p));
70
- }
29
+ /** The cargo features of sk-app every published host carries (crates/sk-app/src/payload.rs `OPTIONAL`, after devtools). */
30
+ export const ENGINE_FEATURES = ["audio", "clipboard", "storages", "indexeddb", "webgpu"] as const;
71
31
 
72
- /** The variant a selection asks for (`host` is the legacy whole-variant spelling). */
73
- export function selectVariant(
74
- sel: { features?: Part[] | undefined; without?: Part[] | undefined; host?: Variant | undefined },
75
- where: string,
76
- ): Variant {
77
- const given = [sel.features && "features", sel.without && "without", sel.host && "host"].filter(Boolean);
78
- if (given.length > 1) throw new ConfigError(`${where}: give one of ${given.join(" / ")}, not several`);
79
- if (sel.features) return variantFor(OPTIONAL.filter((p) => !sel.features!.includes(p)));
80
- if (sel.without) return variantFor(sel.without);
81
- if (sel.host) return variantFor(partsLeftOut(sel.host));
82
- return "standard";
83
- }
32
+ export const PARTS_NOT_SELECTABLE =
33
+ "engine parts are no longer selectable: every published app carries the whole engine. " +
34
+ '"publishDevtools": true in sk.config.json keeps devtools in sk publish builds; ' +
35
+ "to trim the engine, embed it with the sk-app crate (sk_app::embed) and its cargo features";
84
36
 
85
- export function variantWarnings(variant: Variant): string[] {
86
- const off = new Set(partsLeftOut(variant));
87
- const out: string[] = [];
88
- if (!off.has("indexeddb") && off.has("storages")) {
89
- out.push("the host has indexedDB but no storages: its databases are in memory and nothing survives a restart");
90
- }
91
- return out;
37
+ export function parseVariant(v: unknown, where: string): Variant {
38
+ const name = typeof v === "string" ? v.trim() : "";
39
+ if (VARIANTS.includes(name)) return name;
40
+ throw new ConfigError(`${where}: ${JSON.stringify(v)} is not a host variant — ${VARIANTS.join(" or ")}`);
92
41
  }
93
42
 
94
43
  export function cargoFeatureArgs(variant: Variant): string[] {
95
- const off = partsLeftOut(variant);
96
- const features = ["prod", ...(off.includes("devtools") ? ["no-devtools"] : [])];
97
- const defaults = OPTIONAL.filter((p) => p !== "devtools");
98
- if (!off.some((p) => p !== "devtools")) return ["--features", features.join(",")];
99
- return ["--no-default-features", "--features", [...features, ...defaults.filter((p) => !off.includes(p))].join(",")];
44
+ return ["--features", parseVariant(variant, "cargo") === "no-devtools" ? "prod,no-devtools" : "prod"];
100
45
  }
101
46
 
102
47
  export interface WindowsConfig {
@@ -106,12 +51,6 @@ export interface WindowsConfig {
106
51
  copyright?: string | undefined;
107
52
  description?: string | undefined;
108
53
  console?: boolean;
109
- host?: Variant;
110
- features?: Part[];
111
- without?: Part[];
112
- variant: Variant;
113
- /** Whether the config chose the engine parts (`host`, `features` or `without`). */
114
- selected?: boolean;
115
54
  }
116
55
 
117
56
  /** `"macos"`, defaults applied. Read on every platform, so a typo fails a Windows build too. */
@@ -144,6 +83,10 @@ export interface AppConfig {
144
83
  assetsDeclared: boolean;
145
84
  publicDir: string | null;
146
85
  packs: PackConfig[];
86
+ /** Whether `sk build` and `sk publish` compile the app to a native image (`--aot` / `--no-aot` win). */
87
+ aot: boolean;
88
+ /** Whether `sk publish` stamps the standard host (devtools in) instead of no-devtools. */
89
+ publishDevtools: boolean;
147
90
  windows: WindowsConfig;
148
91
  macos: MacConfig;
149
92
  exeName: string;
@@ -162,6 +105,7 @@ export interface PackConfig {
162
105
  }
163
106
 
164
107
  const PACK_NAME = /^[a-z0-9][a-z0-9_-]{0,63}$/;
108
+ export const PACK_KEYS: ReadonlySet<string> = new Set(["name", "match"]);
165
109
 
166
110
  function parsePacks(raw: unknown): PackConfig[] {
167
111
  if (raw === undefined) return [];
@@ -170,11 +114,11 @@ function parsePacks(raw: unknown): PackConfig[] {
170
114
  const seen = new Set<string>();
171
115
  return raw.map((p, i) => {
172
116
  if (!p || typeof p !== "object" || Array.isArray(p)) throw bad(`entry ${i} must be an object`);
173
- const { name, match, ...rest } = p as Record<string, unknown>;
174
- const extra = Object.keys(rest).filter((k) => !k.startsWith("$"));
117
+ const { name, match } = p as Record<string, unknown>;
118
+ const extra = Object.keys(p).filter((k) => !k.startsWith("$") && !PACK_KEYS.has(k));
175
119
  if (extra.length)
176
120
  throw bad(
177
- `entry ${i} has unknown key(s) ${extra.map((k) => JSON.stringify(k)).join(", ")} — known keys are name, match`,
121
+ `entry ${i} has unknown key(s) ${extra.map((k) => JSON.stringify(k)).join(", ")} — known keys are ${[...PACK_KEYS].join(", ")}`,
178
122
  );
179
123
  if (typeof name !== "string" || !PACK_NAME.test(name) || name === "app") {
180
124
  throw bad(
@@ -202,13 +146,15 @@ export interface LaunchConfig {
202
146
  protocols: string[];
203
147
  }
204
148
 
205
- const TOP_LEVEL = new Set([
149
+ export const TOP_LEVEL: ReadonlySet<string> = new Set([
206
150
  "name",
207
151
  "platforms",
208
152
  "productName",
209
153
  "version",
210
154
  "window",
211
155
  "devtools",
156
+ "publishDevtools",
157
+ "aot",
212
158
  "httpCache",
213
159
  "assets",
214
160
  "publicDir",
@@ -285,18 +231,16 @@ function readLaunch(raw: Record<string, unknown>, name: string): LaunchConfig {
285
231
  protocols,
286
232
  };
287
233
  }
288
- const WINDOWS_KEYS = new Set([
234
+ export const WINDOWS_KEYS: ReadonlySet<string> = new Set([
289
235
  "exeName",
290
236
  "icon",
291
237
  "company",
292
238
  "copyright",
293
239
  "description",
294
240
  "console",
295
- "host",
296
- "features",
297
- "without",
298
241
  ]);
299
- const MACOS_KEYS = new Set([
242
+ const REMOVED_WINDOWS_KEYS = new Set(["host", "features", "without"]);
243
+ export const MACOS_KEYS: ReadonlySet<string> = new Set([
300
244
  "bundleId",
301
245
  "exeName",
302
246
  "icon",
@@ -539,7 +483,15 @@ export function loadAppConfig(
539
483
  throw new ConfigError('sk.config.json "define" must be an object of { "NAME": value }');
540
484
  }
541
485
 
542
- const windows: WindowsConfig = { variant: "standard" };
486
+ if (raw.publishDevtools !== undefined && typeof raw.publishDevtools !== "boolean") {
487
+ throw new ConfigError('sk.config.json "publishDevtools" must be true or false');
488
+ }
489
+ const publishDevtools = raw.publishDevtools === true;
490
+ if (raw.aot !== undefined && typeof raw.aot !== "boolean") {
491
+ throw new ConfigError('sk.config.json "aot" must be true or false');
492
+ }
493
+
494
+ const windows: WindowsConfig = {};
543
495
  if (raw.windows !== undefined) {
544
496
  if (!raw.windows || typeof raw.windows !== "object" || Array.isArray(raw.windows)) {
545
497
  throw new ConfigError('sk.config.json "windows" must be an object');
@@ -547,6 +499,9 @@ export function loadAppConfig(
547
499
  const w = raw.windows as Record<string, unknown>;
548
500
  for (const key of Object.keys(w)) {
549
501
  if (key.startsWith("$")) continue;
502
+ if (REMOVED_WINDOWS_KEYS.has(key)) {
503
+ throw new ConfigError(`sk.config.json "windows.${key}": ${PARTS_NOT_SELECTABLE}`);
504
+ }
550
505
  if (!WINDOWS_KEYS.has(key)) {
551
506
  throw new ConfigError(
552
507
  `sk.config.json "windows": unknown key ${JSON.stringify(key)} — known keys are ${[...WINDOWS_KEYS].join(", ")}`,
@@ -563,20 +518,6 @@ export function loadAppConfig(
563
518
  throw new ConfigError('sk.config.json "windows.console" must be true or false');
564
519
  windows.console = w.console;
565
520
  }
566
- if (w.host !== undefined) {
567
- if (typeof w.host !== "string")
568
- throw new ConfigError('sk.config.json "windows.host" must be a host variant, e.g. "no-devtools"');
569
- try {
570
- partsLeftOut(w.host);
571
- } catch (e) {
572
- throw new ConfigError(`sk.config.json "windows.host": ${(e as Error).message}`);
573
- }
574
- windows.host = w.host;
575
- }
576
- if (w.features !== undefined) windows.features = parseParts(w.features, where("windows.features"));
577
- if (w.without !== undefined) windows.without = parseParts(w.without, where("windows.without"));
578
- windows.variant = selectVariant(windows, where('"windows"'));
579
- windows.selected = windows.host !== undefined || windows.features !== undefined || windows.without !== undefined;
580
521
  }
581
522
 
582
523
  if (raw.httpCache !== undefined && raw.httpCache !== false) {
@@ -624,6 +565,8 @@ export function loadAppConfig(
624
565
  assetsDeclared,
625
566
  publicDir,
626
567
  packs,
568
+ publishDevtools,
569
+ aot: raw.aot === true,
627
570
  windows,
628
571
  macos,
629
572
  exeName,
package/cli/create.ts CHANGED
@@ -1,19 +1,18 @@
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 template, the OSes to package for, the engine parts, whether published builds keep devtools,
2
+ // name, the template, the OSes to package for, whether published builds keep devtools,
3
3
  // and the package manager. `--yes` (or no terminal) takes the defaults.
4
4
  //
5
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, a generated
7
- // 256² icon.png and a tsconfig.json that type-checks against the runtime.
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.
8
8
  // Nothing is overwritten: an existing file is an error, not a merge.
9
9
 
10
10
  import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
11
11
  import { basename, extname, join, relative, resolve } from "node:path";
12
12
  import * as p from "@clack/prompts";
13
13
  import { runtimeRequire } from "../runtime-path";
14
- import { ConfigError, OPTIONAL, parseParts, sanitizeExeName, type Part } from "./config";
14
+ import { ConfigError, sanitizeExeName } from "./config";
15
15
  import { CLI_VERSION } from "./host";
16
- import { encodePng } from "./icon";
17
16
  import { currentPlatform, parsePlatform, type Platform } from "./platform";
18
17
  import { colorEnabled, paint } from "./term";
19
18
 
@@ -47,6 +46,8 @@ const TEMPLATE_INFO: Record<Template, TemplateInfo> = {
47
46
 
48
47
  export const TEMPLATES_DIR = resolve(import.meta.dir, "..", "templates");
49
48
 
49
+ export const CONFIG_SCHEMA = "./node_modules/@skathi-native/runtime/sk.config.schema.json";
50
+
50
51
  /** Files whose text has its `{{key}}` placeholders filled in; anything else is copied byte for byte. */
51
52
  const TEXT_FILES = new Set([".vue", ".ts", ".css", ".txt", ".json", ".html", ".svg"]);
52
53
 
@@ -54,21 +55,11 @@ export interface CreateOptions {
54
55
  name?: string | undefined;
55
56
  template?: Template | undefined;
56
57
  platforms?: Platform[] | undefined;
57
- /** Engine parts left out of every build; devtools is {@link CreateOptions.keepDevtools}'s. */
58
- without?: Part[] | undefined;
59
58
  /** Whether `sk publish` keeps devtools (`sk build` always has them). */
60
59
  keepDevtools?: boolean | undefined;
61
60
  packageManager?: PackageManager | undefined;
62
61
  }
63
62
 
64
- const ENGINE_PARTS: { value: Exclude<Part, "devtools">; label: string; hint: string }[] = [
65
- { value: "audio", label: "Audio", hint: "Web Audio, <audio>, sound from <video>" },
66
- { value: "clipboard", label: "Clipboard", hint: "navigator.clipboard" },
67
- { value: "storages", label: "Storage on disk", hint: "localStorage and IndexedDB that survive a restart" },
68
- { value: "indexeddb", label: "IndexedDB", hint: "indexedDB" },
69
- { value: "webgpu", label: "WebGPU", hint: "navigator.gpu" },
70
- ];
71
-
72
63
  /** The package manager this was started from (`npm_config_user_agent`), else bun. */
73
64
  export function detectPackageManager(agent = process.env.npm_config_user_agent ?? ""): PackageManager {
74
65
  return PACKAGE_MANAGERS.find((pm) => agent.startsWith(`${pm}/`)) ?? "bun";
@@ -77,26 +68,6 @@ export function detectPackageManager(agent = process.env.npm_config_user_agent ?
77
68
  export const runScript = (pm: PackageManager, script: string) =>
78
69
  pm === "npm" || pm === "bun" ? `${pm} run ${script}` : `${pm} ${script}`;
79
70
 
80
- function icon(): Uint8Array {
81
- const size = 256;
82
- const data = new Uint8Array(size * size * 4);
83
- const r = 56;
84
- for (let y = 0; y < size; y++) {
85
- for (let x = 0; x < size; x++) {
86
- const dx = Math.max(0, Math.abs(x - 127.5) - (128 - r));
87
- const dy = Math.max(0, Math.abs(y - 127.5) - (128 - r));
88
- const inside = dx * dx + dy * dy <= r * r;
89
- const t = (x + y) / (2 * size);
90
- const o = (y * size + x) * 4;
91
- data[o] = Math.round(0x42 + (0x2f - 0x42) * t);
92
- data[o + 1] = Math.round(0xb8 + (0x6f - 0xb8) * t);
93
- data[o + 2] = Math.round(0x83 + (0xd8 - 0x83) * t);
94
- data[o + 3] = inside ? 255 : 0;
95
- }
96
- }
97
- return encodePng({ width: size, height: size, data });
98
- }
99
-
100
71
  const json = (v: unknown) => JSON.stringify(v, null, 2) + "\n";
101
72
 
102
73
  function listFiles(dir: string, prefix = ""): string[] {
@@ -143,9 +114,6 @@ export function create(target: string, options: CreateOptions = {}): string[] {
143
114
  const template = options.template ?? "showcase";
144
115
  const info = TEMPLATE_INFO[template];
145
116
  const platforms = options.platforms?.length ? options.platforms : [currentPlatform()];
146
- const without: Part[] = OPTIONAL.filter((part) =>
147
- part === "devtools" ? !options.keepDevtools : (options.without ?? []).includes(part),
148
- );
149
117
  const runtimeDeps = (runtimeRequire("./package.json") as { dependencies: Record<string, string> }).dependencies;
150
118
  const sdk = `^${CLI_VERSION}`;
151
119
 
@@ -170,17 +138,19 @@ export function create(target: string, options: CreateOptions = {}): string[] {
170
138
  devDependencies: { "@skathi-native/cli": sdk, typescript: "^5", "vue-tsc": "^3" },
171
139
  }),
172
140
  "sk.config.json": json({
141
+ $schema: CONFIG_SCHEMA,
173
142
  name,
174
143
  productName,
175
144
  version: "0.1.0",
176
145
  platforms,
146
+ publishDevtools: options.keepDevtools === true,
177
147
  window: { title: productName, ...info.window, backdrop: "mica" },
178
148
  assets: ["assets"],
179
149
  ...(info.packs ? { packs: info.packs } : {}),
180
- windows: { exeName, icon: "icon.png", without },
150
+ windows: { exeName, icon: "icon.png" },
181
151
  ...(platforms.includes("macos") ? { macos: { bundleId: `com.example.${slug}` } } : {}),
182
152
  }),
183
- "icon.png": icon(),
153
+ "icon.png": readFileSync(join(TEMPLATES_DIR, "icon.png")),
184
154
  "tsconfig.json": json({
185
155
  extends: "@skathi-native/runtime/tsconfig.app.json",
186
156
  include: ["src/**/*.ts", "src/**/*.vue"],
@@ -206,7 +176,6 @@ export interface CreateFlags {
206
176
  name?: string | undefined;
207
177
  template?: string | undefined;
208
178
  os?: string | undefined;
209
- without?: string | undefined;
210
179
  devtools?: boolean | undefined;
211
180
  pm?: string | undefined;
212
181
  yes?: boolean | undefined;
@@ -242,7 +211,6 @@ export async function createCommand(target: string | undefined, flags: CreateFla
242
211
  ?.split(/[\s,]+/)
243
212
  .filter(Boolean)
244
213
  .map(parsePlatform),
245
- without: flags.without !== undefined ? parseParts(flags.without, "--without") : undefined,
246
214
  keepDevtools: flags.devtools,
247
215
  packageManager: flags.pm !== undefined ? parsePm(flags.pm) : undefined,
248
216
  };
@@ -285,17 +253,6 @@ export async function createCommand(target: string | undefined, flags: CreateFla
285
253
  required: true,
286
254
  }),
287
255
  );
288
- if (!options.without) {
289
- const kept = answered(
290
- await p.multiselect<Exclude<Part, "devtools">>({
291
- message: "Engine parts (leaving one out makes the exe smaller)",
292
- options: ENGINE_PARTS,
293
- initialValues: ENGINE_PARTS.map((e) => e.value),
294
- required: false,
295
- }),
296
- );
297
- options.without = ENGINE_PARTS.map((e) => e.value).filter((v) => !kept.includes(v));
298
- }
299
256
  options.keepDevtools ??= answered(
300
257
  await p.confirm({
301
258
  message: "Keep devtools (F12) in published builds? sk build always has them",
package/cli/help.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { OPTIONAL } from "./config";
2
1
  import { CLI_VERSION } from "./host";
3
2
  import { paint, type Paint } from "./term";
4
3
 
@@ -21,23 +20,23 @@ const BUILD: Section[] = [
21
20
  title: "Options",
22
21
  rows: [
23
22
  ["--platform <os>", "windows, macos or linux (default: this OS)"],
24
- ["--without <parts>", `Leave engine parts out: ${OPTIONAL.join(", ")}`],
25
23
  ["--out <dir>", "Output directory (default: <app>/dist/debug or dist/release)"],
26
24
  ["--define K=V", "A Vite-style define; repeatable"],
27
25
  ["--config <path>", "An sk.config.json outside the app"],
28
26
  ["--sign <identity>", "macOS: codesign identity (- for ad hoc)"],
29
27
  ["--no-sign", "macOS: leave the bundle unsigned"],
30
28
  ["--console", "Windows: keep the console window"],
29
+ ["--aot", "Windows x64: compile the app to a native image (--no-aot: don't)"],
31
30
  ["--json", "Print the result as JSON"],
32
31
  ],
33
32
  },
34
33
  {
35
34
  title: "Advanced",
36
35
  rows: [
37
- ["--features <parts>", "Take only these engine parts"],
38
36
  ["--host <exe>", "Stamp this host instead of the cached one"],
39
37
  ["--payload-only", "Write dist/.sk/app.skpk and stop"],
40
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)"],
41
40
  ],
42
41
  },
43
42
  ];
@@ -53,7 +52,6 @@ const HELP: Record<string, { usage: string; about: string; sections: Section[] }
53
52
  ["--name <name>", "The app's name (default: the directory's)"],
54
53
  ["--template <name>", "showcase (every feature) or minimal"],
55
54
  ["--os <list>", "What to package for: windows, macos, linux"],
56
- ["--without <parts>", "Engine parts to leave out"],
57
55
  ["--devtools", "Keep devtools (F12) in published builds"],
58
56
  ["--pm <name>", "bun, npm, pnpm or yarn"],
59
57
  ["-y, --yes", "Ask nothing, take the defaults"],
@@ -73,7 +71,8 @@ const HELP: Record<string, { usage: string; about: string; sections: Section[] }
73
71
  },
74
72
  publish: {
75
73
  usage: "sk publish [app] [options]",
76
- about: "The release build in <app>/dist/release: minified, devtools only if sk.config.json keeps them.",
74
+ about:
75
+ 'The release build in <app>/dist/release: minified, devtools only with "publishDevtools": true in sk.config.json.',
77
76
  sections: BUILD,
78
77
  },
79
78
  run: {