@incajs/cli 0.0.1 → 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/README.md +49 -91
- package/dist/build.d.mts +3 -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.js +205 -183
- 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/index.d.mts +1 -0
- package/package.json +20 -14
- package/dist/metadata.d.mts +0 -30
package/dist/cli.js
CHANGED
|
@@ -1,15 +1,64 @@
|
|
|
1
|
-
import e from "
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import
|
|
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
|
|
11
60
|
//#region src/adapter/vite/captureOutput.mts
|
|
12
|
-
function
|
|
61
|
+
function C(e) {
|
|
13
62
|
return {
|
|
14
63
|
name: "inca:capture-output",
|
|
15
64
|
writeBundle(t, n) {
|
|
@@ -24,26 +73,26 @@ function g(e) {
|
|
|
24
73
|
}
|
|
25
74
|
//#endregion
|
|
26
75
|
//#region src/adapter/vite/config.mts
|
|
27
|
-
var
|
|
28
|
-
function
|
|
76
|
+
var w = "bundle.js";
|
|
77
|
+
function T({ entry: e, outDir: t, mode: n, watch: r, onOutput: i }) {
|
|
29
78
|
return {
|
|
30
79
|
configFile: !1,
|
|
31
|
-
root:
|
|
32
|
-
mode:
|
|
80
|
+
root: p.dirname(e),
|
|
81
|
+
mode: n,
|
|
33
82
|
clearScreen: !1,
|
|
34
83
|
logLevel: "silent",
|
|
35
|
-
define: { "process.env.NODE_ENV": JSON.stringify(
|
|
36
|
-
plugins: [
|
|
84
|
+
define: { "process.env.NODE_ENV": JSON.stringify(n) },
|
|
85
|
+
plugins: [h({ template: { compilerOptions: { runtimeModuleName: "@vue/runtime-core" } } }), C(i)],
|
|
37
86
|
build: {
|
|
38
87
|
lib: {
|
|
39
|
-
entry:
|
|
88
|
+
entry: e,
|
|
40
89
|
formats: ["es"],
|
|
41
|
-
fileName: () =>
|
|
90
|
+
fileName: () => w
|
|
42
91
|
},
|
|
43
|
-
outDir:
|
|
44
|
-
emptyOutDir:
|
|
45
|
-
minify:
|
|
46
|
-
watch:
|
|
92
|
+
outDir: t,
|
|
93
|
+
emptyOutDir: n === "production",
|
|
94
|
+
minify: n === "production",
|
|
95
|
+
watch: r ? {} : void 0,
|
|
47
96
|
rolldownOptions: { output: {
|
|
48
97
|
chunkFileNames: "chunks/[name]-[hash].js",
|
|
49
98
|
assetFileNames: "assets/[name]-[hash][extname]"
|
|
@@ -53,69 +102,69 @@ function v({ entry: t, outDir: r, mode: i, watch: a, onOutput: o }) {
|
|
|
53
102
|
}
|
|
54
103
|
//#endregion
|
|
55
104
|
//#region src/adapter/vite/build.mts
|
|
56
|
-
async function
|
|
57
|
-
let
|
|
58
|
-
if (await
|
|
59
|
-
entry:
|
|
60
|
-
outDir:
|
|
105
|
+
async function E({ entry: e, outDir: t }) {
|
|
106
|
+
let n;
|
|
107
|
+
if (await m(T({
|
|
108
|
+
entry: e,
|
|
109
|
+
outDir: t,
|
|
61
110
|
mode: "production",
|
|
62
111
|
watch: !1,
|
|
63
|
-
onOutput: (
|
|
64
|
-
|
|
65
|
-
outDir:
|
|
66
|
-
entryFile:
|
|
67
|
-
files:
|
|
112
|
+
onOutput: (e) => {
|
|
113
|
+
n = {
|
|
114
|
+
outDir: t,
|
|
115
|
+
entryFile: p.join(t, e.entryFile),
|
|
116
|
+
files: e.files
|
|
68
117
|
};
|
|
69
118
|
}
|
|
70
|
-
})), !
|
|
71
|
-
return
|
|
119
|
+
})), !n) throw Error("inca: build produced no output");
|
|
120
|
+
return n;
|
|
72
121
|
}
|
|
73
122
|
//#endregion
|
|
74
123
|
//#region src/adapter/vite/watch.mts
|
|
75
|
-
async function
|
|
76
|
-
let { outDir:
|
|
77
|
-
...
|
|
124
|
+
async function D({ onBuild: e, onError: t, ...n }) {
|
|
125
|
+
let { outDir: r } = n, i = await m(T({
|
|
126
|
+
...n,
|
|
78
127
|
watch: !0,
|
|
79
128
|
onOutput: (t) => {
|
|
80
|
-
|
|
81
|
-
outDir:
|
|
82
|
-
entryFile:
|
|
129
|
+
e({
|
|
130
|
+
outDir: r,
|
|
131
|
+
entryFile: p.join(r, t.entryFile),
|
|
83
132
|
files: t.files
|
|
84
133
|
});
|
|
85
134
|
}
|
|
86
135
|
}));
|
|
87
|
-
return
|
|
88
|
-
e.code === "ERROR" &&
|
|
136
|
+
return i.on("event", (e) => {
|
|
137
|
+
e.code === "ERROR" && t({
|
|
89
138
|
message: e.error.message,
|
|
90
139
|
stack: e.error.stack ?? null
|
|
91
140
|
});
|
|
92
|
-
}), { close: () =>
|
|
141
|
+
}), { close: () => i.close() };
|
|
93
142
|
}
|
|
94
143
|
//#endregion
|
|
95
144
|
//#region src/defaultBundler.mts
|
|
96
|
-
var
|
|
97
|
-
watch:
|
|
98
|
-
build:
|
|
145
|
+
var O = {
|
|
146
|
+
watch: D,
|
|
147
|
+
build: E
|
|
99
148
|
};
|
|
100
149
|
//#endregion
|
|
101
150
|
//#region src/entry.mts
|
|
102
|
-
async function
|
|
103
|
-
let
|
|
104
|
-
if (
|
|
105
|
-
let
|
|
106
|
-
if (
|
|
107
|
-
throw Error(`no app entry found — expected ${
|
|
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}`);
|
|
108
157
|
}
|
|
109
|
-
async function
|
|
110
|
-
let
|
|
111
|
-
await
|
|
112
|
-
let
|
|
113
|
-
return await
|
|
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;
|
|
114
163
|
}
|
|
115
164
|
//#endregion
|
|
116
165
|
//#region src/build.mts
|
|
117
|
-
async function
|
|
118
|
-
let
|
|
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);
|
|
119
168
|
return i.build({
|
|
120
169
|
entry: a,
|
|
121
170
|
outDir: r
|
|
@@ -123,44 +172,44 @@ async function w(t = {}) {
|
|
|
123
172
|
}
|
|
124
173
|
//#endregion
|
|
125
174
|
//#region src/dev-client/hostBin.mts
|
|
126
|
-
var
|
|
127
|
-
function
|
|
175
|
+
var M = "INCA_HOST_BIN";
|
|
176
|
+
function N() {
|
|
128
177
|
let e = process.platform === "darwin" || process.platform === "linux" ? process.platform : void 0, t = process.arch === "arm64" || process.arch === "x64" ? process.arch : void 0;
|
|
129
178
|
return e && t ? `@incajs/host-${e}-${t}` : void 0;
|
|
130
179
|
}
|
|
131
|
-
function
|
|
132
|
-
let e =
|
|
180
|
+
function P() {
|
|
181
|
+
let e = N();
|
|
133
182
|
if (e) try {
|
|
134
|
-
return
|
|
183
|
+
return g(import.meta.url).resolve(`${e}/bin/inca-host`);
|
|
135
184
|
} catch {
|
|
136
185
|
return;
|
|
137
186
|
}
|
|
138
187
|
}
|
|
139
|
-
function
|
|
140
|
-
let e = process.env[
|
|
188
|
+
function F() {
|
|
189
|
+
let e = process.env[M];
|
|
141
190
|
if (e) return e;
|
|
142
|
-
let t =
|
|
191
|
+
let t = P();
|
|
143
192
|
if (t) return t;
|
|
144
|
-
let n =
|
|
145
|
-
throw Error(`no inca-host binary found — ${r}, and ${
|
|
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`);
|
|
146
195
|
}
|
|
147
196
|
//#endregion
|
|
148
197
|
//#region src/dev-client/hostError.mts
|
|
149
|
-
var
|
|
198
|
+
var I = class extends Error {
|
|
150
199
|
code;
|
|
151
200
|
hostStack;
|
|
152
201
|
constructor(e, t, n = null) {
|
|
153
202
|
super(e), this.code = t, this.hostStack = n, this.name = "HostError";
|
|
154
203
|
}
|
|
155
204
|
};
|
|
156
|
-
function
|
|
205
|
+
function L(e) {
|
|
157
206
|
return typeof e == "object" && !!e && e.jsonrpc === "2.0";
|
|
158
207
|
}
|
|
159
208
|
//#endregion
|
|
160
209
|
//#region src/dev-client/hostClient.mts
|
|
161
|
-
var
|
|
210
|
+
var R = (e) => {
|
|
162
211
|
process.stderr.write(e.endsWith("\n") ? e : `${e}\n`);
|
|
163
|
-
},
|
|
212
|
+
}, z = class {
|
|
164
213
|
#e;
|
|
165
214
|
#t;
|
|
166
215
|
#n = 1;
|
|
@@ -169,20 +218,20 @@ var j = (e) => {
|
|
|
169
218
|
this.#e = e;
|
|
170
219
|
}
|
|
171
220
|
async start() {
|
|
172
|
-
let e = this.#e.hostBin ??
|
|
221
|
+
let e = this.#e.hostBin ?? F(), t = _(e, ["--dev", this.#e.entryFile], { stdio: [
|
|
173
222
|
"pipe",
|
|
174
223
|
"pipe",
|
|
175
224
|
"pipe"
|
|
176
225
|
] });
|
|
177
226
|
this.#t = t;
|
|
178
|
-
let n = this.#e.onStderr ??
|
|
179
|
-
t.stderr.setEncoding("utf8"), t.stderr.on("data", (e) => n(e)),
|
|
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) => {
|
|
180
229
|
this.#i(e, n);
|
|
181
230
|
}), t.on("exit", (e, t) => {
|
|
182
231
|
let n = /* @__PURE__ */ Error(`inca-host exited (code=${String(e)}, signal=${String(t)}) before answering`);
|
|
183
232
|
for (let { reject: e } of this.#r.values()) e(n);
|
|
184
233
|
this.#r.clear();
|
|
185
|
-
}), await
|
|
234
|
+
}), await v(t, "spawn");
|
|
186
235
|
}
|
|
187
236
|
#i(e, t) {
|
|
188
237
|
let n;
|
|
@@ -192,7 +241,7 @@ var j = (e) => {
|
|
|
192
241
|
t(`[stray stdout] ${e}`);
|
|
193
242
|
return;
|
|
194
243
|
}
|
|
195
|
-
if (!
|
|
244
|
+
if (!L(n)) {
|
|
196
245
|
t(`[stray stdout] ${e}`);
|
|
197
246
|
return;
|
|
198
247
|
}
|
|
@@ -201,7 +250,7 @@ var j = (e) => {
|
|
|
201
250
|
return;
|
|
202
251
|
}
|
|
203
252
|
let r = this.#r.get(n.id);
|
|
204
|
-
r && (this.#r.delete(n.id), "error" in n ? r.reject(new
|
|
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));
|
|
205
254
|
}
|
|
206
255
|
#a(e, t, n) {
|
|
207
256
|
switch (e) {
|
|
@@ -224,7 +273,7 @@ var j = (e) => {
|
|
|
224
273
|
}
|
|
225
274
|
}
|
|
226
275
|
async #o(e) {
|
|
227
|
-
let t =
|
|
276
|
+
let t = v(e, "exit");
|
|
228
277
|
e.kill(), await t;
|
|
229
278
|
}
|
|
230
279
|
async call(e, t) {
|
|
@@ -246,14 +295,14 @@ var j = (e) => {
|
|
|
246
295
|
async stop(e = 2e3) {
|
|
247
296
|
let t = this.#t;
|
|
248
297
|
if (!t || t.exitCode !== null || t.signalCode !== null) return;
|
|
249
|
-
let n =
|
|
250
|
-
this.call("shutdown").catch(() => {}), await Promise.race([n.then(() => "exited"),
|
|
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);
|
|
251
300
|
}
|
|
252
301
|
};
|
|
253
302
|
//#endregion
|
|
254
303
|
//#region src/fault.mts
|
|
255
|
-
function
|
|
256
|
-
return e instanceof
|
|
304
|
+
function B(e) {
|
|
305
|
+
return e instanceof I ? {
|
|
257
306
|
message: e.message,
|
|
258
307
|
stack: e.hostStack
|
|
259
308
|
} : e instanceof Error ? {
|
|
@@ -264,47 +313,47 @@ function N(e) {
|
|
|
264
313
|
stack: null
|
|
265
314
|
};
|
|
266
315
|
}
|
|
267
|
-
function
|
|
316
|
+
function V(e, t, n) {
|
|
268
317
|
e.write(`[inca] ${t}: ${n.message}\n`), n.stack && e.write(`${n.stack}\n`);
|
|
269
318
|
}
|
|
270
319
|
//#endregion
|
|
271
320
|
//#region src/dev.mts
|
|
272
|
-
async function
|
|
273
|
-
let
|
|
321
|
+
async function H(e, t) {
|
|
322
|
+
let n = new Set(t), r;
|
|
274
323
|
try {
|
|
275
|
-
|
|
324
|
+
r = await u(e, {
|
|
276
325
|
recursive: !0,
|
|
277
326
|
withFileTypes: !0
|
|
278
327
|
});
|
|
279
328
|
} catch {
|
|
280
329
|
return;
|
|
281
330
|
}
|
|
282
|
-
await Promise.all(
|
|
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 })));
|
|
283
332
|
}
|
|
284
|
-
async function
|
|
285
|
-
let
|
|
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();
|
|
286
335
|
async function f() {
|
|
287
336
|
try {
|
|
288
337
|
await c?.call("reload");
|
|
289
338
|
} catch (e) {
|
|
290
|
-
|
|
339
|
+
V(o, "reload failed", B(e));
|
|
291
340
|
}
|
|
292
341
|
}
|
|
293
|
-
async function p(
|
|
294
|
-
if (await
|
|
295
|
-
let n = new
|
|
296
|
-
entryFile:
|
|
297
|
-
hostBin:
|
|
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,
|
|
298
347
|
onStderr: (e) => o.write(e),
|
|
299
348
|
onReady: () => {
|
|
300
349
|
l = !0, a.write("[inca] ready\n"), u && (u = !1, f());
|
|
301
350
|
},
|
|
302
|
-
onAppError: (e) =>
|
|
351
|
+
onAppError: (e) => V(o, "app error", e)
|
|
303
352
|
});
|
|
304
353
|
try {
|
|
305
354
|
await n.start();
|
|
306
355
|
} catch (e) {
|
|
307
|
-
|
|
356
|
+
V(o, "failed to start inca-host", B(e));
|
|
308
357
|
return;
|
|
309
358
|
}
|
|
310
359
|
c = n;
|
|
@@ -324,158 +373,131 @@ async function I(t) {
|
|
|
324
373
|
d = d.then(() => p(e));
|
|
325
374
|
},
|
|
326
375
|
onError: (e) => {
|
|
327
|
-
|
|
376
|
+
V(o, "build failed", e);
|
|
328
377
|
}
|
|
329
378
|
});
|
|
330
|
-
await new Promise((
|
|
331
|
-
if (
|
|
332
|
-
|
|
379
|
+
await new Promise((t) => {
|
|
380
|
+
if (e.signal.aborted) {
|
|
381
|
+
t();
|
|
333
382
|
return;
|
|
334
383
|
}
|
|
335
|
-
|
|
384
|
+
e.signal.addEventListener("abort", () => t(), { once: !0 });
|
|
336
385
|
}), await d, await c?.stop(), await m.close();
|
|
337
386
|
}
|
|
338
387
|
//#endregion
|
|
339
|
-
//#region src/metadata.mts
|
|
340
|
-
function L(e) {
|
|
341
|
-
let t = e.indexOf("/");
|
|
342
|
-
return e.startsWith("@") && t !== -1 ? e.slice(t + 1) : e;
|
|
343
|
-
}
|
|
344
|
-
function R(e) {
|
|
345
|
-
return e.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
346
|
-
}
|
|
347
|
-
async function z(t) {
|
|
348
|
-
let n = e.join(t, "package.json"), i;
|
|
349
|
-
try {
|
|
350
|
-
i = await s(n, "utf8");
|
|
351
|
-
} catch {
|
|
352
|
-
throw Error(`no package.json found at ${n}`);
|
|
353
|
-
}
|
|
354
|
-
let a = JSON.parse(i), o = a.inca ?? {}, c = o.productName ?? (a.name ? L(a.name) : void 0);
|
|
355
|
-
if (!c) throw Error(`${n} needs a "name", or "inca": { "productName" }`);
|
|
356
|
-
let l = a.version ?? "0.0.0", u = o.identifier ?? `org.inca.${R(c)}`, d;
|
|
357
|
-
if (o.icon && (d = e.resolve(t, o.icon), !r(d))) throw Error(`"inca.icon" points to ${d}, which doesn't exist`);
|
|
358
|
-
return {
|
|
359
|
-
productName: c,
|
|
360
|
-
identifier: u,
|
|
361
|
-
identifierIsDefault: o.identifier === void 0,
|
|
362
|
-
version: l,
|
|
363
|
-
icon: d
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
//#endregion
|
|
367
388
|
//#region src/plist.mts
|
|
368
|
-
function
|
|
389
|
+
function W(e) {
|
|
369
390
|
return e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
370
391
|
}
|
|
371
|
-
function
|
|
372
|
-
return typeof e == "boolean" ? e ? "<true/>" : "<false/>" : `<string>${
|
|
392
|
+
function G(e) {
|
|
393
|
+
return typeof e == "boolean" ? e ? "<true/>" : "<false/>" : `<string>${W(e)}</string>`;
|
|
373
394
|
}
|
|
374
|
-
function
|
|
395
|
+
function K(e) {
|
|
375
396
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
376
397
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
377
398
|
<plist version="1.0">
|
|
378
399
|
<dict>
|
|
379
|
-
${Object.entries(e).map(([e, t]) => `\t<key>${
|
|
400
|
+
${Object.entries(e).map(([e, t]) => `\t<key>${W(e)}</key>\n\t${G(t)}`).join("\n")}\n</dict>
|
|
380
401
|
</plist>
|
|
381
402
|
`;
|
|
382
403
|
}
|
|
383
404
|
//#endregion
|
|
384
405
|
//#region src/package.mts
|
|
385
|
-
function
|
|
406
|
+
function q() {
|
|
386
407
|
if (process.platform === "darwin") return "macos";
|
|
387
408
|
if (process.platform === "linux") return "linux";
|
|
388
409
|
throw Error(`inca package doesn't support ${process.platform} yet`);
|
|
389
410
|
}
|
|
390
|
-
async function
|
|
391
|
-
await Promise.all(
|
|
392
|
-
let
|
|
393
|
-
await
|
|
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);
|
|
394
415
|
}));
|
|
395
416
|
}
|
|
396
|
-
async function
|
|
397
|
-
let
|
|
398
|
-
await
|
|
417
|
+
async function Y({ metadata: e, output: t, hostBin: n }) {
|
|
418
|
+
let r = p.join(t.outDir, `${e.productName}.app`);
|
|
419
|
+
await d(r, {
|
|
399
420
|
recursive: !0,
|
|
400
421
|
force: !0
|
|
401
422
|
});
|
|
402
|
-
let
|
|
403
|
-
await
|
|
404
|
-
let
|
|
405
|
-
await
|
|
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);
|
|
406
427
|
let m = {
|
|
407
|
-
CFBundleName:
|
|
408
|
-
CFBundleDisplayName:
|
|
409
|
-
CFBundleExecutable:
|
|
410
|
-
CFBundleIdentifier:
|
|
411
|
-
CFBundleVersion:
|
|
412
|
-
CFBundleShortVersionString:
|
|
428
|
+
CFBundleName: e.productName,
|
|
429
|
+
CFBundleDisplayName: e.productName,
|
|
430
|
+
CFBundleExecutable: e.productName,
|
|
431
|
+
CFBundleIdentifier: e.identifier,
|
|
432
|
+
CFBundleVersion: e.version,
|
|
433
|
+
CFBundleShortVersionString: e.version,
|
|
413
434
|
CFBundlePackageType: "APPL",
|
|
414
435
|
CFBundleInfoDictionaryVersion: "6.0",
|
|
415
436
|
NSHighResolutionCapable: !0
|
|
416
437
|
};
|
|
417
|
-
if (
|
|
418
|
-
let
|
|
419
|
-
await
|
|
438
|
+
if (e.icon) {
|
|
439
|
+
let t = p.basename(e.icon);
|
|
440
|
+
await s(e.icon, p.join(l, t)), m.CFBundleIconFile = t;
|
|
420
441
|
}
|
|
421
|
-
return await
|
|
442
|
+
return await f(p.join(i, "Info.plist"), K(m)), await f(p.join(i, "PkgInfo"), "APPL????"), r;
|
|
422
443
|
}
|
|
423
|
-
async function
|
|
424
|
-
let
|
|
425
|
-
await
|
|
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, {
|
|
426
447
|
recursive: !0,
|
|
427
448
|
force: !0
|
|
428
|
-
}), await
|
|
429
|
-
let
|
|
430
|
-
return await
|
|
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;
|
|
431
452
|
}
|
|
432
|
-
async function
|
|
433
|
-
let t = e.cwd ?? process.cwd(), n = e.stdout ?? process.stdout,
|
|
434
|
-
|
|
435
|
-
let o = await
|
|
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({
|
|
436
457
|
cwd: t,
|
|
437
458
|
entry: e.entry,
|
|
459
|
+
config: i,
|
|
438
460
|
bundler: e.bundler
|
|
439
|
-
}), s = e.hostBin ??
|
|
440
|
-
if (!
|
|
461
|
+
}), s = e.hostBin ?? F();
|
|
462
|
+
if (!a(s)) throw Error(`no host binary at ${s} — check that it was built and is executable`);
|
|
441
463
|
let c = {
|
|
442
|
-
metadata:
|
|
464
|
+
metadata: i,
|
|
443
465
|
output: o,
|
|
444
466
|
hostBin: s
|
|
445
467
|
};
|
|
446
|
-
return { appPath:
|
|
468
|
+
return { appPath: r === "macos" ? await Y(c) : await X(c) };
|
|
447
469
|
}
|
|
448
470
|
//#endregion
|
|
449
471
|
//#region src/cli.mts
|
|
450
|
-
var
|
|
451
|
-
async function
|
|
472
|
+
var Q = "Usage: inca <dev|build|package>";
|
|
473
|
+
async function $(e = process.argv) {
|
|
452
474
|
let t = e[2];
|
|
453
475
|
if (t === "build") {
|
|
454
476
|
try {
|
|
455
|
-
let e = await
|
|
477
|
+
let e = await j();
|
|
456
478
|
process.stdout.write(`[inca] built ${e.entryFile}\n`);
|
|
457
479
|
} catch (e) {
|
|
458
|
-
|
|
480
|
+
V(process.stderr, "build failed", B(e)), process.exitCode = 1;
|
|
459
481
|
}
|
|
460
482
|
return;
|
|
461
483
|
}
|
|
462
484
|
if (t === "package") {
|
|
463
485
|
try {
|
|
464
|
-
let { appPath: e } = await
|
|
486
|
+
let { appPath: e } = await Z();
|
|
465
487
|
process.stdout.write(`[inca] packaged ${e}\n`);
|
|
466
488
|
} catch (e) {
|
|
467
|
-
|
|
489
|
+
V(process.stderr, "package failed", B(e)), process.exitCode = 1;
|
|
468
490
|
}
|
|
469
491
|
return;
|
|
470
492
|
}
|
|
471
493
|
if (t !== "dev") {
|
|
472
|
-
process.stderr.write(`${
|
|
494
|
+
process.stderr.write(`${Q}\n`), process.exitCode = 1;
|
|
473
495
|
return;
|
|
474
496
|
}
|
|
475
497
|
let n = new AbortController(), r = () => {
|
|
476
498
|
process.stderr.write("[inca] shutting down\n"), n.abort();
|
|
477
499
|
};
|
|
478
|
-
process.on("SIGINT", r), process.on("SIGTERM", r), await
|
|
500
|
+
process.on("SIGINT", r), process.on("SIGTERM", r), await U({ signal: n.signal });
|
|
479
501
|
}
|
|
480
502
|
//#endregion
|
|
481
|
-
export {
|
|
503
|
+
export { $ as run };
|