@skathi-native/cli 0.1.0-beta.4 → 0.3.0
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/aot/host-globals.json +1 -1
- package/aot/pin.ts +1 -1
- package/aot/toolchain.lock.json +5 -5
- package/aot/transform.ts +9 -1
- package/aot-inputs.ts +21 -2
- package/build.ts +284 -64
- package/check/builtins.json +11 -11
- package/check/bundle.ts +265 -0
- package/check/codes.ts +46 -0
- package/check/css-catalog.json +451 -0
- package/check/css.ts +512 -0
- package/check/finding.ts +63 -1
- package/check/graph.ts +14 -1
- package/check/index.ts +30 -49
- package/check/program.ts +26 -6
- package/cli/aot-build.ts +2 -6
- package/cli/build-app.ts +19 -0
- package/cli/create.ts +70 -12
- package/cli/dev.ts +11 -6
- package/cli/effects.ts +39 -18
- package/cli/gallery.ts +106 -0
- package/cli/sk.ts +5 -2
- package/devtools/commands.ts +26 -1
- package/devtools/ctl.ts +4 -3
- package/effects/compile.ts +160 -31
- package/effects/sk.slang +359 -30
- package/gallery.json +1 -0
- package/package.json +9 -5
- package/prod.ts +78 -10
- package/svelte.ts +76 -0
- package/templates/icon.png +0 -0
- package/templates/showcase/assets/textures/golden.png +0 -0
- package/templates/showcase/assets/textures/hammered.png +0 -0
- package/templates/showcase/assets/textures/noir.png +0 -0
- package/templates/showcase/assets/textures/reeded.png +0 -0
- package/templates/showcase/assets/textures/teal-orange.png +0 -0
- package/templates/showcase/shaders/dissolve.slang +40 -0
- package/templates/showcase/shaders/fireflies.slang +58 -0
- package/templates/showcase/shaders/glass.slang +31 -0
- package/templates/showcase/shaders/grade.slang +34 -0
- package/templates/showcase/shaders/halftone.slang +42 -0
- package/templates/showcase/shaders/lens.slang +51 -0
- package/templates/showcase/shaders/nebula.slang +57 -0
- package/templates/showcase/shaders/orbit.slang +52 -0
- package/templates/showcase/shaders/pond.slang +76 -0
- package/templates/showcase/shaders/ripples.slang +71 -0
- package/templates/showcase/shaders/shatter.slang +116 -0
- package/templates/showcase/shaders/snow.slang +57 -0
- package/templates/showcase/shaders/spotlight.slang +52 -0
- package/templates/showcase/src/App.vue +11 -16
- package/templates/showcase/src/components/FullWindow.vue +77 -0
- package/templates/showcase/src/components/Page.vue +2 -0
- package/templates/showcase/src/fullwindow.ts +36 -0
- package/templates/showcase/src/icons.ts +2 -0
- package/templates/showcase/src/pages/GraphicsPage.vue +122 -0
- package/templates/showcase/src/pages/MotionPage.vue +71 -1
- package/templates/showcase/src/pages/ShadersPage.vue +443 -0
- package/templates/showcase/src/router.ts +32 -1
- package/templates/svelte/.vscode/settings.json +3 -0
- package/templates/svelte/assets/hello.txt +1 -0
- package/templates/svelte/src/App.svelte +142 -0
- package/templates/svelte/src/main.ts +4 -0
- package/vitecompat.ts +2 -0
package/check/index.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
-
import { isAbsolute, join,
|
|
3
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
4
4
|
import { loadAppConfig } from "../cli/config";
|
|
5
5
|
import { appShadersDir, compileAppEffects, EffectsError, hasAppEffects } from "../effects/compile";
|
|
6
6
|
import { resolveCompiler } from "../effects/redslangc";
|
|
7
7
|
import { quietProgress, type Progress } from "../cli/term";
|
|
8
8
|
import { Builtins } from "./builtins";
|
|
9
|
-
import {
|
|
10
|
-
import { parseCheckConfig
|
|
11
|
-
import {
|
|
9
|
+
import { REGISTRY } from "./codes";
|
|
10
|
+
import { parseCheckConfig } from "./config";
|
|
11
|
+
import { cssFindings, readStyleSources } from "./css";
|
|
12
|
+
import { diagnosticsOf, PLATFORM, posix, rangeOf, ZERO_RANGE, type Finding } from "./finding";
|
|
13
|
+
import { BundleLiveness } from "./bundle";
|
|
12
14
|
import { buildGraph, GraphFailure, type ModuleGraph } from "./graph";
|
|
13
15
|
import { Packages } from "./packages";
|
|
14
16
|
import { buildProgram, readUnits, type TypeScript } from "./program";
|
|
15
17
|
import { Rules } from "./rules";
|
|
16
|
-
import type { CheckReport
|
|
18
|
+
import type { CheckReport } from "./schema";
|
|
17
19
|
import { Typing } from "./typing";
|
|
18
20
|
|
|
19
21
|
export type { CheckReport, Diagnostic } from "./schema";
|
|
@@ -21,16 +23,6 @@ export { explain, formatPretty, listCodes } from "./report";
|
|
|
21
23
|
|
|
22
24
|
const PROD_TS = join(import.meta.dir, "..", "prod.ts");
|
|
23
25
|
|
|
24
|
-
/** Packages the SDK provides and answers for under AOT; an app cannot swap or retype them. */
|
|
25
|
-
const PLATFORM = new Set([
|
|
26
|
-
"vue",
|
|
27
|
-
"@vue/runtime-core",
|
|
28
|
-
"@vue/runtime-dom",
|
|
29
|
-
"@vue/reactivity",
|
|
30
|
-
"@vue/shared",
|
|
31
|
-
"@skathi-native/runtime",
|
|
32
|
-
]);
|
|
33
|
-
|
|
34
26
|
export class CheckSetupError extends Error {}
|
|
35
27
|
|
|
36
28
|
export interface CheckOptions {
|
|
@@ -55,6 +47,12 @@ export interface AnalyzeInput {
|
|
|
55
47
|
/** Findings made before the analysis (configuration problems). */
|
|
56
48
|
findings?: Finding[];
|
|
57
49
|
progress?: Progress | undefined;
|
|
50
|
+
/** The production bundle: a rule finding in code it cannot run is not reported. */
|
|
51
|
+
bundle?: ModuleGraph["bundle"];
|
|
52
|
+
/** Stylesheets and pages whose CSS the build includes, besides the components in `modules`. */
|
|
53
|
+
styles?: string[];
|
|
54
|
+
/** The build runs Tailwind over the app's CSS. */
|
|
55
|
+
tailwind?: boolean;
|
|
58
56
|
}
|
|
59
57
|
|
|
60
58
|
export function loadTypeScript(appRoot: string): TypeScript {
|
|
@@ -66,8 +64,6 @@ export function loadTypeScript(appRoot: string): TypeScript {
|
|
|
66
64
|
throw new CheckSetupError("sk check needs the typescript package: add it to the app (bun add -d typescript)");
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
const posix = (path: string) => path.split(sep).join("/");
|
|
70
|
-
|
|
71
67
|
export async function runCheck(options: CheckOptions): Promise<CheckReport> {
|
|
72
68
|
const progress = options.progress ?? quietProgress;
|
|
73
69
|
const config = loadAppConfig(options.target, { configPath: options.configPath });
|
|
@@ -138,6 +134,9 @@ export async function runCheck(options: CheckOptions): Promise<CheckReport> {
|
|
|
138
134
|
modules: graph.modules,
|
|
139
135
|
aliases: graph.aliases,
|
|
140
136
|
declarations: graph.declarations,
|
|
137
|
+
bundle: graph.bundle,
|
|
138
|
+
styles: graph.styles ?? [],
|
|
139
|
+
tailwind: graph.tailwind ?? false,
|
|
141
140
|
allow: checkConfig.allow,
|
|
142
141
|
deps: options.deps ?? true,
|
|
143
142
|
findings,
|
|
@@ -201,6 +200,13 @@ export function analyze(input: AnalyzeInput): CheckReport {
|
|
|
201
200
|
});
|
|
202
201
|
|
|
203
202
|
const analysed = deps ? units : units.filter((u) => !u.owner);
|
|
203
|
+
const styled = [...input.modules.filter((m) => /\.(vue|svelte)$/i.test(m)), ...(input.styles ?? [])];
|
|
204
|
+
if (styled.length) {
|
|
205
|
+
progress.step("CSS");
|
|
206
|
+
findings.push(
|
|
207
|
+
...cssFindings({ sources: readStyleSources(styled), packages, deps, tailwind: input.tailwind ?? false }),
|
|
208
|
+
);
|
|
209
|
+
}
|
|
204
210
|
if (units.length) {
|
|
205
211
|
progress.step("TypeScript program", units.length);
|
|
206
212
|
const built = buildProgram({
|
|
@@ -215,6 +221,7 @@ export function analyze(input: AnalyzeInput): CheckReport {
|
|
|
215
221
|
if (built.configNote) progress.warn(built.configNote);
|
|
216
222
|
const { program, checker } = built;
|
|
217
223
|
const rules = new Rules(typescript, checker, new Builtins(typescript, program, checker));
|
|
224
|
+
const liveness = input.bundle ? new BundleLiveness(typescript, input.bundle) : null;
|
|
218
225
|
progress.step("AOT rules", units.length);
|
|
219
226
|
for (const unit of units) {
|
|
220
227
|
progress.tick();
|
|
@@ -244,7 +251,11 @@ export function analyze(input: AnalyzeInput): CheckReport {
|
|
|
244
251
|
delete unit.sourceFile;
|
|
245
252
|
continue;
|
|
246
253
|
}
|
|
247
|
-
if (deps || !unit.owner)
|
|
254
|
+
if (deps || !unit.owner) {
|
|
255
|
+
const found: Finding[] = [];
|
|
256
|
+
rules.run(unit, file, found);
|
|
257
|
+
findings.push(...found.filter((f) => !liveness || liveness.live(f.file, f.range)));
|
|
258
|
+
}
|
|
248
259
|
}
|
|
249
260
|
progress.step("typing quality");
|
|
250
261
|
const typing = new Typing(
|
|
@@ -279,42 +290,12 @@ function report(
|
|
|
279
290
|
files: number,
|
|
280
291
|
scores: ReturnType<Typing["results"]>,
|
|
281
292
|
): CheckReport {
|
|
282
|
-
const
|
|
283
|
-
const suppress = new Suppressions(input.allow ?? new Map());
|
|
284
|
-
const diagnostics: Diagnostic[] = [];
|
|
293
|
+
const { diagnostics, suppressed } = diagnosticsOf(findings, root, packages, input.allow ?? new Map());
|
|
285
294
|
const owners = new Set<string>();
|
|
286
|
-
let suppressed = 0;
|
|
287
|
-
for (const f of findings) {
|
|
288
|
-
const info = codeInfo(f.code);
|
|
289
|
-
const owner = packages.ownerOf(f.file);
|
|
290
|
-
if (owner && PLATFORM.has(owner.name)) continue;
|
|
291
|
-
const file = rel(f.file);
|
|
292
|
-
if (!info.fatal && suppress.matches(f.code, file, owner?.name ?? null)) {
|
|
293
|
-
suppressed++;
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
296
|
-
diagnostics.push({
|
|
297
|
-
code: f.code,
|
|
298
|
-
severity: info.severity,
|
|
299
|
-
message: f.message,
|
|
300
|
-
file,
|
|
301
|
-
package: owner ? { name: owner.name, version: owner.version } : null,
|
|
302
|
-
range: f.range,
|
|
303
|
-
help: f.help ?? info.fix,
|
|
304
|
-
related: f.related.map((r) => ({ file: rel(r.file), range: r.range, message: r.message })),
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
295
|
for (const u of input.modules) {
|
|
308
296
|
const owner = packages.ownerOf(u);
|
|
309
297
|
if (owner && !PLATFORM.has(owner.name) && (input.deps ?? true)) owners.add(`${owner.name}@${owner.version}`);
|
|
310
298
|
}
|
|
311
|
-
diagnostics.sort(
|
|
312
|
-
(a, b) =>
|
|
313
|
-
(a.file < b.file ? -1 : a.file > b.file ? 1 : 0) ||
|
|
314
|
-
a.range.start.line - b.range.start.line ||
|
|
315
|
-
a.range.start.character - b.range.start.character ||
|
|
316
|
-
a.code.localeCompare(b.code),
|
|
317
|
-
);
|
|
318
299
|
const typing = scores
|
|
319
300
|
.filter((s) => !(s.owner && PLATFORM.has(s.owner.name)))
|
|
320
301
|
.map((s) => ({
|
package/check/program.ts
CHANGED
|
@@ -8,11 +8,11 @@ export type TypeScript = typeof ts;
|
|
|
8
8
|
|
|
9
9
|
/** One file of the bundle as the analysis sees it. */
|
|
10
10
|
export interface Unit {
|
|
11
|
-
/** The file on disk (.vue for a
|
|
11
|
+
/** The file on disk (.vue or .svelte for a component). */
|
|
12
12
|
path: string;
|
|
13
|
-
/** Its name in the TypeScript program: `<path>.ts`/`.js` for a .
|
|
13
|
+
/** Its name in the TypeScript program: `<path>.ts`/`.js` for a component. */
|
|
14
14
|
programPath: string;
|
|
15
|
-
/** The text positions refer to; for a
|
|
15
|
+
/** The text positions refer to; for a component everything but its scripts is blanked. */
|
|
16
16
|
text: string;
|
|
17
17
|
/** TypeScript rather than JavaScript. */
|
|
18
18
|
typed: boolean;
|
|
@@ -27,6 +27,7 @@ export interface Unreadable {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const TS_FILE = /\.[cm]?tsx?$/i;
|
|
30
|
+
const COMPONENT_FILE = /\.(vue|svelte)$/i;
|
|
30
31
|
|
|
31
32
|
/** The scripts of an SFC at their own offsets, everything else replaced by spaces. */
|
|
32
33
|
export function vueScripts(source: string, path: string): { text: string; typed: boolean } | null {
|
|
@@ -41,6 +42,25 @@ export function vueScripts(source: string, path: string): { text: string; typed:
|
|
|
41
42
|
return { text: chars.join(""), typed: blocks.some((b) => /^tsx?$/.test(b!.lang ?? "")) };
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
const blank = (text: string) => text.replace(/[^\r\n]/g, " ");
|
|
46
|
+
|
|
47
|
+
/** The `<script>` blocks of a Svelte component at their own offsets, everything else replaced by spaces. */
|
|
48
|
+
export function svelteScripts(source: string): { text: string; typed: boolean } | null {
|
|
49
|
+
// A `<script>` in a comment or in `<svelte:head>` is markup, not the component's script.
|
|
50
|
+
const scan = source.replace(/<!--[\s\S]*?-->|<svelte:head[\s>][\s\S]*?<\/svelte:head\s*>/gi, blank);
|
|
51
|
+
const chars = blank(source).split("");
|
|
52
|
+
let found = false;
|
|
53
|
+
let typed = false;
|
|
54
|
+
for (const m of scan.matchAll(/<script(\s[^>]*)?>([\s\S]*?)<\/script\s*>/gi)) {
|
|
55
|
+
const attrs = m[1] ?? "";
|
|
56
|
+
const start = m.index + "<script".length + attrs.length + 1;
|
|
57
|
+
for (let i = 0; i < m[2]!.length; i++) chars[start + i] = source[start + i]!;
|
|
58
|
+
found = true;
|
|
59
|
+
if (/\blang\s*=\s*["']?(ts|typescript)\b/i.test(attrs)) typed = true;
|
|
60
|
+
}
|
|
61
|
+
return found ? { text: chars.join(""), typed } : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
44
64
|
export function readUnits(
|
|
45
65
|
modules: string[],
|
|
46
66
|
packages: Packages,
|
|
@@ -57,10 +77,10 @@ export function readUnits(
|
|
|
57
77
|
unreadable.push({ path, owner, message: (e as Error).message });
|
|
58
78
|
continue;
|
|
59
79
|
}
|
|
60
|
-
if (
|
|
80
|
+
if (COMPONENT_FILE.test(path)) {
|
|
61
81
|
let scripts: ReturnType<typeof vueScripts>;
|
|
62
82
|
try {
|
|
63
|
-
scripts = vueScripts(source, path);
|
|
83
|
+
scripts = /\.svelte$/i.test(path) ? svelteScripts(source) : vueScripts(source, path);
|
|
64
84
|
} catch (e) {
|
|
65
85
|
unreadable.push({ path, owner, message: (e as Error).message });
|
|
66
86
|
continue;
|
|
@@ -188,7 +208,7 @@ export function buildProgram(input: ProgramInput): BuiltProgram {
|
|
|
188
208
|
}
|
|
189
209
|
const found = typescript.resolveModuleName(specifier, importer, options, host).resolvedModule;
|
|
190
210
|
if (found) return found;
|
|
191
|
-
if (
|
|
211
|
+
if (COMPONENT_FILE.test(specifier) && specifier.startsWith(".")) {
|
|
192
212
|
for (const ext of ["ts", "js"] as const) {
|
|
193
213
|
const path = resolve(dirname(importer), `${specifier}.${ext}`);
|
|
194
214
|
if (own.has(key(path)))
|
package/cli/aot-build.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { join, resolve } from "node:path";
|
|
|
12
12
|
import { AotError, compileNative, compilerInfo, compilerMismatch, nativeManifest, repoSkAot } from "../aot/native";
|
|
13
13
|
import type { CompilerInfo } from "../aot/pin";
|
|
14
14
|
import { TRANSFORM } from "../aot/transform";
|
|
15
|
+
import { diagnosticLine } from "../check/finding";
|
|
15
16
|
import { exitCode, formatPretty, runCheck, type CheckReport } from "../check/index";
|
|
16
17
|
import { ConfigError } from "./config";
|
|
17
18
|
import { CLI_VERSION, HostError, REPO_ROOT, type HostAot, type ResolvedHost } from "./host";
|
|
@@ -113,11 +114,6 @@ export async function resolveAotCompiler(
|
|
|
113
114
|
return { path: fetched.path, info: await compilerInfo(fetched.path), source: "release" };
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
/** One line per diagnostic, for warnings that do not stop the build. */
|
|
117
|
-
export function checkLine(d: CheckReport["diagnostics"][number]): string {
|
|
118
|
-
return `${d.file}:${d.range.start.line + 1}:${d.range.start.character + 1} ${d.code} ${d.message}`;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
117
|
/** `sk check` over the app: errors (and fatal findings) refuse the build with the report; warnings are printed. */
|
|
122
118
|
export async function aotCheck(
|
|
123
119
|
target: string,
|
|
@@ -133,7 +129,7 @@ export async function aotCheck(
|
|
|
133
129
|
"Fix the errors (sk explain <CODE> says how), or build with --no-aot.",
|
|
134
130
|
);
|
|
135
131
|
}
|
|
136
|
-
for (const d of report.diagnostics) progress.warn(
|
|
132
|
+
for (const d of report.diagnostics) progress.warn(diagnosticLine(d));
|
|
137
133
|
return report;
|
|
138
134
|
}
|
|
139
135
|
|
package/cli/build-app.ts
CHANGED
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
import { createHash } from "node:crypto";
|
|
16
16
|
import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
17
17
|
import { join, relative, resolve, sep } from "node:path";
|
|
18
|
+
import { parseCheckConfig } from "../check/config";
|
|
19
|
+
import { cssDiagnostics, readStyleSources } from "../check/css";
|
|
20
|
+
import { diagnosticLine } from "../check/finding";
|
|
21
|
+
import type { BuildStyles } from "../check/graph";
|
|
18
22
|
import { aotCheck, aotPlatformProblem, buildNative, hostAot, type NativeBuild } from "./aot-build";
|
|
19
23
|
import { collectAssets, type AssetFile } from "./assets";
|
|
20
24
|
import { ConfigError, loadAppConfig, parseVariant, type AppConfig, type PackConfig, type Variant } from "./config";
|
|
@@ -100,6 +104,18 @@ function readBuilderAssets(path: string): BuilderAsset[] {
|
|
|
100
104
|
);
|
|
101
105
|
}
|
|
102
106
|
|
|
107
|
+
/** SK4001–SK4005 over the CSS the bundle includes, one line each; `--aot` has them from its full check. */
|
|
108
|
+
function cssWarnings(config: AppConfig, stylesJson: string): string[] {
|
|
109
|
+
if (!existsSync(stylesJson)) return [];
|
|
110
|
+
const styles = JSON.parse(readFileSync(stylesJson, "utf8")) as BuildStyles;
|
|
111
|
+
return cssDiagnostics({
|
|
112
|
+
root: config.appRoot,
|
|
113
|
+
sources: readStyleSources(styles.files),
|
|
114
|
+
allow: parseCheckConfig(config.raw.check).allow,
|
|
115
|
+
tailwind: styles.tailwind,
|
|
116
|
+
}).map(diagnosticLine);
|
|
117
|
+
}
|
|
118
|
+
|
|
103
119
|
export interface MacBundle extends AppBundleResult {
|
|
104
120
|
bundleId: string;
|
|
105
121
|
iconSizes: number[];
|
|
@@ -411,8 +427,10 @@ async function build(options: BuildOptions, progress: Progress): Promise<BuildRe
|
|
|
411
427
|
|
|
412
428
|
const jsOut = join(work, "app.prod.js");
|
|
413
429
|
const assetsJson = join(work, "assets.json");
|
|
430
|
+
const stylesJson = join(work, "styles.json");
|
|
414
431
|
// A stale list from an older build must not survive a builder that wrote none.
|
|
415
432
|
rmSync(assetsJson, { force: true });
|
|
433
|
+
rmSync(stylesJson, { force: true });
|
|
416
434
|
const tb = performance.now();
|
|
417
435
|
const defineArgs = (options.defines ?? []).map((d) => `--define=${d}`);
|
|
418
436
|
const pathArgs = [
|
|
@@ -447,6 +465,7 @@ async function build(options: BuildOptions, progress: Progress): Promise<BuildRe
|
|
|
447
465
|
const windowJson = readFileSync(join(work, "window.json"));
|
|
448
466
|
const msBundle = performance.now() - tb;
|
|
449
467
|
if (aot) await aotCheck(options.target, options.configPath, progress, options.color ?? false);
|
|
468
|
+
else for (const line of cssWarnings(config, stylesJson)) progress.warn(line);
|
|
450
469
|
|
|
451
470
|
progress.step("assets");
|
|
452
471
|
const ta = performance.now();
|
package/cli/create.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
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
|
-
// It copies templates/<template>/
|
|
6
|
-
// package.json (the app root the builders resolve npm dependencies from), sk.config.json, the
|
|
7
|
-
//
|
|
5
|
+
// It copies the template (templates/<template>/ here, or the gallery repo's) with the placeholders filled
|
|
6
|
+
// in, and writes package.json (the app root the builders resolve npm dependencies from), sk.config.json, icon.png (the
|
|
7
|
+
// template's own, else the Skathi icon) 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";
|
|
@@ -12,6 +12,7 @@ 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
14
|
import { ConfigError, sanitizeExeName } from "./config";
|
|
15
|
+
import { fetchGallery, galleryDir } from "./gallery";
|
|
15
16
|
import { CLI_VERSION } from "./host";
|
|
16
17
|
import { currentPlatform, parsePlatform, type Platform } from "./platform";
|
|
17
18
|
import { colorEnabled, paint } from "./term";
|
|
@@ -19,15 +20,30 @@ import { colorEnabled, paint } from "./term";
|
|
|
19
20
|
export const PACKAGE_MANAGERS = ["bun", "npm", "pnpm", "yarn"] as const;
|
|
20
21
|
export type PackageManager = (typeof PACKAGE_MANAGERS)[number];
|
|
21
22
|
|
|
22
|
-
export const TEMPLATES = ["showcase", "minimal"] as const;
|
|
23
|
+
export const TEMPLATES = ["showcase", "minimal", "svelte", "player", "weather"] as const;
|
|
23
24
|
export type Template = (typeof TEMPLATES)[number];
|
|
24
25
|
|
|
26
|
+
interface Checker {
|
|
27
|
+
script: string;
|
|
28
|
+
devDependencies: Record<string, string>;
|
|
29
|
+
/** The component files the app's tsconfig.json includes besides its .ts sources. */
|
|
30
|
+
sources: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const VUE_TSC: Checker = { script: "vue-tsc --noEmit", devDependencies: { "vue-tsc": "^3" }, sources: "src/**/*.vue" };
|
|
34
|
+
const SVELTE_CHECK: Checker = {
|
|
35
|
+
script: "svelte-check",
|
|
36
|
+
devDependencies: { "svelte-check": "^4" },
|
|
37
|
+
sources: "src/**/*.svelte",
|
|
38
|
+
};
|
|
39
|
+
|
|
25
40
|
interface TemplateInfo {
|
|
26
41
|
hint: string;
|
|
27
|
-
/** Taken at the versions the runtime itself depends on. */
|
|
42
|
+
/** Taken at the versions the runtime itself depends on, or accepts as a peer. */
|
|
28
43
|
dependencies: string[];
|
|
29
44
|
window: Record<string, unknown>;
|
|
30
45
|
packs?: { name: string; match?: string[] }[];
|
|
46
|
+
checker: Checker;
|
|
31
47
|
}
|
|
32
48
|
|
|
33
49
|
const TEMPLATE_INFO: Record<Template, TemplateInfo> = {
|
|
@@ -36,20 +52,57 @@ const TEMPLATE_INFO: Record<Template, TemplateInfo> = {
|
|
|
36
52
|
dependencies: ["pinia", "vue-router"],
|
|
37
53
|
window: { width: 1100, height: 720, minWidth: 480, minHeight: 360, titleBarStyle: "hidden", titleBarHeight: 40 },
|
|
38
54
|
packs: [{ name: "media", match: ["assets/media/**"] }],
|
|
55
|
+
checker: VUE_TSC,
|
|
39
56
|
},
|
|
40
57
|
minimal: {
|
|
41
58
|
hint: "one window, one component",
|
|
42
59
|
dependencies: [],
|
|
43
60
|
window: { width: 760, height: 520, titleBarStyle: "default" },
|
|
61
|
+
checker: VUE_TSC,
|
|
62
|
+
},
|
|
63
|
+
svelte: {
|
|
64
|
+
hint: "the minimal app in Svelte 5",
|
|
65
|
+
dependencies: ["svelte"],
|
|
66
|
+
window: { width: 760, height: 520, titleBarStyle: "default" },
|
|
67
|
+
checker: SVELTE_CHECK,
|
|
68
|
+
},
|
|
69
|
+
player: {
|
|
70
|
+
hint: "a music player in Svelte 5, dressed in shaders",
|
|
71
|
+
dependencies: ["svelte"],
|
|
72
|
+
window: { width: 1240, height: 800, minWidth: 480, minHeight: 600, titleBarStyle: "hidden", titleBarHeight: 44 },
|
|
73
|
+
packs: [{ name: "media", match: ["assets/music/**", "assets/covers/**"] }],
|
|
74
|
+
checker: SVELTE_CHECK,
|
|
75
|
+
},
|
|
76
|
+
weather: {
|
|
77
|
+
hint: "a weather app in Vue, its sky and rain drawn by shaders",
|
|
78
|
+
dependencies: [],
|
|
79
|
+
window: { width: 1180, height: 880, minWidth: 980, minHeight: 780, titleBarStyle: "hidden", titleBarHeight: 72 },
|
|
80
|
+
packs: [{ name: "textures", match: ["assets/textures/**"] }],
|
|
81
|
+
checker: VUE_TSC,
|
|
44
82
|
},
|
|
45
83
|
};
|
|
46
84
|
|
|
47
85
|
export const TEMPLATES_DIR = resolve(import.meta.dir, "..", "templates");
|
|
48
86
|
|
|
87
|
+
/** Templates kept in the skathi-templates repo rather than in this package. */
|
|
88
|
+
const GALLERY: ReadonlySet<Template> = new Set(["player", "weather"]);
|
|
89
|
+
|
|
90
|
+
function templateDir(template: Template): string {
|
|
91
|
+
if (!GALLERY.has(template)) return join(TEMPLATES_DIR, template);
|
|
92
|
+
const dir = galleryDir(template);
|
|
93
|
+
if (!dir) throw new ConfigError(`sk create: the ${template} template has not been downloaded`);
|
|
94
|
+
return dir;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Downloads the template first when it lives in the gallery repo. */
|
|
98
|
+
export async function prepareTemplate(template: Template): Promise<void> {
|
|
99
|
+
if (GALLERY.has(template)) await fetchGallery(template);
|
|
100
|
+
}
|
|
101
|
+
|
|
49
102
|
export const CONFIG_SCHEMA = "./node_modules/@skathi-native/runtime/sk.config.schema.json";
|
|
50
103
|
|
|
51
104
|
/** 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"]);
|
|
105
|
+
const TEXT_FILES = new Set([".vue", ".svelte", ".ts", ".css", ".txt", ".json", ".html", ".svg"]);
|
|
53
106
|
|
|
54
107
|
export interface CreateOptions {
|
|
55
108
|
name?: string | undefined;
|
|
@@ -79,7 +132,7 @@ function listFiles(dir: string, prefix = ""): string[] {
|
|
|
79
132
|
|
|
80
133
|
/** The template's files, keyed by app-relative path; `{{key}}` is replaced in text files, escaped for a string literal except in .txt. */
|
|
81
134
|
export function templateFiles(template: Template, values: Record<string, string>): Record<string, string | Uint8Array> {
|
|
82
|
-
const dir =
|
|
135
|
+
const dir = templateDir(template);
|
|
83
136
|
const out: Record<string, string | Uint8Array> = {};
|
|
84
137
|
for (const rel of listFiles(dir)) {
|
|
85
138
|
const bytes = readFileSync(join(dir, rel));
|
|
@@ -114,10 +167,15 @@ export function create(target: string, options: CreateOptions = {}): string[] {
|
|
|
114
167
|
const template = options.template ?? "showcase";
|
|
115
168
|
const info = TEMPLATE_INFO[template];
|
|
116
169
|
const platforms = options.platforms?.length ? options.platforms : [currentPlatform()];
|
|
117
|
-
const
|
|
170
|
+
const runtimePkg = runtimeRequire("./package.json") as {
|
|
171
|
+
dependencies: Record<string, string>;
|
|
172
|
+
peerDependencies?: Record<string, string>;
|
|
173
|
+
};
|
|
174
|
+
const runtimeDeps = { ...runtimePkg.peerDependencies, ...runtimePkg.dependencies };
|
|
118
175
|
const sdk = `^${CLI_VERSION}`;
|
|
119
176
|
|
|
120
177
|
const files: Record<string, string | Uint8Array> = {
|
|
178
|
+
"icon.png": readFileSync(join(TEMPLATES_DIR, "icon.png")),
|
|
121
179
|
...templateFiles(template, { name, productName }),
|
|
122
180
|
"package.json": json({
|
|
123
181
|
name: slug,
|
|
@@ -129,13 +187,13 @@ export function create(target: string, options: CreateOptions = {}): string[] {
|
|
|
129
187
|
build: "sk build",
|
|
130
188
|
publish: "sk publish",
|
|
131
189
|
check: "sk check",
|
|
132
|
-
typecheck:
|
|
190
|
+
typecheck: info.checker.script,
|
|
133
191
|
},
|
|
134
192
|
dependencies: {
|
|
135
193
|
"@skathi-native/runtime": sdk,
|
|
136
194
|
...Object.fromEntries(info.dependencies.map((dep) => [dep, runtimeDeps[dep]])),
|
|
137
195
|
},
|
|
138
|
-
devDependencies: { "@skathi-native/cli": sdk, typescript: "^
|
|
196
|
+
devDependencies: { "@skathi-native/cli": sdk, typescript: "^6", ...info.checker.devDependencies },
|
|
139
197
|
}),
|
|
140
198
|
"sk.config.json": json({
|
|
141
199
|
$schema: CONFIG_SCHEMA,
|
|
@@ -150,10 +208,9 @@ export function create(target: string, options: CreateOptions = {}): string[] {
|
|
|
150
208
|
windows: { exeName, icon: "icon.png" },
|
|
151
209
|
...(platforms.includes("macos") ? { macos: { bundleId: `com.example.${slug}` } } : {}),
|
|
152
210
|
}),
|
|
153
|
-
"icon.png": readFileSync(join(TEMPLATES_DIR, "icon.png")),
|
|
154
211
|
"tsconfig.json": json({
|
|
155
212
|
extends: "@skathi-native/runtime/tsconfig.app.json",
|
|
156
|
-
include: ["src/**/*.ts",
|
|
213
|
+
include: ["src/**/*.ts", info.checker.sources],
|
|
157
214
|
}),
|
|
158
215
|
".gitignore": "node_modules/\ndist/\n",
|
|
159
216
|
};
|
|
@@ -271,6 +328,7 @@ export async function createCommand(target: string | undefined, flags: CreateFla
|
|
|
271
328
|
|
|
272
329
|
dir ??= "my-app";
|
|
273
330
|
const pm = options.packageManager ?? detectPackageManager();
|
|
331
|
+
await prepareTemplate(options.template ?? "showcase");
|
|
274
332
|
create(dir, options);
|
|
275
333
|
const where = relative(process.cwd(), resolve(dir)) || ".";
|
|
276
334
|
const next = [...(where === "." ? [] : [`cd ${where}`]), `${pm} install`, runScript(pm, "dev")].join("\n");
|
package/cli/dev.ts
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
// -p sk-app`); the cached dev host of this version; a download of it from the release (host-fetch.ts).
|
|
6
6
|
//
|
|
7
7
|
// An app with shaders/*.slang has them compiled into <dist>/effects, which the host reads through
|
|
8
|
-
// SK_EFFECTS_DIR, and recompiled on every change
|
|
9
|
-
//
|
|
10
|
-
// --sk-host-info has no `devReload: ["effects"]`)
|
|
11
|
-
// diagnostics and keeps the last good build running.
|
|
8
|
+
// SK_EFFECTS_DIR, and recompiled on every change, the first shader of an app that had none too. A
|
|
9
|
+
// good rebuild reaches the running app as a message beside the HMR changes.json and replaces its
|
|
10
|
+
// effects in place; a host that predates that (its --sk-host-info has no `devReload: ["effects"]`)
|
|
11
|
+
// is restarted. A failed rebuild prints the diagnostics and keeps the last good build running.
|
|
12
12
|
|
|
13
13
|
import { spawn, type ChildProcess } from "node:child_process";
|
|
14
14
|
import { existsSync, mkdirSync } from "node:fs";
|
|
@@ -137,12 +137,17 @@ export async function dev(
|
|
|
137
137
|
let host = start();
|
|
138
138
|
let restarting = false;
|
|
139
139
|
let effectsWatch: EffectsWatch | null = null;
|
|
140
|
-
if (
|
|
140
|
+
if (!overridden) {
|
|
141
|
+
const shaderCompiler = async (): Promise<string> => {
|
|
142
|
+
compiler ??= (await resolveCompiler({ named: options.shaderCompiler, log: (line) => console.log(c.dim(line)) }))
|
|
143
|
+
.path;
|
|
144
|
+
return compiler;
|
|
145
|
+
};
|
|
141
146
|
effectsWatch = devEffectsWatch({
|
|
142
147
|
appRoot: config.appRoot,
|
|
143
148
|
dist,
|
|
144
149
|
out: effectsDir,
|
|
145
|
-
compiler,
|
|
150
|
+
compiler: shaderCompiler,
|
|
146
151
|
inPlace: reloadsEffects(exe),
|
|
147
152
|
restart: () => {
|
|
148
153
|
restarting = true;
|
package/cli/effects.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// (HLSL, WGSL, MSL), so a build made on one OS runs on all three. `sk build` puts them into the payload
|
|
3
3
|
// as `sk/effects/*` entries; `sk dev` writes them to dist/.sk-dev/effects and points the dev host there.
|
|
4
4
|
|
|
5
|
-
import { watch, writeFileSync, type FSWatcher } from "node:fs";
|
|
6
|
-
import { join } from "node:path";
|
|
5
|
+
import { existsSync, watch, writeFileSync, type FSWatcher } from "node:fs";
|
|
6
|
+
import { basename, join } from "node:path";
|
|
7
7
|
import {
|
|
8
8
|
appShadersDir,
|
|
9
9
|
compileAppEffects,
|
|
@@ -69,12 +69,13 @@ export interface EffectsWatch {
|
|
|
69
69
|
close(): void;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
/// Recompiles into `out` when a `.slang` under shaders/ changes, debounced
|
|
73
|
-
/// last good files and reports through `onError`.
|
|
72
|
+
/// Recompiles into `out` when a `.slang` under shaders/ changes, debounced; an app without shaders/
|
|
73
|
+
/// is watched for one. A failed compile keeps the last good files and reports through `onError`.
|
|
74
|
+
/// `compiler` may be resolved on the first rebuild, so an app without shaders never fetches one.
|
|
74
75
|
export function watchAppEffects(options: {
|
|
75
76
|
appRoot: string;
|
|
76
77
|
out: string;
|
|
77
|
-
compiler: string;
|
|
78
|
+
compiler: string | (() => Promise<string>);
|
|
78
79
|
onBuilt: (effects: AppEffects) => void;
|
|
79
80
|
onError: (message: string) => void;
|
|
80
81
|
debounceMs?: number;
|
|
@@ -90,7 +91,8 @@ export function watchAppEffects(options: {
|
|
|
90
91
|
}
|
|
91
92
|
running = true;
|
|
92
93
|
try {
|
|
93
|
-
const
|
|
94
|
+
const compiler = typeof options.compiler === "string" ? options.compiler : await options.compiler();
|
|
95
|
+
const effects = await compileAppEffects(options.appRoot, compiler);
|
|
94
96
|
writeEffectFiles(options.out, effects.files);
|
|
95
97
|
options.onBuilt(effects);
|
|
96
98
|
} catch (e) {
|
|
@@ -105,18 +107,37 @@ export function watchAppEffects(options: {
|
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
109
|
};
|
|
110
|
+
const schedule = () => {
|
|
111
|
+
if (timer) clearTimeout(timer);
|
|
112
|
+
timer = setTimeout(() => {
|
|
113
|
+
timer = null;
|
|
114
|
+
void rebuild();
|
|
115
|
+
}, options.debounceMs ?? 120);
|
|
116
|
+
};
|
|
108
117
|
let watcher: FSWatcher | null = null;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
118
|
+
const watchShaders = () => {
|
|
119
|
+
try {
|
|
120
|
+
watcher = watch(dir, { recursive: true }, (_event, file) => {
|
|
121
|
+
if (file && !String(file).endsWith(".slang")) return;
|
|
122
|
+
schedule();
|
|
123
|
+
});
|
|
124
|
+
} catch (e) {
|
|
125
|
+
options.onError(`cannot watch ${dir}: ${e instanceof Error ? e.message : String(e)}`);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
if (existsSync(dir)) {
|
|
129
|
+
watchShaders();
|
|
130
|
+
} else {
|
|
131
|
+
try {
|
|
132
|
+
watcher = watch(options.appRoot, (_event, file) => {
|
|
133
|
+
if (file !== basename(dir) || !existsSync(dir)) return;
|
|
134
|
+
watcher?.close();
|
|
135
|
+
watchShaders();
|
|
136
|
+
schedule();
|
|
137
|
+
});
|
|
138
|
+
} catch (e) {
|
|
139
|
+
options.onError(`cannot watch ${options.appRoot}: ${e instanceof Error ? e.message : String(e)}`);
|
|
140
|
+
}
|
|
120
141
|
}
|
|
121
142
|
return {
|
|
122
143
|
close() {
|
|
@@ -135,7 +156,7 @@ export function devEffectsWatch(options: {
|
|
|
135
156
|
appRoot: string;
|
|
136
157
|
dist: string;
|
|
137
158
|
out: string;
|
|
138
|
-
compiler: string;
|
|
159
|
+
compiler: string | (() => Promise<string>);
|
|
139
160
|
inPlace: boolean;
|
|
140
161
|
restart: () => void;
|
|
141
162
|
log: (line: string) => void;
|