@vicinae/api 0.8.3 → 0.8.4
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.
|
@@ -14,9 +14,10 @@ const View = ({ children }) => {
|
|
|
14
14
|
const NavigationProvider = ({ root }) => {
|
|
15
15
|
const [navStack, setNavStack] = (0, react_1.useState)([root]);
|
|
16
16
|
const pop = () => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
// we ask Vicinae to pop the current view, but we need to wait
|
|
18
|
+
// for the pop-view event to be fired in order to dismount it from
|
|
19
|
+
// our local view stack: otherwise Vicinae might miss a render.
|
|
20
|
+
bus_1.bus.turboRequest("ui.popView", {});
|
|
20
21
|
};
|
|
21
22
|
const push = (node) => {
|
|
22
23
|
bus_1.bus.turboRequest("ui.pushView", {}).then(() => {
|
|
@@ -67,17 +67,20 @@ class Develop extends core_1.Command {
|
|
|
67
67
|
const { flags } = await this.parse(Develop);
|
|
68
68
|
const logger = new logger_js_1.Logger();
|
|
69
69
|
const pkgPath = (0, node_path_1.join)(flags.target, "package.json");
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
const parseManifest = () => {
|
|
71
|
+
if (!(0, node_fs_1.existsSync)(pkgPath)) {
|
|
72
|
+
logger.logError(`No package.json found at ${pkgPath}. Does this location point to a valid extension repository?`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
const json = JSON.parse((0, node_fs_1.readFileSync)(pkgPath, "utf8"));
|
|
76
|
+
const e = manifest_js_1.default.safeParse(json);
|
|
77
|
+
if (e.error) {
|
|
78
|
+
logger.logError(`${pkgPath} is not a valid extension manifest: ${e.error}`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
return e.data;
|
|
82
|
+
};
|
|
83
|
+
let manifest = parseManifest();
|
|
81
84
|
const vicinae = new vicinae_js_1.VicinaeClient();
|
|
82
85
|
const typeCheck = async () => {
|
|
83
86
|
const spawned = (0, node_child_process_1.spawn)("npx", ["tsc", "--noEmit"]);
|
|
@@ -90,14 +93,17 @@ class Develop extends core_1.Command {
|
|
|
90
93
|
});
|
|
91
94
|
};
|
|
92
95
|
const build = async (outDir) => {
|
|
96
|
+
/*
|
|
93
97
|
logger.logInfo("Started type checking in background thread");
|
|
94
98
|
typeCheck().then(({ error, ok }) => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
if (!ok) {
|
|
100
|
+
logger.logInfo(`Type checking error: ${error}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
logger.logInfo("Done type checking");
|
|
99
104
|
});
|
|
100
|
-
|
|
105
|
+
*/
|
|
106
|
+
const entryPoints = manifest.commands.map((cmd) => (0, node_path_1.join)("src", `${cmd.name}.tsx`)).filter(node_fs_1.existsSync);
|
|
101
107
|
logger.logInfo(`entrypoints [${entryPoints.join(", ")}]`);
|
|
102
108
|
const promises = manifest.commands.map((cmd) => {
|
|
103
109
|
const base = (0, node_path_1.join)(process.cwd(), "src", `${cmd.name}`);
|
|
@@ -105,14 +111,14 @@ class Develop extends core_1.Command {
|
|
|
105
111
|
const tsSource = `${base}.ts`;
|
|
106
112
|
let source = tsxSource;
|
|
107
113
|
if (cmd.mode == "view" && !(0, node_fs_1.existsSync)(tsxSource)) {
|
|
108
|
-
throw new Error(`
|
|
114
|
+
throw new Error(`could not find entrypoint src/${cmd.name}.tsx for command ${cmd.name}.`);
|
|
109
115
|
}
|
|
110
116
|
// we allow .ts or .tsx for no-view
|
|
111
117
|
if (cmd.mode == "no-view") {
|
|
112
118
|
if (!(0, node_fs_1.existsSync)(tsxSource)) {
|
|
113
119
|
source = tsSource;
|
|
114
120
|
if (!(0, node_fs_1.existsSync)(tsSource)) {
|
|
115
|
-
throw new Error(`
|
|
121
|
+
throw new Error(`could not find entrypoint src/${cmd.name}.{ts,tsx} for command ${cmd.name}.`);
|
|
116
122
|
}
|
|
117
123
|
}
|
|
118
124
|
}
|
|
@@ -141,6 +147,23 @@ class Develop extends core_1.Command {
|
|
|
141
147
|
console.error(`Failed to ping vicinae\n`, pingError.message);
|
|
142
148
|
return;
|
|
143
149
|
}
|
|
150
|
+
const safeBuild = async (extensionDir) => {
|
|
151
|
+
try {
|
|
152
|
+
const start = performance.now();
|
|
153
|
+
await build(extensionDir);
|
|
154
|
+
const time = performance.now() - start;
|
|
155
|
+
logger.logReady(`Extension built in ${Math.round(time)}ms 🚀`);
|
|
156
|
+
vicinae.refreshDevSession(id);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
if (error instanceof Error) {
|
|
160
|
+
logger.logError(`Failed to build extension: ${error.message}`);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
logger.logError(`Failed to build extension: ${error}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
|
144
167
|
process.chdir(flags.target);
|
|
145
168
|
const dataDir = (0, utils_js_1.extensionDataDir)();
|
|
146
169
|
const id = `${manifest.name}`;
|
|
@@ -148,10 +171,9 @@ class Develop extends core_1.Command {
|
|
|
148
171
|
const logFile = (0, node_path_1.join)(extensionDir, "dev.log");
|
|
149
172
|
const pidFile = (0, node_path_1.join)(extensionDir, "cli.pid");
|
|
150
173
|
(0, node_fs_1.mkdirSync)(extensionDir, { recursive: true });
|
|
151
|
-
await build(extensionDir);
|
|
152
|
-
logger.logReady("built extension successfully");
|
|
153
174
|
(0, node_fs_1.writeFileSync)(pidFile, `${process.pid}`);
|
|
154
175
|
(0, node_fs_1.writeFileSync)(logFile, "");
|
|
176
|
+
await safeBuild(extensionDir);
|
|
155
177
|
process.on("SIGINT", () => {
|
|
156
178
|
logger.logInfo("Shutting down...");
|
|
157
179
|
vicinae.stopDevSession(id);
|
|
@@ -167,16 +189,12 @@ class Develop extends core_1.Command {
|
|
|
167
189
|
awaitWriteFinish: { pollInterval: 100, stabilityThreshold: 100 },
|
|
168
190
|
ignoreInitial: true,
|
|
169
191
|
})
|
|
170
|
-
.on("all", (_, path) => {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
build(extensionDir);
|
|
174
|
-
logger.logReady("built extension successfully");
|
|
175
|
-
vicinae.refreshDevSession(id);
|
|
176
|
-
}
|
|
177
|
-
catch (error) {
|
|
178
|
-
logger.logEvent(`Failed to build extension: ${error}`);
|
|
192
|
+
.on("all", async (_, path) => {
|
|
193
|
+
if (path.endsWith('package.json')) {
|
|
194
|
+
manifest = parseManifest();
|
|
179
195
|
}
|
|
196
|
+
logger.logEvent(`changed file ${path}`);
|
|
197
|
+
await safeBuild(extensionDir);
|
|
180
198
|
});
|
|
181
199
|
const logFiles = new Map();
|
|
182
200
|
chokidar.watch(logFile).on("all", async (_, path) => {
|
|
@@ -184,7 +202,7 @@ class Develop extends core_1.Command {
|
|
|
184
202
|
if (!stats.isFile())
|
|
185
203
|
return;
|
|
186
204
|
if (!logFiles.has(path)) {
|
|
187
|
-
logger.logInfo(`Monitoring new log file at ${path}`);
|
|
205
|
+
//logger.logInfo(`Monitoring new log file at ${path}`);
|
|
188
206
|
logFiles.set(path, { cursor: 0, path });
|
|
189
207
|
}
|
|
190
208
|
const info = logFiles.get(path);
|