@incajs/cli 0.0.2 → 0.0.3
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/dist/adapter/types.d.mts +26 -0
- package/dist/adapter/vite/build.d.mts +1 -1
- package/dist/adapter/vite/config.d.mts +7 -1
- package/dist/adapter/vite/logger.d.mts +7 -0
- package/dist/adapter/vite/unsupported.d.mts +23 -0
- package/dist/adapter/vite/watch.d.mts +1 -1
- package/dist/build.d.mts +4 -0
- package/dist/chunks/{defaults-EWjAFeZ3.js → defaults-D_1rymg4.js} +95 -95
- package/dist/chunks/{dist-BVKUE9C4.js → dist-DZ5asakr.js} +1 -1
- package/dist/cli.js +368 -212
- package/dist/config.js +1 -1
- package/dist/dev-client/hostClient.d.mts +5 -0
- package/dist/dev-lock.d.mts +10 -0
- package/dist/dev.d.mts +4 -1
- package/dist/error.d.mts +11 -0
- package/dist/log.d.mts +28 -0
- package/dist/package.d.mts +3 -1
- package/package.json +4 -4
- package/dist/fault.d.mts +0 -6
package/dist/cli.js
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
import { i as e, n as t, o as n, r, t as i } from "./chunks/defaults-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import p from "node:
|
|
5
|
-
import {
|
|
6
|
-
import h from "
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import y from "node:
|
|
11
|
-
import
|
|
1
|
+
import { i as e, n as t, o as n, r, t as i } from "./chunks/defaults-D_1rymg4.js";
|
|
2
|
+
import a from "node:path";
|
|
3
|
+
import { existsSync as o } from "node:fs";
|
|
4
|
+
import { chmod as s, cp as c, mkdir as l, readFile as u, readdir as d, rm as f, writeFile as p } from "node:fs/promises";
|
|
5
|
+
import { styleText as m } from "node:util";
|
|
6
|
+
import { build as h } from "vite";
|
|
7
|
+
import g from "@vitejs/plugin-vue";
|
|
8
|
+
import { createRequire as _ } from "node:module";
|
|
9
|
+
import { spawn as v } from "node:child_process";
|
|
10
|
+
import { once as y } from "node:events";
|
|
11
|
+
import b from "node:readline";
|
|
12
|
+
import { setTimeout as x } from "node:timers/promises";
|
|
13
|
+
//#region src/error.mts
|
|
14
|
+
var S = class extends Error {
|
|
15
|
+
code;
|
|
16
|
+
name = "IncaError";
|
|
17
|
+
constructor(e, t) {
|
|
18
|
+
super(t), this.code = e;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
12
22
|
//#region src/config/loader.mts
|
|
13
|
-
async function
|
|
23
|
+
async function C(e) {
|
|
14
24
|
let { config: t } = await n({
|
|
15
25
|
cwd: e,
|
|
16
26
|
name: "inca",
|
|
@@ -21,18 +31,18 @@ async function x(e) {
|
|
|
21
31
|
extend: !1
|
|
22
32
|
});
|
|
23
33
|
return {
|
|
24
|
-
entry: t.entry ?
|
|
25
|
-
outDir:
|
|
34
|
+
entry: t.entry ? a.resolve(e, t.entry) : void 0,
|
|
35
|
+
outDir: a.resolve(e, t.outDir ?? i.outDir)
|
|
26
36
|
};
|
|
27
37
|
}
|
|
28
|
-
async function
|
|
29
|
-
let
|
|
38
|
+
async function ee(e) {
|
|
39
|
+
let s = a.join(e, "package.json"), c;
|
|
30
40
|
try {
|
|
31
|
-
|
|
41
|
+
c = await u(s, "utf8");
|
|
32
42
|
} catch {
|
|
33
|
-
throw
|
|
43
|
+
throw new S("ERR_INCA_PACKAGE_JSON_NOT_FOUND", `no package.json found at ${s}`);
|
|
34
44
|
}
|
|
35
|
-
let
|
|
45
|
+
let l = JSON.parse(c), { config: d, layers: f } = await n({
|
|
36
46
|
cwd: e,
|
|
37
47
|
name: "inca",
|
|
38
48
|
packageJson: "inca",
|
|
@@ -40,15 +50,15 @@ async function S(e) {
|
|
|
40
50
|
globalRc: !1,
|
|
41
51
|
giget: !1,
|
|
42
52
|
extend: !1
|
|
43
|
-
}),
|
|
44
|
-
if (!h) throw
|
|
45
|
-
let g =
|
|
46
|
-
if (
|
|
47
|
-
let y =
|
|
53
|
+
}), p = f?.find((e) => e.configFile === "package.json"), m = Object.keys(p?.config ?? {}).length > 0, h = d.productName ?? r(l.name);
|
|
54
|
+
if (!h) throw new S("ERR_INCA_PRODUCT_NAME_MISSING", `${s} needs a "name", or "productName" in inca.config.ts`);
|
|
55
|
+
let g = d.version ?? l.version ?? i.version, _ = d.identifier ?? t(h), v;
|
|
56
|
+
if (d.icon && (v = a.resolve(e, d.icon), !o(v))) throw new S("ERR_INCA_ICON_NOT_FOUND", `"icon" points to ${v}, which doesn't exist`);
|
|
57
|
+
let y = d.entry ? a.resolve(e, d.entry) : void 0, b = a.resolve(e, d.outDir ?? i.outDir);
|
|
48
58
|
return {
|
|
49
59
|
productName: h,
|
|
50
60
|
identifier: _,
|
|
51
|
-
identifierIsDefault:
|
|
61
|
+
identifierIsDefault: d.identifier === void 0,
|
|
52
62
|
version: g,
|
|
53
63
|
icon: v,
|
|
54
64
|
entry: y,
|
|
@@ -58,12 +68,12 @@ async function S(e) {
|
|
|
58
68
|
}
|
|
59
69
|
//#endregion
|
|
60
70
|
//#region src/adapter/vite/captureOutput.mts
|
|
61
|
-
function
|
|
71
|
+
function te(e) {
|
|
62
72
|
return {
|
|
63
73
|
name: "inca:capture-output",
|
|
64
74
|
writeBundle(t, n) {
|
|
65
75
|
let r = Object.keys(n), i = Object.values(n).find((e) => e.type === "chunk" && e.isEntry);
|
|
66
|
-
if (!i) throw
|
|
76
|
+
if (!i) throw new S("ERR_INCA_BUILD_NO_ENTRY_CHUNK", "build produced no entry chunk");
|
|
67
77
|
e({
|
|
68
78
|
entryFile: i.fileName,
|
|
69
79
|
files: r
|
|
@@ -72,22 +82,77 @@ function C(e) {
|
|
|
72
82
|
};
|
|
73
83
|
}
|
|
74
84
|
//#endregion
|
|
85
|
+
//#region src/adapter/vite/logger.mts
|
|
86
|
+
var ne = "Build failed with ";
|
|
87
|
+
function re(e, t) {
|
|
88
|
+
let n = /* @__PURE__ */ new WeakSet(), r = /* @__PURE__ */ new Set(), i = {
|
|
89
|
+
hasWarned: !1,
|
|
90
|
+
info(t) {
|
|
91
|
+
e.write(`${t}\n`);
|
|
92
|
+
},
|
|
93
|
+
warn(e) {
|
|
94
|
+
i.hasWarned = !0, t.write(`${e}\n`);
|
|
95
|
+
},
|
|
96
|
+
warnOnce(e) {
|
|
97
|
+
r.has(e) || (r.add(e), i.warn(e));
|
|
98
|
+
},
|
|
99
|
+
error(e, r) {
|
|
100
|
+
i.hasWarned = !0, r?.error && n.add(r.error), !e.includes(ne) && t.write(`${e.replace(/\n\s+at .*/g, "")}\n`);
|
|
101
|
+
},
|
|
102
|
+
clearScreen() {},
|
|
103
|
+
hasErrorLogged(e) {
|
|
104
|
+
return n.has(e);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
return i;
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/adapter/vite/unsupported.mts
|
|
111
|
+
var w = /\.(?:css|pcss|postcss|sass|scss|less|styl|stylus)(?:\?|$)/, T = [{
|
|
112
|
+
code: "ERR_INCA_UNSUPPORTED_STYLE",
|
|
113
|
+
name: "a <style> block",
|
|
114
|
+
matches: (e) => e.includes("vue&type=style"),
|
|
115
|
+
hint: "the renderer applies no stylesheet — use a :style binding instead"
|
|
116
|
+
}, {
|
|
117
|
+
code: "ERR_INCA_UNSUPPORTED_STYLESHEET",
|
|
118
|
+
name: "a stylesheet import",
|
|
119
|
+
matches: (e) => w.test(e),
|
|
120
|
+
hint: "the renderer applies no stylesheet — use a :style binding instead"
|
|
121
|
+
}];
|
|
122
|
+
function E(e = T) {
|
|
123
|
+
return {
|
|
124
|
+
name: "inca:reject-unsupported",
|
|
125
|
+
enforce: "pre",
|
|
126
|
+
transform(t, n) {
|
|
127
|
+
let r = e.find((e) => e.matches(n));
|
|
128
|
+
if (!r) return null;
|
|
129
|
+
let i = a.relative(process.cwd(), n.split("?")[0] ?? n);
|
|
130
|
+
throw new S(r.code, `${r.code}: ${i} uses ${r.name}, unsupported for now: ${r.hint}`);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
75
135
|
//#region src/adapter/vite/config.mts
|
|
76
|
-
var
|
|
77
|
-
function
|
|
136
|
+
var D = "bundle.js";
|
|
137
|
+
function O({ entry: e, outDir: t, mode: n, watch: r, onOutput: i, stdout: o, stderr: s, quiet: c }) {
|
|
78
138
|
return {
|
|
79
139
|
configFile: !1,
|
|
80
|
-
root:
|
|
140
|
+
root: a.dirname(e),
|
|
81
141
|
mode: n,
|
|
82
142
|
clearScreen: !1,
|
|
83
|
-
logLevel: "silent",
|
|
143
|
+
logLevel: c ? "silent" : "info",
|
|
144
|
+
customLogger: re(o, s),
|
|
84
145
|
define: { "process.env.NODE_ENV": JSON.stringify(n) },
|
|
85
|
-
plugins: [
|
|
146
|
+
plugins: [
|
|
147
|
+
g({ template: { compilerOptions: { runtimeModuleName: "@vue/runtime-core" } } }),
|
|
148
|
+
E(),
|
|
149
|
+
te(i)
|
|
150
|
+
],
|
|
86
151
|
build: {
|
|
87
152
|
lib: {
|
|
88
153
|
entry: e,
|
|
89
154
|
formats: ["es"],
|
|
90
|
-
fileName: () =>
|
|
155
|
+
fileName: () => D
|
|
91
156
|
},
|
|
92
157
|
outDir: t,
|
|
93
158
|
emptyOutDir: n === "production",
|
|
@@ -102,138 +167,93 @@ function T({ entry: e, outDir: t, mode: n, watch: r, onOutput: i }) {
|
|
|
102
167
|
}
|
|
103
168
|
//#endregion
|
|
104
169
|
//#region src/adapter/vite/build.mts
|
|
105
|
-
async function
|
|
106
|
-
let
|
|
107
|
-
if (await
|
|
170
|
+
async function k({ entry: e, outDir: t, stdout: n = process.stdout, stderr: r = process.stderr, quiet: i = !1 }) {
|
|
171
|
+
let o;
|
|
172
|
+
if (await h(O({
|
|
108
173
|
entry: e,
|
|
109
174
|
outDir: t,
|
|
110
175
|
mode: "production",
|
|
111
176
|
watch: !1,
|
|
177
|
+
stdout: n,
|
|
178
|
+
stderr: r,
|
|
179
|
+
quiet: i,
|
|
112
180
|
onOutput: (e) => {
|
|
113
|
-
|
|
181
|
+
o = {
|
|
114
182
|
outDir: t,
|
|
115
|
-
entryFile:
|
|
183
|
+
entryFile: a.join(t, e.entryFile),
|
|
116
184
|
files: e.files
|
|
117
185
|
};
|
|
118
186
|
}
|
|
119
|
-
})), !
|
|
120
|
-
return
|
|
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
|
-
});
|
|
187
|
+
})), !o) throw new S("ERR_INCA_BUILD_NO_OUTPUT", "build produced no output");
|
|
188
|
+
return o;
|
|
172
189
|
}
|
|
173
190
|
//#endregion
|
|
174
191
|
//#region src/dev-client/hostBin.mts
|
|
175
|
-
var
|
|
176
|
-
function
|
|
192
|
+
var A = "INCA_HOST_BIN";
|
|
193
|
+
function j() {
|
|
177
194
|
let e = process.platform === "darwin" || process.platform === "linux" ? process.platform : void 0, t = process.arch === "arm64" || process.arch === "x64" ? process.arch : void 0;
|
|
178
195
|
return e && t ? `@incajs/host-${e}-${t}` : void 0;
|
|
179
196
|
}
|
|
180
|
-
function
|
|
181
|
-
let e =
|
|
197
|
+
function M() {
|
|
198
|
+
let e = j();
|
|
182
199
|
if (e) try {
|
|
183
|
-
return
|
|
200
|
+
return _(import.meta.url).resolve(`${e}/bin/inca-host`);
|
|
184
201
|
} catch {
|
|
185
202
|
return;
|
|
186
203
|
}
|
|
187
204
|
}
|
|
188
|
-
function
|
|
189
|
-
let e = process.env[
|
|
205
|
+
function N() {
|
|
206
|
+
let e = process.env[A];
|
|
190
207
|
if (e) return e;
|
|
191
|
-
let t =
|
|
208
|
+
let t = M();
|
|
192
209
|
if (t) return t;
|
|
193
|
-
let n =
|
|
194
|
-
throw
|
|
210
|
+
let n = j();
|
|
211
|
+
throw new S("ERR_INCA_HOST_BIN_UNRESOLVED", `no inca-host binary found — ${n ? `no ${n} package is installed for it` : `this platform (${process.platform}/${process.arch}) has no published package`}, and ${A} isn't set to one`);
|
|
195
212
|
}
|
|
196
213
|
//#endregion
|
|
197
214
|
//#region src/dev-client/hostError.mts
|
|
198
|
-
var
|
|
215
|
+
var P = class extends Error {
|
|
199
216
|
code;
|
|
200
217
|
hostStack;
|
|
201
218
|
constructor(e, t, n = null) {
|
|
202
219
|
super(e), this.code = t, this.hostStack = n, this.name = "HostError";
|
|
203
220
|
}
|
|
204
221
|
};
|
|
205
|
-
function
|
|
222
|
+
function ie(e) {
|
|
206
223
|
return typeof e == "object" && !!e && e.jsonrpc === "2.0";
|
|
207
224
|
}
|
|
208
225
|
//#endregion
|
|
209
226
|
//#region src/dev-client/hostClient.mts
|
|
210
|
-
var
|
|
227
|
+
var ae = (e) => {
|
|
211
228
|
process.stderr.write(e.endsWith("\n") ? e : `${e}\n`);
|
|
212
|
-
},
|
|
229
|
+
}, oe = class {
|
|
213
230
|
#e;
|
|
214
231
|
#t;
|
|
215
232
|
#n = 1;
|
|
216
233
|
#r = /* @__PURE__ */ new Map();
|
|
234
|
+
#i = !1;
|
|
217
235
|
constructor(e) {
|
|
218
236
|
this.#e = e;
|
|
219
237
|
}
|
|
220
238
|
async start() {
|
|
221
|
-
let e = this.#e.hostBin ??
|
|
239
|
+
let e = this.#e.hostBin ?? N(), t = v(e, ["--dev", this.#e.entryFile], { stdio: [
|
|
222
240
|
"pipe",
|
|
223
241
|
"pipe",
|
|
224
242
|
"pipe"
|
|
225
243
|
] });
|
|
226
244
|
this.#t = t;
|
|
227
|
-
let n = this.#e.onStderr ??
|
|
228
|
-
t.stderr.setEncoding("utf8"), t.stderr.on("data", (e) => n(e)),
|
|
229
|
-
|
|
245
|
+
let n = this.#e.onStderr ?? ae;
|
|
246
|
+
t.stderr.setEncoding("utf8"), t.stderr.on("data", (e) => n(e)), t.stdin.on("error", (e) => {
|
|
247
|
+
e.code !== "EPIPE" && n(`inca-host stdin: ${e.message}\n`);
|
|
248
|
+
}), b.createInterface({ input: t.stdout }).on("line", (e) => {
|
|
249
|
+
this.#a(e, n);
|
|
230
250
|
}), t.on("exit", (e, t) => {
|
|
231
251
|
let n = /* @__PURE__ */ Error(`inca-host exited (code=${String(e)}, signal=${String(t)}) before answering`);
|
|
232
252
|
for (let { reject: e } of this.#r.values()) e(n);
|
|
233
|
-
this.#r.clear();
|
|
234
|
-
}), await
|
|
253
|
+
this.#r.clear(), this.#i || this.#e.onExit?.(e, t);
|
|
254
|
+
}), await y(t, "spawn");
|
|
235
255
|
}
|
|
236
|
-
#
|
|
256
|
+
#a(e, t) {
|
|
237
257
|
let n;
|
|
238
258
|
try {
|
|
239
259
|
n = JSON.parse(e);
|
|
@@ -241,23 +261,23 @@ var R = (e) => {
|
|
|
241
261
|
t(`[stray stdout] ${e}`);
|
|
242
262
|
return;
|
|
243
263
|
}
|
|
244
|
-
if (!
|
|
264
|
+
if (!ie(n)) {
|
|
245
265
|
t(`[stray stdout] ${e}`);
|
|
246
266
|
return;
|
|
247
267
|
}
|
|
248
268
|
if ("method" in n) {
|
|
249
|
-
this.#
|
|
269
|
+
this.#o(n.method, n.params, t);
|
|
250
270
|
return;
|
|
251
271
|
}
|
|
252
272
|
let r = this.#r.get(n.id);
|
|
253
|
-
r && (this.#r.delete(n.id), "error" in n ? r.reject(new
|
|
273
|
+
r && (this.#r.delete(n.id), "error" in n ? r.reject(new P(n.error.message, n.error.code, n.error.data?.stack ?? null)) : r.resolve(n.result));
|
|
254
274
|
}
|
|
255
|
-
#
|
|
275
|
+
#o(e, t, n) {
|
|
256
276
|
switch (e) {
|
|
257
277
|
case "ready": {
|
|
258
278
|
let { protocol: e } = t;
|
|
259
279
|
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.#
|
|
280
|
+
n(`inca-host speaks protocol ${String(e)}, this package was built for 0 — stopping it rather than carrying on`), this.#t && this.#s(this.#t);
|
|
261
281
|
return;
|
|
262
282
|
}
|
|
263
283
|
this.#e.onReady?.();
|
|
@@ -272,8 +292,9 @@ var R = (e) => {
|
|
|
272
292
|
}
|
|
273
293
|
}
|
|
274
294
|
}
|
|
275
|
-
async #
|
|
276
|
-
|
|
295
|
+
async #s(e) {
|
|
296
|
+
this.#i = !0;
|
|
297
|
+
let t = y(e, "exit");
|
|
277
298
|
e.kill(), await t;
|
|
278
299
|
}
|
|
279
300
|
async call(e, t) {
|
|
@@ -289,141 +310,266 @@ var R = (e) => {
|
|
|
289
310
|
this.#r.set(r, {
|
|
290
311
|
resolve: e,
|
|
291
312
|
reject: t
|
|
292
|
-
}), n.stdin.write(`${i}\n
|
|
313
|
+
}), n.stdin.write(`${i}\n`, (e) => {
|
|
314
|
+
e && (this.#r.delete(r), t(e));
|
|
315
|
+
});
|
|
293
316
|
});
|
|
294
317
|
}
|
|
295
318
|
async stop(e = 2e3) {
|
|
296
319
|
let t = this.#t;
|
|
297
320
|
if (!t || t.exitCode !== null || t.signalCode !== null) return;
|
|
298
|
-
|
|
299
|
-
|
|
321
|
+
this.#i = !0;
|
|
322
|
+
let n = y(t, "exit");
|
|
323
|
+
this.call("shutdown").catch(() => {}), await Promise.race([n.then(() => "exited"), x(e).then(() => "timeout")]) === "timeout" && (t.kill(), await n);
|
|
300
324
|
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
325
|
+
}, F = "[inca]", I = new Intl.DateTimeFormat(void 0, {
|
|
326
|
+
hour: "numeric",
|
|
327
|
+
minute: "numeric",
|
|
328
|
+
second: "numeric"
|
|
329
|
+
});
|
|
330
|
+
function L(e, t, n) {
|
|
331
|
+
let r = m(["bold", n], F, { stream: e });
|
|
332
|
+
return t.timestamp ? `${m("dim", I.format(/* @__PURE__ */ new Date()), { stream: e })} ${r}` : r;
|
|
333
|
+
}
|
|
334
|
+
function R(e, t, n = {}) {
|
|
335
|
+
e.write(`${L(e, n, "cyan")} ${t}\n`);
|
|
336
|
+
}
|
|
337
|
+
function z(e) {
|
|
338
|
+
let t = e.code;
|
|
339
|
+
return typeof t == "string" ? t : null;
|
|
340
|
+
}
|
|
304
341
|
function B(e) {
|
|
305
|
-
return e
|
|
342
|
+
return /\bERR_INCA_[A-Z0-9_]+/.exec(e)?.[0] ?? null;
|
|
343
|
+
}
|
|
344
|
+
function V(e) {
|
|
345
|
+
let t = e.stack;
|
|
346
|
+
if (!t) return null;
|
|
347
|
+
for (let n of [`${e.name}: ${e.message}`, e.message]) if (t.startsWith(n)) return t.slice(n.length).replace(/^\r?\n/, "") || null;
|
|
348
|
+
return t;
|
|
349
|
+
}
|
|
350
|
+
function H(e) {
|
|
351
|
+
let t = /^(?:\w*Error: )?(ERR_INCA_[A-Z0-9_]+): /.exec(e);
|
|
352
|
+
return t ? {
|
|
353
|
+
message: e.slice(t[0].length),
|
|
354
|
+
stack: null,
|
|
355
|
+
code: t[1]
|
|
356
|
+
} : {
|
|
357
|
+
message: e.replace(/^\w*Error: /, ""),
|
|
358
|
+
stack: null,
|
|
359
|
+
code: null
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function U(e) {
|
|
363
|
+
return e instanceof P ? {
|
|
306
364
|
message: e.message,
|
|
307
|
-
stack: e.hostStack
|
|
365
|
+
stack: e.hostStack,
|
|
366
|
+
code: z(e)
|
|
308
367
|
} : e instanceof Error ? {
|
|
309
368
|
message: e.message,
|
|
310
|
-
stack: e
|
|
369
|
+
stack: V(e),
|
|
370
|
+
code: z(e) ?? B(e.message)
|
|
311
371
|
} : {
|
|
312
372
|
message: String(e),
|
|
313
|
-
stack: null
|
|
373
|
+
stack: null,
|
|
374
|
+
code: null
|
|
314
375
|
};
|
|
315
376
|
}
|
|
316
|
-
function
|
|
317
|
-
|
|
377
|
+
function W(e, t, n, r = {}) {
|
|
378
|
+
let i = n.code ? ` (${m("bold", n.code, { stream: e })})` : "";
|
|
379
|
+
e.write(`${L(e, r, "red")} ${t}${i}: ${n.message}\n`), n.stack && e.write(`${n.stack}\n`);
|
|
380
|
+
}
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/adapter/vite/watch.mts
|
|
383
|
+
async function G({ onBuild: e, onError: t, stdout: n = process.stdout, stderr: r = process.stderr, quiet: i = !1, ...o }) {
|
|
384
|
+
let { outDir: s } = o, c, l = await h(O({
|
|
385
|
+
...o,
|
|
386
|
+
watch: !0,
|
|
387
|
+
stdout: n,
|
|
388
|
+
stderr: r,
|
|
389
|
+
quiet: i,
|
|
390
|
+
onOutput: (t) => {
|
|
391
|
+
e({
|
|
392
|
+
outDir: s,
|
|
393
|
+
entryFile: a.join(s, t.entryFile),
|
|
394
|
+
files: t.files,
|
|
395
|
+
changed: c
|
|
396
|
+
}), c = void 0;
|
|
397
|
+
}
|
|
398
|
+
}));
|
|
399
|
+
return l.on("change", (e) => {
|
|
400
|
+
c ??= {
|
|
401
|
+
file: e,
|
|
402
|
+
at: Date.now()
|
|
403
|
+
};
|
|
404
|
+
}), l.on("event", (e) => {
|
|
405
|
+
if (e.code !== "ERROR") return;
|
|
406
|
+
c = void 0;
|
|
407
|
+
let { errors: n } = e.error;
|
|
408
|
+
t(H(n?.[0]?.message ?? e.error.message));
|
|
409
|
+
}), { close: () => l.close() };
|
|
410
|
+
}
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/defaultBundler.mts
|
|
413
|
+
var K = {
|
|
414
|
+
watch: G,
|
|
415
|
+
build: k
|
|
416
|
+
};
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/entry.mts
|
|
419
|
+
async function q(e) {
|
|
420
|
+
let t = a.join(e, "src/main.mts");
|
|
421
|
+
if (o(t)) return t;
|
|
422
|
+
let n = a.join(e, "src/App.vue");
|
|
423
|
+
if (o(n)) return se(n, e);
|
|
424
|
+
throw new S("ERR_INCA_ENTRY_NOT_FOUND", `no app entry found — expected ${t} or ${n}`);
|
|
425
|
+
}
|
|
426
|
+
async function se(e, t) {
|
|
427
|
+
let n = a.join(t, "node_modules/.inca");
|
|
428
|
+
await l(n, { recursive: !0 });
|
|
429
|
+
let r = a.join(n, "entry.mts"), i = JSON.stringify(e.split(a.sep).join("/"));
|
|
430
|
+
return await p(r, `import { createIncaApp } from "incajs/vue";\nimport App from ${i};\ncreateIncaApp(App).mount();\n`), r;
|
|
431
|
+
}
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/build.mts
|
|
434
|
+
async function J(e = {}) {
|
|
435
|
+
let t = e.cwd ?? process.cwd(), n = e.config ?? await C(t), r = n.outDir, i = e.bundler ?? K, a = e.entry ?? n.entry ?? await q(t);
|
|
436
|
+
return i.build({
|
|
437
|
+
entry: a,
|
|
438
|
+
outDir: r,
|
|
439
|
+
stdout: e.stdout,
|
|
440
|
+
stderr: e.stderr
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region src/dev-lock.mts
|
|
445
|
+
function ce(e) {
|
|
446
|
+
return a.join(e, "node_modules/.inca/dev.pid");
|
|
447
|
+
}
|
|
448
|
+
function le(e) {
|
|
449
|
+
try {
|
|
450
|
+
return process.kill(e, 0), !0;
|
|
451
|
+
} catch (e) {
|
|
452
|
+
return e.code === "EPERM";
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
async function ue(e) {
|
|
456
|
+
let t = ce(e), n = Number.parseInt(await u(t, "utf8").catch(() => ""), 10);
|
|
457
|
+
if (Number.isInteger(n) && le(n)) throw new S("ERR_INCA_DEV_RUNNING", `inca dev is already running for this app (pid ${String(n)})`);
|
|
458
|
+
return await l(a.dirname(t), { recursive: !0 }), await p(t, String(process.pid)), () => f(t, { force: !0 });
|
|
318
459
|
}
|
|
319
460
|
//#endregion
|
|
320
461
|
//#region src/dev.mts
|
|
321
|
-
|
|
462
|
+
var Y = { timestamp: !0 };
|
|
463
|
+
async function de(e, t) {
|
|
322
464
|
let n = new Set(t), r;
|
|
323
465
|
try {
|
|
324
|
-
r = await
|
|
466
|
+
r = await d(e, {
|
|
325
467
|
recursive: !0,
|
|
326
468
|
withFileTypes: !0
|
|
327
469
|
});
|
|
328
470
|
} catch {
|
|
329
471
|
return;
|
|
330
472
|
}
|
|
331
|
-
await Promise.all(r.filter((e) => e.isFile()).map((t) =>
|
|
473
|
+
await Promise.all(r.filter((e) => e.isFile()).map((t) => a.relative(e, a.join(t.parentPath, t.name))).filter((e) => !n.has(e)).map((t) => f(a.join(e, t), { force: !0 })));
|
|
332
474
|
}
|
|
333
|
-
async function
|
|
334
|
-
let t = e.cwd ?? process.cwd(), n = await
|
|
335
|
-
|
|
475
|
+
async function fe(e) {
|
|
476
|
+
let t = e.cwd ?? process.cwd(), n = await C(t), r = await ue(t), i = n.outDir, o = e.bundler ?? K, s = e.stdout ?? process.stdout, c = e.stderr ?? process.stderr, l = e.entry ?? n.entry ?? await q(t), u, d = !1, f = !1, p = Promise.resolve(), h = () => {}, g = new Promise((e) => {
|
|
477
|
+
h = e;
|
|
478
|
+
});
|
|
479
|
+
async function _() {
|
|
336
480
|
try {
|
|
337
|
-
await
|
|
481
|
+
return await u?.call("reload"), !0;
|
|
338
482
|
} catch (e) {
|
|
339
|
-
|
|
483
|
+
return W(c, "reload failed", U(e), Y), !1;
|
|
340
484
|
}
|
|
341
485
|
}
|
|
342
|
-
async function
|
|
343
|
-
if (await
|
|
344
|
-
let
|
|
345
|
-
entryFile:
|
|
486
|
+
async function v(n) {
|
|
487
|
+
if (await de(n.outDir, n.files), !u) {
|
|
488
|
+
let t = new oe({
|
|
489
|
+
entryFile: n.entryFile,
|
|
346
490
|
hostBin: e.hostBin,
|
|
347
|
-
onStderr: (e) =>
|
|
491
|
+
onStderr: (e) => c.write(e),
|
|
348
492
|
onReady: () => {
|
|
349
|
-
|
|
493
|
+
d = !0, R(s, "ready", Y), f && (f = !1, _());
|
|
350
494
|
},
|
|
351
|
-
onAppError: (e) =>
|
|
495
|
+
onAppError: (e) => W(c, "app error", e, Y),
|
|
496
|
+
onExit: () => {
|
|
497
|
+
R(s, "host exited — stopping", Y), h();
|
|
498
|
+
}
|
|
352
499
|
});
|
|
353
500
|
try {
|
|
354
|
-
await
|
|
501
|
+
await t.start();
|
|
355
502
|
} catch (e) {
|
|
356
|
-
|
|
503
|
+
W(c, "failed to start inca-host", U(e), Y);
|
|
357
504
|
return;
|
|
358
505
|
}
|
|
359
|
-
|
|
506
|
+
u = t;
|
|
360
507
|
return;
|
|
361
508
|
}
|
|
362
|
-
if (!
|
|
363
|
-
|
|
509
|
+
if (!d) {
|
|
510
|
+
f = !0;
|
|
364
511
|
return;
|
|
365
512
|
}
|
|
366
|
-
await
|
|
513
|
+
if (await _() && n.changed) {
|
|
514
|
+
let e = m("dim", a.relative(t, n.changed.file), { stream: s }), r = Date.now() - n.changed.at;
|
|
515
|
+
R(s, `${m("green", "reload")} ${e} (${r}ms)`, Y);
|
|
516
|
+
}
|
|
367
517
|
}
|
|
368
|
-
let
|
|
369
|
-
entry:
|
|
370
|
-
outDir:
|
|
518
|
+
let y = await o.watch({
|
|
519
|
+
entry: l,
|
|
520
|
+
outDir: i,
|
|
371
521
|
mode: "development",
|
|
522
|
+
stdout: s,
|
|
523
|
+
stderr: c,
|
|
372
524
|
onBuild: (e) => {
|
|
373
|
-
|
|
525
|
+
p = p.then(() => v(e));
|
|
374
526
|
},
|
|
375
527
|
onError: (e) => {
|
|
376
|
-
|
|
528
|
+
W(c, "build failed", e, Y);
|
|
377
529
|
}
|
|
378
530
|
});
|
|
379
|
-
|
|
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();
|
|
531
|
+
e.signal.aborted ? h() : e.signal.addEventListener("abort", () => h(), { once: !0 }), await g, await p, await u?.stop(), await y.close(), await r();
|
|
386
532
|
}
|
|
387
533
|
//#endregion
|
|
388
534
|
//#region src/plist.mts
|
|
389
|
-
function
|
|
535
|
+
function X(e) {
|
|
390
536
|
return e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
391
537
|
}
|
|
392
|
-
function
|
|
393
|
-
return typeof e == "boolean" ? e ? "<true/>" : "<false/>" : `<string>${
|
|
538
|
+
function pe(e) {
|
|
539
|
+
return typeof e == "boolean" ? e ? "<true/>" : "<false/>" : `<string>${X(e)}</string>`;
|
|
394
540
|
}
|
|
395
|
-
function
|
|
541
|
+
function me(e) {
|
|
396
542
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
397
543
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
398
544
|
<plist version="1.0">
|
|
399
545
|
<dict>
|
|
400
|
-
${Object.entries(e).map(([e, t]) => `\t<key>${
|
|
546
|
+
${Object.entries(e).map(([e, t]) => `\t<key>${X(e)}</key>\n\t${pe(t)}`).join("\n")}\n</dict>
|
|
401
547
|
</plist>
|
|
402
548
|
`;
|
|
403
549
|
}
|
|
404
550
|
//#endregion
|
|
405
551
|
//#region src/package.mts
|
|
406
|
-
function
|
|
552
|
+
function he() {
|
|
407
553
|
if (process.platform === "darwin") return "macos";
|
|
408
554
|
if (process.platform === "linux") return "linux";
|
|
409
|
-
throw
|
|
555
|
+
throw new S("ERR_INCA_PLATFORM_UNSUPPORTED", `inca package doesn't support ${process.platform} yet`);
|
|
410
556
|
}
|
|
411
|
-
async function
|
|
557
|
+
async function Z(e, t) {
|
|
412
558
|
await Promise.all(e.files.map(async (n) => {
|
|
413
|
-
let r =
|
|
414
|
-
await
|
|
559
|
+
let r = a.join(t, n);
|
|
560
|
+
await l(a.dirname(r), { recursive: !0 }), await c(a.join(e.outDir, n), r);
|
|
415
561
|
}));
|
|
416
562
|
}
|
|
417
|
-
async function
|
|
418
|
-
let r =
|
|
419
|
-
await
|
|
563
|
+
async function Q({ metadata: e, output: t, hostBin: n }) {
|
|
564
|
+
let r = a.join(t.outDir, `${e.productName}.app`);
|
|
565
|
+
await f(r, {
|
|
420
566
|
recursive: !0,
|
|
421
567
|
force: !0
|
|
422
568
|
});
|
|
423
|
-
let i =
|
|
424
|
-
await
|
|
425
|
-
let
|
|
426
|
-
await
|
|
569
|
+
let i = a.join(r, "Contents"), o = a.join(i, "MacOS"), u = a.join(i, "Resources");
|
|
570
|
+
await l(o, { recursive: !0 }), await l(u, { recursive: !0 });
|
|
571
|
+
let d = a.join(o, e.productName);
|
|
572
|
+
await c(n, d), await s(d, 493), await Z(t, u);
|
|
427
573
|
let m = {
|
|
428
574
|
CFBundleName: e.productName,
|
|
429
575
|
CFBundleDisplayName: e.productName,
|
|
@@ -436,68 +582,78 @@ async function Y({ metadata: e, output: t, hostBin: n }) {
|
|
|
436
582
|
NSHighResolutionCapable: !0
|
|
437
583
|
};
|
|
438
584
|
if (e.icon) {
|
|
439
|
-
let t =
|
|
440
|
-
await
|
|
585
|
+
let t = a.basename(e.icon);
|
|
586
|
+
await c(e.icon, a.join(u, t)), m.CFBundleIconFile = t;
|
|
441
587
|
}
|
|
442
|
-
return await
|
|
588
|
+
return await p(a.join(i, "Info.plist"), me(m)), await p(a.join(i, "PkgInfo"), "APPL????"), r;
|
|
443
589
|
}
|
|
444
|
-
async function
|
|
445
|
-
let i = e(t.productName),
|
|
446
|
-
await
|
|
590
|
+
async function ge({ metadata: t, output: n, hostBin: r }) {
|
|
591
|
+
let i = e(t.productName), o = a.join(n.outDir, i);
|
|
592
|
+
await f(o, {
|
|
447
593
|
recursive: !0,
|
|
448
594
|
force: !0
|
|
449
|
-
}), await
|
|
450
|
-
let
|
|
451
|
-
return await
|
|
452
|
-
}
|
|
453
|
-
async function
|
|
454
|
-
let t = e.cwd ?? process.cwd(), n = e.stdout ?? process.stdout, r = e.target ??
|
|
455
|
-
i.usedPackageJsonKey && n
|
|
456
|
-
let
|
|
595
|
+
}), await l(o, { recursive: !0 });
|
|
596
|
+
let u = a.join(o, i);
|
|
597
|
+
return await c(r, u), await s(u, 493), await Z(n, o), o;
|
|
598
|
+
}
|
|
599
|
+
async function _e(e = {}) {
|
|
600
|
+
let t = e.cwd ?? process.cwd(), n = e.stdout ?? process.stdout, r = e.target ?? he(), i = await ee(t);
|
|
601
|
+
i.usedPackageJsonKey && R(n, "the \"inca\" key in package.json is deprecated — move these settings to inca.config.ts"), i.identifierIsDefault && R(n, `no "identifier" set in inca.config.ts — using generated identifier ${i.identifier}`);
|
|
602
|
+
let a = await J({
|
|
457
603
|
cwd: t,
|
|
458
604
|
entry: e.entry,
|
|
459
605
|
config: i,
|
|
460
|
-
bundler: e.bundler
|
|
461
|
-
|
|
462
|
-
|
|
606
|
+
bundler: e.bundler,
|
|
607
|
+
stdout: n,
|
|
608
|
+
stderr: e.stderr
|
|
609
|
+
}), s = e.hostBin ?? N();
|
|
610
|
+
if (!o(s)) throw new S("ERR_INCA_HOST_BIN_NOT_FOUND", `no host binary at ${s} — check that it was built and is executable`);
|
|
463
611
|
let c = {
|
|
464
612
|
metadata: i,
|
|
465
|
-
output:
|
|
613
|
+
output: a,
|
|
466
614
|
hostBin: s
|
|
467
615
|
};
|
|
468
|
-
return { appPath: r === "macos" ? await
|
|
616
|
+
return { appPath: r === "macos" ? await Q(c) : await ge(c) };
|
|
469
617
|
}
|
|
470
618
|
//#endregion
|
|
471
619
|
//#region src/cli.mts
|
|
472
|
-
var
|
|
473
|
-
|
|
620
|
+
var ve = "Usage: inca <dev|build|package>";
|
|
621
|
+
function $(e) {
|
|
622
|
+
return a.relative(process.cwd(), e);
|
|
623
|
+
}
|
|
624
|
+
async function ye(e = process.argv) {
|
|
474
625
|
let t = e[2];
|
|
475
626
|
if (t === "build") {
|
|
476
627
|
try {
|
|
477
|
-
let e = await
|
|
478
|
-
process.stdout
|
|
628
|
+
let e = await J();
|
|
629
|
+
R(process.stdout, `built ${$(e.entryFile)}`);
|
|
479
630
|
} catch (e) {
|
|
480
|
-
|
|
631
|
+
W(process.stderr, "build failed", U(e)), process.exitCode = 1;
|
|
481
632
|
}
|
|
482
633
|
return;
|
|
483
634
|
}
|
|
484
635
|
if (t === "package") {
|
|
485
636
|
try {
|
|
486
|
-
let { appPath: e } = await
|
|
487
|
-
process.stdout
|
|
637
|
+
let { appPath: e } = await _e();
|
|
638
|
+
R(process.stdout, `packaged ${$(e)}`);
|
|
488
639
|
} catch (e) {
|
|
489
|
-
|
|
640
|
+
W(process.stderr, "package failed", U(e)), process.exitCode = 1;
|
|
490
641
|
}
|
|
491
642
|
return;
|
|
492
643
|
}
|
|
493
644
|
if (t !== "dev") {
|
|
494
|
-
process.stderr.write(`${
|
|
645
|
+
process.stderr.write(`${ve}\n`), process.exitCode = 1;
|
|
495
646
|
return;
|
|
496
647
|
}
|
|
497
648
|
let n = new AbortController(), r = () => {
|
|
498
|
-
process.stderr
|
|
649
|
+
n.signal.aborted || (R(process.stderr, "shutting down", { timestamp: !0 }), n.abort());
|
|
499
650
|
};
|
|
500
|
-
process.on("SIGINT", r), process.on("SIGTERM", r)
|
|
651
|
+
process.on("SIGINT", r), process.on("SIGTERM", r);
|
|
652
|
+
try {
|
|
653
|
+
await fe({ signal: n.signal });
|
|
654
|
+
} catch (e) {
|
|
655
|
+
W(process.stderr, "dev failed", U(e), { timestamp: !0 }), process.exitCode = 1;
|
|
656
|
+
}
|
|
501
657
|
}
|
|
502
658
|
//#endregion
|
|
503
|
-
export {
|
|
659
|
+
export { ye as run };
|