@skathi-native/cli 0.0.0 → 0.1.0-beta.2

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 (81) hide show
  1. package/aot-inputs.ts +294 -0
  2. package/ascii.ts +397 -0
  3. package/build.ts +1236 -0
  4. package/check/builtins.json +1219 -0
  5. package/check/builtins.ts +112 -0
  6. package/check/codes.ts +178 -0
  7. package/check/command.ts +105 -0
  8. package/check/config.ts +76 -0
  9. package/check/finding.ts +30 -0
  10. package/check/graph.ts +69 -0
  11. package/check/highlight.ts +40 -0
  12. package/check/index.ts +308 -0
  13. package/check/packages.ts +54 -0
  14. package/check/program.ts +209 -0
  15. package/check/report.ts +219 -0
  16. package/check/rules.ts +307 -0
  17. package/check/schema.ts +69 -0
  18. package/check/typing.ts +703 -0
  19. package/cli/assets.ts +114 -0
  20. package/cli/build-app.ts +587 -0
  21. package/cli/config.ts +646 -0
  22. package/cli/create.ts +327 -0
  23. package/cli/dev.ts +92 -0
  24. package/cli/elf.ts +142 -0
  25. package/cli/help.ts +160 -0
  26. package/cli/host-fetch.ts +178 -0
  27. package/cli/host.ts +378 -0
  28. package/cli/icon.ts +303 -0
  29. package/cli/macos-bundle.ts +451 -0
  30. package/cli/pe.ts +429 -0
  31. package/cli/platform.ts +74 -0
  32. package/cli/sk.ts +290 -0
  33. package/cli/skpk.ts +268 -0
  34. package/cli/stamp.ts +254 -0
  35. package/cli/term.ts +176 -0
  36. package/cli/versioninfo.ts +123 -0
  37. package/css-prefixes.ts +118 -0
  38. package/devtools/apps.ts +68 -0
  39. package/devtools/commands.ts +860 -0
  40. package/devtools/ctl.ts +166 -0
  41. package/package.json +52 -3
  42. package/prod.ts +701 -0
  43. package/runtime-path.ts +24 -0
  44. package/tailwind.ts +76 -0
  45. package/templates/minimal/assets/hello.txt +1 -0
  46. package/templates/minimal/src/App.vue +142 -0
  47. package/templates/minimal/src/main.ts +4 -0
  48. package/templates/showcase/assets/hello.txt +1 -0
  49. package/templates/showcase/assets/media/aurora.png +0 -0
  50. package/templates/showcase/assets/media/clip.mp4 +0 -0
  51. package/templates/showcase/assets/media/sticker.tgs +0 -0
  52. package/templates/showcase/src/App.vue +128 -0
  53. package/templates/showcase/src/components/Card.vue +41 -0
  54. package/templates/showcase/src/components/Icon.vue +29 -0
  55. package/templates/showcase/src/components/Missing.vue +26 -0
  56. package/templates/showcase/src/components/Page.vue +41 -0
  57. package/templates/showcase/src/components/Titlebar.vue +128 -0
  58. package/templates/showcase/src/engine.ts +33 -0
  59. package/templates/showcase/src/icons.ts +22 -0
  60. package/templates/showcase/src/main.ts +7 -0
  61. package/templates/showcase/src/pages/AudioPage.vue +124 -0
  62. package/templates/showcase/src/pages/FilesPage.vue +91 -0
  63. package/templates/showcase/src/pages/FormsPage.vue +139 -0
  64. package/templates/showcase/src/pages/GraphicsPage.vue +156 -0
  65. package/templates/showcase/src/pages/HomePage.vue +141 -0
  66. package/templates/showcase/src/pages/LocalePage.vue +71 -0
  67. package/templates/showcase/src/pages/MediaPage.vue +85 -0
  68. package/templates/showcase/src/pages/MotionPage.vue +199 -0
  69. package/templates/showcase/src/pages/NetworkPage.vue +103 -0
  70. package/templates/showcase/src/pages/PermissionsPage.vue +80 -0
  71. package/templates/showcase/src/pages/StoragePage.vue +117 -0
  72. package/templates/showcase/src/pages/StylesPage.vue +199 -0
  73. package/templates/showcase/src/pages/SystemPage.vue +89 -0
  74. package/templates/showcase/src/pages/TrayPage.vue +66 -0
  75. package/templates/showcase/src/pages/WindowPage.vue +128 -0
  76. package/templates/showcase/src/product.ts +2 -0
  77. package/templates/showcase/src/router.ts +149 -0
  78. package/templates/showcase/src/stores/counter.ts +9 -0
  79. package/templates/showcase/src/stores/desktop.ts +115 -0
  80. package/templates/showcase/src/styles.css +140 -0
  81. package/vitecompat.ts +1151 -0
package/cli/help.ts ADDED
@@ -0,0 +1,160 @@
1
+ import { OPTIONAL } from "./config";
2
+ import { CLI_VERSION } from "./host";
3
+ import { paint, type Paint } from "./term";
4
+
5
+ type Row = [string, string];
6
+ type Section = { title: string; rows: Row[] };
7
+
8
+ const COMMANDS: Row[] = [
9
+ ["create [dir]", "Start a new app"],
10
+ ["dev [app]", "Run the app with hot reload"],
11
+ ["build [app]", "Debug build: devtools on, not minified"],
12
+ ["publish [app]", "Release build to ship"],
13
+ ["run [app]", "Build, then start the app"],
14
+ ["check [app]", "What breaks under AOT, and how well the code is typed"],
15
+ ["explain <code>", "What a check code means and how to fix it"],
16
+ ["host <command>", "Manage the prebuilt engine hosts"],
17
+ ];
18
+
19
+ const BUILD: Section[] = [
20
+ {
21
+ title: "Options",
22
+ rows: [
23
+ ["--platform <os>", "windows, macos or linux (default: this OS)"],
24
+ ["--without <parts>", `Leave engine parts out: ${OPTIONAL.join(", ")}`],
25
+ ["--out <dir>", "Output directory (default: <app>/dist/debug or dist/release)"],
26
+ ["--define K=V", "A Vite-style define; repeatable"],
27
+ ["--config <path>", "An sk.config.json outside the app"],
28
+ ["--sign <identity>", "macOS: codesign identity (- for ad hoc)"],
29
+ ["--no-sign", "macOS: leave the bundle unsigned"],
30
+ ["--console", "Windows: keep the console window"],
31
+ ["--json", "Print the result as JSON"],
32
+ ],
33
+ },
34
+ {
35
+ title: "Advanced",
36
+ rows: [
37
+ ["--features <parts>", "Take only these engine parts"],
38
+ ["--host <exe>", "Stamp this host instead of the cached one"],
39
+ ["--payload-only", "Write dist/.sk/app.skpk and stop"],
40
+ ["--aot-inputs", "Keep the typed sources for a later AOT compile"],
41
+ ],
42
+ },
43
+ ];
44
+
45
+ const HELP: Record<string, { usage: string; about: string; sections: Section[] }> = {
46
+ create: {
47
+ usage: "sk create [dir] [options]",
48
+ about: "Start a new app. In a terminal it asks for whatever the options leave open.",
49
+ sections: [
50
+ {
51
+ title: "Options",
52
+ rows: [
53
+ ["--name <name>", "The app's name (default: the directory's)"],
54
+ ["--template <name>", "showcase (every feature) or minimal"],
55
+ ["--os <list>", "What to package for: windows, macos, linux"],
56
+ ["--without <parts>", "Engine parts to leave out"],
57
+ ["--devtools", "Keep devtools (F12) in published builds"],
58
+ ["--pm <name>", "bun, npm, pnpm or yarn"],
59
+ ["-y, --yes", "Ask nothing, take the defaults"],
60
+ ],
61
+ },
62
+ ],
63
+ },
64
+ dev: {
65
+ usage: "sk dev [app] [options]",
66
+ about: "Run the app with hot reload: edits to .vue, .ts and .css apply without a restart.",
67
+ sections: [{ title: "Options", rows: [["--exe <host>", "Run this dev host instead of the cached one"]] }],
68
+ },
69
+ build: {
70
+ usage: "sk build [app] [options]",
71
+ about: "A debug build in <app>/dist/debug: devtools (F12) on, the bundle not minified.",
72
+ sections: BUILD,
73
+ },
74
+ publish: {
75
+ usage: "sk publish [app] [options]",
76
+ about: "The release build in <app>/dist/release: minified, devtools only if sk.config.json keeps them.",
77
+ sections: BUILD,
78
+ },
79
+ run: {
80
+ usage: "sk run [app] [options] [-- app args]",
81
+ about: "sk build, then start the app with its output in this terminal.",
82
+ sections: BUILD,
83
+ },
84
+ check: {
85
+ usage: "sk check [app] [options]",
86
+ about: "What in the bundle, app code and node_modules, breaks or slows down under AOT, and how well it is typed.",
87
+ sections: [
88
+ {
89
+ title: "Options",
90
+ rows: [
91
+ ["--format json", "One JSON report on stdout (schema skathi.check)"],
92
+ ["--deny-warnings", "Fail on warnings too"],
93
+ ["--no-deps", "Only the app's own code"],
94
+ ["--config <path>", "An sk.config.json outside the app"],
95
+ ],
96
+ },
97
+ {
98
+ title: "Exit codes",
99
+ rows: [
100
+ ["0", "Clean"],
101
+ ["1", "Errors (or warnings with --deny-warnings)"],
102
+ ["2", "Bad usage or config, or the check failed"],
103
+ ],
104
+ },
105
+ ],
106
+ },
107
+ explain: {
108
+ usage: "sk explain <code> | --list",
109
+ about: "What a check code means, an example, and how to fix it.",
110
+ sections: [{ title: "Options", rows: [["--list", "Every code"]] }],
111
+ },
112
+ host: {
113
+ usage: "sk host <command>",
114
+ about: "The engine host is the prebuilt executable an app is packed into. sk build fetches it on demand.",
115
+ sections: [
116
+ {
117
+ title: "Commands",
118
+ rows: [
119
+ ["fetch", "Download this version's hosts into the local cache"],
120
+ ["path", "Which host sk build would use"],
121
+ ["info [exe]", "What a host says about itself"],
122
+ ["add <exe>", "Verify a host and add it to the cache"],
123
+ ["build", "In a Skathi checkout: build the hosts with cargo"],
124
+ ],
125
+ },
126
+ ],
127
+ },
128
+ };
129
+
130
+ function rows(p: Paint, list: Row[]): string[] {
131
+ const width = Math.max(...list.map(([name]) => name.length));
132
+ return list.map(([name, text]) => ` ${p.cyan(name.padEnd(width))} ${text}`);
133
+ }
134
+
135
+ function sections(p: Paint, list: Section[]): string[] {
136
+ return list.flatMap((s) => ["", p.bold(s.title), ...rows(p, s.rows)]);
137
+ }
138
+
139
+ const head = (p: Paint) => `${p.bold("sk")} ${p.dim(CLI_VERSION)} Skathi apps for Windows, macOS and Linux`;
140
+
141
+ export function topHelp(color: boolean): string {
142
+ const p = paint(color);
143
+ return [
144
+ head(p),
145
+ "",
146
+ `${p.bold("Usage")} sk <command> [app] [options]`,
147
+ "",
148
+ p.bold("Commands"),
149
+ ...rows(p, COMMANDS),
150
+ "",
151
+ p.dim("Run sk <command> --help for its options. [app] is a directory (default: .)."),
152
+ ].join("\n");
153
+ }
154
+
155
+ export function commandHelp(command: string, color: boolean): string | null {
156
+ const help = HELP[command];
157
+ if (!help) return null;
158
+ const p = paint(color);
159
+ return [`${p.bold("Usage")} ${help.usage}`, "", help.about, ...sections(p, help.sections)].join("\n");
160
+ }
@@ -0,0 +1,178 @@
1
+ // Prebuilt bare hosts from the Skathi GitHub release of the CLI's own version, so `sk build`
2
+ // needs neither a checkout nor a Rust toolchain. The release (.github/workflows/release.yml,
3
+ // scripts/release-hosts.ts) carries one gzipped host per platform, arch and variant, plus
4
+ // `hosts.json`, which names each with its sha256 and its `--sk-host-info`.
5
+ //
6
+ // Assets are read through the GitHub API, so a private repository works with GH_TOKEN or
7
+ // GITHUB_TOKEN set. SK_HOST_REPO (owner/name) and SK_HOST_API point elsewhere, a fork or a mirror.
8
+
9
+ import { chmodSync, mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
10
+ import { dirname, join } from "node:path";
11
+ import { partsLeftOut, VARIANTS, type Variant } from "./config";
12
+ import {
13
+ CLI_VERSION,
14
+ cachedHost,
15
+ HostError,
16
+ resolveHost,
17
+ type HostInfo,
18
+ type ResolvedHost,
19
+ type ResolveOptions,
20
+ } from "./host";
21
+ import { currentPlatform, type Platform } from "./platform";
22
+
23
+ export const MANIFEST_NAME = "hosts.json";
24
+ export const DEFAULT_REPO = "argon-chat/skathi";
25
+
26
+ export interface HostManifestEntry {
27
+ platform: Platform;
28
+ arch: string;
29
+ variant: Variant;
30
+ /** The release asset: the host, gzipped. */
31
+ file: string;
32
+ /** Of the host itself, not of the gzip. */
33
+ sha256: string;
34
+ size: number;
35
+ info: HostInfo;
36
+ }
37
+
38
+ export interface HostManifest {
39
+ skathi: string;
40
+ hosts: HostManifestEntry[];
41
+ }
42
+
43
+ export const hostAssetName = (platform: Platform, arch: string, variant: Variant): string =>
44
+ `sk-host-${platform}-${arch}-${variant}${platform === "windows" ? ".exe" : ""}.gz`;
45
+
46
+ export const sha256 = (bytes: Uint8Array): string =>
47
+ new Bun.CryptoHasher("sha256").update(new Uint8Array(bytes)).digest("hex");
48
+
49
+ interface ReleaseAsset {
50
+ name: string;
51
+ url: string;
52
+ size: number;
53
+ }
54
+
55
+ export interface FetchOptions {
56
+ variant: Variant;
57
+ version?: string;
58
+ platform?: Platform;
59
+ arch?: string;
60
+ log?: (line: string) => void;
61
+ }
62
+
63
+ function source() {
64
+ const repo = process.env.SK_HOST_REPO || DEFAULT_REPO;
65
+ const api = (process.env.SK_HOST_API || "https://api.github.com").replace(/\/+$/, "");
66
+ const token = process.env.GH_TOKEN || process.env.GITHUB_TOKEN;
67
+ const headers: Record<string, string> = { "User-Agent": "skathi-cli", "X-GitHub-Api-Version": "2022-11-28" };
68
+ if (token) headers.Authorization = `Bearer ${token}`;
69
+ return { repo, api, headers };
70
+ }
71
+
72
+ async function download(asset: ReleaseAsset, headers: Record<string, string>): Promise<Uint8Array<ArrayBuffer>> {
73
+ const res = await fetch(asset.url, { headers: { ...headers, Accept: "application/octet-stream" } });
74
+ if (!res.ok) throw new HostError(`downloading ${asset.name}: HTTP ${res.status}`);
75
+ return new Uint8Array(await res.arrayBuffer());
76
+ }
77
+
78
+ /** Downloads the host for `variant` from the release of `version` into the local cache, checked against `hosts.json`. */
79
+ export async function fetchHost(options: FetchOptions): Promise<{ path: string; info: HostInfo }> {
80
+ const version = options.version ?? CLI_VERSION;
81
+ const platform = options.platform ?? currentPlatform();
82
+ const arch = options.arch ?? process.arch;
83
+ const log = options.log ?? (() => {});
84
+ const { repo, api, headers } = source();
85
+
86
+ const tag = `v${version}`;
87
+ const res = await fetch(`${api}/repos/${repo}/releases/tags/${tag}`, {
88
+ headers: { ...headers, Accept: "application/vnd.github+json" },
89
+ });
90
+ if (res.status === 404) {
91
+ throw new HostError(
92
+ `github.com/${repo} has no ${tag} release` +
93
+ (headers.Authorization ? "" : " (a private repository needs GH_TOKEN or GITHUB_TOKEN)"),
94
+ );
95
+ }
96
+ if (!res.ok) throw new HostError(`github.com/${repo} release ${tag}: HTTP ${res.status}`);
97
+ const assets = ((await res.json()) as { assets?: ReleaseAsset[] }).assets ?? [];
98
+ const asset = (name: string) => assets.find((a) => a.name === name);
99
+
100
+ const manifestAsset = asset(MANIFEST_NAME);
101
+ if (!manifestAsset) throw new HostError(`release ${tag} of github.com/${repo} has no ${MANIFEST_NAME}`);
102
+ const manifest = JSON.parse(new TextDecoder().decode(await download(manifestAsset, headers))) as HostManifest;
103
+ const entry = manifest.hosts.find((h) => h.platform === platform && h.arch === arch && h.variant === options.variant);
104
+ if (!entry) {
105
+ const offered = manifest.hosts
106
+ .filter((h) => h.platform === platform && h.arch === arch)
107
+ .map((h) => h.variant)
108
+ .join(", ");
109
+ throw new HostError(
110
+ `release ${tag} has no ${options.variant} host for ${platform}-${arch}` +
111
+ (offered ? ` (it has: ${offered}); other variants are built from a checkout with sk host build` : ""),
112
+ );
113
+ }
114
+ const hostAsset = asset(entry.file);
115
+ if (!hostAsset) throw new HostError(`release ${tag} lists ${entry.file} in ${MANIFEST_NAME} but does not carry it`);
116
+
117
+ log(`downloading ${entry.file} (${(hostAsset.size / 1048576).toFixed(1)} MB) from github.com/${repo} ${tag}`);
118
+ const bytes = Bun.gunzipSync(await download(hostAsset, headers));
119
+ if (bytes.length !== entry.size || sha256(bytes) !== entry.sha256) {
120
+ throw new HostError(`${entry.file} does not match the sha256 in ${MANIFEST_NAME}; nothing was cached`);
121
+ }
122
+
123
+ const dest = cachedHost(version, options.variant, platform);
124
+ mkdirSync(dirname(dest), { recursive: true });
125
+ const tmp = `${dest}.partial`;
126
+ writeFileSync(tmp, bytes);
127
+ if (process.platform !== "win32") chmodSync(tmp, 0o755);
128
+ rmSync(dest, { force: true });
129
+ renameSync(tmp, dest);
130
+ writeFileSync(join(dirname(dest), "host.json"), JSON.stringify(entry.info, null, 2) + "\n");
131
+ log(`cached ${options.variant} host ${version} → ${dest}`);
132
+ return { path: dest, info: entry.info };
133
+ }
134
+
135
+ /**
136
+ * The published variant that can stand in for `variant`: devtools exactly as asked, and every other
137
+ * part the app may use, with the fewest extra. A host with a part the app does not use only costs size.
138
+ */
139
+ export function standIn(variant: Variant, published: readonly Variant[] = VARIANTS): Variant | null {
140
+ const off = new Set(partsLeftOut(variant));
141
+ const fits = published.filter((v) => {
142
+ const o = partsLeftOut(v);
143
+ return o.includes("devtools") === off.has("devtools") && o.every((p) => off.has(p));
144
+ });
145
+ return fits.sort((a, b) => partsLeftOut(b).length - partsLeftOut(a).length)[0] ?? null;
146
+ }
147
+
148
+ /**
149
+ * {@link resolveHost}, and when it finds nothing for this OS and no host was named, a download into the
150
+ * cache first. A variant no release carries falls back to its {@link standIn}, with `substitute` saying
151
+ * so. SK_HOST_OFFLINE=1 turns the download off.
152
+ */
153
+ export async function resolveOrFetchHost(options: ResolveOptions): Promise<ResolvedHost & { substitute?: string }> {
154
+ try {
155
+ return resolveHost(options);
156
+ } catch (e) {
157
+ const named = options.host ?? process.env.SK_HOST;
158
+ const cross = (options.platform ?? currentPlatform()) !== currentPlatform();
159
+ if (!(e instanceof HostError) || named || cross || process.env.SK_HOST_OFFLINE === "1") throw e;
160
+ const instead = VARIANTS.includes(options.variant) ? null : standIn(options.variant);
161
+ if (instead) {
162
+ const host = await resolveOrFetchHost({ ...options, variant: instead });
163
+ const extra = partsLeftOut(instead).length < partsLeftOut(options.variant).length;
164
+ return {
165
+ ...host,
166
+ substitute:
167
+ `no prebuilt ${options.variant} host: using ${instead}` +
168
+ (extra ? ", which also carries parts this app leaves out (sk host build makes an exact one)" : ""),
169
+ };
170
+ }
171
+ try {
172
+ await fetchHost({ variant: options.variant, ...(options.log && { log: options.log }) });
173
+ } catch (f) {
174
+ throw new HostError(`${e.message}\n(downloading it failed too: ${(f as Error).message})`);
175
+ }
176
+ return resolveHost(options);
177
+ }
178
+ }