arri 0.58.1 → 0.60.1
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 +5 -3
- package/dist/cli.cjs +57 -210
- package/dist/cli.mjs +31 -183
- package/dist/index.cjs +570 -13
- package/dist/index.d.cts +30 -10
- package/dist/index.d.mts +30 -10
- package/dist/index.d.ts +30 -10
- package/dist/index.mjs +548 -9
- package/dist/shared/arri.7f2f73b2.cjs +177 -0
- package/dist/shared/arri.f4637ba5.mjs +163 -0
- package/package.json +9 -8
- package/dist/shared/arri.a671ac34.cjs +0 -527
- package/dist/shared/arri.c8a11d3d.mjs +0 -493
|
@@ -1,527 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs');
|
|
4
|
-
const listhen = require('@joshmossas/listhen');
|
|
5
|
-
const c12 = require('c12');
|
|
6
|
-
const citty = require('citty');
|
|
7
|
-
const esbuild = require('esbuild');
|
|
8
|
-
const h3 = require('h3');
|
|
9
|
-
const path = require('pathe');
|
|
10
|
-
const fs$1 = require('node:fs/promises');
|
|
11
|
-
const codegenUtils = require('@arrirpc/codegen-utils');
|
|
12
|
-
const schema = require('@arrirpc/schema');
|
|
13
|
-
const ofetch = require('@joshmossas/ofetch');
|
|
14
|
-
const consola = require('consola');
|
|
15
|
-
const prettier = require('prettier');
|
|
16
|
-
|
|
17
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
18
|
-
|
|
19
|
-
function _interopNamespaceCompat(e) {
|
|
20
|
-
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
21
|
-
const n = Object.create(null);
|
|
22
|
-
if (e) {
|
|
23
|
-
for (const k in e) {
|
|
24
|
-
n[k] = e[k];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
n.default = e;
|
|
28
|
-
return n;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const esbuild__namespace = /*#__PURE__*/_interopNamespaceCompat(esbuild);
|
|
32
|
-
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
33
|
-
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs$1);
|
|
34
|
-
const prettier__default = /*#__PURE__*/_interopDefaultCompat(prettier);
|
|
35
|
-
|
|
36
|
-
const logger = consola.createConsola().withTag("arri");
|
|
37
|
-
const GEN_APP_FILE = "__arri_app.ts";
|
|
38
|
-
const OUT_APP_FILE = "app.mjs";
|
|
39
|
-
const OUT_SERVER_ENTRY = "server.mjs";
|
|
40
|
-
const OUT_CODEGEN = "codegen.mjs";
|
|
41
|
-
async function setupWorkingDir(config) {
|
|
42
|
-
const arriDir = path__default.resolve(config.rootDir, config.buildDir);
|
|
43
|
-
const outDir = path__default.resolve(config.rootDir, ".output");
|
|
44
|
-
if (fs.existsSync(arriDir)) {
|
|
45
|
-
await fs__default.rm(arriDir, { recursive: true, force: true });
|
|
46
|
-
}
|
|
47
|
-
if (fs.existsSync(outDir)) {
|
|
48
|
-
await fs__default.rm(outDir, { recursive: true, force: true });
|
|
49
|
-
}
|
|
50
|
-
await fs__default.mkdir(arriDir);
|
|
51
|
-
await fs__default.mkdir(outDir);
|
|
52
|
-
}
|
|
53
|
-
async function createAppWithRoutesModule(config) {
|
|
54
|
-
const glob = await import('globby');
|
|
55
|
-
const appModule = path__default.resolve(config.rootDir, config.srcDir, config.entry);
|
|
56
|
-
const appImportParts = path__default.relative(path__default.resolve(config.rootDir, config.buildDir), appModule).split(".");
|
|
57
|
-
appImportParts.pop();
|
|
58
|
-
const routes = [];
|
|
59
|
-
const existingRoutes = [];
|
|
60
|
-
await Promise.all(
|
|
61
|
-
config.procedureGlobPatterns.map(async (pattern) => {
|
|
62
|
-
const results = await getFsRouteBatch(glob.globby, pattern, config);
|
|
63
|
-
for (const result of results) {
|
|
64
|
-
if (!existingRoutes.includes(result.name)) {
|
|
65
|
-
routes.push(result);
|
|
66
|
-
existingRoutes.push(result.name);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
);
|
|
71
|
-
routes.sort((a2, b) => a2.name < b.name ? -1 : 1);
|
|
72
|
-
const module = await prettier__default.format(
|
|
73
|
-
`import sourceMapSupport from 'source-map-support';
|
|
74
|
-
sourceMapSupport.install();
|
|
75
|
-
import app from '${appImportParts.join(".")}';
|
|
76
|
-
${routes.map(
|
|
77
|
-
(route) => `import ${route.importName} from '${route.importPath}';`
|
|
78
|
-
).join("\n")}
|
|
79
|
-
|
|
80
|
-
${routes.map((route) => `app.rpc('${route.name}', ${route.importName});`).join("\n")}
|
|
81
|
-
|
|
82
|
-
export default app;`,
|
|
83
|
-
{ parser: "typescript", tabWidth: 4 }
|
|
84
|
-
);
|
|
85
|
-
await fs__default.writeFile(
|
|
86
|
-
path__default.resolve(config.rootDir, config.buildDir, GEN_APP_FILE),
|
|
87
|
-
module
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
async function getFsRouteBatch(glob, globPattern, config) {
|
|
91
|
-
if (!config.procedureDir) {
|
|
92
|
-
return [];
|
|
93
|
-
}
|
|
94
|
-
const target = `${config.rootDir}/${config.srcDir}/${config.procedureDir}/${globPattern}`.split("//").join("/").split("//").join("/");
|
|
95
|
-
const files = await glob(target, {
|
|
96
|
-
onlyFiles: true
|
|
97
|
-
});
|
|
98
|
-
const routes = [];
|
|
99
|
-
for (const file of files) {
|
|
100
|
-
const meta = getRpcMetaFromPath(config, file);
|
|
101
|
-
if (meta) {
|
|
102
|
-
const importParts = path__default.relative(path__default.resolve(config.rootDir, config.buildDir), file).split(".");
|
|
103
|
-
importParts.pop();
|
|
104
|
-
routes.push({
|
|
105
|
-
name: meta.id,
|
|
106
|
-
importName: codegenUtils.camelCase(meta.id.split(".").join("_")),
|
|
107
|
-
importPath: `./${importParts.join(".")}`
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return routes;
|
|
112
|
-
}
|
|
113
|
-
const disallowedNameChars = "~`!@#$%^&*()-+=[]{}\\|:;\"'<>,./";
|
|
114
|
-
const getRpcMetaFromPath = (config, filePath) => {
|
|
115
|
-
if (!config.procedureDir) {
|
|
116
|
-
return void 0;
|
|
117
|
-
}
|
|
118
|
-
const resolvedFilePath = filePath.split("./").join("/");
|
|
119
|
-
const parts = resolvedFilePath.split("/");
|
|
120
|
-
const reversedParts = [...parts].reverse();
|
|
121
|
-
const nameParts = [];
|
|
122
|
-
for (const part of reversedParts) {
|
|
123
|
-
if (part === config.procedureDir) {
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
nameParts.push(part);
|
|
127
|
-
}
|
|
128
|
-
const fileName = nameParts.reverse().pop() ?? "";
|
|
129
|
-
const serviceParts = nameParts.filter((part) => part.trim().length > 0).map((part) => codegenUtils.removeDisallowedChars(part, disallowedNameChars));
|
|
130
|
-
const fileNameParts = fileName.split(".");
|
|
131
|
-
if (!fileNameParts.length) {
|
|
132
|
-
return void 0;
|
|
133
|
-
}
|
|
134
|
-
const rpcName = codegenUtils.removeDisallowedChars(
|
|
135
|
-
fileNameParts[0],
|
|
136
|
-
disallowedNameChars
|
|
137
|
-
);
|
|
138
|
-
const httpParts = [
|
|
139
|
-
...serviceParts.map((part) => codegenUtils.kebabCase(part)),
|
|
140
|
-
codegenUtils.kebabCase(rpcName)
|
|
141
|
-
];
|
|
142
|
-
return {
|
|
143
|
-
id: [...serviceParts, rpcName].join("."),
|
|
144
|
-
httpPath: `/${httpParts.join("/")}`
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
function isInsideDir(dir, parentDir) {
|
|
148
|
-
if (path__default.resolve(dir).startsWith(path__default.resolve(parentDir))) {
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
async function getArriPackageMetadata() {
|
|
154
|
-
const npmPackageResponse = await ofetch.ofetch("https://registry.npmjs.com/arri");
|
|
155
|
-
const arriInfo = schema.a.safeParse(NpmRegistryPackage, npmPackageResponse);
|
|
156
|
-
if (!arriInfo.success) {
|
|
157
|
-
const errors = schema.a.errors(NpmRegistryPackage, npmPackageResponse);
|
|
158
|
-
console.warn(errors);
|
|
159
|
-
throw new schema.ValidationError({
|
|
160
|
-
message: "Arri parsing response from registry",
|
|
161
|
-
errors
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
return arriInfo.value;
|
|
165
|
-
}
|
|
166
|
-
const NpmPackageVersion = schema.a.partial(
|
|
167
|
-
schema.a.object({
|
|
168
|
-
name: schema.a.string(),
|
|
169
|
-
version: schema.a.string(),
|
|
170
|
-
_id: schema.a.string(),
|
|
171
|
-
maintainers: schema.a.array(
|
|
172
|
-
schema.a.object({
|
|
173
|
-
name: schema.a.string(),
|
|
174
|
-
email: schema.a.string()
|
|
175
|
-
})
|
|
176
|
-
),
|
|
177
|
-
bin: schema.a.record(schema.a.string()),
|
|
178
|
-
dist: schema.a.any(),
|
|
179
|
-
main: schema.a.string(),
|
|
180
|
-
type: schema.a.string(),
|
|
181
|
-
types: schema.a.string(),
|
|
182
|
-
module: schema.a.string(),
|
|
183
|
-
gitHead: schema.a.string(),
|
|
184
|
-
_npmUser: schema.a.object({
|
|
185
|
-
name: schema.a.string(),
|
|
186
|
-
email: schema.a.string()
|
|
187
|
-
}),
|
|
188
|
-
description: schema.a.string(),
|
|
189
|
-
directories: schema.a.record(schema.a.any()),
|
|
190
|
-
_nodeVersion: schema.a.string(),
|
|
191
|
-
dependencies: schema.a.record(schema.a.string()),
|
|
192
|
-
_hasShrinkWrap: schema.a.boolean(),
|
|
193
|
-
_npmOperationalInternal: schema.a.any()
|
|
194
|
-
})
|
|
195
|
-
);
|
|
196
|
-
const NpmRegistryPackage = schema.a.object({
|
|
197
|
-
_id: schema.a.string(),
|
|
198
|
-
_rev: schema.a.string(),
|
|
199
|
-
name: schema.a.string(),
|
|
200
|
-
description: schema.a.string(),
|
|
201
|
-
"dist-tags": schema.a.record(schema.a.string()),
|
|
202
|
-
versions: schema.a.record(NpmPackageVersion),
|
|
203
|
-
time: schema.a.record(schema.a.string()),
|
|
204
|
-
maintainers: schema.a.array(
|
|
205
|
-
schema.a.object({
|
|
206
|
-
name: schema.a.string(),
|
|
207
|
-
email: schema.a.string()
|
|
208
|
-
})
|
|
209
|
-
),
|
|
210
|
-
author: schema.a.object({
|
|
211
|
-
name: schema.a.string(),
|
|
212
|
-
url: schema.a.string()
|
|
213
|
-
}),
|
|
214
|
-
repository: schema.a.optional(
|
|
215
|
-
schema.a.partial(
|
|
216
|
-
schema.a.object({
|
|
217
|
-
type: schema.a.string(),
|
|
218
|
-
url: schema.a.string(),
|
|
219
|
-
directory: schema.a.string()
|
|
220
|
-
})
|
|
221
|
-
)
|
|
222
|
-
),
|
|
223
|
-
license: schema.a.optional(schema.a.string()),
|
|
224
|
-
homepage: schema.a.optional(schema.a.string()),
|
|
225
|
-
bugs: schema.a.optional(
|
|
226
|
-
schema.a.partial(
|
|
227
|
-
schema.a.object({
|
|
228
|
-
url: schema.a.string()
|
|
229
|
-
})
|
|
230
|
-
)
|
|
231
|
-
),
|
|
232
|
-
readme: schema.a.optional(schema.a.string()),
|
|
233
|
-
readmeFilename: schema.a.optional(schema.a.string())
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
function isArriConfig(input) {
|
|
237
|
-
if (typeof input !== "object" || input === null) {
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
if ("generators" in input) {
|
|
241
|
-
if (!Array.isArray(input.generators)) {
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
if ("port" in input) {
|
|
246
|
-
if (typeof input.port !== "number") {
|
|
247
|
-
return false;
|
|
248
|
-
}
|
|
249
|
-
if (Number.isNaN(input.port)) {
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
if ("entry" in input && typeof input.entry !== "string") {
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
return true;
|
|
257
|
-
}
|
|
258
|
-
function isResolvedArriConfig(input) {
|
|
259
|
-
if (!isArriConfig(input)) {
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
return typeof input.rootDir === "string" && typeof input.srcDir === "string" && (typeof input.procedureDir === "string" || typeof input.procedureDir === "boolean") && Array.isArray(input.procedureGlobPatterns) && Array.isArray(input.generators);
|
|
263
|
-
}
|
|
264
|
-
const defaultConfig = {
|
|
265
|
-
port: 3e3,
|
|
266
|
-
rootDir: ".",
|
|
267
|
-
srcDir: "src",
|
|
268
|
-
entry: "app.ts",
|
|
269
|
-
serverEntry: "",
|
|
270
|
-
procedureDir: "procedures",
|
|
271
|
-
procedureGlobPatterns: ["**/*.rpc.ts"],
|
|
272
|
-
generators: [],
|
|
273
|
-
buildDir: ".arri",
|
|
274
|
-
esbuild: {},
|
|
275
|
-
https: false,
|
|
276
|
-
http2: false,
|
|
277
|
-
devServer: {}
|
|
278
|
-
};
|
|
279
|
-
function defineConfig(config) {
|
|
280
|
-
return {
|
|
281
|
-
port: config.port ?? defaultConfig.port,
|
|
282
|
-
rootDir: config.rootDir ?? defaultConfig.rootDir,
|
|
283
|
-
srcDir: config.srcDir ?? defaultConfig.srcDir,
|
|
284
|
-
entry: config.entry ?? defaultConfig.entry,
|
|
285
|
-
procedureDir: config.procedureDir ?? defaultConfig.procedureDir,
|
|
286
|
-
procedureGlobPatterns: config.procedureGlobPatterns ?? defaultConfig.procedureGlobPatterns,
|
|
287
|
-
generators: config.generators ?? defaultConfig.generators,
|
|
288
|
-
buildDir: config.buildDir ?? defaultConfig.buildDir,
|
|
289
|
-
esbuild: config.esbuild ?? defaultConfig.esbuild,
|
|
290
|
-
serverEntry: config.serverEntry ?? "",
|
|
291
|
-
https: config.https ?? false,
|
|
292
|
-
http2: config.http2 ?? false,
|
|
293
|
-
devServer: config.devServer ?? {}
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const DEV_ENDPOINT_ROOT = `/__arri_dev__`;
|
|
298
|
-
const DEV_DEFINITION_ENDPOINT = `${DEV_ENDPOINT_ROOT}/__definition`;
|
|
299
|
-
const dev = citty.defineCommand({
|
|
300
|
-
meta: {
|
|
301
|
-
name: "dev",
|
|
302
|
-
description: "Start the arri dev server"
|
|
303
|
-
},
|
|
304
|
-
args: {
|
|
305
|
-
config: {
|
|
306
|
-
type: "string",
|
|
307
|
-
description: "Path to the arri config file",
|
|
308
|
-
alias: "c",
|
|
309
|
-
default: "./arri.config.ts"
|
|
310
|
-
}
|
|
311
|
-
},
|
|
312
|
-
async run({ args }) {
|
|
313
|
-
const { config } = await c12.loadConfig({
|
|
314
|
-
configFile: path__default.resolve(args.config)
|
|
315
|
-
});
|
|
316
|
-
if (!isResolvedArriConfig(config)) {
|
|
317
|
-
throw new Error("Unable to find config");
|
|
318
|
-
}
|
|
319
|
-
const appEntry = path__default.resolve(
|
|
320
|
-
config.rootDir,
|
|
321
|
-
config.srcDir,
|
|
322
|
-
config.entry
|
|
323
|
-
);
|
|
324
|
-
if (!fs.existsSync(appEntry)) {
|
|
325
|
-
throw new Error(`Unable to find entry at ${appEntry}`);
|
|
326
|
-
}
|
|
327
|
-
await startDevServer(config);
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
async function bundleFilesContext(config) {
|
|
331
|
-
return await esbuild__namespace.context({
|
|
332
|
-
...config.esbuild,
|
|
333
|
-
entryPoints: [
|
|
334
|
-
path__default.resolve(config.rootDir, config.buildDir, GEN_APP_FILE)
|
|
335
|
-
],
|
|
336
|
-
outfile: path__default.resolve(config.rootDir, ".output", OUT_APP_FILE),
|
|
337
|
-
format: "esm",
|
|
338
|
-
bundle: true,
|
|
339
|
-
packages: "external",
|
|
340
|
-
sourcemap: config.esbuild.sourcemap ?? true,
|
|
341
|
-
target: config.esbuild.target ?? "node20",
|
|
342
|
-
platform: config.esbuild.platform ?? "node"
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
async function createDevServer(config) {
|
|
346
|
-
const h3$1 = await import('h3');
|
|
347
|
-
const app = h3$1.createApp();
|
|
348
|
-
const dynamicHandler = h3.dynamicEventHandler(
|
|
349
|
-
() => "<div>initializing server...</div>"
|
|
350
|
-
);
|
|
351
|
-
app.use(dynamicHandler);
|
|
352
|
-
let ws;
|
|
353
|
-
const listener = await listhen.listen(h3.toNodeListener(app), {
|
|
354
|
-
port: config.port,
|
|
355
|
-
https: config.https,
|
|
356
|
-
http2: config.http2,
|
|
357
|
-
public: true,
|
|
358
|
-
ws: {
|
|
359
|
-
resolve(info) {
|
|
360
|
-
if (ws?.resolve) {
|
|
361
|
-
return ws.resolve(info);
|
|
362
|
-
}
|
|
363
|
-
return {};
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
let secondaryListener;
|
|
368
|
-
if (config.devServer.httpWithHttps) {
|
|
369
|
-
secondaryListener = await listhen.listen(h3.toNodeListener(app), {
|
|
370
|
-
port: config.devServer.httpWithHttpsPort ?? config.port + 1,
|
|
371
|
-
https: false,
|
|
372
|
-
http2: config.http2,
|
|
373
|
-
public: true,
|
|
374
|
-
ws: {
|
|
375
|
-
resolve(info) {
|
|
376
|
-
if (ws?.resolve) {
|
|
377
|
-
return ws.resolve(info);
|
|
378
|
-
}
|
|
379
|
-
return {};
|
|
380
|
-
}
|
|
381
|
-
},
|
|
382
|
-
qr: false,
|
|
383
|
-
showURL: false
|
|
384
|
-
});
|
|
385
|
-
logger.info(
|
|
386
|
-
`Serving unencrypted traffic from port ${secondaryListener.address.port}`
|
|
387
|
-
);
|
|
388
|
-
}
|
|
389
|
-
async function reload() {
|
|
390
|
-
const appEntry = (await import(path__default.resolve(
|
|
391
|
-
config.rootDir,
|
|
392
|
-
".output",
|
|
393
|
-
`${OUT_APP_FILE}?version=${Date.now()}`
|
|
394
|
-
))).default;
|
|
395
|
-
dynamicHandler.set(h3.fromNodeMiddleware(appEntry.h3App.handler));
|
|
396
|
-
ws = appEntry.h3App.websocket;
|
|
397
|
-
return appEntry.getAppDefinition();
|
|
398
|
-
}
|
|
399
|
-
await reload();
|
|
400
|
-
return {
|
|
401
|
-
h3App: app,
|
|
402
|
-
listener,
|
|
403
|
-
secondaryListener,
|
|
404
|
-
reload,
|
|
405
|
-
ws
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
async function startDevServer(config) {
|
|
409
|
-
await setupWorkingDir(config);
|
|
410
|
-
const watcher = await import('chokidar');
|
|
411
|
-
let fileWatcher;
|
|
412
|
-
await createAppWithRoutesModule(config);
|
|
413
|
-
const context = await bundleFilesContext(config);
|
|
414
|
-
await context.rebuild();
|
|
415
|
-
const devServer = await createDevServer(config);
|
|
416
|
-
let appDef = await devServer.reload();
|
|
417
|
-
let appDefStr = JSON.stringify(appDef);
|
|
418
|
-
if (config.generators.length) {
|
|
419
|
-
logger.info(`Running generators...`);
|
|
420
|
-
await generateClientsFromDefinition(appDef, config);
|
|
421
|
-
} else {
|
|
422
|
-
logger.warn(`No generators specified in config. Skipping codegen.`);
|
|
423
|
-
}
|
|
424
|
-
const cleanExit = async () => {
|
|
425
|
-
process.exit();
|
|
426
|
-
};
|
|
427
|
-
process.on("exit", async () => {
|
|
428
|
-
await Promise.allSettled([fileWatcher?.close(), context.dispose()]);
|
|
429
|
-
});
|
|
430
|
-
process.on("SIGINT", cleanExit);
|
|
431
|
-
process.on("SIGTERM", cleanExit);
|
|
432
|
-
async function load(_isRestart, _reason) {
|
|
433
|
-
if (fileWatcher) {
|
|
434
|
-
await fileWatcher.close();
|
|
435
|
-
}
|
|
436
|
-
const srcDir = path__default.resolve(config.rootDir ?? "", config.srcDir);
|
|
437
|
-
const dirsToWatch = [srcDir];
|
|
438
|
-
if (config.esbuild.alias) {
|
|
439
|
-
for (const key of Object.keys(config.esbuild.alias)) {
|
|
440
|
-
const alias = config.esbuild.alias[key];
|
|
441
|
-
if (alias) {
|
|
442
|
-
if (!isInsideDir(alias, srcDir)) {
|
|
443
|
-
dirsToWatch.push(alias);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
if (config.devServer.additionalWatchDirs?.length) {
|
|
449
|
-
for (const dir of config.devServer.additionalWatchDirs) {
|
|
450
|
-
dirsToWatch.push(dir);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
const buildDir = path__default.resolve(config.rootDir, config.buildDir);
|
|
454
|
-
const outDir = path__default.resolve(config.rootDir, ".output");
|
|
455
|
-
fileWatcher = watcher.watch(dirsToWatch, {
|
|
456
|
-
ignoreInitial: true,
|
|
457
|
-
ignored: [
|
|
458
|
-
buildDir,
|
|
459
|
-
outDir,
|
|
460
|
-
"**/.output",
|
|
461
|
-
"**/dist/**",
|
|
462
|
-
"**/node_modules/**",
|
|
463
|
-
"**/.git/**"
|
|
464
|
-
]
|
|
465
|
-
});
|
|
466
|
-
fileWatcher.on("all", async (eventName, _path) => {
|
|
467
|
-
if (eventName === "addDir" || eventName === "add") {
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
await createAppWithRoutesModule(config);
|
|
471
|
-
try {
|
|
472
|
-
const reloadStart = (/* @__PURE__ */ new Date()).getTime();
|
|
473
|
-
logger.log(
|
|
474
|
-
"Change detected. Bundling files and restarting server...."
|
|
475
|
-
);
|
|
476
|
-
await context.rebuild();
|
|
477
|
-
const newAppDef = await devServer.reload();
|
|
478
|
-
const newAppDefStr = JSON.stringify(newAppDef);
|
|
479
|
-
logger.log(
|
|
480
|
-
`Server restarted in ${( new Date()).getTime() - reloadStart}ms`
|
|
481
|
-
);
|
|
482
|
-
if (config.generators.length && newAppDefStr !== appDefStr) {
|
|
483
|
-
logger.info(
|
|
484
|
-
`App Definition updated. Regenerating clients...`
|
|
485
|
-
);
|
|
486
|
-
await generateClientsFromDefinition(newAppDef, config);
|
|
487
|
-
appDef = newAppDef;
|
|
488
|
-
appDefStr = newAppDefStr;
|
|
489
|
-
}
|
|
490
|
-
} catch (err) {
|
|
491
|
-
logger.error("ERROR", err);
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
await load();
|
|
496
|
-
}
|
|
497
|
-
async function generateClientsFromDefinition(appDef, config) {
|
|
498
|
-
const startTime = (/* @__PURE__ */ new Date()).getTime();
|
|
499
|
-
try {
|
|
500
|
-
const clientCount = config.generators.length;
|
|
501
|
-
await Promise.allSettled(
|
|
502
|
-
config.generators.map(
|
|
503
|
-
(generator) => generator.generator(appDef, true)
|
|
504
|
-
)
|
|
505
|
-
);
|
|
506
|
-
logger.success(
|
|
507
|
-
`Generated ${clientCount} client${clientCount === 1 ? "" : "s"} in ${( new Date()).getTime() - startTime}ms`
|
|
508
|
-
);
|
|
509
|
-
} catch (err) {
|
|
510
|
-
logger.error(err);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
exports.DEV_DEFINITION_ENDPOINT = DEV_DEFINITION_ENDPOINT;
|
|
515
|
-
exports.GEN_APP_FILE = GEN_APP_FILE;
|
|
516
|
-
exports.OUT_APP_FILE = OUT_APP_FILE;
|
|
517
|
-
exports.OUT_CODEGEN = OUT_CODEGEN;
|
|
518
|
-
exports.OUT_SERVER_ENTRY = OUT_SERVER_ENTRY;
|
|
519
|
-
exports.createAppWithRoutesModule = createAppWithRoutesModule;
|
|
520
|
-
exports.defaultConfig = defaultConfig;
|
|
521
|
-
exports.defineConfig = defineConfig;
|
|
522
|
-
exports.dev = dev;
|
|
523
|
-
exports.getArriPackageMetadata = getArriPackageMetadata;
|
|
524
|
-
exports.isArriConfig = isArriConfig;
|
|
525
|
-
exports.isResolvedArriConfig = isResolvedArriConfig;
|
|
526
|
-
exports.logger = logger;
|
|
527
|
-
exports.setupWorkingDir = setupWorkingDir;
|