@tuyau/core 0.2.0 → 0.2.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/build/commands/generate.js +21 -3
- package/package.json +3 -3
|
@@ -193,6 +193,23 @@ var ApiTypesGenerator = class {
|
|
|
193
193
|
return { params, name, path: pattern, method: methods, types: typeName };
|
|
194
194
|
}).filter((route) => !!route.name);
|
|
195
195
|
}
|
|
196
|
+
async #writeIndexFile() {
|
|
197
|
+
const filePath = this.#getDestinationDirectory() + "/index.ts";
|
|
198
|
+
const exist = existsSync(filePath);
|
|
199
|
+
if (exist) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const file = this.#project.createSourceFile(filePath, "", {
|
|
203
|
+
overwrite: true
|
|
204
|
+
});
|
|
205
|
+
if (!file) throw new Error("Unable to create the index.ts file");
|
|
206
|
+
file.removeText().insertText(0, (writer) => {
|
|
207
|
+
writer.writeLine(`/// <reference path="../adonisrc.ts" />`);
|
|
208
|
+
writer.newLine();
|
|
209
|
+
writer.writeLine(`export * from './api.js'`);
|
|
210
|
+
});
|
|
211
|
+
await file.save();
|
|
212
|
+
}
|
|
196
213
|
async #writeApiFile(options) {
|
|
197
214
|
const file = this.#project.createSourceFile(this.#destination, "", { overwrite: true });
|
|
198
215
|
if (!file) throw new Error("Unable to create the api.ts file");
|
|
@@ -220,8 +237,8 @@ var ApiTypesGenerator = class {
|
|
|
220
237
|
writer.writeLine(`export const api = {`).writeLine(` routes,`).writeLine(` definition: {} as ApiDefinition`).writeLine(`}`);
|
|
221
238
|
if (isTuyauInertiaInstalled) {
|
|
222
239
|
writer.writeLine(`declare module '@tuyau/inertia/types' {`);
|
|
223
|
-
writer.writeLine(` type
|
|
224
|
-
writer.writeLine(` export interface Api extends
|
|
240
|
+
writer.writeLine(` type InertiaApi = typeof api`);
|
|
241
|
+
writer.writeLine(` export interface Api extends InertiaApi {}`);
|
|
225
242
|
writer.writeLine(`}`);
|
|
226
243
|
}
|
|
227
244
|
});
|
|
@@ -260,7 +277,7 @@ var ApiTypesGenerator = class {
|
|
|
260
277
|
const typeName = this.#generateTypeName(route);
|
|
261
278
|
typesByPattern[typeName] = {
|
|
262
279
|
request: schemaImport ? `MakeTuyauRequest<${schemaImport}>` : "unknown",
|
|
263
|
-
response: `MakeTuyauResponse<import('${relativePath}').default['${routeHandler.method}']>`
|
|
280
|
+
response: `MakeTuyauResponse<import('${relativePath}').default['${routeHandler.method}'], ${!!schemaImport}>`
|
|
264
281
|
};
|
|
265
282
|
currentLevel.$url = {};
|
|
266
283
|
for (const method of methods) currentLevel[method] = typeName;
|
|
@@ -271,6 +288,7 @@ var ApiTypesGenerator = class {
|
|
|
271
288
|
typesByPattern
|
|
272
289
|
);
|
|
273
290
|
await this.#writeApiFile({ definition, typesByPattern, routesNameArray });
|
|
291
|
+
await this.#writeIndexFile();
|
|
274
292
|
}
|
|
275
293
|
};
|
|
276
294
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuyau/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "MIT",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"@poppinss/cliui": "^6.4.1",
|
|
33
33
|
"@poppinss/matchit": "^3.1.2",
|
|
34
34
|
"@types/node": "^20.16.5",
|
|
35
|
-
"@tuyau/client": "0.
|
|
36
|
-
"@tuyau/utils": "0.0.
|
|
35
|
+
"@tuyau/client": "0.2.0",
|
|
36
|
+
"@tuyau/utils": "0.0.5"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public",
|