@kizunajs/cli 2.0.0-beta.10 → 2.0.0-beta.12
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/cli.cjs +9 -9
- package/dist/cli.mjs +9 -9
- package/dist/index.cjs +13 -12
- package/dist/index.d.cts +25 -18
- package/dist/index.d.mts +25 -18
- package/dist/index.mjs +13 -12
- package/dist/{route-map-C484dhbj.mjs → route-map-Bt94ERSi.mjs} +64 -41
- package/dist/{route-map-I400Eb9_.cjs → route-map-CTy0nJPu.cjs} +66 -43
- package/package.json +3 -3
package/dist/cli.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_route_map = require("./route-map-
|
|
2
|
+
const require_route_map = require("./route-map-CTy0nJPu.cjs");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
let node_fs = require("node:fs");
|
|
5
5
|
let node_util = require("node:util");
|
|
@@ -59,13 +59,13 @@ const loadOrDie = async (configPath) => {
|
|
|
59
59
|
return config;
|
|
60
60
|
};
|
|
61
61
|
/**
|
|
62
|
-
* A
|
|
63
|
-
*
|
|
62
|
+
* A file writes where its config says, not where the command was run from, so
|
|
63
|
+
* `kizuna generate --config apps/api/kizuna.config.ts` lands the same files
|
|
64
64
|
* wherever it is invoked.
|
|
65
65
|
*/
|
|
66
|
-
const besideConfig = (configPath,
|
|
67
|
-
...
|
|
68
|
-
output: (0, node_path.resolve)((0, node_path.dirname)(configPath),
|
|
66
|
+
const besideConfig = (configPath, files) => files.map((file) => ({
|
|
67
|
+
...file,
|
|
68
|
+
output: (0, node_path.resolve)((0, node_path.dirname)(configPath), file.output)
|
|
69
69
|
}));
|
|
70
70
|
const runGenerate = async (values) => {
|
|
71
71
|
const configPath = configPathFrom(values.config);
|
|
@@ -83,7 +83,7 @@ const runGenerate = async (values) => {
|
|
|
83
83
|
const typesCurrent = (0, node_fs.existsSync)(typesPath) ? (0, node_fs.readFileSync)(typesPath, "utf8") : void 0;
|
|
84
84
|
const typesBehind = typesCurrent !== types;
|
|
85
85
|
if (values.check) {
|
|
86
|
-
const stale = require_route_map.
|
|
86
|
+
const stale = require_route_map.checkFiles(config.api, [...besideConfig(configPath, [...config.clients, ...config.generators]), require_route_map.snapshotTarget(configPath)]);
|
|
87
87
|
if (!typesBehind && stale.length === 0) {
|
|
88
88
|
process.stdout.write("Everything kizuna generates is up to date.\n");
|
|
89
89
|
return;
|
|
@@ -93,8 +93,8 @@ const runGenerate = async (values) => {
|
|
|
93
93
|
process.exit(1);
|
|
94
94
|
}
|
|
95
95
|
if (typesBehind) (0, node_fs.writeFileSync)(typesPath, types);
|
|
96
|
-
const written = require_route_map.
|
|
97
|
-
const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((
|
|
96
|
+
const written = require_route_map.writeFiles(config.api, [...besideConfig(configPath, [...config.clients, ...config.generators]), require_route_map.snapshotTarget(configPath)]);
|
|
97
|
+
const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((file) => file.changed).map((file) => displayPath(file.output))];
|
|
98
98
|
process.stdout.write(changed.length > 0 ? `Wrote:\n${changed.map((file) => ` ${file}`).join("\n")}\n` : "Everything was already up to date.\n");
|
|
99
99
|
};
|
|
100
100
|
const runRoutes = async (values) => {
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { _ as loadConfig, a as ConfigSyntaxError, c as formatStale, d as diffSnapshots, f as formatChange, h as snapshotTarget, i as readSnapshot, l as
|
|
2
|
+
import { _ as loadConfig, a as ConfigSyntaxError, c as formatStale, d as diffSnapshots, f as formatChange, h as snapshotTarget, i as readSnapshot, l as writeFiles, m as snapshotPathFor, n as routeMap, o as generateConfigTypes, p as hasBreakingChange, r as diffAgainst, s as checkFiles, t as formatRoutes } from "./route-map-Bt94ERSi.mjs";
|
|
3
3
|
import { dirname, relative, resolve } from "node:path";
|
|
4
4
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
@@ -59,13 +59,13 @@ const loadOrDie = async (configPath) => {
|
|
|
59
59
|
return config;
|
|
60
60
|
};
|
|
61
61
|
/**
|
|
62
|
-
* A
|
|
63
|
-
*
|
|
62
|
+
* A file writes where its config says, not where the command was run from, so
|
|
63
|
+
* `kizuna generate --config apps/api/kizuna.config.ts` lands the same files
|
|
64
64
|
* wherever it is invoked.
|
|
65
65
|
*/
|
|
66
|
-
const besideConfig = (configPath,
|
|
67
|
-
...
|
|
68
|
-
output: resolve(dirname(configPath),
|
|
66
|
+
const besideConfig = (configPath, files) => files.map((file) => ({
|
|
67
|
+
...file,
|
|
68
|
+
output: resolve(dirname(configPath), file.output)
|
|
69
69
|
}));
|
|
70
70
|
const runGenerate = async (values) => {
|
|
71
71
|
const configPath = configPathFrom(values.config);
|
|
@@ -83,7 +83,7 @@ const runGenerate = async (values) => {
|
|
|
83
83
|
const typesCurrent = existsSync(typesPath) ? readFileSync(typesPath, "utf8") : void 0;
|
|
84
84
|
const typesBehind = typesCurrent !== types;
|
|
85
85
|
if (values.check) {
|
|
86
|
-
const stale =
|
|
86
|
+
const stale = checkFiles(config.api, [...besideConfig(configPath, [...config.clients, ...config.generators]), snapshotTarget(configPath)]);
|
|
87
87
|
if (!typesBehind && stale.length === 0) {
|
|
88
88
|
process.stdout.write("Everything kizuna generates is up to date.\n");
|
|
89
89
|
return;
|
|
@@ -93,8 +93,8 @@ const runGenerate = async (values) => {
|
|
|
93
93
|
process.exit(1);
|
|
94
94
|
}
|
|
95
95
|
if (typesBehind) writeFileSync(typesPath, types);
|
|
96
|
-
const written =
|
|
97
|
-
const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((
|
|
96
|
+
const written = writeFiles(config.api, [...besideConfig(configPath, [...config.clients, ...config.generators]), snapshotTarget(configPath)]);
|
|
97
|
+
const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((file) => file.changed).map((file) => displayPath(file.output))];
|
|
98
98
|
process.stdout.write(changed.length > 0 ? `Wrote:\n${changed.map((file) => ` ${file}`).join("\n")}\n` : "Everything was already up to date.\n");
|
|
99
99
|
};
|
|
100
100
|
const runRoutes = async (values) => {
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_route_map = require("./route-map-
|
|
2
|
+
const require_route_map = require("./route-map-CTy0nJPu.cjs");
|
|
3
3
|
let kizunajs_generator = require("kizunajs/generator");
|
|
4
4
|
//#region src/api-notices.ts
|
|
5
5
|
const readSunset = (route) => {
|
|
@@ -8,14 +8,7 @@ const readSunset = (route) => {
|
|
|
8
8
|
return typeof declared === "string" ? declared : declared.date;
|
|
9
9
|
};
|
|
10
10
|
const daysBetween = (from, to) => Math.ceil((to.getTime() - from.getTime()) / 864e5);
|
|
11
|
-
|
|
12
|
-
* Every route that is deprecated or has a sunset date, soonest first, with
|
|
13
|
-
* undated deprecations last.
|
|
14
|
-
*
|
|
15
|
-
* Reads the same `deprecated` field the generated clients carry in an
|
|
16
|
-
* editor, so a watcher and a hover agree.
|
|
17
|
-
*/
|
|
18
|
-
const apiNotices = (0, kizunajs_generator.createGenerator)((options) => {
|
|
11
|
+
const noticesWalk = (options) => {
|
|
19
12
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
20
13
|
const notices = [];
|
|
21
14
|
return {
|
|
@@ -42,7 +35,15 @@ const apiNotices = (0, kizunajs_generator.createGenerator)((options) => {
|
|
|
42
35
|
});
|
|
43
36
|
}
|
|
44
37
|
};
|
|
45
|
-
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Every route that is deprecated or has a sunset date, soonest first, with
|
|
41
|
+
* undated deprecations last.
|
|
42
|
+
*
|
|
43
|
+
* Reads the same `deprecated` field the generated clients carry in an
|
|
44
|
+
* editor, so a watcher and a hover agree.
|
|
45
|
+
*/
|
|
46
|
+
const apiNotices = (api, options = {}) => (0, kizunajs_generator.walkApi)(api, noticesWalk(options));
|
|
46
47
|
/**
|
|
47
48
|
* One line per notice, for a watcher to print.
|
|
48
49
|
*
|
|
@@ -64,7 +65,7 @@ const formatNotice = (notice) => {
|
|
|
64
65
|
//#endregion
|
|
65
66
|
exports.ConfigSyntaxError = require_route_map.ConfigSyntaxError;
|
|
66
67
|
exports.apiNotices = apiNotices;
|
|
67
|
-
exports.
|
|
68
|
+
exports.checkFiles = require_route_map.checkFiles;
|
|
68
69
|
exports.diffAgainst = require_route_map.diffAgainst;
|
|
69
70
|
exports.diffApis = require_route_map.diffApis;
|
|
70
71
|
exports.diffSchemas = require_route_map.diffSchemas;
|
|
@@ -76,4 +77,4 @@ exports.generateConfigTypes = require_route_map.generateConfigTypes;
|
|
|
76
77
|
exports.hasBreakingChange = require_route_map.hasBreakingChange;
|
|
77
78
|
exports.loadConfig = require_route_map.loadConfig;
|
|
78
79
|
exports.routeMap = require_route_map.routeMap;
|
|
79
|
-
exports.
|
|
80
|
+
exports.writeFiles = require_route_map.writeFiles;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
|
|
1
|
+
import { ApiDefinition, DiffSettings, GeneratedFile } from "kizunajs";
|
|
3
2
|
//#region src/load-config.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* One api a config declares, with everything generated from it. A config that
|
|
@@ -8,7 +7,11 @@ import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
|
|
|
8
7
|
interface LoadedApi {
|
|
9
8
|
name: string;
|
|
10
9
|
api: ApiDefinition;
|
|
11
|
-
clients: readonly
|
|
10
|
+
clients: readonly GeneratedFile[];
|
|
11
|
+
/**
|
|
12
|
+
* The files the config's plugins generate.
|
|
13
|
+
*/
|
|
14
|
+
generators: readonly GeneratedFile[];
|
|
12
15
|
/**
|
|
13
16
|
* Where `kizuna generate` writes the `Config`, when the config says.
|
|
14
17
|
*/
|
|
@@ -60,7 +63,7 @@ interface Notice {
|
|
|
60
63
|
* Reads the same `deprecated` field the generated clients carry in an
|
|
61
64
|
* editor, so a watcher and a hover agree.
|
|
62
65
|
*/
|
|
63
|
-
declare const apiNotices: (
|
|
66
|
+
declare const apiNotices: (api: ApiDefinition, options?: {
|
|
64
67
|
now?: Date;
|
|
65
68
|
}) => Notice[];
|
|
66
69
|
/**
|
|
@@ -157,18 +160,16 @@ declare const hasBreakingChange: (changes: Change[]) => boolean;
|
|
|
157
160
|
//#endregion
|
|
158
161
|
//#region src/generate-clients.d.ts
|
|
159
162
|
/**
|
|
160
|
-
* A
|
|
163
|
+
* A file that was written, and whether it had to be.
|
|
161
164
|
*/
|
|
162
|
-
interface
|
|
163
|
-
kind: string;
|
|
165
|
+
interface WrittenFile {
|
|
164
166
|
output: string;
|
|
165
167
|
changed: boolean;
|
|
166
168
|
}
|
|
167
169
|
/**
|
|
168
|
-
* A generated
|
|
170
|
+
* A generated file that does not match its api.
|
|
169
171
|
*/
|
|
170
|
-
interface
|
|
171
|
-
kind: string;
|
|
172
|
+
interface StaleFile {
|
|
172
173
|
output: string;
|
|
173
174
|
/**
|
|
174
175
|
* `missing` when nothing is there, `outdated` when what is there is old.
|
|
@@ -176,22 +177,24 @@ interface StaleClient {
|
|
|
176
177
|
reason: 'missing' | 'outdated';
|
|
177
178
|
}
|
|
178
179
|
/**
|
|
179
|
-
* Writes every
|
|
180
|
-
* matches so watchers and build tools see no
|
|
180
|
+
* Writes every generated file, the clients and what plugins generate, leaving
|
|
181
|
+
* a file alone when it already matches so watchers and build tools see no
|
|
182
|
+
* change.
|
|
181
183
|
*/
|
|
182
|
-
declare const
|
|
184
|
+
declare const writeFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => WrittenFile[];
|
|
183
185
|
/**
|
|
184
|
-
* Every
|
|
186
|
+
* Every generated file that no longer matches its api, without writing
|
|
187
|
+
* anything.
|
|
185
188
|
*
|
|
186
189
|
* This is what a pipeline runs: a generated client that has fallen behind is a
|
|
187
190
|
* compile error waiting to happen in whatever imports it.
|
|
188
191
|
*/
|
|
189
|
-
declare const
|
|
192
|
+
declare const checkFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => StaleFile[];
|
|
190
193
|
/**
|
|
191
194
|
* What a pipeline prints when a check fails, naming the command that fixes it
|
|
192
195
|
* rather than printing a diff nobody reads.
|
|
193
196
|
*/
|
|
194
|
-
declare const formatStale: (stale: readonly
|
|
197
|
+
declare const formatStale: (stale: readonly StaleFile[], command?: string) => string;
|
|
195
198
|
//#endregion
|
|
196
199
|
//#region src/generate-types.d.ts
|
|
197
200
|
declare class ConfigSyntaxError extends Error {}
|
|
@@ -261,14 +264,18 @@ interface RouteEntry {
|
|
|
261
264
|
tool?: string;
|
|
262
265
|
deprecated?: string;
|
|
263
266
|
sunset?: string;
|
|
267
|
+
/**
|
|
268
|
+
* `true` when the route is `hidden`: served, but in no generated client.
|
|
269
|
+
*/
|
|
270
|
+
hidden?: true;
|
|
264
271
|
}
|
|
265
272
|
/**
|
|
266
273
|
* Every route an api serves, in the order it declares them.
|
|
267
274
|
*/
|
|
268
|
-
declare const routeMap: (
|
|
275
|
+
declare const routeMap: (api: ApiDefinition, _options?: Record<string, never>) => RouteEntry[];
|
|
269
276
|
/**
|
|
270
277
|
* The route map as aligned columns, one route per line.
|
|
271
278
|
*/
|
|
272
279
|
declare const formatRoutes: (entries: readonly RouteEntry[]) => string;
|
|
273
280
|
//#endregion
|
|
274
|
-
export { type Change, type ChangeLevel, ConfigSyntaxError, type DiffAgainstOptions, type Direction, type LoadedApi, type Notice, type RouteEntry, type SchemaChange, type
|
|
281
|
+
export { type Change, type ChangeLevel, ConfigSyntaxError, type DiffAgainstOptions, type Direction, type LoadedApi, type Notice, type RouteEntry, type SchemaChange, type StaleFile, type WrittenFile, apiNotices, checkFiles, diffAgainst, diffApis, diffSchemas, formatChange, formatNotice, formatRoutes, formatStale, generateConfigTypes, hasBreakingChange, loadConfig, routeMap, writeFiles };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
|
|
1
|
+
import { ApiDefinition, DiffSettings, GeneratedFile } from "kizunajs";
|
|
3
2
|
//#region src/load-config.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* One api a config declares, with everything generated from it. A config that
|
|
@@ -8,7 +7,11 @@ import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
|
|
|
8
7
|
interface LoadedApi {
|
|
9
8
|
name: string;
|
|
10
9
|
api: ApiDefinition;
|
|
11
|
-
clients: readonly
|
|
10
|
+
clients: readonly GeneratedFile[];
|
|
11
|
+
/**
|
|
12
|
+
* The files the config's plugins generate.
|
|
13
|
+
*/
|
|
14
|
+
generators: readonly GeneratedFile[];
|
|
12
15
|
/**
|
|
13
16
|
* Where `kizuna generate` writes the `Config`, when the config says.
|
|
14
17
|
*/
|
|
@@ -60,7 +63,7 @@ interface Notice {
|
|
|
60
63
|
* Reads the same `deprecated` field the generated clients carry in an
|
|
61
64
|
* editor, so a watcher and a hover agree.
|
|
62
65
|
*/
|
|
63
|
-
declare const apiNotices: (
|
|
66
|
+
declare const apiNotices: (api: ApiDefinition, options?: {
|
|
64
67
|
now?: Date;
|
|
65
68
|
}) => Notice[];
|
|
66
69
|
/**
|
|
@@ -157,18 +160,16 @@ declare const hasBreakingChange: (changes: Change[]) => boolean;
|
|
|
157
160
|
//#endregion
|
|
158
161
|
//#region src/generate-clients.d.ts
|
|
159
162
|
/**
|
|
160
|
-
* A
|
|
163
|
+
* A file that was written, and whether it had to be.
|
|
161
164
|
*/
|
|
162
|
-
interface
|
|
163
|
-
kind: string;
|
|
165
|
+
interface WrittenFile {
|
|
164
166
|
output: string;
|
|
165
167
|
changed: boolean;
|
|
166
168
|
}
|
|
167
169
|
/**
|
|
168
|
-
* A generated
|
|
170
|
+
* A generated file that does not match its api.
|
|
169
171
|
*/
|
|
170
|
-
interface
|
|
171
|
-
kind: string;
|
|
172
|
+
interface StaleFile {
|
|
172
173
|
output: string;
|
|
173
174
|
/**
|
|
174
175
|
* `missing` when nothing is there, `outdated` when what is there is old.
|
|
@@ -176,22 +177,24 @@ interface StaleClient {
|
|
|
176
177
|
reason: 'missing' | 'outdated';
|
|
177
178
|
}
|
|
178
179
|
/**
|
|
179
|
-
* Writes every
|
|
180
|
-
* matches so watchers and build tools see no
|
|
180
|
+
* Writes every generated file, the clients and what plugins generate, leaving
|
|
181
|
+
* a file alone when it already matches so watchers and build tools see no
|
|
182
|
+
* change.
|
|
181
183
|
*/
|
|
182
|
-
declare const
|
|
184
|
+
declare const writeFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => WrittenFile[];
|
|
183
185
|
/**
|
|
184
|
-
* Every
|
|
186
|
+
* Every generated file that no longer matches its api, without writing
|
|
187
|
+
* anything.
|
|
185
188
|
*
|
|
186
189
|
* This is what a pipeline runs: a generated client that has fallen behind is a
|
|
187
190
|
* compile error waiting to happen in whatever imports it.
|
|
188
191
|
*/
|
|
189
|
-
declare const
|
|
192
|
+
declare const checkFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => StaleFile[];
|
|
190
193
|
/**
|
|
191
194
|
* What a pipeline prints when a check fails, naming the command that fixes it
|
|
192
195
|
* rather than printing a diff nobody reads.
|
|
193
196
|
*/
|
|
194
|
-
declare const formatStale: (stale: readonly
|
|
197
|
+
declare const formatStale: (stale: readonly StaleFile[], command?: string) => string;
|
|
195
198
|
//#endregion
|
|
196
199
|
//#region src/generate-types.d.ts
|
|
197
200
|
declare class ConfigSyntaxError extends Error {}
|
|
@@ -261,14 +264,18 @@ interface RouteEntry {
|
|
|
261
264
|
tool?: string;
|
|
262
265
|
deprecated?: string;
|
|
263
266
|
sunset?: string;
|
|
267
|
+
/**
|
|
268
|
+
* `true` when the route is `hidden`: served, but in no generated client.
|
|
269
|
+
*/
|
|
270
|
+
hidden?: true;
|
|
264
271
|
}
|
|
265
272
|
/**
|
|
266
273
|
* Every route an api serves, in the order it declares them.
|
|
267
274
|
*/
|
|
268
|
-
declare const routeMap: (
|
|
275
|
+
declare const routeMap: (api: ApiDefinition, _options?: Record<string, never>) => RouteEntry[];
|
|
269
276
|
/**
|
|
270
277
|
* The route map as aligned columns, one route per line.
|
|
271
278
|
*/
|
|
272
279
|
declare const formatRoutes: (entries: readonly RouteEntry[]) => string;
|
|
273
280
|
//#endregion
|
|
274
|
-
export { type Change, type ChangeLevel, ConfigSyntaxError, type DiffAgainstOptions, type Direction, type LoadedApi, type Notice, type RouteEntry, type SchemaChange, type
|
|
281
|
+
export { type Change, type ChangeLevel, ConfigSyntaxError, type DiffAgainstOptions, type Direction, type LoadedApi, type Notice, type RouteEntry, type SchemaChange, type StaleFile, type WrittenFile, apiNotices, checkFiles, diffAgainst, diffApis, diffSchemas, formatChange, formatNotice, formatRoutes, formatStale, generateConfigTypes, hasBreakingChange, loadConfig, routeMap, writeFiles };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as loadConfig, a as ConfigSyntaxError, c as formatStale, f as formatChange, g as diffSchemas, l as
|
|
2
|
-
import {
|
|
1
|
+
import { _ as loadConfig, a as ConfigSyntaxError, c as formatStale, f as formatChange, g as diffSchemas, l as writeFiles, n as routeMap, o as generateConfigTypes, p as hasBreakingChange, r as diffAgainst, s as checkFiles, t as formatRoutes, u as diffApis } from "./route-map-Bt94ERSi.mjs";
|
|
2
|
+
import { walkApi } from "kizunajs/generator";
|
|
3
3
|
//#region src/api-notices.ts
|
|
4
4
|
const readSunset = (route) => {
|
|
5
5
|
const declared = route.sunset;
|
|
@@ -7,14 +7,7 @@ const readSunset = (route) => {
|
|
|
7
7
|
return typeof declared === "string" ? declared : declared.date;
|
|
8
8
|
};
|
|
9
9
|
const daysBetween = (from, to) => Math.ceil((to.getTime() - from.getTime()) / 864e5);
|
|
10
|
-
|
|
11
|
-
* Every route that is deprecated or has a sunset date, soonest first, with
|
|
12
|
-
* undated deprecations last.
|
|
13
|
-
*
|
|
14
|
-
* Reads the same `deprecated` field the generated clients carry in an
|
|
15
|
-
* editor, so a watcher and a hover agree.
|
|
16
|
-
*/
|
|
17
|
-
const apiNotices = createGenerator((options) => {
|
|
10
|
+
const noticesWalk = (options) => {
|
|
18
11
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
19
12
|
const notices = [];
|
|
20
13
|
return {
|
|
@@ -41,7 +34,15 @@ const apiNotices = createGenerator((options) => {
|
|
|
41
34
|
});
|
|
42
35
|
}
|
|
43
36
|
};
|
|
44
|
-
}
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Every route that is deprecated or has a sunset date, soonest first, with
|
|
40
|
+
* undated deprecations last.
|
|
41
|
+
*
|
|
42
|
+
* Reads the same `deprecated` field the generated clients carry in an
|
|
43
|
+
* editor, so a watcher and a hover agree.
|
|
44
|
+
*/
|
|
45
|
+
const apiNotices = (api, options = {}) => walkApi(api, noticesWalk(options));
|
|
45
46
|
/**
|
|
46
47
|
* One line per notice, for a watcher to print.
|
|
47
48
|
*
|
|
@@ -61,4 +62,4 @@ const formatNotice = (notice) => {
|
|
|
61
62
|
return `${notice.method} ${notice.path} ${notice.routeKey} ${parts.join(", ")}${suffix}`;
|
|
62
63
|
};
|
|
63
64
|
//#endregion
|
|
64
|
-
export { ConfigSyntaxError, apiNotices,
|
|
65
|
+
export { ConfigSyntaxError, apiNotices, checkFiles, diffAgainst, diffApis, diffSchemas, formatChange, formatNotice, formatRoutes, formatStale, generateConfigTypes, hasBreakingChange, loadConfig, routeMap, writeFiles };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createJiti } from "jiti";
|
|
2
2
|
import { apiEntries } from "kizunajs";
|
|
3
|
-
import {
|
|
3
|
+
import { deriveToolNames, flattenJobs, readDef, readObjectShape, resolveResponseBody, toToolName, unwrapOptionalWrappers, walkApi } from "kizunajs/generator";
|
|
4
4
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
5
|
import { parse, stringify } from "yaml";
|
|
6
6
|
import { flattenRoutes } from "kizunajs/adapter";
|
|
@@ -25,6 +25,7 @@ const loadConfig = async (configPath) => {
|
|
|
25
25
|
name,
|
|
26
26
|
api: entry.api,
|
|
27
27
|
clients: entry.clients ?? [],
|
|
28
|
+
generators: entry.generators ?? [],
|
|
28
29
|
typesOutput: entry.typescript?.outputFile,
|
|
29
30
|
diff: entry.diff ?? {}
|
|
30
31
|
}));
|
|
@@ -183,10 +184,10 @@ const sunsetOf = (route) => {
|
|
|
183
184
|
if (declared === void 0) return void 0;
|
|
184
185
|
return typeof declared === "string" ? declared : declared.date;
|
|
185
186
|
};
|
|
186
|
-
const routeSnapshots =
|
|
187
|
+
const routeSnapshots = (api) => {
|
|
187
188
|
const routes = {};
|
|
188
|
-
return {
|
|
189
|
-
processRoute({ routeKey, route, deprecated }) {
|
|
189
|
+
return walkApi(api, {
|
|
190
|
+
processRoute({ routeKey, route, deprecated, hidden }) {
|
|
190
191
|
const sunset = sunsetOf(route);
|
|
191
192
|
const responses = {};
|
|
192
193
|
for (const [status, response] of Object.entries(route.responses)) {
|
|
@@ -198,6 +199,7 @@ const routeSnapshots = createGenerator(() => {
|
|
|
198
199
|
path: route.path,
|
|
199
200
|
statuses: Object.keys(route.responses).map(Number).sort((a, b) => a - b),
|
|
200
201
|
deprecated,
|
|
202
|
+
...hidden ? { hidden: true } : {},
|
|
201
203
|
...sunset === void 0 ? {} : { sunset },
|
|
202
204
|
...route.body ? { body: toSchemaNode(route.body) } : {},
|
|
203
205
|
...route.query ? { query: toSchemaNode(route.query) } : {},
|
|
@@ -206,8 +208,8 @@ const routeSnapshots = createGenerator(() => {
|
|
|
206
208
|
};
|
|
207
209
|
},
|
|
208
210
|
finalize: () => routes
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
+
});
|
|
212
|
+
};
|
|
211
213
|
/**
|
|
212
214
|
* Everything `kizuna diff` compares, as plain data.
|
|
213
215
|
*
|
|
@@ -219,7 +221,7 @@ const toSnapshot = (api) => {
|
|
|
219
221
|
const jobs = declared ? flattenJobs(declared).map((job) => job.jobKey).sort() : [];
|
|
220
222
|
const tools = Object.fromEntries(flattenRoutes(api.routes).filter(({ route }) => route.tool !== void 0 && route.tool !== false).map(({ routeKey }) => [routeKey, toToolName(routeKey)]));
|
|
221
223
|
return {
|
|
222
|
-
routes: routeSnapshots(api
|
|
224
|
+
routes: routeSnapshots(api),
|
|
223
225
|
jobs,
|
|
224
226
|
tools
|
|
225
227
|
};
|
|
@@ -244,9 +246,8 @@ const snapshotPathFor = (configPath) => {
|
|
|
244
246
|
* `kizuna generate --check` refuses to let it go stale.
|
|
245
247
|
*/
|
|
246
248
|
const snapshotTarget = (configPath) => ({
|
|
247
|
-
kind: "snapshot",
|
|
248
249
|
output: snapshotPathFor(configPath),
|
|
249
|
-
|
|
250
|
+
render: renderSnapshot
|
|
250
251
|
});
|
|
251
252
|
//#endregion
|
|
252
253
|
//#region src/diff-apis.ts
|
|
@@ -355,6 +356,17 @@ const diffSnapshots = (before, after, options = {}) => {
|
|
|
355
356
|
summary: `${httpLabel(arrived, key)} ${change.summary}`
|
|
356
357
|
});
|
|
357
358
|
}
|
|
359
|
+
if (gone.hidden !== true && arrived.hidden === true) changes.push({
|
|
360
|
+
level: "breaking",
|
|
361
|
+
key,
|
|
362
|
+
summary: `${httpLabel(arrived, key)} is now hidden`,
|
|
363
|
+
detail: "the server still serves it, but it is no longer in the generated clients or the OpenAPI document"
|
|
364
|
+
});
|
|
365
|
+
if (gone.hidden === true && arrived.hidden !== true) changes.push({
|
|
366
|
+
level: "added",
|
|
367
|
+
key,
|
|
368
|
+
summary: `${httpLabel(arrived, key)} is no longer hidden`
|
|
369
|
+
});
|
|
358
370
|
if (!gone.deprecated && arrived.deprecated) changes.push({
|
|
359
371
|
level: "changed",
|
|
360
372
|
key,
|
|
@@ -430,38 +442,37 @@ const currentContents = (output) => {
|
|
|
430
442
|
}
|
|
431
443
|
};
|
|
432
444
|
/**
|
|
433
|
-
* Writes every
|
|
434
|
-
* matches so watchers and build tools see no
|
|
445
|
+
* Writes every generated file, the clients and what plugins generate, leaving
|
|
446
|
+
* a file alone when it already matches so watchers and build tools see no
|
|
447
|
+
* change.
|
|
435
448
|
*/
|
|
436
|
-
const
|
|
437
|
-
const rendered =
|
|
438
|
-
const changed = currentContents(
|
|
449
|
+
const writeFiles = (contract, files) => files.map((file) => {
|
|
450
|
+
const rendered = file.render(contract);
|
|
451
|
+
const changed = currentContents(file.output) !== rendered;
|
|
439
452
|
if (changed) {
|
|
440
|
-
mkdirSync(dirname(
|
|
441
|
-
writeFileSync(
|
|
453
|
+
mkdirSync(dirname(file.output), { recursive: true });
|
|
454
|
+
writeFileSync(file.output, rendered);
|
|
442
455
|
}
|
|
443
456
|
return {
|
|
444
|
-
|
|
445
|
-
output: client.output,
|
|
457
|
+
output: file.output,
|
|
446
458
|
changed
|
|
447
459
|
};
|
|
448
460
|
});
|
|
449
461
|
/**
|
|
450
|
-
* Every
|
|
462
|
+
* Every generated file that no longer matches its api, without writing
|
|
463
|
+
* anything.
|
|
451
464
|
*
|
|
452
465
|
* This is what a pipeline runs: a generated client that has fallen behind is a
|
|
453
466
|
* compile error waiting to happen in whatever imports it.
|
|
454
467
|
*/
|
|
455
|
-
const
|
|
456
|
-
const current = currentContents(
|
|
468
|
+
const checkFiles = (contract, files) => files.flatMap((file) => {
|
|
469
|
+
const current = currentContents(file.output);
|
|
457
470
|
if (current === void 0) return [{
|
|
458
|
-
|
|
459
|
-
output: client.output,
|
|
471
|
+
output: file.output,
|
|
460
472
|
reason: "missing"
|
|
461
473
|
}];
|
|
462
|
-
if (current !==
|
|
463
|
-
|
|
464
|
-
output: client.output,
|
|
474
|
+
if (current !== file.render(contract)) return [{
|
|
475
|
+
output: file.output,
|
|
465
476
|
reason: "outdated"
|
|
466
477
|
}];
|
|
467
478
|
return [];
|
|
@@ -471,9 +482,9 @@ const checkClients = (contract, clients) => clients.flatMap((client) => {
|
|
|
471
482
|
* rather than printing a diff nobody reads.
|
|
472
483
|
*/
|
|
473
484
|
const formatStale = (stale, command = "kizuna generate") => {
|
|
474
|
-
const lines = stale.map((
|
|
475
|
-
const where = relative(process.cwd(),
|
|
476
|
-
return
|
|
485
|
+
const lines = stale.map((file) => {
|
|
486
|
+
const where = relative(process.cwd(), file.output);
|
|
487
|
+
return file.reason === "missing" ? ` ${where} has not been generated` : ` ${where} is behind the config`;
|
|
477
488
|
});
|
|
478
489
|
return [
|
|
479
490
|
stale.length === 1 ? "A generated file is out of date:" : `${stale.length} generated files are out of date:`,
|
|
@@ -600,12 +611,22 @@ const typeOfStringUnion = (expression, key) => {
|
|
|
600
611
|
return codes.length > 0 ? codes.join(" | ") : "never";
|
|
601
612
|
};
|
|
602
613
|
/**
|
|
614
|
+
* The repo's Prettier `printWidth`. A line the generator writes longer than this
|
|
615
|
+
* is one `pnpm format` would rewrite, and `--check` would then report the file
|
|
616
|
+
* as behind.
|
|
617
|
+
*/
|
|
618
|
+
const PRINT_WIDTH = 140;
|
|
619
|
+
/**
|
|
603
620
|
* Each plugin in order, as a tuple, so a handler reaches each one under its own
|
|
604
|
-
* slug.
|
|
621
|
+
* slug. It wraps one plugin per line when the line would run past
|
|
622
|
+
* {@link PRINT_WIDTH}, the way Prettier does.
|
|
605
623
|
*/
|
|
606
|
-
const typeOfPluginList = (expression, used) => {
|
|
624
|
+
const typeOfPluginList = (expression, used, prefix) => {
|
|
607
625
|
if (!ts.isArrayLiteralExpression(expression)) throw new ConfigSyntaxError("`plugins` has to be an array, so each plugin keeps its place.");
|
|
608
|
-
|
|
626
|
+
const entries = expression.elements.map((element) => typeOfValue(element, used, "plugins"));
|
|
627
|
+
const inline = `[${entries.join(", ")}]`;
|
|
628
|
+
if (`${prefix}${inline};`.length <= PRINT_WIDTH) return inline;
|
|
629
|
+
return `[\n${entries.map((entry) => ` ${entry},`).join("\n")}\n ]`;
|
|
609
630
|
};
|
|
610
631
|
/**
|
|
611
632
|
* The `issueCodes` inside `validation`, or nothing when it declares none.
|
|
@@ -702,7 +723,7 @@ const generateConfigTypes = (configSource, fileName = "kizuna.config.ts", output
|
|
|
702
723
|
else if (key === "validation") {
|
|
703
724
|
const codes = issueCodesOf(value);
|
|
704
725
|
if (codes !== void 0) lines.push(` validation: {\n issueCodes: ${codes};\n };`);
|
|
705
|
-
} else if (key === "plugins") lines.push(` ${key}: ${typeOfPluginList(value, used)};`);
|
|
726
|
+
} else if (key === "plugins") lines.push(` ${key}: ${typeOfPluginList(value, used, ` ${key}: `)};`);
|
|
706
727
|
else lines.push(` ${key}: ${typeOfValue(value, used, key)};`);
|
|
707
728
|
}
|
|
708
729
|
const configDir = dirname(resolve(fileName));
|
|
@@ -798,11 +819,11 @@ const describeSunset = (sunset) => {
|
|
|
798
819
|
/**
|
|
799
820
|
* Every route an api serves, in the order it declares them.
|
|
800
821
|
*/
|
|
801
|
-
const routeMap =
|
|
822
|
+
const routeMap = (api, _options = {}) => {
|
|
802
823
|
const entries = [];
|
|
803
824
|
const toolKeys = [];
|
|
804
|
-
return {
|
|
805
|
-
processRoute({ routeKey, route, routeTags, deprecated, deprecationMessage }) {
|
|
825
|
+
return walkApi(api, {
|
|
826
|
+
processRoute({ routeKey, route, routeTags, deprecated, deprecationMessage, hidden }) {
|
|
806
827
|
if (route.tool) toolKeys.push({
|
|
807
828
|
key: routeKey,
|
|
808
829
|
origin: "route"
|
|
@@ -814,7 +835,8 @@ const routeMap = createGenerator((_options, _api) => {
|
|
|
814
835
|
auth: describeAuth(route.auth),
|
|
815
836
|
tags: routeTags,
|
|
816
837
|
deprecated: deprecated ? deprecationMessage ?? "" : void 0,
|
|
817
|
-
sunset: describeSunset(route.sunset)
|
|
838
|
+
sunset: describeSunset(route.sunset),
|
|
839
|
+
...hidden ? { hidden: true } : {}
|
|
818
840
|
});
|
|
819
841
|
},
|
|
820
842
|
finalize() {
|
|
@@ -824,8 +846,8 @@ const routeMap = createGenerator((_options, _api) => {
|
|
|
824
846
|
tool: names.get(entry.key) ?? (toolKeys.some((tool) => tool.key === entry.key) ? toToolName(entry.key) : void 0)
|
|
825
847
|
}));
|
|
826
848
|
}
|
|
827
|
-
};
|
|
828
|
-
}
|
|
849
|
+
});
|
|
850
|
+
};
|
|
829
851
|
const pad = (text, width) => text + " ".repeat(Math.max(0, width - text.length));
|
|
830
852
|
/**
|
|
831
853
|
* The route map as aligned columns, one route per line.
|
|
@@ -840,10 +862,11 @@ const formatRoutes = (entries) => {
|
|
|
840
862
|
`auth: ${entry.auth}`,
|
|
841
863
|
entry.tool && `tool: ${entry.tool}`,
|
|
842
864
|
entry.deprecated !== void 0 && `deprecated${entry.deprecated ? `, ${entry.deprecated}` : ""}`,
|
|
843
|
-
entry.sunset && `sunset ${entry.sunset}
|
|
865
|
+
entry.sunset && `sunset ${entry.sunset}`,
|
|
866
|
+
entry.hidden && "hidden"
|
|
844
867
|
].filter(Boolean);
|
|
845
868
|
return `${pad(entry.method, methodWidth)} ${pad(entry.path, pathWidth)} ${pad(entry.key, keyWidth)} ${notes.join(" ")}`.trimEnd();
|
|
846
869
|
}).join("\n");
|
|
847
870
|
};
|
|
848
871
|
//#endregion
|
|
849
|
-
export { loadConfig as _, ConfigSyntaxError as a, formatStale as c, diffSnapshots as d, formatChange as f, diffSchemas as g, snapshotTarget as h, readSnapshot as i,
|
|
872
|
+
export { loadConfig as _, ConfigSyntaxError as a, formatStale as c, diffSnapshots as d, formatChange as f, diffSchemas as g, snapshotTarget as h, readSnapshot as i, writeFiles as l, snapshotPathFor as m, routeMap as n, generateConfigTypes as o, hasBreakingChange as p, diffAgainst as r, checkFiles as s, formatRoutes as t, diffApis as u };
|
|
@@ -48,6 +48,7 @@ const loadConfig = async (configPath) => {
|
|
|
48
48
|
name,
|
|
49
49
|
api: entry.api,
|
|
50
50
|
clients: entry.clients ?? [],
|
|
51
|
+
generators: entry.generators ?? [],
|
|
51
52
|
typesOutput: entry.typescript?.outputFile,
|
|
52
53
|
diff: entry.diff ?? {}
|
|
53
54
|
}));
|
|
@@ -206,10 +207,10 @@ const sunsetOf = (route) => {
|
|
|
206
207
|
if (declared === void 0) return void 0;
|
|
207
208
|
return typeof declared === "string" ? declared : declared.date;
|
|
208
209
|
};
|
|
209
|
-
const routeSnapshots = (
|
|
210
|
+
const routeSnapshots = (api) => {
|
|
210
211
|
const routes = {};
|
|
211
|
-
return {
|
|
212
|
-
processRoute({ routeKey, route, deprecated }) {
|
|
212
|
+
return (0, kizunajs_generator.walkApi)(api, {
|
|
213
|
+
processRoute({ routeKey, route, deprecated, hidden }) {
|
|
213
214
|
const sunset = sunsetOf(route);
|
|
214
215
|
const responses = {};
|
|
215
216
|
for (const [status, response] of Object.entries(route.responses)) {
|
|
@@ -221,6 +222,7 @@ const routeSnapshots = (0, kizunajs_generator.createGenerator)(() => {
|
|
|
221
222
|
path: route.path,
|
|
222
223
|
statuses: Object.keys(route.responses).map(Number).sort((a, b) => a - b),
|
|
223
224
|
deprecated,
|
|
225
|
+
...hidden ? { hidden: true } : {},
|
|
224
226
|
...sunset === void 0 ? {} : { sunset },
|
|
225
227
|
...route.body ? { body: toSchemaNode(route.body) } : {},
|
|
226
228
|
...route.query ? { query: toSchemaNode(route.query) } : {},
|
|
@@ -229,8 +231,8 @@ const routeSnapshots = (0, kizunajs_generator.createGenerator)(() => {
|
|
|
229
231
|
};
|
|
230
232
|
},
|
|
231
233
|
finalize: () => routes
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
+
});
|
|
235
|
+
};
|
|
234
236
|
/**
|
|
235
237
|
* Everything `kizuna diff` compares, as plain data.
|
|
236
238
|
*
|
|
@@ -242,7 +244,7 @@ const toSnapshot = (api) => {
|
|
|
242
244
|
const jobs = declared ? (0, kizunajs_generator.flattenJobs)(declared).map((job) => job.jobKey).sort() : [];
|
|
243
245
|
const tools = Object.fromEntries((0, kizunajs_adapter.flattenRoutes)(api.routes).filter(({ route }) => route.tool !== void 0 && route.tool !== false).map(({ routeKey }) => [routeKey, (0, kizunajs_generator.toToolName)(routeKey)]));
|
|
244
246
|
return {
|
|
245
|
-
routes: routeSnapshots(api
|
|
247
|
+
routes: routeSnapshots(api),
|
|
246
248
|
jobs,
|
|
247
249
|
tools
|
|
248
250
|
};
|
|
@@ -267,9 +269,8 @@ const snapshotPathFor = (configPath) => {
|
|
|
267
269
|
* `kizuna generate --check` refuses to let it go stale.
|
|
268
270
|
*/
|
|
269
271
|
const snapshotTarget = (configPath) => ({
|
|
270
|
-
kind: "snapshot",
|
|
271
272
|
output: snapshotPathFor(configPath),
|
|
272
|
-
|
|
273
|
+
render: renderSnapshot
|
|
273
274
|
});
|
|
274
275
|
//#endregion
|
|
275
276
|
//#region src/diff-apis.ts
|
|
@@ -378,6 +379,17 @@ const diffSnapshots = (before, after, options = {}) => {
|
|
|
378
379
|
summary: `${httpLabel(arrived, key)} ${change.summary}`
|
|
379
380
|
});
|
|
380
381
|
}
|
|
382
|
+
if (gone.hidden !== true && arrived.hidden === true) changes.push({
|
|
383
|
+
level: "breaking",
|
|
384
|
+
key,
|
|
385
|
+
summary: `${httpLabel(arrived, key)} is now hidden`,
|
|
386
|
+
detail: "the server still serves it, but it is no longer in the generated clients or the OpenAPI document"
|
|
387
|
+
});
|
|
388
|
+
if (gone.hidden === true && arrived.hidden !== true) changes.push({
|
|
389
|
+
level: "added",
|
|
390
|
+
key,
|
|
391
|
+
summary: `${httpLabel(arrived, key)} is no longer hidden`
|
|
392
|
+
});
|
|
381
393
|
if (!gone.deprecated && arrived.deprecated) changes.push({
|
|
382
394
|
level: "changed",
|
|
383
395
|
key,
|
|
@@ -453,38 +465,37 @@ const currentContents = (output) => {
|
|
|
453
465
|
}
|
|
454
466
|
};
|
|
455
467
|
/**
|
|
456
|
-
* Writes every
|
|
457
|
-
* matches so watchers and build tools see no
|
|
468
|
+
* Writes every generated file, the clients and what plugins generate, leaving
|
|
469
|
+
* a file alone when it already matches so watchers and build tools see no
|
|
470
|
+
* change.
|
|
458
471
|
*/
|
|
459
|
-
const
|
|
460
|
-
const rendered =
|
|
461
|
-
const changed = currentContents(
|
|
472
|
+
const writeFiles = (contract, files) => files.map((file) => {
|
|
473
|
+
const rendered = file.render(contract);
|
|
474
|
+
const changed = currentContents(file.output) !== rendered;
|
|
462
475
|
if (changed) {
|
|
463
|
-
(0, node_fs.mkdirSync)((0, node_path.dirname)(
|
|
464
|
-
(0, node_fs.writeFileSync)(
|
|
476
|
+
(0, node_fs.mkdirSync)((0, node_path.dirname)(file.output), { recursive: true });
|
|
477
|
+
(0, node_fs.writeFileSync)(file.output, rendered);
|
|
465
478
|
}
|
|
466
479
|
return {
|
|
467
|
-
|
|
468
|
-
output: client.output,
|
|
480
|
+
output: file.output,
|
|
469
481
|
changed
|
|
470
482
|
};
|
|
471
483
|
});
|
|
472
484
|
/**
|
|
473
|
-
* Every
|
|
485
|
+
* Every generated file that no longer matches its api, without writing
|
|
486
|
+
* anything.
|
|
474
487
|
*
|
|
475
488
|
* This is what a pipeline runs: a generated client that has fallen behind is a
|
|
476
489
|
* compile error waiting to happen in whatever imports it.
|
|
477
490
|
*/
|
|
478
|
-
const
|
|
479
|
-
const current = currentContents(
|
|
491
|
+
const checkFiles = (contract, files) => files.flatMap((file) => {
|
|
492
|
+
const current = currentContents(file.output);
|
|
480
493
|
if (current === void 0) return [{
|
|
481
|
-
|
|
482
|
-
output: client.output,
|
|
494
|
+
output: file.output,
|
|
483
495
|
reason: "missing"
|
|
484
496
|
}];
|
|
485
|
-
if (current !==
|
|
486
|
-
|
|
487
|
-
output: client.output,
|
|
497
|
+
if (current !== file.render(contract)) return [{
|
|
498
|
+
output: file.output,
|
|
488
499
|
reason: "outdated"
|
|
489
500
|
}];
|
|
490
501
|
return [];
|
|
@@ -494,9 +505,9 @@ const checkClients = (contract, clients) => clients.flatMap((client) => {
|
|
|
494
505
|
* rather than printing a diff nobody reads.
|
|
495
506
|
*/
|
|
496
507
|
const formatStale = (stale, command = "kizuna generate") => {
|
|
497
|
-
const lines = stale.map((
|
|
498
|
-
const where = (0, node_path.relative)(process.cwd(),
|
|
499
|
-
return
|
|
508
|
+
const lines = stale.map((file) => {
|
|
509
|
+
const where = (0, node_path.relative)(process.cwd(), file.output);
|
|
510
|
+
return file.reason === "missing" ? ` ${where} has not been generated` : ` ${where} is behind the config`;
|
|
500
511
|
});
|
|
501
512
|
return [
|
|
502
513
|
stale.length === 1 ? "A generated file is out of date:" : `${stale.length} generated files are out of date:`,
|
|
@@ -623,12 +634,22 @@ const typeOfStringUnion = (expression, key) => {
|
|
|
623
634
|
return codes.length > 0 ? codes.join(" | ") : "never";
|
|
624
635
|
};
|
|
625
636
|
/**
|
|
637
|
+
* The repo's Prettier `printWidth`. A line the generator writes longer than this
|
|
638
|
+
* is one `pnpm format` would rewrite, and `--check` would then report the file
|
|
639
|
+
* as behind.
|
|
640
|
+
*/
|
|
641
|
+
const PRINT_WIDTH = 140;
|
|
642
|
+
/**
|
|
626
643
|
* Each plugin in order, as a tuple, so a handler reaches each one under its own
|
|
627
|
-
* slug.
|
|
644
|
+
* slug. It wraps one plugin per line when the line would run past
|
|
645
|
+
* {@link PRINT_WIDTH}, the way Prettier does.
|
|
628
646
|
*/
|
|
629
|
-
const typeOfPluginList = (expression, used) => {
|
|
647
|
+
const typeOfPluginList = (expression, used, prefix) => {
|
|
630
648
|
if (!typescript.default.isArrayLiteralExpression(expression)) throw new ConfigSyntaxError("`plugins` has to be an array, so each plugin keeps its place.");
|
|
631
|
-
|
|
649
|
+
const entries = expression.elements.map((element) => typeOfValue(element, used, "plugins"));
|
|
650
|
+
const inline = `[${entries.join(", ")}]`;
|
|
651
|
+
if (`${prefix}${inline};`.length <= PRINT_WIDTH) return inline;
|
|
652
|
+
return `[\n${entries.map((entry) => ` ${entry},`).join("\n")}\n ]`;
|
|
632
653
|
};
|
|
633
654
|
/**
|
|
634
655
|
* The `issueCodes` inside `validation`, or nothing when it declares none.
|
|
@@ -725,7 +746,7 @@ const generateConfigTypes = (configSource, fileName = "kizuna.config.ts", output
|
|
|
725
746
|
else if (key === "validation") {
|
|
726
747
|
const codes = issueCodesOf(value);
|
|
727
748
|
if (codes !== void 0) lines.push(` validation: {\n issueCodes: ${codes};\n };`);
|
|
728
|
-
} else if (key === "plugins") lines.push(` ${key}: ${typeOfPluginList(value, used)};`);
|
|
749
|
+
} else if (key === "plugins") lines.push(` ${key}: ${typeOfPluginList(value, used, ` ${key}: `)};`);
|
|
729
750
|
else lines.push(` ${key}: ${typeOfValue(value, used, key)};`);
|
|
730
751
|
}
|
|
731
752
|
const configDir = (0, node_path.dirname)((0, node_path.resolve)(fileName));
|
|
@@ -821,11 +842,11 @@ const describeSunset = (sunset) => {
|
|
|
821
842
|
/**
|
|
822
843
|
* Every route an api serves, in the order it declares them.
|
|
823
844
|
*/
|
|
824
|
-
const routeMap = (
|
|
845
|
+
const routeMap = (api, _options = {}) => {
|
|
825
846
|
const entries = [];
|
|
826
847
|
const toolKeys = [];
|
|
827
|
-
return {
|
|
828
|
-
processRoute({ routeKey, route, routeTags, deprecated, deprecationMessage }) {
|
|
848
|
+
return (0, kizunajs_generator.walkApi)(api, {
|
|
849
|
+
processRoute({ routeKey, route, routeTags, deprecated, deprecationMessage, hidden }) {
|
|
829
850
|
if (route.tool) toolKeys.push({
|
|
830
851
|
key: routeKey,
|
|
831
852
|
origin: "route"
|
|
@@ -837,7 +858,8 @@ const routeMap = (0, kizunajs_generator.createGenerator)((_options, _api) => {
|
|
|
837
858
|
auth: describeAuth(route.auth),
|
|
838
859
|
tags: routeTags,
|
|
839
860
|
deprecated: deprecated ? deprecationMessage ?? "" : void 0,
|
|
840
|
-
sunset: describeSunset(route.sunset)
|
|
861
|
+
sunset: describeSunset(route.sunset),
|
|
862
|
+
...hidden ? { hidden: true } : {}
|
|
841
863
|
});
|
|
842
864
|
},
|
|
843
865
|
finalize() {
|
|
@@ -847,8 +869,8 @@ const routeMap = (0, kizunajs_generator.createGenerator)((_options, _api) => {
|
|
|
847
869
|
tool: names.get(entry.key) ?? (toolKeys.some((tool) => tool.key === entry.key) ? (0, kizunajs_generator.toToolName)(entry.key) : void 0)
|
|
848
870
|
}));
|
|
849
871
|
}
|
|
850
|
-
};
|
|
851
|
-
}
|
|
872
|
+
});
|
|
873
|
+
};
|
|
852
874
|
const pad = (text, width) => text + " ".repeat(Math.max(0, width - text.length));
|
|
853
875
|
/**
|
|
854
876
|
* The route map as aligned columns, one route per line.
|
|
@@ -863,7 +885,8 @@ const formatRoutes = (entries) => {
|
|
|
863
885
|
`auth: ${entry.auth}`,
|
|
864
886
|
entry.tool && `tool: ${entry.tool}`,
|
|
865
887
|
entry.deprecated !== void 0 && `deprecated${entry.deprecated ? `, ${entry.deprecated}` : ""}`,
|
|
866
|
-
entry.sunset && `sunset ${entry.sunset}
|
|
888
|
+
entry.sunset && `sunset ${entry.sunset}`,
|
|
889
|
+
entry.hidden && "hidden"
|
|
867
890
|
].filter(Boolean);
|
|
868
891
|
return `${pad(entry.method, methodWidth)} ${pad(entry.path, pathWidth)} ${pad(entry.key, keyWidth)} ${notes.join(" ")}`.trimEnd();
|
|
869
892
|
}).join("\n");
|
|
@@ -881,10 +904,10 @@ Object.defineProperty(exports, "__toESM", {
|
|
|
881
904
|
return __toESM;
|
|
882
905
|
}
|
|
883
906
|
});
|
|
884
|
-
Object.defineProperty(exports, "
|
|
907
|
+
Object.defineProperty(exports, "checkFiles", {
|
|
885
908
|
enumerable: true,
|
|
886
909
|
get: function() {
|
|
887
|
-
return
|
|
910
|
+
return checkFiles;
|
|
888
911
|
}
|
|
889
912
|
});
|
|
890
913
|
Object.defineProperty(exports, "diffAgainst", {
|
|
@@ -971,9 +994,9 @@ Object.defineProperty(exports, "snapshotTarget", {
|
|
|
971
994
|
return snapshotTarget;
|
|
972
995
|
}
|
|
973
996
|
});
|
|
974
|
-
Object.defineProperty(exports, "
|
|
997
|
+
Object.defineProperty(exports, "writeFiles", {
|
|
975
998
|
enumerable: true,
|
|
976
999
|
get: function() {
|
|
977
|
-
return
|
|
1000
|
+
return writeFiles;
|
|
978
1001
|
}
|
|
979
1002
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kizunajs/cli",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.12",
|
|
4
4
|
"description": "Command line tooling for Kizuna.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kizunajs",
|
|
@@ -62,14 +62,14 @@
|
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"zod": "^4.0.0",
|
|
65
|
-
"kizunajs": "2.0.0-beta.
|
|
65
|
+
"kizunajs": "2.0.0-beta.12"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/node": "^24",
|
|
69
69
|
"@types/react": "^19.2.18",
|
|
70
70
|
"tsdown": "^0.21.0",
|
|
71
71
|
"zod": "^4.0.0",
|
|
72
|
-
"kizunajs": "2.0.0-beta.
|
|
72
|
+
"kizunajs": "2.0.0-beta.12"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"build": "tsdown src/index.ts src/cli.ts --format esm,cjs --dts --clean --external kizunajs --external zod --external jiti --external typescript",
|