arri 0.0.18 → 0.0.20
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/chunks/index.cjs +10 -9
- package/dist/chunks/index.mjs +10 -9
- package/dist/cli.cjs +348 -225
- package/dist/cli.mjs +348 -213
- package/dist/codegen.mjs +4 -4
- package/dist/index.cjs +5 -2
- package/dist/index.d.cts +4 -1
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.mjs +6 -4
- package/dist/shared/{arri.4d2ea869.mjs → arri.c6b92822.mjs} +1 -1
- package/dist/shared/{arri.54e67ffe.mjs → arri.e547206a.mjs} +1 -1
- package/package.json +8 -8
package/dist/cli.cjs
CHANGED
|
@@ -2,18 +2,11 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const citty = require('citty');
|
|
5
|
+
const node_child_process = require('node:child_process');
|
|
5
6
|
const fs$e = require('node:fs');
|
|
6
|
-
const ofetch = require('ofetch');
|
|
7
|
-
const require$$0 = require('fs');
|
|
8
|
-
const prettier = require('prettier');
|
|
9
|
-
require('@sinclair/typebox');
|
|
10
|
-
require('h3');
|
|
11
|
-
const app = require('./shared/arri.38792eb4.cjs');
|
|
12
|
-
require('@sinclair/typebox/errors');
|
|
13
|
-
require('@sinclair/typebox/value');
|
|
14
|
-
const dart = require('./shared/arri.234caf5e.cjs');
|
|
15
7
|
const fs$f = require('node:fs/promises');
|
|
16
8
|
const path$e = require('pathe');
|
|
9
|
+
const require$$0 = require('fs');
|
|
17
10
|
const require$$0$1 = require('path');
|
|
18
11
|
const require$$2 = require('os');
|
|
19
12
|
const require$$3 = require('crypto');
|
|
@@ -31,29 +24,25 @@ const require$$0$2 = require('util');
|
|
|
31
24
|
const require$$0$3 = require('stream');
|
|
32
25
|
const consola = require('consola');
|
|
33
26
|
const esbuild = require('esbuild');
|
|
27
|
+
const prettier = require('prettier');
|
|
28
|
+
const app = require('./shared/arri.38792eb4.cjs');
|
|
29
|
+
const index = require('./index.cjs');
|
|
34
30
|
require('node:stream');
|
|
31
|
+
const ofetch = require('ofetch');
|
|
32
|
+
require('@sinclair/typebox');
|
|
33
|
+
require('h3');
|
|
34
|
+
require('@sinclair/typebox/errors');
|
|
35
|
+
require('@sinclair/typebox/value');
|
|
36
|
+
const dart = require('./shared/arri.234caf5e.cjs');
|
|
35
37
|
const listhen = require('listhen');
|
|
36
38
|
require('child_process');
|
|
37
39
|
|
|
38
40
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
39
41
|
|
|
40
|
-
function _interopNamespaceCompat(e) {
|
|
41
|
-
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
42
|
-
const n = Object.create(null);
|
|
43
|
-
if (e) {
|
|
44
|
-
for (const k in e) {
|
|
45
|
-
n[k] = e[k];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
n.default = e;
|
|
49
|
-
return n;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
42
|
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs$e);
|
|
53
|
-
const require$$0__default = /*#__PURE__*/_interopDefaultCompat(require$$0);
|
|
54
|
-
const prettier__namespace = /*#__PURE__*/_interopNamespaceCompat(prettier);
|
|
55
43
|
const fs__default$1 = /*#__PURE__*/_interopDefaultCompat(fs$f);
|
|
56
44
|
const path__default$1 = /*#__PURE__*/_interopDefaultCompat(path$e);
|
|
45
|
+
const require$$0__default = /*#__PURE__*/_interopDefaultCompat(require$$0);
|
|
57
46
|
const require$$0__default$1 = /*#__PURE__*/_interopDefaultCompat(require$$0$1);
|
|
58
47
|
const require$$2__default = /*#__PURE__*/_interopDefaultCompat(require$$2);
|
|
59
48
|
const require$$3__default = /*#__PURE__*/_interopDefaultCompat(require$$3);
|
|
@@ -65,74 +54,7 @@ const v8__default = /*#__PURE__*/_interopDefaultCompat(v8);
|
|
|
65
54
|
const require$$0__default$4 = /*#__PURE__*/_interopDefaultCompat(require$$0$4);
|
|
66
55
|
const require$$0__default$2 = /*#__PURE__*/_interopDefaultCompat(require$$0$2);
|
|
67
56
|
const require$$0__default$3 = /*#__PURE__*/_interopDefaultCompat(require$$0$3);
|
|
68
|
-
|
|
69
|
-
const codegenDart = citty.defineCommand({
|
|
70
|
-
args: {
|
|
71
|
-
location: {
|
|
72
|
-
type: "positional",
|
|
73
|
-
required: true,
|
|
74
|
-
description: "The path to an Arri definition file or a url that returns an Arri definition file."
|
|
75
|
-
},
|
|
76
|
-
clientName: {
|
|
77
|
-
type: "string",
|
|
78
|
-
alias: ["name"],
|
|
79
|
-
required: true
|
|
80
|
-
},
|
|
81
|
-
outFile: {
|
|
82
|
-
type: "string",
|
|
83
|
-
alias: ["out", "o"],
|
|
84
|
-
required: true
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
async run({ args }) {
|
|
88
|
-
const isUrl = args.location.startsWith("http://") || args.location.startsWith("https://");
|
|
89
|
-
let def;
|
|
90
|
-
if (isUrl) {
|
|
91
|
-
const result = await ofetch.ofetch(args.location);
|
|
92
|
-
def = result;
|
|
93
|
-
} else {
|
|
94
|
-
if (!fs$e.existsSync(args.location)) {
|
|
95
|
-
throw new Error(`Unable to find ${args.location}`);
|
|
96
|
-
}
|
|
97
|
-
const jsonString = JSON.parse(
|
|
98
|
-
fs$e.readFileSync(args.location, { encoding: "utf-8" })
|
|
99
|
-
);
|
|
100
|
-
def = jsonString;
|
|
101
|
-
}
|
|
102
|
-
if (!def) {
|
|
103
|
-
throw new Error("Unable to load ApplicationDefinition json file");
|
|
104
|
-
}
|
|
105
|
-
await dart.dartClientGenerator({
|
|
106
|
-
clientName: args.clientName,
|
|
107
|
-
outputFile: args.outFile
|
|
108
|
-
}).generator(def);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
const codegenTypescript = citty.defineCommand({
|
|
112
|
-
args: {
|
|
113
|
-
location: {
|
|
114
|
-
type: "positional",
|
|
115
|
-
required: true,
|
|
116
|
-
description: "The path to an Arri definition file or a url that returns an Arri definition file."
|
|
117
|
-
},
|
|
118
|
-
clientName: {
|
|
119
|
-
type: "string",
|
|
120
|
-
alias: ["name"],
|
|
121
|
-
required: true
|
|
122
|
-
},
|
|
123
|
-
outFile: {
|
|
124
|
-
type: "string",
|
|
125
|
-
alias: ["out", "o"],
|
|
126
|
-
required: true
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
const codegen = citty.defineCommand({
|
|
131
|
-
subCommands: {
|
|
132
|
-
dart: codegenDart,
|
|
133
|
-
typescript: codegenTypescript
|
|
134
|
-
}
|
|
135
|
-
});
|
|
57
|
+
const prettier__default = /*#__PURE__*/_interopDefaultCompat(prettier);
|
|
136
58
|
|
|
137
59
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
138
60
|
|
|
@@ -165,12 +87,12 @@ function getAugmentedNamespace(n) {
|
|
|
165
87
|
return a;
|
|
166
88
|
}
|
|
167
89
|
|
|
168
|
-
var main$
|
|
90
|
+
var main$2 = {exports: {}};
|
|
169
91
|
|
|
170
92
|
const name = "dotenv";
|
|
171
93
|
const version$2 = "16.3.1";
|
|
172
94
|
const description = "Loads environment variables from .env file";
|
|
173
|
-
const main$
|
|
95
|
+
const main$1 = "lib/main.js";
|
|
174
96
|
const types$2 = "lib/main.d.ts";
|
|
175
97
|
const exports$1 = {
|
|
176
98
|
".": {
|
|
@@ -233,7 +155,7 @@ const _package = {
|
|
|
233
155
|
name: name,
|
|
234
156
|
version: version$2,
|
|
235
157
|
description: description,
|
|
236
|
-
main: main$
|
|
158
|
+
main: main$1,
|
|
237
159
|
types: types$2,
|
|
238
160
|
exports: exports$1,
|
|
239
161
|
scripts: scripts,
|
|
@@ -248,23 +170,23 @@ const _package = {
|
|
|
248
170
|
};
|
|
249
171
|
|
|
250
172
|
const _package$1 = {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
173
|
+
__proto__: null,
|
|
174
|
+
browser: browser,
|
|
175
|
+
default: _package,
|
|
176
|
+
description: description,
|
|
177
|
+
devDependencies: devDependencies,
|
|
178
|
+
engines: engines,
|
|
179
|
+
exports: exports$1,
|
|
180
|
+
funding: funding,
|
|
181
|
+
keywords: keywords$2,
|
|
182
|
+
license: license,
|
|
183
|
+
main: main$1,
|
|
184
|
+
name: name,
|
|
185
|
+
readmeFilename: readmeFilename,
|
|
186
|
+
repository: repository,
|
|
187
|
+
scripts: scripts,
|
|
188
|
+
types: types$2,
|
|
189
|
+
version: version$2
|
|
268
190
|
};
|
|
269
191
|
|
|
270
192
|
const require$$4 = /*@__PURE__*/getAugmentedNamespace(_package$1);
|
|
@@ -574,15 +496,15 @@ const DotenvModule = {
|
|
|
574
496
|
populate
|
|
575
497
|
};
|
|
576
498
|
|
|
577
|
-
main$
|
|
578
|
-
main$
|
|
579
|
-
main$
|
|
580
|
-
main$
|
|
581
|
-
main$
|
|
582
|
-
var parse_1$2 = main$
|
|
583
|
-
main$
|
|
499
|
+
main$2.exports.configDotenv = DotenvModule.configDotenv;
|
|
500
|
+
main$2.exports._configVault = DotenvModule._configVault;
|
|
501
|
+
main$2.exports._parseVault = DotenvModule._parseVault;
|
|
502
|
+
main$2.exports.config = DotenvModule.config;
|
|
503
|
+
main$2.exports.decrypt = DotenvModule.decrypt;
|
|
504
|
+
var parse_1$2 = main$2.exports.parse = DotenvModule.parse;
|
|
505
|
+
main$2.exports.populate = DotenvModule.populate;
|
|
584
506
|
|
|
585
|
-
main$
|
|
507
|
+
main$2.exports = DotenvModule;
|
|
586
508
|
|
|
587
509
|
const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
|
|
588
510
|
const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
@@ -19887,9 +19809,294 @@ const globby = normalizeArguments(async (patterns, options) => {
|
|
|
19887
19809
|
return unionFastGlobResults(results, filter);
|
|
19888
19810
|
});
|
|
19889
19811
|
|
|
19812
|
+
async function setupWorkingDir(config) {
|
|
19813
|
+
const arriDir = path__default$1.resolve(config.rootDir, config.buildDir);
|
|
19814
|
+
const outDir = path__default$1.resolve(config.rootDir, ".output");
|
|
19815
|
+
if (fs$e.existsSync(arriDir)) {
|
|
19816
|
+
await fs__default$1.rm(arriDir, { recursive: true, force: true });
|
|
19817
|
+
}
|
|
19818
|
+
if (fs$e.existsSync(outDir)) {
|
|
19819
|
+
await fs__default$1.rm(outDir, { recursive: true, force: true });
|
|
19820
|
+
}
|
|
19821
|
+
await fs__default$1.mkdir(arriDir);
|
|
19822
|
+
await fs__default$1.mkdir(outDir);
|
|
19823
|
+
}
|
|
19824
|
+
async function createRoutesModule(config) {
|
|
19825
|
+
const routes = [];
|
|
19826
|
+
await Promise.all(
|
|
19827
|
+
config.procedureGlobPatterns.map(async (pattern) => {
|
|
19828
|
+
const results = await getVirtualRouteBatch(pattern, config);
|
|
19829
|
+
for (const result of results) {
|
|
19830
|
+
routes.push(result);
|
|
19831
|
+
}
|
|
19832
|
+
})
|
|
19833
|
+
);
|
|
19834
|
+
routes.sort((a, b) => a.name < b.name ? -1 : 1);
|
|
19835
|
+
const module = await prettier__default.format(
|
|
19836
|
+
`${routes.map(
|
|
19837
|
+
(route) => `import ${route.importName} from '${route.importPath}';`
|
|
19838
|
+
).join("\n")}
|
|
19839
|
+
const routes: { id: string; route: any }[] = [${routes.map(
|
|
19840
|
+
(route) => `{ id: '${route.name}', route: ${route.importName} }`
|
|
19841
|
+
).join(",\n")}
|
|
19842
|
+
];
|
|
19843
|
+
export default routes`,
|
|
19844
|
+
{ parser: "typescript", tabWidth: 4 }
|
|
19845
|
+
);
|
|
19846
|
+
await fs__default$1.writeFile(
|
|
19847
|
+
path__default$1.resolve(config.rootDir, config.buildDir, "routes.ts"),
|
|
19848
|
+
module
|
|
19849
|
+
);
|
|
19850
|
+
}
|
|
19851
|
+
async function getVirtualRouteBatch(globPattern, config) {
|
|
19852
|
+
if (!config.procedureDir) {
|
|
19853
|
+
return [];
|
|
19854
|
+
}
|
|
19855
|
+
const target = `${config.rootDir}/${config.srcDir}/${config.procedureDir}/${globPattern}`.split("//").join("/").split("//").join("/");
|
|
19856
|
+
const files = await globby(target, {
|
|
19857
|
+
onlyFiles: true
|
|
19858
|
+
});
|
|
19859
|
+
const routes = [];
|
|
19860
|
+
for (const file of files) {
|
|
19861
|
+
const meta = getRpcMetaFromPath(config, file);
|
|
19862
|
+
if (meta) {
|
|
19863
|
+
const importParts = path__default$1.relative(path__default$1.resolve(config.rootDir, config.buildDir), file).split(".");
|
|
19864
|
+
importParts.pop();
|
|
19865
|
+
routes.push({
|
|
19866
|
+
name: meta.id,
|
|
19867
|
+
importName: app.camelCase(meta.id.split(".").join("_")),
|
|
19868
|
+
importPath: `./${importParts.join(".")}`
|
|
19869
|
+
});
|
|
19870
|
+
}
|
|
19871
|
+
}
|
|
19872
|
+
return routes;
|
|
19873
|
+
}
|
|
19874
|
+
const disallowedNameChars = "~`!@#$%^&*()-+=[]{}\\|:;\"'<>,./";
|
|
19875
|
+
const getRpcMetaFromPath = (config, filePath) => {
|
|
19876
|
+
if (!config.procedureDir) {
|
|
19877
|
+
return void 0;
|
|
19878
|
+
}
|
|
19879
|
+
const resolvedFilePath = filePath.split("./").join("/");
|
|
19880
|
+
const parts = resolvedFilePath.split("/");
|
|
19881
|
+
const reversedParts = [...parts].reverse();
|
|
19882
|
+
const nameParts = [];
|
|
19883
|
+
for (const part of reversedParts) {
|
|
19884
|
+
if (part === config.procedureDir) {
|
|
19885
|
+
break;
|
|
19886
|
+
}
|
|
19887
|
+
nameParts.push(part);
|
|
19888
|
+
}
|
|
19889
|
+
const fileName = nameParts.reverse().pop() ?? "";
|
|
19890
|
+
const serviceParts = nameParts.filter((part) => part.trim().length > 0).map((part) => app.removeDisallowedChars(part, disallowedNameChars));
|
|
19891
|
+
const fileNameParts = fileName.split(".");
|
|
19892
|
+
if (!fileNameParts.length) {
|
|
19893
|
+
return void 0;
|
|
19894
|
+
}
|
|
19895
|
+
const rpcName = app.removeDisallowedChars(
|
|
19896
|
+
fileNameParts[0],
|
|
19897
|
+
disallowedNameChars
|
|
19898
|
+
);
|
|
19899
|
+
const httpParts = [
|
|
19900
|
+
...serviceParts.map((part) => app.kebabCase(part)),
|
|
19901
|
+
app.kebabCase(rpcName)
|
|
19902
|
+
];
|
|
19903
|
+
return {
|
|
19904
|
+
id: [...serviceParts, rpcName].join("."),
|
|
19905
|
+
httpPath: `/${httpParts.join("/")}`
|
|
19906
|
+
};
|
|
19907
|
+
};
|
|
19908
|
+
|
|
19909
|
+
const build = citty.defineCommand({
|
|
19910
|
+
args: {
|
|
19911
|
+
config: {
|
|
19912
|
+
type: "string",
|
|
19913
|
+
description: "Path to the arri config file",
|
|
19914
|
+
alias: "c",
|
|
19915
|
+
default: "./arri.config.ts"
|
|
19916
|
+
},
|
|
19917
|
+
skipCodegen: {
|
|
19918
|
+
type: "boolean",
|
|
19919
|
+
default: false
|
|
19920
|
+
}
|
|
19921
|
+
},
|
|
19922
|
+
async run({ args }) {
|
|
19923
|
+
const { config } = await loadConfig({
|
|
19924
|
+
configFile: args.config,
|
|
19925
|
+
defaultConfig: index.defaultConfig
|
|
19926
|
+
});
|
|
19927
|
+
if (!config) {
|
|
19928
|
+
throw new Error("Unable to find arri config");
|
|
19929
|
+
}
|
|
19930
|
+
await startBuild(config);
|
|
19931
|
+
}
|
|
19932
|
+
});
|
|
19933
|
+
const logger$1 = consola.createConsola({
|
|
19934
|
+
fancy: true
|
|
19935
|
+
}).withTag("arri");
|
|
19936
|
+
async function startBuild(config) {
|
|
19937
|
+
logger$1.log("Bundling server....");
|
|
19938
|
+
await setupWorkingDir(config);
|
|
19939
|
+
await Promise.all([
|
|
19940
|
+
createRoutesModule(config),
|
|
19941
|
+
createBuildEntryModule(config),
|
|
19942
|
+
createBuildCodegenModule(config)
|
|
19943
|
+
]);
|
|
19944
|
+
await bundleFiles$1(config);
|
|
19945
|
+
logger$1.log("Finished bundling");
|
|
19946
|
+
const clientCount = config.clientGenerators.length;
|
|
19947
|
+
const codegenModule = path__default$1.resolve(config.rootDir, ".output", "codegen.js");
|
|
19948
|
+
if (clientCount > 0) {
|
|
19949
|
+
logger$1.log("Generating clients");
|
|
19950
|
+
node_child_process.execSync(`node ${codegenModule}`);
|
|
19951
|
+
const defJson = path__default$1.resolve(
|
|
19952
|
+
config.rootDir,
|
|
19953
|
+
".output",
|
|
19954
|
+
"__definition.json"
|
|
19955
|
+
);
|
|
19956
|
+
const def = JSON.parse(fs$e.readFileSync(defJson, { encoding: "utf-8" }));
|
|
19957
|
+
if (app.isApplicationDef(def)) {
|
|
19958
|
+
await Promise.all(
|
|
19959
|
+
config.clientGenerators.map((plugin) => plugin.generator(def))
|
|
19960
|
+
);
|
|
19961
|
+
}
|
|
19962
|
+
logger$1.log(`${clientCount} clients generated`);
|
|
19963
|
+
} else {
|
|
19964
|
+
logger$1.log("No client generators specified. Skipping codegen.");
|
|
19965
|
+
}
|
|
19966
|
+
logger$1.log("Cleaning up files");
|
|
19967
|
+
await fs__default$1.rm(codegenModule);
|
|
19968
|
+
logger$1.log(
|
|
19969
|
+
`Build finished! You can start your server by running "node .output/server.js"`
|
|
19970
|
+
);
|
|
19971
|
+
}
|
|
19972
|
+
async function bundleFiles$1(config) {
|
|
19973
|
+
await esbuild.build({
|
|
19974
|
+
...config.esbuild,
|
|
19975
|
+
entryPoints: [
|
|
19976
|
+
path__default$1.resolve(config.rootDir, config.buildDir, "server.ts"),
|
|
19977
|
+
path__default$1.resolve(config.rootDir, config.buildDir, "codegen.ts")
|
|
19978
|
+
],
|
|
19979
|
+
platform: config.esbuild.platform ?? "node",
|
|
19980
|
+
target: config.esbuild.target ?? "node18",
|
|
19981
|
+
bundle: true,
|
|
19982
|
+
outdir: path__default$1.resolve(config.rootDir, ".output")
|
|
19983
|
+
});
|
|
19984
|
+
}
|
|
19985
|
+
async function createBuildEntryModule(config) {
|
|
19986
|
+
const appModule = path__default$1.resolve(config.rootDir, config.srcDir, config.entry);
|
|
19987
|
+
const appImportParts = path__default$1.relative(path__default$1.resolve(config.rootDir, config.buildDir), appModule).split(".");
|
|
19988
|
+
appImportParts.pop();
|
|
19989
|
+
const virtualEntry = `import { toNodeListener } from 'h3';
|
|
19990
|
+
import { listen } from 'listhen';
|
|
19991
|
+
import routes from './routes';
|
|
19992
|
+
import app from './${appImportParts.join(".")}';
|
|
19993
|
+
|
|
19994
|
+
for (const route of routes) {
|
|
19995
|
+
app.registerRpc(route.id, route.route);
|
|
19996
|
+
}
|
|
19997
|
+
|
|
19998
|
+
void listen(toNodeListener(app.getH3Instance()), {
|
|
19999
|
+
port: process.env.PORT ?? ${config.port},
|
|
20000
|
+
});`;
|
|
20001
|
+
await fs__default$1.writeFile(
|
|
20002
|
+
path__default$1.resolve(config.rootDir, config.buildDir, "server.ts"),
|
|
20003
|
+
virtualEntry
|
|
20004
|
+
);
|
|
20005
|
+
}
|
|
20006
|
+
async function createBuildCodegenModule(config) {
|
|
20007
|
+
const appModule = path__default$1.resolve(config.rootDir, config.srcDir, config.entry);
|
|
20008
|
+
const appImportParts = path__default$1.relative(path__default$1.resolve(config.rootDir, config.buildDir), appModule).split(".");
|
|
20009
|
+
appImportParts.pop();
|
|
20010
|
+
const virtualModule = await prettier__default.format(
|
|
20011
|
+
`
|
|
20012
|
+
import { writeFileSync } from 'node:fs';
|
|
20013
|
+
import path from 'pathe';
|
|
20014
|
+
import app from './${appImportParts.join(".")}';
|
|
20015
|
+
|
|
20016
|
+
const def = app.getAppDefinition();
|
|
20017
|
+
writeFileSync(
|
|
20018
|
+
path.resolve(__dirname, "__definition.json"),
|
|
20019
|
+
JSON.stringify(def),
|
|
20020
|
+
);`,
|
|
20021
|
+
{ tabWidth: 4, parser: "typescript" }
|
|
20022
|
+
);
|
|
20023
|
+
await fs__default$1.writeFile(
|
|
20024
|
+
path__default$1.resolve(config.rootDir, config.buildDir, "codegen.ts"),
|
|
20025
|
+
virtualModule
|
|
20026
|
+
);
|
|
20027
|
+
}
|
|
20028
|
+
|
|
20029
|
+
const codegenDart = citty.defineCommand({
|
|
20030
|
+
args: {
|
|
20031
|
+
location: {
|
|
20032
|
+
type: "positional",
|
|
20033
|
+
required: true,
|
|
20034
|
+
description: "The path to an Arri definition file or a url that returns an Arri definition file."
|
|
20035
|
+
},
|
|
20036
|
+
clientName: {
|
|
20037
|
+
type: "string",
|
|
20038
|
+
alias: ["name"],
|
|
20039
|
+
required: true
|
|
20040
|
+
},
|
|
20041
|
+
outFile: {
|
|
20042
|
+
type: "string",
|
|
20043
|
+
alias: ["out", "o"],
|
|
20044
|
+
required: true
|
|
20045
|
+
}
|
|
20046
|
+
},
|
|
20047
|
+
async run({ args }) {
|
|
20048
|
+
const isUrl = args.location.startsWith("http://") || args.location.startsWith("https://");
|
|
20049
|
+
let def;
|
|
20050
|
+
if (isUrl) {
|
|
20051
|
+
const result = await ofetch.ofetch(args.location);
|
|
20052
|
+
def = result;
|
|
20053
|
+
} else {
|
|
20054
|
+
if (!fs$e.existsSync(args.location)) {
|
|
20055
|
+
throw new Error(`Unable to find ${args.location}`);
|
|
20056
|
+
}
|
|
20057
|
+
const jsonString = JSON.parse(
|
|
20058
|
+
fs$e.readFileSync(args.location, { encoding: "utf-8" })
|
|
20059
|
+
);
|
|
20060
|
+
def = jsonString;
|
|
20061
|
+
}
|
|
20062
|
+
if (!def) {
|
|
20063
|
+
throw new Error("Unable to load ApplicationDefinition json file");
|
|
20064
|
+
}
|
|
20065
|
+
await dart.dartClientGenerator({
|
|
20066
|
+
clientName: args.clientName,
|
|
20067
|
+
outputFile: args.outFile
|
|
20068
|
+
}).generator(def);
|
|
20069
|
+
}
|
|
20070
|
+
});
|
|
20071
|
+
const codegenTypescript = citty.defineCommand({
|
|
20072
|
+
args: {
|
|
20073
|
+
location: {
|
|
20074
|
+
type: "positional",
|
|
20075
|
+
required: true,
|
|
20076
|
+
description: "The path to an Arri definition file or a url that returns an Arri definition file."
|
|
20077
|
+
},
|
|
20078
|
+
clientName: {
|
|
20079
|
+
type: "string",
|
|
20080
|
+
alias: ["name"],
|
|
20081
|
+
required: true
|
|
20082
|
+
},
|
|
20083
|
+
outFile: {
|
|
20084
|
+
type: "string",
|
|
20085
|
+
alias: ["out", "o"],
|
|
20086
|
+
required: true
|
|
20087
|
+
}
|
|
20088
|
+
}
|
|
20089
|
+
});
|
|
20090
|
+
const codegen = citty.defineCommand({
|
|
20091
|
+
subCommands: {
|
|
20092
|
+
dart: codegenDart,
|
|
20093
|
+
typescript: codegenTypescript
|
|
20094
|
+
}
|
|
20095
|
+
});
|
|
20096
|
+
|
|
19890
20097
|
const logger = consola.createConsola({
|
|
19891
20098
|
fancy: true
|
|
19892
|
-
}).withTag("
|
|
20099
|
+
}).withTag("arri");
|
|
19893
20100
|
const dev = citty.defineCommand({
|
|
19894
20101
|
meta: {
|
|
19895
20102
|
name: "dev",
|
|
@@ -19906,14 +20113,19 @@ const dev = citty.defineCommand({
|
|
|
19906
20113
|
async run({ args }) {
|
|
19907
20114
|
process.env.ARRI_DEV_MODE = "true";
|
|
19908
20115
|
const config = await loadConfig({
|
|
19909
|
-
configFile: path__default$1.resolve(args.config)
|
|
20116
|
+
configFile: path__default$1.resolve(args.config),
|
|
20117
|
+
defaultConfig: index.defaultConfig
|
|
19910
20118
|
});
|
|
19911
|
-
|
|
20119
|
+
if (!config) {
|
|
20120
|
+
throw new Error("Unable to find config");
|
|
20121
|
+
}
|
|
20122
|
+
await startDevServer(config.config);
|
|
19912
20123
|
}
|
|
19913
20124
|
});
|
|
19914
20125
|
async function bundleFiles(config) {
|
|
19915
20126
|
const outDir = path__default$1.resolve(config.rootDir, ".output");
|
|
19916
20127
|
await esbuild.build({
|
|
20128
|
+
...config.esbuild,
|
|
19917
20129
|
entryPoints: [
|
|
19918
20130
|
path__default$1.resolve(config.rootDir, config.buildDir, "entry.ts")
|
|
19919
20131
|
],
|
|
@@ -19923,16 +20135,18 @@ async function bundleFiles(config) {
|
|
|
19923
20135
|
platform: "node"
|
|
19924
20136
|
});
|
|
19925
20137
|
}
|
|
19926
|
-
|
|
20138
|
+
const startListener = (config, showQr = false) => listhen.listenAndWatch(path__default$1.resolve(config.rootDir, ".output", "entry.js"), {
|
|
20139
|
+
public: true,
|
|
20140
|
+
port: config.port,
|
|
20141
|
+
logger,
|
|
20142
|
+
qr: showQr
|
|
20143
|
+
});
|
|
20144
|
+
async function startDevServer(config) {
|
|
19927
20145
|
await setupWorkingDir(config);
|
|
19928
20146
|
let fileWatcher;
|
|
19929
20147
|
await Promise.all([createRoutesModule(config), createEntryModule(config)]);
|
|
19930
20148
|
await bundleFiles(config);
|
|
19931
|
-
await
|
|
19932
|
-
public: true,
|
|
19933
|
-
port: config.port,
|
|
19934
|
-
logger
|
|
19935
|
-
});
|
|
20149
|
+
let listener = await startListener(config, true);
|
|
19936
20150
|
setTimeout(async () => {
|
|
19937
20151
|
await generateClients(config);
|
|
19938
20152
|
}, 1e3);
|
|
@@ -19955,8 +20169,12 @@ async function main$1(config) {
|
|
|
19955
20169
|
await createRoutesModule(config);
|
|
19956
20170
|
let bundleCreated = false;
|
|
19957
20171
|
try {
|
|
19958
|
-
logger.log(
|
|
20172
|
+
logger.log(
|
|
20173
|
+
"Change detected. Bundling files and restarting server...."
|
|
20174
|
+
);
|
|
19959
20175
|
await bundleFiles(config);
|
|
20176
|
+
await listener.close();
|
|
20177
|
+
listener = await startListener(config);
|
|
19960
20178
|
bundleCreated = true;
|
|
19961
20179
|
} catch (err) {
|
|
19962
20180
|
logger.error(err);
|
|
@@ -19996,18 +20214,6 @@ async function generateClients(config) {
|
|
|
19996
20214
|
console.error(err);
|
|
19997
20215
|
}
|
|
19998
20216
|
}
|
|
19999
|
-
async function setupWorkingDir(config) {
|
|
20000
|
-
const arriDir = path__default$1.resolve(config.rootDir, config.buildDir);
|
|
20001
|
-
const outDir = path__default$1.resolve(config.rootDir, ".output");
|
|
20002
|
-
if (fs$e.existsSync(arriDir)) {
|
|
20003
|
-
await fs__default$1.rm(arriDir, { recursive: true, force: true });
|
|
20004
|
-
}
|
|
20005
|
-
if (fs$e.existsSync(outDir)) {
|
|
20006
|
-
await fs__default$1.rm(outDir, { recursive: true, force: true });
|
|
20007
|
-
}
|
|
20008
|
-
await fs__default$1.mkdir(arriDir);
|
|
20009
|
-
await fs__default$1.mkdir(outDir);
|
|
20010
|
-
}
|
|
20011
20217
|
async function createEntryModule(config) {
|
|
20012
20218
|
const appModule = path__default$1.resolve(config.rootDir, config.srcDir, config.entry);
|
|
20013
20219
|
const appImportParts = path__default$1.relative(path__default$1.resolve(config.rootDir, config.buildDir), appModule).split(".");
|
|
@@ -20027,93 +20233,10 @@ export default app.getH3Instance();`;
|
|
|
20027
20233
|
virtualEntry
|
|
20028
20234
|
);
|
|
20029
20235
|
}
|
|
20030
|
-
async function createRoutesModule(config) {
|
|
20031
|
-
const routes = [];
|
|
20032
|
-
await Promise.all(
|
|
20033
|
-
config.procedureGlobPatterns.map(async (pattern) => {
|
|
20034
|
-
const results = await getVirtualRouteBatch(pattern, config);
|
|
20035
|
-
for (const result of results) {
|
|
20036
|
-
routes.push(result);
|
|
20037
|
-
}
|
|
20038
|
-
})
|
|
20039
|
-
);
|
|
20040
|
-
routes.sort((a, b) => a.name < b.name ? -1 : 1);
|
|
20041
|
-
const module = await prettier__namespace.format(
|
|
20042
|
-
`${routes.map(
|
|
20043
|
-
(route) => `import ${route.importName} from '${route.importPath}';`
|
|
20044
|
-
).join("\n")}
|
|
20045
|
-
const routes: { id: string; route: any }[] = [${routes.map(
|
|
20046
|
-
(route) => `{ id: '${route.name}', route: ${route.importName} }`
|
|
20047
|
-
).join(",\n")}
|
|
20048
|
-
];
|
|
20049
|
-
export default routes`,
|
|
20050
|
-
{ parser: "typescript", tabWidth: 4 }
|
|
20051
|
-
);
|
|
20052
|
-
await fs__default$1.writeFile(
|
|
20053
|
-
path__default$1.resolve(config.rootDir, config.buildDir, "routes.ts"),
|
|
20054
|
-
module
|
|
20055
|
-
);
|
|
20056
|
-
}
|
|
20057
|
-
async function getVirtualRouteBatch(globPattern, config) {
|
|
20058
|
-
if (!config.procedureDir) {
|
|
20059
|
-
return [];
|
|
20060
|
-
}
|
|
20061
|
-
const target = `${config.rootDir}/${config.srcDir}/${config.procedureDir}/${globPattern}`.split("//").join("/").split("//").join("/");
|
|
20062
|
-
const files = await globby(target, {
|
|
20063
|
-
onlyFiles: true
|
|
20064
|
-
});
|
|
20065
|
-
const routes = [];
|
|
20066
|
-
for (const file of files) {
|
|
20067
|
-
const meta = getRpcMetaFromPath(config, file);
|
|
20068
|
-
if (meta) {
|
|
20069
|
-
const importParts = path__default$1.relative(path__default$1.resolve(config.rootDir, config.buildDir), file).split(".");
|
|
20070
|
-
importParts.pop();
|
|
20071
|
-
routes.push({
|
|
20072
|
-
name: meta.id,
|
|
20073
|
-
importName: app.camelCase(meta.id.split(".").join("_")),
|
|
20074
|
-
importPath: `./${importParts.join(".")}`
|
|
20075
|
-
});
|
|
20076
|
-
}
|
|
20077
|
-
}
|
|
20078
|
-
return routes;
|
|
20079
|
-
}
|
|
20080
|
-
const disallowedNameChars = "~`!@#$%^&*()-+=[]{}\\|:;\"'<>,./";
|
|
20081
|
-
const getRpcMetaFromPath = (config, filePath) => {
|
|
20082
|
-
if (!config.procedureDir) {
|
|
20083
|
-
return void 0;
|
|
20084
|
-
}
|
|
20085
|
-
const resolvedFilePath = filePath.split("./").join("/");
|
|
20086
|
-
const parts = resolvedFilePath.split("/");
|
|
20087
|
-
const reversedParts = [...parts].reverse();
|
|
20088
|
-
const nameParts = [];
|
|
20089
|
-
for (const part of reversedParts) {
|
|
20090
|
-
if (part === config.procedureDir) {
|
|
20091
|
-
break;
|
|
20092
|
-
}
|
|
20093
|
-
nameParts.push(part);
|
|
20094
|
-
}
|
|
20095
|
-
const fileName = nameParts.reverse().pop() ?? "";
|
|
20096
|
-
const serviceParts = nameParts.filter((part) => part.trim().length > 0).map((part) => app.removeDisallowedChars(part, disallowedNameChars));
|
|
20097
|
-
const fileNameParts = fileName.split(".");
|
|
20098
|
-
if (!fileNameParts.length) {
|
|
20099
|
-
return void 0;
|
|
20100
|
-
}
|
|
20101
|
-
const rpcName = app.removeDisallowedChars(
|
|
20102
|
-
fileNameParts[0],
|
|
20103
|
-
disallowedNameChars
|
|
20104
|
-
);
|
|
20105
|
-
const httpParts = [
|
|
20106
|
-
...serviceParts.map((part) => app.kebabCase(part)),
|
|
20107
|
-
app.kebabCase(rpcName)
|
|
20108
|
-
];
|
|
20109
|
-
return {
|
|
20110
|
-
id: [...serviceParts, rpcName].join("."),
|
|
20111
|
-
httpPath: `/${httpParts.join("/")}`
|
|
20112
|
-
};
|
|
20113
|
-
};
|
|
20114
20236
|
|
|
20115
20237
|
const main = citty.defineCommand({
|
|
20116
20238
|
subCommands: {
|
|
20239
|
+
build,
|
|
20117
20240
|
dev,
|
|
20118
20241
|
codegen
|
|
20119
20242
|
}
|