@skathi-native/cli 0.1.0-beta.1 → 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.
- package/cli/create.ts +100 -184
- package/cli/help.ts +160 -0
- package/cli/sk.ts +19 -85
- package/package.json +3 -2
- package/templates/minimal/assets/hello.txt +1 -0
- package/templates/minimal/src/App.vue +142 -0
- package/templates/minimal/src/main.ts +4 -0
- package/templates/showcase/assets/hello.txt +1 -0
- package/templates/showcase/assets/media/aurora.png +0 -0
- package/templates/showcase/assets/media/clip.mp4 +0 -0
- package/templates/showcase/assets/media/sticker.tgs +0 -0
- package/templates/showcase/src/App.vue +128 -0
- package/templates/showcase/src/components/Card.vue +41 -0
- package/templates/showcase/src/components/Icon.vue +29 -0
- package/templates/showcase/src/components/Missing.vue +26 -0
- package/templates/showcase/src/components/Page.vue +41 -0
- package/templates/showcase/src/components/Titlebar.vue +128 -0
- package/templates/showcase/src/engine.ts +33 -0
- package/templates/showcase/src/icons.ts +22 -0
- package/templates/showcase/src/main.ts +7 -0
- package/templates/showcase/src/pages/AudioPage.vue +124 -0
- package/templates/showcase/src/pages/FilesPage.vue +91 -0
- package/templates/showcase/src/pages/FormsPage.vue +139 -0
- package/templates/showcase/src/pages/GraphicsPage.vue +156 -0
- package/templates/showcase/src/pages/HomePage.vue +141 -0
- package/templates/showcase/src/pages/LocalePage.vue +71 -0
- package/templates/showcase/src/pages/MediaPage.vue +85 -0
- package/templates/showcase/src/pages/MotionPage.vue +199 -0
- package/templates/showcase/src/pages/NetworkPage.vue +103 -0
- package/templates/showcase/src/pages/PermissionsPage.vue +80 -0
- package/templates/showcase/src/pages/StoragePage.vue +117 -0
- package/templates/showcase/src/pages/StylesPage.vue +199 -0
- package/templates/showcase/src/pages/SystemPage.vue +89 -0
- package/templates/showcase/src/pages/TrayPage.vue +66 -0
- package/templates/showcase/src/pages/WindowPage.vue +128 -0
- package/templates/showcase/src/product.ts +2 -0
- package/templates/showcase/src/router.ts +149 -0
- package/templates/showcase/src/stores/counter.ts +9 -0
- package/templates/showcase/src/stores/desktop.ts +115 -0
- package/templates/showcase/src/styles.css +140 -0
package/cli/create.ts
CHANGED
|
@@ -1,16 +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 OSes to package for, the engine parts, whether published builds keep devtools,
|
|
3
|
-
// and
|
|
2
|
+
// name, the template, the OSes to package for, the engine parts, whether published builds keep devtools,
|
|
3
|
+
// and the package manager. `--yes` (or no terminal) takes the defaults.
|
|
4
4
|
//
|
|
5
|
-
// It
|
|
6
|
-
//
|
|
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.
|
|
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,
|
|
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 {
|
|
13
|
+
import { runtimeRequire } from "../runtime-path";
|
|
13
14
|
import { ConfigError, OPTIONAL, parseParts, sanitizeExeName, type Part } from "./config";
|
|
15
|
+
import { CLI_VERSION } from "./host";
|
|
14
16
|
import { encodePng } from "./icon";
|
|
15
17
|
import { currentPlatform, parsePlatform, type Platform } from "./platform";
|
|
16
18
|
import { colorEnabled, paint } from "./term";
|
|
@@ -18,14 +20,44 @@ import { colorEnabled, paint } from "./term";
|
|
|
18
20
|
export const PACKAGE_MANAGERS = ["bun", "npm", "pnpm", "yarn"] as const;
|
|
19
21
|
export type PackageManager = (typeof PACKAGE_MANAGERS)[number];
|
|
20
22
|
|
|
23
|
+
export const TEMPLATES = ["showcase", "minimal"] as const;
|
|
24
|
+
export type Template = (typeof TEMPLATES)[number];
|
|
25
|
+
|
|
26
|
+
interface TemplateInfo {
|
|
27
|
+
hint: string;
|
|
28
|
+
/** Taken at the versions the runtime itself depends on. */
|
|
29
|
+
dependencies: string[];
|
|
30
|
+
window: Record<string, unknown>;
|
|
31
|
+
packs?: { name: string; match?: string[] }[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const TEMPLATE_INFO: Record<Template, TemplateInfo> = {
|
|
35
|
+
showcase: {
|
|
36
|
+
hint: "every Skathi feature, one page each",
|
|
37
|
+
dependencies: ["pinia", "vue-router"],
|
|
38
|
+
window: { width: 1100, height: 720, minWidth: 480, minHeight: 360, titleBarStyle: "hidden", titleBarHeight: 40 },
|
|
39
|
+
packs: [{ name: "media", match: ["assets/media/**"] }],
|
|
40
|
+
},
|
|
41
|
+
minimal: {
|
|
42
|
+
hint: "one window, one component",
|
|
43
|
+
dependencies: [],
|
|
44
|
+
window: { width: 760, height: 520, titleBarStyle: "default" },
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const TEMPLATES_DIR = resolve(import.meta.dir, "..", "templates");
|
|
49
|
+
|
|
50
|
+
/** Files whose text has its `{{key}}` placeholders filled in; anything else is copied byte for byte. */
|
|
51
|
+
const TEXT_FILES = new Set([".vue", ".ts", ".css", ".txt", ".json", ".html", ".svg"]);
|
|
52
|
+
|
|
21
53
|
export interface CreateOptions {
|
|
22
54
|
name?: string | undefined;
|
|
55
|
+
template?: Template | undefined;
|
|
23
56
|
platforms?: Platform[] | undefined;
|
|
24
57
|
/** Engine parts left out of every build; devtools is {@link CreateOptions.keepDevtools}'s. */
|
|
25
58
|
without?: Part[] | undefined;
|
|
26
59
|
/** Whether `sk publish` keeps devtools (`sk build` always has them). */
|
|
27
60
|
keepDevtools?: boolean | undefined;
|
|
28
|
-
router?: boolean | undefined;
|
|
29
61
|
packageManager?: PackageManager | undefined;
|
|
30
62
|
}
|
|
31
63
|
|
|
@@ -67,145 +99,31 @@ function icon(): Uint8Array {
|
|
|
67
99
|
|
|
68
100
|
const json = (v: unknown) => JSON.stringify(v, null, 2) + "\n";
|
|
69
101
|
|
|
70
|
-
|
|
71
|
-
.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
padding: 24px;
|
|
76
|
-
color: white;
|
|
102
|
+
function listFiles(dir: string, prefix = ""): string[] {
|
|
103
|
+
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
104
|
+
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
105
|
+
return entry.isDirectory() ? listFiles(join(dir, entry.name), rel) : [rel];
|
|
106
|
+
});
|
|
77
107
|
}
|
|
78
|
-
.title {
|
|
79
|
-
font-size: 22px;
|
|
80
|
-
font-weight: 600;
|
|
81
|
-
}
|
|
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
|
-
|
|
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
108
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
109
|
+
/** The template's files, keyed by app-relative path; `{{key}}` is replaced in text files, escaped for a string literal except in .txt. */
|
|
110
|
+
export function templateFiles(template: Template, values: Record<string, string>): Record<string, string | Uint8Array> {
|
|
111
|
+
const dir = join(TEMPLATES_DIR, template);
|
|
112
|
+
const out: Record<string, string | Uint8Array> = {};
|
|
113
|
+
for (const rel of listFiles(dir)) {
|
|
114
|
+
const bytes = readFileSync(join(dir, rel));
|
|
115
|
+
const ext = extname(rel);
|
|
116
|
+
if (!TEXT_FILES.has(ext)) {
|
|
117
|
+
out[rel] = bytes;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
out[rel] = bytes.toString("utf8").replace(/\{\{(\w+)\}\}/g, (whole, key: string) => {
|
|
121
|
+
const value = values[key];
|
|
122
|
+
if (value === undefined) return whole;
|
|
123
|
+
return ext === ".txt" ? value : JSON.stringify(value).slice(1, -1);
|
|
124
|
+
});
|
|
122
125
|
}
|
|
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
|
-
};
|
|
126
|
+
return out;
|
|
209
127
|
}
|
|
210
128
|
|
|
211
129
|
/** Writes the app; every option has a default. Returns the files written. */
|
|
@@ -222,66 +140,52 @@ export function create(target: string, options: CreateOptions = {}): string[] {
|
|
|
222
140
|
.toLowerCase()
|
|
223
141
|
.replace(/[^a-z0-9]+/g, "-")
|
|
224
142
|
.replace(/^-|-$/g, "") || "app";
|
|
143
|
+
const template = options.template ?? "showcase";
|
|
144
|
+
const info = TEMPLATE_INFO[template];
|
|
225
145
|
const platforms = options.platforms?.length ? options.platforms : [currentPlatform()];
|
|
226
146
|
const without: Part[] = OPTIONAL.filter((part) =>
|
|
227
147
|
part === "devtools" ? !options.keepDevtools : (options.without ?? []).includes(part),
|
|
228
148
|
);
|
|
229
|
-
const
|
|
230
|
-
const
|
|
231
|
-
const pkg = (name: string) => rel(dirname(runtimeRequire.resolve(`${name}/package.json`)));
|
|
149
|
+
const runtimeDeps = (runtimeRequire("./package.json") as { dependencies: Record<string, string> }).dependencies;
|
|
150
|
+
const sdk = `^${CLI_VERSION}`;
|
|
232
151
|
|
|
233
152
|
const files: Record<string, string | Uint8Array> = {
|
|
153
|
+
...templateFiles(template, { name, productName }),
|
|
234
154
|
"package.json": json({
|
|
235
155
|
name: slug,
|
|
236
156
|
version: "0.1.0",
|
|
237
157
|
private: true,
|
|
238
158
|
type: "module",
|
|
239
|
-
scripts: {
|
|
159
|
+
scripts: {
|
|
160
|
+
dev: "sk dev",
|
|
161
|
+
build: "sk build",
|
|
162
|
+
publish: "sk publish",
|
|
163
|
+
check: "sk check",
|
|
164
|
+
typecheck: "vue-tsc --noEmit",
|
|
165
|
+
},
|
|
166
|
+
dependencies: {
|
|
167
|
+
"@skathi-native/runtime": sdk,
|
|
168
|
+
...Object.fromEntries(info.dependencies.map((dep) => [dep, runtimeDeps[dep]])),
|
|
169
|
+
},
|
|
170
|
+
devDependencies: { "@skathi-native/cli": sdk, typescript: "^5", "vue-tsc": "^3" },
|
|
240
171
|
}),
|
|
241
172
|
"sk.config.json": json({
|
|
242
173
|
name,
|
|
243
174
|
productName,
|
|
244
175
|
version: "0.1.0",
|
|
245
176
|
platforms,
|
|
246
|
-
window: { title: productName,
|
|
177
|
+
window: { title: productName, ...info.window, backdrop: "mica" },
|
|
247
178
|
assets: ["assets"],
|
|
179
|
+
...(info.packs ? { packs: info.packs } : {}),
|
|
248
180
|
windows: { exeName, icon: "icon.png", without },
|
|
249
181
|
...(platforms.includes("macos") ? { macos: { bundleId: `com.example.${slug}` } } : {}),
|
|
250
182
|
}),
|
|
251
|
-
...sources(productName, options.router ?? false),
|
|
252
|
-
"assets/hello.txt": `hello from ${name}'s assets\n`,
|
|
253
183
|
"icon.png": icon(),
|
|
254
184
|
"tsconfig.json": json({
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
],
|
|
185
|
+
extends: "@skathi-native/runtime/tsconfig.app.json",
|
|
186
|
+
include: ["src/**/*.ts", "src/**/*.vue"],
|
|
284
187
|
}),
|
|
188
|
+
".gitignore": "node_modules/\ndist/\n",
|
|
285
189
|
};
|
|
286
190
|
|
|
287
191
|
for (const rel of Object.keys(files)) {
|
|
@@ -300,10 +204,10 @@ export function create(target: string, options: CreateOptions = {}): string[] {
|
|
|
300
204
|
|
|
301
205
|
export interface CreateFlags {
|
|
302
206
|
name?: string | undefined;
|
|
207
|
+
template?: string | undefined;
|
|
303
208
|
os?: string | undefined;
|
|
304
209
|
without?: string | undefined;
|
|
305
210
|
devtools?: boolean | undefined;
|
|
306
|
-
router?: boolean | undefined;
|
|
307
211
|
pm?: string | undefined;
|
|
308
212
|
yes?: boolean | undefined;
|
|
309
213
|
}
|
|
@@ -314,6 +218,12 @@ function parsePm(v: string): PackageManager {
|
|
|
314
218
|
return pm;
|
|
315
219
|
}
|
|
316
220
|
|
|
221
|
+
export function parseTemplate(v: string): Template {
|
|
222
|
+
const template = TEMPLATES.find((t) => t === v.trim().toLowerCase());
|
|
223
|
+
if (!template) throw new ConfigError(`--template ${JSON.stringify(v)}: expected one of ${TEMPLATES.join(", ")}`);
|
|
224
|
+
return template;
|
|
225
|
+
}
|
|
226
|
+
|
|
317
227
|
function answered<T>(value: T): Exclude<T, symbol> {
|
|
318
228
|
if (p.isCancel(value) || typeof value === "symbol") {
|
|
319
229
|
p.cancel("Nothing was created.");
|
|
@@ -327,13 +237,13 @@ export async function createCommand(target: string | undefined, flags: CreateFla
|
|
|
327
237
|
const ask = !flags.yes && process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
328
238
|
const options: CreateOptions = {
|
|
329
239
|
name: flags.name,
|
|
240
|
+
template: flags.template !== undefined ? parseTemplate(flags.template) : undefined,
|
|
330
241
|
platforms: flags.os
|
|
331
242
|
?.split(/[\s,]+/)
|
|
332
243
|
.filter(Boolean)
|
|
333
244
|
.map(parsePlatform),
|
|
334
245
|
without: flags.without !== undefined ? parseParts(flags.without, "--without") : undefined,
|
|
335
246
|
keepDevtools: flags.devtools,
|
|
336
|
-
router: flags.router,
|
|
337
247
|
packageManager: flags.pm !== undefined ? parsePm(flags.pm) : undefined,
|
|
338
248
|
};
|
|
339
249
|
let dir = target;
|
|
@@ -356,6 +266,13 @@ export async function createCommand(target: string | undefined, flags: CreateFla
|
|
|
356
266
|
validate: (v) => (v?.trim() ? undefined : "it needs a name"),
|
|
357
267
|
}),
|
|
358
268
|
);
|
|
269
|
+
options.template ??= answered(
|
|
270
|
+
await p.select<Template>({
|
|
271
|
+
message: "Template",
|
|
272
|
+
options: TEMPLATES.map((t) => ({ value: t, label: t, hint: TEMPLATE_INFO[t].hint })),
|
|
273
|
+
initialValue: "showcase",
|
|
274
|
+
}),
|
|
275
|
+
);
|
|
359
276
|
options.platforms ??= answered(
|
|
360
277
|
await p.multiselect<Platform>({
|
|
361
278
|
message: "Package it for",
|
|
@@ -385,7 +302,6 @@ export async function createCommand(target: string | undefined, flags: CreateFla
|
|
|
385
302
|
initialValue: false,
|
|
386
303
|
}),
|
|
387
304
|
);
|
|
388
|
-
options.router ??= answered(await p.confirm({ message: "Add vue-router and pinia?", initialValue: true }));
|
|
389
305
|
options.packageManager ??= answered(
|
|
390
306
|
await p.select<PackageManager>({
|
|
391
307
|
message: "Package manager",
|
|
@@ -399,7 +315,7 @@ export async function createCommand(target: string | undefined, flags: CreateFla
|
|
|
399
315
|
const pm = options.packageManager ?? detectPackageManager();
|
|
400
316
|
create(dir, options);
|
|
401
317
|
const where = relative(process.cwd(), resolve(dir)) || ".";
|
|
402
|
-
const next = [...(where === "." ? [] : [`cd ${where}`]), runScript(pm, "dev")].join("\n");
|
|
318
|
+
const next = [...(where === "." ? [] : [`cd ${where}`]), `${pm} install`, runScript(pm, "dev")].join("\n");
|
|
403
319
|
if (ask) {
|
|
404
320
|
p.note(next, "Next");
|
|
405
321
|
p.outro(`${options.name ?? basename(resolve(dir))} is ready`);
|
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
|
+
}
|