@incajs/cli 0.0.0 → 0.0.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/LICENSE +5 -0
- package/README.md +66 -2
- package/bin/inca.mjs +7 -0
- package/dist/adapter/types.d.mts +47 -0
- package/dist/adapter/vite/build.d.mts +8 -0
- package/dist/adapter/vite/captureOutput.d.mts +15 -0
- package/dist/adapter/vite/config.d.mts +26 -0
- package/dist/adapter/vite/index.d.mts +2 -0
- package/dist/adapter/vite/watch.d.mts +8 -0
- package/dist/build.d.mts +21 -0
- package/dist/chunks/__vite-optional-peer-dep_dotenv_c12-CxKvRg9-.js +3 -0
- package/dist/chunks/__vite-optional-peer-dep_giget_c12-BYcrHYBM.js +5 -0
- package/dist/chunks/__vite-optional-peer-dep_jiti_c12-DZVJNj6v.js +5 -0
- package/dist/chunks/_format-BKs7bsc4.js +98 -0
- package/dist/chunks/defaults-EWjAFeZ3.js +1184 -0
- package/dist/chunks/dist-BVKUE9C4.js +114 -0
- package/dist/chunks/json5-feUuPtTt.js +756 -0
- package/dist/chunks/jsonc-BdzClvC8.js +46 -0
- package/dist/chunks/ohash-CHaRSTtv.js +231 -0
- package/dist/chunks/toml-BERh2MAo.js +417 -0
- package/dist/chunks/yaml-N2dF3WHm.js +2123 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.js +503 -0
- package/dist/config/defaults.d.mts +44 -0
- package/dist/config/index.d.mts +18 -0
- package/dist/config/loader.d.mts +37 -0
- package/dist/config/types.d.mts +35 -0
- package/dist/config.js +5 -0
- package/dist/defaultBundler.d.mts +7 -0
- package/dist/dev-client/hostBin.d.mts +9 -0
- package/dist/dev-client/hostClient.d.mts +50 -0
- package/dist/dev-client/hostError.d.mts +6 -0
- package/dist/dev-client/index.d.mts +4 -0
- package/dist/dev-client/protocol.d.mts +38 -0
- package/dist/dev.d.mts +25 -0
- package/dist/entry.d.mts +8 -0
- package/dist/fault.d.mts +6 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.js +0 -0
- package/dist/package.d.mts +45 -0
- package/dist/plist.d.mts +4 -0
- package/package.json +64 -3
package/dist/cli.d.mts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
import { i as e, n as t, o as n, r, t as i } from "./chunks/defaults-EWjAFeZ3.js";
|
|
2
|
+
import { existsSync as a } from "node:fs";
|
|
3
|
+
import { chmod as o, cp as s, mkdir as c, readFile as l, readdir as u, rm as d, writeFile as f } from "node:fs/promises";
|
|
4
|
+
import p from "node:path";
|
|
5
|
+
import { build as m } from "vite";
|
|
6
|
+
import h from "@vitejs/plugin-vue";
|
|
7
|
+
import { createRequire as g } from "node:module";
|
|
8
|
+
import { spawn as _ } from "node:child_process";
|
|
9
|
+
import { once as v } from "node:events";
|
|
10
|
+
import y from "node:readline";
|
|
11
|
+
import { setTimeout as b } from "node:timers/promises";
|
|
12
|
+
//#region src/config/loader.mts
|
|
13
|
+
async function x(e) {
|
|
14
|
+
let { config: t } = await n({
|
|
15
|
+
cwd: e,
|
|
16
|
+
name: "inca",
|
|
17
|
+
packageJson: "inca",
|
|
18
|
+
rcFile: !1,
|
|
19
|
+
globalRc: !1,
|
|
20
|
+
giget: !1,
|
|
21
|
+
extend: !1
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
entry: t.entry ? p.resolve(e, t.entry) : void 0,
|
|
25
|
+
outDir: p.resolve(e, t.outDir ?? i.outDir)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async function S(e) {
|
|
29
|
+
let o = p.join(e, "package.json"), s;
|
|
30
|
+
try {
|
|
31
|
+
s = await l(o, "utf8");
|
|
32
|
+
} catch {
|
|
33
|
+
throw Error(`no package.json found at ${o}`);
|
|
34
|
+
}
|
|
35
|
+
let c = JSON.parse(s), { config: u, layers: d } = await n({
|
|
36
|
+
cwd: e,
|
|
37
|
+
name: "inca",
|
|
38
|
+
packageJson: "inca",
|
|
39
|
+
rcFile: !1,
|
|
40
|
+
globalRc: !1,
|
|
41
|
+
giget: !1,
|
|
42
|
+
extend: !1
|
|
43
|
+
}), f = d?.find((e) => e.configFile === "package.json"), m = Object.keys(f?.config ?? {}).length > 0, h = u.productName ?? r(c.name);
|
|
44
|
+
if (!h) throw Error(`${o} needs a "name", or "productName" in inca.config.ts`);
|
|
45
|
+
let g = u.version ?? c.version ?? i.version, _ = u.identifier ?? t(h), v;
|
|
46
|
+
if (u.icon && (v = p.resolve(e, u.icon), !a(v))) throw Error(`"icon" points to ${v}, which doesn't exist`);
|
|
47
|
+
let y = u.entry ? p.resolve(e, u.entry) : void 0, b = p.resolve(e, u.outDir ?? i.outDir);
|
|
48
|
+
return {
|
|
49
|
+
productName: h,
|
|
50
|
+
identifier: _,
|
|
51
|
+
identifierIsDefault: u.identifier === void 0,
|
|
52
|
+
version: g,
|
|
53
|
+
icon: v,
|
|
54
|
+
entry: y,
|
|
55
|
+
outDir: b,
|
|
56
|
+
usedPackageJsonKey: m
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/adapter/vite/captureOutput.mts
|
|
61
|
+
function C(e) {
|
|
62
|
+
return {
|
|
63
|
+
name: "inca:capture-output",
|
|
64
|
+
writeBundle(t, n) {
|
|
65
|
+
let r = Object.keys(n), i = Object.values(n).find((e) => e.type === "chunk" && e.isEntry);
|
|
66
|
+
if (!i) throw Error("inca: build produced no entry chunk");
|
|
67
|
+
e({
|
|
68
|
+
entryFile: i.fileName,
|
|
69
|
+
files: r
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/adapter/vite/config.mts
|
|
76
|
+
var w = "bundle.js";
|
|
77
|
+
function T({ entry: e, outDir: t, mode: n, watch: r, onOutput: i }) {
|
|
78
|
+
return {
|
|
79
|
+
configFile: !1,
|
|
80
|
+
root: p.dirname(e),
|
|
81
|
+
mode: n,
|
|
82
|
+
clearScreen: !1,
|
|
83
|
+
logLevel: "silent",
|
|
84
|
+
define: { "process.env.NODE_ENV": JSON.stringify(n) },
|
|
85
|
+
plugins: [h({ template: { compilerOptions: { runtimeModuleName: "@vue/runtime-core" } } }), C(i)],
|
|
86
|
+
build: {
|
|
87
|
+
lib: {
|
|
88
|
+
entry: e,
|
|
89
|
+
formats: ["es"],
|
|
90
|
+
fileName: () => w
|
|
91
|
+
},
|
|
92
|
+
outDir: t,
|
|
93
|
+
emptyOutDir: n === "production",
|
|
94
|
+
minify: n === "production",
|
|
95
|
+
watch: r ? {} : void 0,
|
|
96
|
+
rolldownOptions: { output: {
|
|
97
|
+
chunkFileNames: "chunks/[name]-[hash].js",
|
|
98
|
+
assetFileNames: "assets/[name]-[hash][extname]"
|
|
99
|
+
} }
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/adapter/vite/build.mts
|
|
105
|
+
async function E({ entry: e, outDir: t }) {
|
|
106
|
+
let n;
|
|
107
|
+
if (await m(T({
|
|
108
|
+
entry: e,
|
|
109
|
+
outDir: t,
|
|
110
|
+
mode: "production",
|
|
111
|
+
watch: !1,
|
|
112
|
+
onOutput: (e) => {
|
|
113
|
+
n = {
|
|
114
|
+
outDir: t,
|
|
115
|
+
entryFile: p.join(t, e.entryFile),
|
|
116
|
+
files: e.files
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
})), !n) throw Error("inca: build produced no output");
|
|
120
|
+
return n;
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/adapter/vite/watch.mts
|
|
124
|
+
async function D({ onBuild: e, onError: t, ...n }) {
|
|
125
|
+
let { outDir: r } = n, i = await m(T({
|
|
126
|
+
...n,
|
|
127
|
+
watch: !0,
|
|
128
|
+
onOutput: (t) => {
|
|
129
|
+
e({
|
|
130
|
+
outDir: r,
|
|
131
|
+
entryFile: p.join(r, t.entryFile),
|
|
132
|
+
files: t.files
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}));
|
|
136
|
+
return i.on("event", (e) => {
|
|
137
|
+
e.code === "ERROR" && t({
|
|
138
|
+
message: e.error.message,
|
|
139
|
+
stack: e.error.stack ?? null
|
|
140
|
+
});
|
|
141
|
+
}), { close: () => i.close() };
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/defaultBundler.mts
|
|
145
|
+
var O = {
|
|
146
|
+
watch: D,
|
|
147
|
+
build: E
|
|
148
|
+
};
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/entry.mts
|
|
151
|
+
async function k(e) {
|
|
152
|
+
let t = p.join(e, "src/main.mts");
|
|
153
|
+
if (a(t)) return t;
|
|
154
|
+
let n = p.join(e, "src/App.vue");
|
|
155
|
+
if (a(n)) return A(n, e);
|
|
156
|
+
throw Error(`no app entry found — expected ${t} or ${n}`);
|
|
157
|
+
}
|
|
158
|
+
async function A(e, t) {
|
|
159
|
+
let n = p.join(t, "node_modules/.inca");
|
|
160
|
+
await c(n, { recursive: !0 });
|
|
161
|
+
let r = p.join(n, "entry.mts"), i = JSON.stringify(e.split(p.sep).join("/"));
|
|
162
|
+
return await f(r, `import { createIncaApp } from "incajs/vue";\nimport App from ${i};\ncreateIncaApp(App).mount();\n`), r;
|
|
163
|
+
}
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/build.mts
|
|
166
|
+
async function j(e = {}) {
|
|
167
|
+
let t = e.cwd ?? process.cwd(), n = e.config ?? await x(t), r = n.outDir, i = e.bundler ?? O, a = e.entry ?? n.entry ?? await k(t);
|
|
168
|
+
return i.build({
|
|
169
|
+
entry: a,
|
|
170
|
+
outDir: r
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/dev-client/hostBin.mts
|
|
175
|
+
var M = "INCA_HOST_BIN";
|
|
176
|
+
function N() {
|
|
177
|
+
let e = process.platform === "darwin" || process.platform === "linux" ? process.platform : void 0, t = process.arch === "arm64" || process.arch === "x64" ? process.arch : void 0;
|
|
178
|
+
return e && t ? `@incajs/host-${e}-${t}` : void 0;
|
|
179
|
+
}
|
|
180
|
+
function P() {
|
|
181
|
+
let e = N();
|
|
182
|
+
if (e) try {
|
|
183
|
+
return g(import.meta.url).resolve(`${e}/bin/inca-host`);
|
|
184
|
+
} catch {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function F() {
|
|
189
|
+
let e = process.env[M];
|
|
190
|
+
if (e) return e;
|
|
191
|
+
let t = P();
|
|
192
|
+
if (t) return t;
|
|
193
|
+
let n = N(), r = n ? `no ${n} package is installed for it` : `this platform (${process.platform}/${process.arch}) has no published package`;
|
|
194
|
+
throw Error(`no inca-host binary found — ${r}, and ${M} isn't set to one`);
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/dev-client/hostError.mts
|
|
198
|
+
var I = class extends Error {
|
|
199
|
+
code;
|
|
200
|
+
hostStack;
|
|
201
|
+
constructor(e, t, n = null) {
|
|
202
|
+
super(e), this.code = t, this.hostStack = n, this.name = "HostError";
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
function L(e) {
|
|
206
|
+
return typeof e == "object" && !!e && e.jsonrpc === "2.0";
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/dev-client/hostClient.mts
|
|
210
|
+
var R = (e) => {
|
|
211
|
+
process.stderr.write(e.endsWith("\n") ? e : `${e}\n`);
|
|
212
|
+
}, z = class {
|
|
213
|
+
#e;
|
|
214
|
+
#t;
|
|
215
|
+
#n = 1;
|
|
216
|
+
#r = /* @__PURE__ */ new Map();
|
|
217
|
+
constructor(e) {
|
|
218
|
+
this.#e = e;
|
|
219
|
+
}
|
|
220
|
+
async start() {
|
|
221
|
+
let e = this.#e.hostBin ?? F(), t = _(e, ["--dev", this.#e.entryFile], { stdio: [
|
|
222
|
+
"pipe",
|
|
223
|
+
"pipe",
|
|
224
|
+
"pipe"
|
|
225
|
+
] });
|
|
226
|
+
this.#t = t;
|
|
227
|
+
let n = this.#e.onStderr ?? R;
|
|
228
|
+
t.stderr.setEncoding("utf8"), t.stderr.on("data", (e) => n(e)), y.createInterface({ input: t.stdout }).on("line", (e) => {
|
|
229
|
+
this.#i(e, n);
|
|
230
|
+
}), t.on("exit", (e, t) => {
|
|
231
|
+
let n = /* @__PURE__ */ Error(`inca-host exited (code=${String(e)}, signal=${String(t)}) before answering`);
|
|
232
|
+
for (let { reject: e } of this.#r.values()) e(n);
|
|
233
|
+
this.#r.clear();
|
|
234
|
+
}), await v(t, "spawn");
|
|
235
|
+
}
|
|
236
|
+
#i(e, t) {
|
|
237
|
+
let n;
|
|
238
|
+
try {
|
|
239
|
+
n = JSON.parse(e);
|
|
240
|
+
} catch {
|
|
241
|
+
t(`[stray stdout] ${e}`);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (!L(n)) {
|
|
245
|
+
t(`[stray stdout] ${e}`);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if ("method" in n) {
|
|
249
|
+
this.#a(n.method, n.params, t);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
let r = this.#r.get(n.id);
|
|
253
|
+
r && (this.#r.delete(n.id), "error" in n ? r.reject(new I(n.error.message, n.error.code, n.error.data?.stack ?? null)) : r.resolve(n.result));
|
|
254
|
+
}
|
|
255
|
+
#a(e, t, n) {
|
|
256
|
+
switch (e) {
|
|
257
|
+
case "ready": {
|
|
258
|
+
let { protocol: e } = t;
|
|
259
|
+
if (e !== 0) {
|
|
260
|
+
n(`inca-host speaks protocol ${String(e)}, this package was built for 0 — stopping it rather than carrying on`), this.#t && this.#o(this.#t);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
this.#e.onReady?.();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
case "appError":
|
|
267
|
+
this.#e.onAppError?.(t);
|
|
268
|
+
return;
|
|
269
|
+
default: {
|
|
270
|
+
let r = this.#e.integrations?.[e];
|
|
271
|
+
r ? r(t) : n(`[unhandled notification] ${e}`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async #o(e) {
|
|
276
|
+
let t = v(e, "exit");
|
|
277
|
+
e.kill(), await t;
|
|
278
|
+
}
|
|
279
|
+
async call(e, t) {
|
|
280
|
+
let n = this.#t;
|
|
281
|
+
if (!n) throw Error("HostClient.start() has not been called");
|
|
282
|
+
let r = this.#n++, i = JSON.stringify({
|
|
283
|
+
jsonrpc: "2.0",
|
|
284
|
+
id: r,
|
|
285
|
+
method: e,
|
|
286
|
+
params: t
|
|
287
|
+
});
|
|
288
|
+
return new Promise((e, t) => {
|
|
289
|
+
this.#r.set(r, {
|
|
290
|
+
resolve: e,
|
|
291
|
+
reject: t
|
|
292
|
+
}), n.stdin.write(`${i}\n`);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
async stop(e = 2e3) {
|
|
296
|
+
let t = this.#t;
|
|
297
|
+
if (!t || t.exitCode !== null || t.signalCode !== null) return;
|
|
298
|
+
let n = v(t, "exit");
|
|
299
|
+
this.call("shutdown").catch(() => {}), await Promise.race([n.then(() => "exited"), b(e).then(() => "timeout")]) === "timeout" && (t.kill(), await n);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region src/fault.mts
|
|
304
|
+
function B(e) {
|
|
305
|
+
return e instanceof I ? {
|
|
306
|
+
message: e.message,
|
|
307
|
+
stack: e.hostStack
|
|
308
|
+
} : e instanceof Error ? {
|
|
309
|
+
message: e.message,
|
|
310
|
+
stack: e.stack ?? null
|
|
311
|
+
} : {
|
|
312
|
+
message: String(e),
|
|
313
|
+
stack: null
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function V(e, t, n) {
|
|
317
|
+
e.write(`[inca] ${t}: ${n.message}\n`), n.stack && e.write(`${n.stack}\n`);
|
|
318
|
+
}
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/dev.mts
|
|
321
|
+
async function H(e, t) {
|
|
322
|
+
let n = new Set(t), r;
|
|
323
|
+
try {
|
|
324
|
+
r = await u(e, {
|
|
325
|
+
recursive: !0,
|
|
326
|
+
withFileTypes: !0
|
|
327
|
+
});
|
|
328
|
+
} catch {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
await Promise.all(r.filter((e) => e.isFile()).map((t) => p.relative(e, p.join(t.parentPath, t.name))).filter((e) => !n.has(e)).map((t) => d(p.join(e, t), { force: !0 })));
|
|
332
|
+
}
|
|
333
|
+
async function U(e) {
|
|
334
|
+
let t = e.cwd ?? process.cwd(), n = await x(t), r = n.outDir, i = e.bundler ?? O, a = e.stdout ?? process.stdout, o = e.stderr ?? process.stderr, s = e.entry ?? n.entry ?? await k(t), c, l = !1, u = !1, d = Promise.resolve();
|
|
335
|
+
async function f() {
|
|
336
|
+
try {
|
|
337
|
+
await c?.call("reload");
|
|
338
|
+
} catch (e) {
|
|
339
|
+
V(o, "reload failed", B(e));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
async function p(t) {
|
|
343
|
+
if (await H(t.outDir, t.files), !c) {
|
|
344
|
+
let n = new z({
|
|
345
|
+
entryFile: t.entryFile,
|
|
346
|
+
hostBin: e.hostBin,
|
|
347
|
+
onStderr: (e) => o.write(e),
|
|
348
|
+
onReady: () => {
|
|
349
|
+
l = !0, a.write("[inca] ready\n"), u && (u = !1, f());
|
|
350
|
+
},
|
|
351
|
+
onAppError: (e) => V(o, "app error", e)
|
|
352
|
+
});
|
|
353
|
+
try {
|
|
354
|
+
await n.start();
|
|
355
|
+
} catch (e) {
|
|
356
|
+
V(o, "failed to start inca-host", B(e));
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
c = n;
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (!l) {
|
|
363
|
+
u = !0;
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
await f();
|
|
367
|
+
}
|
|
368
|
+
let m = await i.watch({
|
|
369
|
+
entry: s,
|
|
370
|
+
outDir: r,
|
|
371
|
+
mode: "development",
|
|
372
|
+
onBuild: (e) => {
|
|
373
|
+
d = d.then(() => p(e));
|
|
374
|
+
},
|
|
375
|
+
onError: (e) => {
|
|
376
|
+
V(o, "build failed", e);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
await new Promise((t) => {
|
|
380
|
+
if (e.signal.aborted) {
|
|
381
|
+
t();
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
e.signal.addEventListener("abort", () => t(), { once: !0 });
|
|
385
|
+
}), await d, await c?.stop(), await m.close();
|
|
386
|
+
}
|
|
387
|
+
//#endregion
|
|
388
|
+
//#region src/plist.mts
|
|
389
|
+
function W(e) {
|
|
390
|
+
return e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
391
|
+
}
|
|
392
|
+
function G(e) {
|
|
393
|
+
return typeof e == "boolean" ? e ? "<true/>" : "<false/>" : `<string>${W(e)}</string>`;
|
|
394
|
+
}
|
|
395
|
+
function K(e) {
|
|
396
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
397
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
398
|
+
<plist version="1.0">
|
|
399
|
+
<dict>
|
|
400
|
+
${Object.entries(e).map(([e, t]) => `\t<key>${W(e)}</key>\n\t${G(t)}`).join("\n")}\n</dict>
|
|
401
|
+
</plist>
|
|
402
|
+
`;
|
|
403
|
+
}
|
|
404
|
+
//#endregion
|
|
405
|
+
//#region src/package.mts
|
|
406
|
+
function q() {
|
|
407
|
+
if (process.platform === "darwin") return "macos";
|
|
408
|
+
if (process.platform === "linux") return "linux";
|
|
409
|
+
throw Error(`inca package doesn't support ${process.platform} yet`);
|
|
410
|
+
}
|
|
411
|
+
async function J(e, t) {
|
|
412
|
+
await Promise.all(e.files.map(async (n) => {
|
|
413
|
+
let r = p.join(t, n);
|
|
414
|
+
await c(p.dirname(r), { recursive: !0 }), await s(p.join(e.outDir, n), r);
|
|
415
|
+
}));
|
|
416
|
+
}
|
|
417
|
+
async function Y({ metadata: e, output: t, hostBin: n }) {
|
|
418
|
+
let r = p.join(t.outDir, `${e.productName}.app`);
|
|
419
|
+
await d(r, {
|
|
420
|
+
recursive: !0,
|
|
421
|
+
force: !0
|
|
422
|
+
});
|
|
423
|
+
let i = p.join(r, "Contents"), a = p.join(i, "MacOS"), l = p.join(i, "Resources");
|
|
424
|
+
await c(a, { recursive: !0 }), await c(l, { recursive: !0 });
|
|
425
|
+
let u = p.join(a, e.productName);
|
|
426
|
+
await s(n, u), await o(u, 493), await J(t, l);
|
|
427
|
+
let m = {
|
|
428
|
+
CFBundleName: e.productName,
|
|
429
|
+
CFBundleDisplayName: e.productName,
|
|
430
|
+
CFBundleExecutable: e.productName,
|
|
431
|
+
CFBundleIdentifier: e.identifier,
|
|
432
|
+
CFBundleVersion: e.version,
|
|
433
|
+
CFBundleShortVersionString: e.version,
|
|
434
|
+
CFBundlePackageType: "APPL",
|
|
435
|
+
CFBundleInfoDictionaryVersion: "6.0",
|
|
436
|
+
NSHighResolutionCapable: !0
|
|
437
|
+
};
|
|
438
|
+
if (e.icon) {
|
|
439
|
+
let t = p.basename(e.icon);
|
|
440
|
+
await s(e.icon, p.join(l, t)), m.CFBundleIconFile = t;
|
|
441
|
+
}
|
|
442
|
+
return await f(p.join(i, "Info.plist"), K(m)), await f(p.join(i, "PkgInfo"), "APPL????"), r;
|
|
443
|
+
}
|
|
444
|
+
async function X({ metadata: t, output: n, hostBin: r }) {
|
|
445
|
+
let i = e(t.productName), a = p.join(n.outDir, i);
|
|
446
|
+
await d(a, {
|
|
447
|
+
recursive: !0,
|
|
448
|
+
force: !0
|
|
449
|
+
}), await c(a, { recursive: !0 });
|
|
450
|
+
let l = p.join(a, i);
|
|
451
|
+
return await s(r, l), await o(l, 493), await J(n, a), a;
|
|
452
|
+
}
|
|
453
|
+
async function Z(e = {}) {
|
|
454
|
+
let t = e.cwd ?? process.cwd(), n = e.stdout ?? process.stdout, r = e.target ?? q(), i = await S(t);
|
|
455
|
+
i.usedPackageJsonKey && n.write("[inca] the \"inca\" key in package.json is deprecated — move these settings to inca.config.ts\n"), i.identifierIsDefault && n.write(`[inca] no "identifier" set in inca.config.ts — using generated identifier ${i.identifier}\n`);
|
|
456
|
+
let o = await j({
|
|
457
|
+
cwd: t,
|
|
458
|
+
entry: e.entry,
|
|
459
|
+
config: i,
|
|
460
|
+
bundler: e.bundler
|
|
461
|
+
}), s = e.hostBin ?? F();
|
|
462
|
+
if (!a(s)) throw Error(`no host binary at ${s} — check that it was built and is executable`);
|
|
463
|
+
let c = {
|
|
464
|
+
metadata: i,
|
|
465
|
+
output: o,
|
|
466
|
+
hostBin: s
|
|
467
|
+
};
|
|
468
|
+
return { appPath: r === "macos" ? await Y(c) : await X(c) };
|
|
469
|
+
}
|
|
470
|
+
//#endregion
|
|
471
|
+
//#region src/cli.mts
|
|
472
|
+
var Q = "Usage: inca <dev|build|package>";
|
|
473
|
+
async function $(e = process.argv) {
|
|
474
|
+
let t = e[2];
|
|
475
|
+
if (t === "build") {
|
|
476
|
+
try {
|
|
477
|
+
let e = await j();
|
|
478
|
+
process.stdout.write(`[inca] built ${e.entryFile}\n`);
|
|
479
|
+
} catch (e) {
|
|
480
|
+
V(process.stderr, "build failed", B(e)), process.exitCode = 1;
|
|
481
|
+
}
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
if (t === "package") {
|
|
485
|
+
try {
|
|
486
|
+
let { appPath: e } = await Z();
|
|
487
|
+
process.stdout.write(`[inca] packaged ${e}\n`);
|
|
488
|
+
} catch (e) {
|
|
489
|
+
V(process.stderr, "package failed", B(e)), process.exitCode = 1;
|
|
490
|
+
}
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
if (t !== "dev") {
|
|
494
|
+
process.stderr.write(`${Q}\n`), process.exitCode = 1;
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
let n = new AbortController(), r = () => {
|
|
498
|
+
process.stderr.write("[inca] shutting down\n"), n.abort();
|
|
499
|
+
};
|
|
500
|
+
process.on("SIGINT", r), process.on("SIGTERM", r), await U({ signal: n.signal });
|
|
501
|
+
}
|
|
502
|
+
//#endregion
|
|
503
|
+
export { $ as run };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { IncaConfig } from './types.mts';
|
|
2
|
+
/**
|
|
3
|
+
* The `IncaConfig` fields whose default is a fixed value rather than one
|
|
4
|
+
* derived from `package.json` or the filesystem — importable alongside
|
|
5
|
+
* `defineConfig` for an app that wants to inherit or reference them.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { defaultConfig, defineConfig } from "@incajs/cli/config";
|
|
10
|
+
*
|
|
11
|
+
* export default defineConfig({
|
|
12
|
+
* ...defaultConfig,
|
|
13
|
+
* outDir: "build",
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const defaultConfig: Required<Pick<IncaConfig, "outDir" | "version">>;
|
|
18
|
+
/**
|
|
19
|
+
* Strips an npm scope off a package name.
|
|
20
|
+
*
|
|
21
|
+
* @param name - a `package.json` `"name"`, e.g. `@incajs/cli` or `incajs`
|
|
22
|
+
* @returns the name with its scope removed, e.g. `cli`; an unscoped name
|
|
23
|
+
* passes through unchanged
|
|
24
|
+
*/
|
|
25
|
+
export declare function unscopedName(name: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Turns a display name into a filesystem/URL-safe slug.
|
|
28
|
+
*
|
|
29
|
+
* @param name - e.g. a `productName`
|
|
30
|
+
* @returns `name` lowercased, with runs of non-`[a-z0-9]` collapsed to a
|
|
31
|
+
* single `-` and trimmed from both ends
|
|
32
|
+
*/
|
|
33
|
+
export declare function slugify(name: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* @param pkgName - `package.json`'s own `"name"`, if it has one
|
|
36
|
+
* @returns the `productName` a plain `package.json` implies — its name with
|
|
37
|
+
* any scope stripped — or `undefined` if it has none
|
|
38
|
+
*/
|
|
39
|
+
export declare function defaultProductName(pkgName: string | undefined): string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* @param productName - the app's resolved display name
|
|
42
|
+
* @returns a generated `identifier`, e.g. `org.inca.click-counter`
|
|
43
|
+
*/
|
|
44
|
+
export declare function defaultIdentifier(productName: string): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IncaConfig } from './types.mts';
|
|
2
|
+
export { defaultConfig } from './defaults.mts';
|
|
3
|
+
export type { IncaConfig } from './types.mts';
|
|
4
|
+
/**
|
|
5
|
+
* Type-completion helper for `inca.config.ts` — an identity function at
|
|
6
|
+
* runtime, the same way `defineConfig` from `vite` or `vitest/config` works.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { defineConfig } from "@incajs/cli/config";
|
|
11
|
+
*
|
|
12
|
+
* export default defineConfig({
|
|
13
|
+
* productName: "Click Counter",
|
|
14
|
+
* identifier: "com.example.click-counter",
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const defineConfig: import('c12').DefineConfig<IncaConfig, import('c12').ConfigLayerMeta>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** `entry`/`outDir` only — what `build()`/`dev()` need, with no `package.json` requirement. */
|
|
2
|
+
export interface ResolvedBuildConfig {
|
|
3
|
+
/** Absolute path, if `inca.config.ts` set one. */
|
|
4
|
+
entry?: string;
|
|
5
|
+
/** Absolute path. */
|
|
6
|
+
outDir: string;
|
|
7
|
+
}
|
|
8
|
+
/** An app's full config, as `inca package` needs it. */
|
|
9
|
+
export interface ResolvedAppConfig extends ResolvedBuildConfig {
|
|
10
|
+
productName: string;
|
|
11
|
+
identifier: string;
|
|
12
|
+
/** True when `identifier` was generated rather than set explicitly. */
|
|
13
|
+
identifierIsDefault: boolean;
|
|
14
|
+
version: string;
|
|
15
|
+
/** Absolute path, if the app declared one. */
|
|
16
|
+
icon?: string;
|
|
17
|
+
/** package.json's `"inca"` key is deprecated; callers warn when this is true. */
|
|
18
|
+
usedPackageJsonKey: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Loads just `entry`/`outDir` from `inca.config.ts`, with derived defaults.
|
|
22
|
+
* Never touches `package.json`.
|
|
23
|
+
*
|
|
24
|
+
* @param cwd - the app's root directory
|
|
25
|
+
* @returns `entry`/`outDir`, resolved to absolute paths
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveBuildConfig(cwd: string): Promise<ResolvedBuildConfig>;
|
|
28
|
+
/**
|
|
29
|
+
* Loads an app's full config for `inca package`: `inca.config.ts` over
|
|
30
|
+
* `package.json`'s `"inca"` key over derived defaults.
|
|
31
|
+
*
|
|
32
|
+
* @param cwd - the app's root directory
|
|
33
|
+
* @returns the resolved config
|
|
34
|
+
* @throws if `package.json` is missing, has neither a `name` nor a
|
|
35
|
+
* `productName`, or an `icon` doesn't resolve to a real file
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolveAppConfig(cwd: string): Promise<ResolvedAppConfig>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An app's own `inca.config.ts` (or `.js`/`.json`), loaded by `@incajs/cli`.
|
|
3
|
+
* `package.json`'s `"inca"` key still works as a fallback, but is
|
|
4
|
+
* deprecated — this file wins where both are present.
|
|
5
|
+
*/
|
|
6
|
+
export interface IncaConfig {
|
|
7
|
+
/** Path to an icon file, resolved relative to this config file's own directory. */
|
|
8
|
+
icon?: string;
|
|
9
|
+
/**
|
|
10
|
+
* A reverse-DNS-style unique id — e.g. macOS's `CFBundleIdentifier`.
|
|
11
|
+
* @default a generated `org.inca.<slug>`
|
|
12
|
+
*/
|
|
13
|
+
identifier?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The app's display name.
|
|
16
|
+
* @default package.json's "name", with any npm scope stripped
|
|
17
|
+
*/
|
|
18
|
+
productName?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The packaged app's version.
|
|
21
|
+
* @default package.json's own "version"
|
|
22
|
+
*/
|
|
23
|
+
version?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The app's entry point.
|
|
26
|
+
* @default resolved automatically — a committed `src/main.mts`, or
|
|
27
|
+
* `src/App.vue` wrapped in a synthesized one
|
|
28
|
+
*/
|
|
29
|
+
entry?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Where a build's output is written.
|
|
32
|
+
* @default "dist"
|
|
33
|
+
*/
|
|
34
|
+
outDir?: string;
|
|
35
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Bundler } from './adapter/types.mts';
|
|
2
|
+
/**
|
|
3
|
+
* `adapter/vite` wired in as the one adapter `dev` and `build` share by
|
|
4
|
+
* default — a single place to swap bundlers, and the reason they can't
|
|
5
|
+
* drift onto different ones.
|
|
6
|
+
*/
|
|
7
|
+
export declare const defaultBundler: Bundler;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where `inca-host` itself lives: `INCA_HOST_BIN` if set, otherwise the
|
|
3
|
+
* per-platform npm package for this OS/arch (`@incajs/host-<os>-<arch>`, an
|
|
4
|
+
* `optionalDependency` of this package).
|
|
5
|
+
* @throws if neither resolves — no override is set, and either this
|
|
6
|
+
* platform has no published binary, or the optional dependency carrying
|
|
7
|
+
* it failed to install.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveHostBin(): string;
|