vovk-cli 0.0.1-draft.340 → 0.0.1-draft.345
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/client-templates/cjs/index.cjs.ejs +2 -2
- package/client-templates/ts/index.ts.ejs +1 -1
- package/dist/bundle/index.mjs +12 -0
- package/dist/dev/index.mjs +0 -1
- package/dist/dev/writeMetaJson.mjs +0 -1
- package/dist/generate/ensureClient.mjs +1 -1
- package/dist/generate/generate.mjs +10 -4
- package/dist/generate/getProjectFullSchema.d.mts +1 -3
- package/dist/generate/getProjectFullSchema.mjs +1 -2
- package/dist/generate/getTemplateClientImports.mjs +11 -1
- package/dist/generate/index.mjs +1 -2
- package/dist/generate/writeOneClientFile.d.mts +2 -1
- package/dist/generate/writeOneClientFile.mjs +7 -7
- package/dist/getProjectInfo/getConfig/index.mjs +0 -12
- package/dist/getProjectInfo/getMetaSchema.d.mts +1 -30
- package/dist/getProjectInfo/getMetaSchema.mjs +1 -24
- package/dist/index.mjs +4 -5
- package/dist/init/createStandardSchemaValidatorFile.d.mts +2 -2
- package/dist/init/createStandardSchemaValidatorFile.mjs +6 -5
- package/dist/init/index.mjs +9 -9
- package/dist/types.d.mts +2 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<%- t.getFirstLineBanner() %>
|
|
2
2
|
const { createRPC } = require('<%= t.commonImports.createRPC %>');
|
|
3
3
|
const { schema } = require('./schema.cjs');
|
|
4
|
-
const openapi = require('./openapi.cjs');
|
|
4
|
+
const { openapi } = require('./openapi.cjs');
|
|
5
5
|
const { validateOnClient = null } = <%- t.imports.validateOnClient ? `require('${t.imports.validateOnClient}')` : '{}'%>;
|
|
6
6
|
<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment) => { %>
|
|
7
7
|
<% Object.entries(t.segmentMeta[segment.segmentName].reExports).forEach(([reExportWhatCommaDivisible, reExportFrom]) => {
|
|
@@ -12,7 +12,7 @@ exports['<%= reExportWhat.split(/\s+as\s+/)[1] ?? reExportWhat %>'] = require('<
|
|
|
12
12
|
<% Object.keys(segment.controllers).forEach((rpcModuleName) => { %>
|
|
13
13
|
exports.<%= rpcModuleName %> = createRPC(
|
|
14
14
|
schema, '<%= segment.segmentName %>', '<%= rpcModuleName %>', require('<%= t.segmentImports[segment.segmentName].fetcher %>').fetcher,
|
|
15
|
-
{ validateOnClient:
|
|
15
|
+
{ validateOnClient: <%- t.segmentImports[segment.segmentName].validateOnClient ? `require('${t.segmentImports[segment.segmentName].validateOnClient}').validateOnClient` : 'undefined' %>, <%- typeof t.segmentMeta[segment.segmentName].segmentNameOverride === 'string' ? `segmentNameOverride: '${t.segmentMeta[segment.segmentName].segmentNameOverride}', ` : '' %><%- segment.segmentType === 'mixin' ? '' : `apiRoot: '${t.segmentMeta[segment.segmentName].forceApiRoot ?? t.apiRoot}'` %> }
|
|
16
16
|
);
|
|
17
17
|
<% })
|
|
18
18
|
}) %>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { VovkClientFetcher } from 'vovk';
|
|
3
3
|
import { createRPC } from '<%= t.commonImports.module.createRPC %>';
|
|
4
4
|
import { schema } from './schema<%= t.nodeNextResolutionExt.ts %>';
|
|
5
|
-
import { openapi } from './openapi<%= t.nodeNextResolutionExt.
|
|
5
|
+
import { openapi } from './openapi<%= t.nodeNextResolutionExt.ts %>';
|
|
6
6
|
<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { if(segment.segmentType !== 'mixin') { %>
|
|
7
7
|
import type { Controllers as Controllers<%= i %> } from "<%= t.segmentMeta[segment.segmentName].segmentImportPath %>";
|
|
8
8
|
<% }
|
package/dist/bundle/index.mjs
CHANGED
|
@@ -30,6 +30,7 @@ export async function bundle({ projectInfo, fullSchema, cliBundleOptions, }) {
|
|
|
30
30
|
fullSchema,
|
|
31
31
|
locatedSegments,
|
|
32
32
|
cliGenerateOptions: {
|
|
33
|
+
schemaPath: cliBundleOptions?.schemaPath,
|
|
33
34
|
origin: cliBundleOptions?.origin,
|
|
34
35
|
openapiSpec: cliBundleOptions?.openapiSpec,
|
|
35
36
|
openapiGetModuleName: cliBundleOptions?.openapiGetModuleName,
|
|
@@ -63,6 +64,16 @@ export async function bundle({ projectInfo, fullSchema, cliBundleOptions, }) {
|
|
|
63
64
|
tsconfig,
|
|
64
65
|
});
|
|
65
66
|
log.debug(`Bundled schema.ts to ${chalkHighlightThing(outDirAbsolute)}`);
|
|
67
|
+
await build({
|
|
68
|
+
entry: path.join(tsFullClientOutAbsoluteDirInput, './openapi.ts'),
|
|
69
|
+
dts: true,
|
|
70
|
+
format: ['cjs'],
|
|
71
|
+
fixedExtension: true,
|
|
72
|
+
outDir: outDirAbsolute,
|
|
73
|
+
clean: false,
|
|
74
|
+
tsconfig,
|
|
75
|
+
});
|
|
76
|
+
log.debug(`Bundled openapi.ts to ${chalkHighlightThing(outDirAbsolute)}`);
|
|
66
77
|
const requiresGroup = groupBy(Object.entries(bundleConfig.requires), ([, relativePath]) => relativePath);
|
|
67
78
|
for (const [relativePath, group] of Object.entries(requiresGroup)) {
|
|
68
79
|
await generate({
|
|
@@ -72,6 +83,7 @@ export async function bundle({ projectInfo, fullSchema, cliBundleOptions, }) {
|
|
|
72
83
|
fullSchema,
|
|
73
84
|
locatedSegments,
|
|
74
85
|
cliGenerateOptions: {
|
|
86
|
+
schemaPath: cliBundleOptions?.schemaPath,
|
|
75
87
|
origin: cliBundleOptions?.origin,
|
|
76
88
|
composedFrom: group.map(([templateName]) => templateName),
|
|
77
89
|
composedOut: path.resolve(outDirAbsolute, relativePath),
|
package/dist/dev/index.mjs
CHANGED
|
@@ -7,7 +7,6 @@ export default async function writeMetaJson(schemaOutAbsolutePath, projectInfo)
|
|
|
7
7
|
const metaJsonPath = path.join(schemaOutAbsolutePath, META_FILE_NAME + '.json');
|
|
8
8
|
const metaStr = JSON.stringify(getMetaSchema({
|
|
9
9
|
config: projectInfo.config,
|
|
10
|
-
package: projectInfo.packageJson,
|
|
11
10
|
}), null, 2);
|
|
12
11
|
const existingStr = await fs.readFile(metaJsonPath, 'utf-8').catch(() => null);
|
|
13
12
|
if (existingStr !== metaStr) {
|
|
@@ -21,7 +21,7 @@ export default async function ensureClient(projectInfo, locatedSegments) {
|
|
|
21
21
|
fullSchema: {
|
|
22
22
|
$schema: VovkSchemaIdEnum.SCHEMA,
|
|
23
23
|
segments: getEmptySegmentRecordSchema(locatedSegments.map(({ segmentName }) => segmentName)),
|
|
24
|
-
meta: getMetaSchema({ config: projectInfo.config
|
|
24
|
+
meta: getMetaSchema({ config: projectInfo.config }),
|
|
25
25
|
},
|
|
26
26
|
locatedSegments,
|
|
27
27
|
});
|
|
@@ -93,8 +93,10 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
|
|
|
93
93
|
// preserve original object, so segments can be extended
|
|
94
94
|
.map((segment) => ({ ...segment }))),
|
|
95
95
|
};
|
|
96
|
-
const { config, cwd, log, srcRoot, vovkCliPackage } = projectInfo;
|
|
97
|
-
Object.entries(config.generatorConfig.segments ?? {})
|
|
96
|
+
const { config, cwd, log, srcRoot, vovkCliPackage, packageJson: projectPackageJson } = projectInfo;
|
|
97
|
+
Object.entries(config.generatorConfig.segments ?? {})
|
|
98
|
+
.filter(([, segmentConfig]) => segmentConfig.openAPIMixin)
|
|
99
|
+
.forEach(([segmentName, segmentConfig]) => {
|
|
98
100
|
fullSchema.segments = {
|
|
99
101
|
...fullSchema.segments,
|
|
100
102
|
[segmentName]: openAPIToVovkSchema({ ...segmentConfig.openAPIMixin, segmentName }).segments[segmentName],
|
|
@@ -135,7 +137,8 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
|
|
|
135
137
|
: { data: { imports: [] }, content: templateContent };
|
|
136
138
|
const { package: packageJson, readme, origin, snippets, } = getGeneratorConfig({
|
|
137
139
|
schema: fullSchema,
|
|
138
|
-
|
|
140
|
+
configs: [templateDef.generatorConfig ?? {}],
|
|
141
|
+
projectPackageJson,
|
|
139
142
|
isBundle,
|
|
140
143
|
segmentName: null,
|
|
141
144
|
});
|
|
@@ -172,6 +175,7 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
|
|
|
172
175
|
isBundle,
|
|
173
176
|
origin: cliGenerateOptions?.origin ?? origin,
|
|
174
177
|
configKey: 'composedClient',
|
|
178
|
+
cliSchemaPath: cliGenerateOptions?.schemaPath ?? null,
|
|
175
179
|
});
|
|
176
180
|
const outAbsoluteDir = path.resolve(cwd, outCwdRelativeDir);
|
|
177
181
|
return {
|
|
@@ -215,7 +219,8 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
|
|
|
215
219
|
const results = await Promise.all(segmentNames.map(async (segmentName) => {
|
|
216
220
|
const { package: packageJson, readme, origin, snippets, } = getGeneratorConfig({
|
|
217
221
|
schema: fullSchema,
|
|
218
|
-
|
|
222
|
+
configs: [templateDef.generatorConfig ?? {}],
|
|
223
|
+
projectPackageJson,
|
|
219
224
|
segmentName,
|
|
220
225
|
isBundle,
|
|
221
226
|
});
|
|
@@ -253,6 +258,7 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
|
|
|
253
258
|
isBundle,
|
|
254
259
|
origin: cliGenerateOptions?.origin ?? origin,
|
|
255
260
|
configKey: 'segmentedClient',
|
|
261
|
+
cliSchemaPath: cliGenerateOptions?.schemaPath ?? null,
|
|
256
262
|
});
|
|
257
263
|
return {
|
|
258
264
|
written,
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { VovkStrictConfig, type VovkSchema } from 'vovk';
|
|
2
2
|
import type { ProjectInfo } from '../getProjectInfo/index.mjs';
|
|
3
|
-
|
|
4
|
-
export declare function getProjectFullSchema({ schemaOutAbsolutePath, isNextInstalled, log, package: packageJson, config, }: {
|
|
3
|
+
export declare function getProjectFullSchema({ schemaOutAbsolutePath, isNextInstalled, log, config, }: {
|
|
5
4
|
schemaOutAbsolutePath: string;
|
|
6
5
|
isNextInstalled: boolean;
|
|
7
6
|
log: ProjectInfo['log'];
|
|
8
|
-
package: PackageJson;
|
|
9
7
|
config: VovkStrictConfig;
|
|
10
8
|
}): Promise<VovkSchema>;
|
|
@@ -4,13 +4,12 @@ import { glob } from 'glob';
|
|
|
4
4
|
import { VovkSchemaIdEnum } from 'vovk';
|
|
5
5
|
import { META_FILE_NAME, ROOT_SEGMENT_FILE_NAME } from '../dev/writeOneSegmentSchemaFile.mjs';
|
|
6
6
|
import getMetaSchema from '../getProjectInfo/getMetaSchema.mjs';
|
|
7
|
-
export async function getProjectFullSchema({ schemaOutAbsolutePath, isNextInstalled, log,
|
|
7
|
+
export async function getProjectFullSchema({ schemaOutAbsolutePath, isNextInstalled, log, config, }) {
|
|
8
8
|
const result = {
|
|
9
9
|
$schema: VovkSchemaIdEnum.SCHEMA,
|
|
10
10
|
segments: {},
|
|
11
11
|
meta: getMetaSchema({
|
|
12
12
|
config,
|
|
13
|
-
package: packageJson,
|
|
14
13
|
}),
|
|
15
14
|
};
|
|
16
15
|
const isEmptyLogOrWarn = isNextInstalled ? log.warn : log.debug;
|
|
@@ -2,7 +2,17 @@ import path from 'node:path';
|
|
|
2
2
|
import { getGeneratorConfig } from 'vovk';
|
|
3
3
|
import { ROOT_SEGMENT_FILE_NAME } from '../dev/writeOneSegmentSchemaFile.mjs';
|
|
4
4
|
export default function getTemplateClientImports({ fullSchema, outCwdRelativeDir, segmentName, isBundle, }) {
|
|
5
|
-
const { imports } = getGeneratorConfig({ schema: fullSchema, segmentName, isBundle });
|
|
5
|
+
const { imports: configImports } = getGeneratorConfig({ schema: fullSchema, segmentName, isBundle });
|
|
6
|
+
const validateOnClientImport = configImports?.validateOnClient ?? null;
|
|
7
|
+
const fetcherImport = configImports?.fetcher ?? 'vovk';
|
|
8
|
+
const createRPCImport = configImports?.createRPC ?? 'vovk';
|
|
9
|
+
const imports = {
|
|
10
|
+
fetcher: typeof fetcherImport === 'string' ? [fetcherImport] : fetcherImport,
|
|
11
|
+
validateOnClient: typeof validateOnClientImport === 'string'
|
|
12
|
+
? [validateOnClientImport]
|
|
13
|
+
: (validateOnClientImport ?? null),
|
|
14
|
+
createRPC: typeof createRPCImport === 'string' ? [createRPCImport] : createRPCImport,
|
|
15
|
+
};
|
|
6
16
|
const getImportPath = (p, s = '') => p.startsWith('.') ? path.relative(path.join(outCwdRelativeDir, s), p) : p;
|
|
7
17
|
const clientImports = {
|
|
8
18
|
composedClient: {
|
package/dist/generate/index.mjs
CHANGED
|
@@ -37,13 +37,12 @@ export class VovkGenerate {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
async getFullSchema() {
|
|
40
|
-
const { log, config, cwd, isNextInstalled
|
|
40
|
+
const { log, config, cwd, isNextInstalled } = this.#projectInfo;
|
|
41
41
|
const { schemaPath } = this.#cliGenerateOptions;
|
|
42
42
|
const fullSchema = await getProjectFullSchema({
|
|
43
43
|
schemaOutAbsolutePath: path.resolve(cwd, schemaPath ?? config.schemaOutDir),
|
|
44
44
|
isNextInstalled,
|
|
45
45
|
log,
|
|
46
|
-
package: packageJson,
|
|
47
46
|
config,
|
|
48
47
|
});
|
|
49
48
|
return fullSchema;
|
|
@@ -5,7 +5,7 @@ import type { ClientTemplateFile } from './getClientTemplateFiles.mjs';
|
|
|
5
5
|
import type { Segment } from '../locateSegments.mjs';
|
|
6
6
|
import { OpenAPIObject } from 'openapi3-ts/oas31';
|
|
7
7
|
export declare function normalizeOutTemplatePath(out: string, packageJson: PackageJson): string;
|
|
8
|
-
export default function writeOneClientFile({ cwd, projectInfo, clientTemplateFile, fullSchema, prettifyClient, segmentName, templateContent, matterResult: { data, content }, openapi, package: packageJson, readme, snippets, isEnsuringClient, outCwdRelativeDir, locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage, isBundle, origin, configKey, }: {
|
|
8
|
+
export default function writeOneClientFile({ cwd, projectInfo, clientTemplateFile, fullSchema, prettifyClient, segmentName, templateContent, matterResult: { data, content }, openapi, package: packageJson, readme, snippets, isEnsuringClient, outCwdRelativeDir, locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage, isBundle, origin, configKey, cliSchemaPath, }: {
|
|
9
9
|
cwd: string;
|
|
10
10
|
projectInfo: ProjectInfo;
|
|
11
11
|
clientTemplateFile: ClientTemplateFile;
|
|
@@ -34,6 +34,7 @@ export default function writeOneClientFile({ cwd, projectInfo, clientTemplateFil
|
|
|
34
34
|
isBundle: boolean;
|
|
35
35
|
origin: string | null;
|
|
36
36
|
configKey: 'composedClient' | 'segmentedClient';
|
|
37
|
+
cliSchemaPath: string | null;
|
|
37
38
|
}): Promise<{
|
|
38
39
|
written: boolean;
|
|
39
40
|
}>;
|
|
@@ -16,16 +16,16 @@ export default async function writeOneClientFile({ cwd, projectInfo, clientTempl
|
|
|
16
16
|
// imports,
|
|
17
17
|
templateContent, matterResult: { data, content }, openapi, package: packageJson, readme, snippets, isEnsuringClient, outCwdRelativeDir,
|
|
18
18
|
// templateDef,
|
|
19
|
-
locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage, isBundle, origin, configKey, }) {
|
|
19
|
+
locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage, isBundle, origin, configKey, cliSchemaPath, }) {
|
|
20
20
|
const { config, apiRoot } = projectInfo;
|
|
21
21
|
const { templateFilePath, relativeDir } = clientTemplateFile;
|
|
22
22
|
const locatedSegmentsByName = _.keyBy(locatedSegments, 'segmentName');
|
|
23
23
|
const outPath = normalizeOutTemplatePath(path.resolve(cwd, outCwdRelativeDir, typeof segmentName === 'string' ? segmentName || ROOT_SEGMENT_FILE_NAME : '', relativeDir, path.basename(templateFilePath).replace('.ejs', '')), packageJson);
|
|
24
|
-
let placeholder =
|
|
25
|
-
?
|
|
24
|
+
let placeholder = templateFilePath.endsWith('.json.ejs')
|
|
25
|
+
? ''
|
|
26
|
+
: `// This is a temporary placeholder to avoid compilation errors if client is imported before it's generated.
|
|
26
27
|
// If you still see this text, the client is not generated yet because of an unknown problem.
|
|
27
|
-
// Feel free to report an issue at https://github.com/finom/vovk/issues
|
|
28
|
-
: '{}';
|
|
28
|
+
// Feel free to report an issue at https://github.com/finom/vovk/issues`;
|
|
29
29
|
placeholder = outPath.endsWith('.py') ? placeholder.replace(/\/\//g, '#') : placeholder;
|
|
30
30
|
const getFirstLineBanner = (type = 'c') => {
|
|
31
31
|
const text = `auto-generated by vovk-cli v${vovkCliPackage.version} at ${new Date().toISOString()}`;
|
|
@@ -64,8 +64,8 @@ locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage,
|
|
|
64
64
|
mjs: isNodeNextResolution ? '.mjs' : '',
|
|
65
65
|
},
|
|
66
66
|
schemaOutDir: typeof segmentName === 'string'
|
|
67
|
-
? path.relative(path.join(outCwdRelativeDir, segmentName || ROOT_SEGMENT_FILE_NAME), config.schemaOutDir)
|
|
68
|
-
: path.relative(outCwdRelativeDir, config.schemaOutDir),
|
|
67
|
+
? path.relative(path.join(outCwdRelativeDir, segmentName || ROOT_SEGMENT_FILE_NAME), cliSchemaPath ?? config.schemaOutDir)
|
|
68
|
+
: path.relative(outCwdRelativeDir, cliSchemaPath ?? config.schemaOutDir),
|
|
69
69
|
commonImports: getTemplateClientImports({ fullSchema, isBundle, outCwdRelativeDir, segmentName })['composedClient'],
|
|
70
70
|
segmentImports: Object.fromEntries(Object.values(fullSchema.segments).map(({ segmentName: sName }) => {
|
|
71
71
|
const clientImports = getTemplateClientImports({ fullSchema, segmentName: sName, isBundle, outCwdRelativeDir });
|
|
@@ -17,16 +17,6 @@ export default async function getConfig({ configPath, cwd, logLevel, }) {
|
|
|
17
17
|
const env = process.env;
|
|
18
18
|
const clientTemplateDefs = getTemplateDefs(conf.clientTemplateDefs);
|
|
19
19
|
const srcRoot = await getRelativeSrcRoot({ cwd });
|
|
20
|
-
const validateOnClientImport = conf.generatorConfig?.imports?.validateOnClient ?? null;
|
|
21
|
-
const fetcherImport = conf.generatorConfig?.imports?.fetcher ?? 'vovk';
|
|
22
|
-
const createRPCImport = conf.generatorConfig?.imports?.createRPC ?? 'vovk';
|
|
23
|
-
const imports = {
|
|
24
|
-
fetcher: typeof fetcherImport === 'string' ? [fetcherImport] : fetcherImport,
|
|
25
|
-
validateOnClient: typeof validateOnClientImport === 'string'
|
|
26
|
-
? [validateOnClientImport]
|
|
27
|
-
: (validateOnClientImport ?? null),
|
|
28
|
-
createRPC: typeof createRPCImport === 'string' ? [createRPCImport] : createRPCImport,
|
|
29
|
-
};
|
|
30
20
|
const config = {
|
|
31
21
|
$schema: VovkSchemaIdEnum.CONFIG,
|
|
32
22
|
clientTemplateDefs,
|
|
@@ -51,7 +41,6 @@ export default async function getConfig({ configPath, cwd, logLevel, }) {
|
|
|
51
41
|
requires: {
|
|
52
42
|
[BuiltInTemplateName.readme]: '.',
|
|
53
43
|
[BuiltInTemplateName.packageJson]: '.',
|
|
54
|
-
[BuiltInTemplateName.openapiJson]: '.',
|
|
55
44
|
},
|
|
56
45
|
generatorConfig: {},
|
|
57
46
|
...conf.bundle,
|
|
@@ -74,7 +63,6 @@ export default async function getConfig({ configPath, cwd, logLevel, }) {
|
|
|
74
63
|
libs: conf.libs ?? {},
|
|
75
64
|
generatorConfig: {
|
|
76
65
|
...conf.generatorConfig,
|
|
77
|
-
imports,
|
|
78
66
|
origin: (env.VOVK_ORIGIN ?? conf?.generatorConfig?.origin ?? '').replace(/\/$/, ''), // Remove trailing slash
|
|
79
67
|
segments: Object.fromEntries(await Promise.all(Object.entries(conf.generatorConfig?.segments ?? {}).map(async ([key, value]) => [
|
|
80
68
|
key,
|
|
@@ -1,36 +1,7 @@
|
|
|
1
1
|
import { VovkSchemaIdEnum, VovkStrictConfig } from 'vovk';
|
|
2
|
-
|
|
3
|
-
export default function getMetaSchema({ config, package: packageJson, }: {
|
|
2
|
+
export default function getMetaSchema({ config }: {
|
|
4
3
|
config: VovkStrictConfig;
|
|
5
|
-
package: PackageJson;
|
|
6
4
|
}): {
|
|
7
5
|
config: VovkStrictConfig;
|
|
8
6
|
$schema: VovkSchemaIdEnum;
|
|
9
|
-
package: {
|
|
10
|
-
main: string;
|
|
11
|
-
module: string;
|
|
12
|
-
types: string;
|
|
13
|
-
exports: {
|
|
14
|
-
'.': {
|
|
15
|
-
import: string;
|
|
16
|
-
require: string;
|
|
17
|
-
types: string;
|
|
18
|
-
};
|
|
19
|
-
'./schema': {
|
|
20
|
-
import: string;
|
|
21
|
-
require: string;
|
|
22
|
-
types: string;
|
|
23
|
-
};
|
|
24
|
-
'./openapi': {
|
|
25
|
-
import: string;
|
|
26
|
-
require: string;
|
|
27
|
-
types: string;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
name?: string | undefined;
|
|
31
|
-
version?: string | undefined;
|
|
32
|
-
description?: string | undefined;
|
|
33
|
-
author?: PackageJson.Person | undefined;
|
|
34
|
-
license?: string | undefined;
|
|
35
|
-
};
|
|
36
7
|
};
|
|
@@ -1,31 +1,8 @@
|
|
|
1
1
|
import { VovkSchemaIdEnum } from 'vovk';
|
|
2
2
|
import pick from 'lodash/pick.js';
|
|
3
|
-
export default function getMetaSchema({ config
|
|
3
|
+
export default function getMetaSchema({ config }) {
|
|
4
4
|
return {
|
|
5
5
|
$schema: VovkSchemaIdEnum.META,
|
|
6
|
-
package: {
|
|
7
|
-
...pick(packageJson, ['name', 'version', 'description', 'author', 'license']),
|
|
8
|
-
main: './index.cjs',
|
|
9
|
-
module: './index.mjs',
|
|
10
|
-
types: './index.d.mts',
|
|
11
|
-
exports: {
|
|
12
|
-
'.': {
|
|
13
|
-
import: './index.mjs',
|
|
14
|
-
require: './index.cjs',
|
|
15
|
-
types: './index.d.mts',
|
|
16
|
-
},
|
|
17
|
-
'./schema': {
|
|
18
|
-
import: './schema.cjs',
|
|
19
|
-
require: './schema.cjs',
|
|
20
|
-
types: './schema.d.cts',
|
|
21
|
-
},
|
|
22
|
-
'./openapi': {
|
|
23
|
-
import: './openapi.cjs',
|
|
24
|
-
require: './openapi.cjs',
|
|
25
|
-
types: './openapi.d.cts',
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
6
|
...{
|
|
30
7
|
config: (config
|
|
31
8
|
? pick(config, [...config.emitConfig, '$schema'])
|
package/dist/index.mjs
CHANGED
|
@@ -123,8 +123,8 @@ program
|
|
|
123
123
|
.option('--exclude, --exclude-segments <segments...>', 'exclude segments')
|
|
124
124
|
.option('--prebundle-out-dir, --prebundle-out <path>', 'path to output directory for prebundle')
|
|
125
125
|
.option('--keep-prebundle-dir', 'do not delete prebundle directory after bundling')
|
|
126
|
-
.option('--
|
|
127
|
-
.option('--
|
|
126
|
+
.option('--schema, --schema-path <path>', 'path to schema folder (default: .vovk-schema)')
|
|
127
|
+
.option('--config, --config-path <config>', 'path to config file')
|
|
128
128
|
.option('--origin <url>', 'set the origin URL for the generated client')
|
|
129
129
|
.option('--tsconfig <path>', 'path to tsconfig.json for bundling by tsdown')
|
|
130
130
|
.option('--openapi, --openapi-spec <openapi_path_or_urls...>', 'use OpenAPI schema instead of Vovk schema')
|
|
@@ -134,16 +134,15 @@ program
|
|
|
134
134
|
.option('--log-level <level>', 'set the log level')
|
|
135
135
|
.action(async (cliBundleOptions) => {
|
|
136
136
|
const projectInfo = await getProjectInfo({
|
|
137
|
-
configPath: cliBundleOptions.
|
|
137
|
+
configPath: cliBundleOptions.configPath,
|
|
138
138
|
srcRootRequired: false,
|
|
139
139
|
logLevel: cliBundleOptions.logLevel,
|
|
140
140
|
});
|
|
141
|
-
const { cwd, config, log, isNextInstalled
|
|
141
|
+
const { cwd, config, log, isNextInstalled } = projectInfo;
|
|
142
142
|
const fullSchema = await getProjectFullSchema({
|
|
143
143
|
schemaOutAbsolutePath: path.resolve(cwd, cliBundleOptions?.schema ?? config.schemaOutDir),
|
|
144
144
|
log,
|
|
145
145
|
isNextInstalled,
|
|
146
|
-
package: packageJson,
|
|
147
146
|
config,
|
|
148
147
|
});
|
|
149
148
|
await bundle({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function createStandardSchemaValidatorFile({
|
|
2
|
-
|
|
1
|
+
export declare function createStandardSchemaValidatorFile({ root, validationLibrary, }: {
|
|
2
|
+
root: string;
|
|
3
3
|
validationLibrary: 'arktype' | 'valibot';
|
|
4
4
|
}): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
|
-
import getRelativeSrcRoot from '../getProjectInfo/getConfig/getRelativeSrcRoot.mjs';
|
|
3
2
|
import path from 'path';
|
|
3
|
+
import getRelativeSrcRoot from '../getProjectInfo/getConfig/getRelativeSrcRoot.mjs';
|
|
4
4
|
function getCode(validationLibrary) {
|
|
5
5
|
if (validationLibrary === 'valibot') {
|
|
6
6
|
return `
|
|
@@ -29,10 +29,11 @@ export default withArk;
|
|
|
29
29
|
}
|
|
30
30
|
throw new Error(`Unknown validation library: ${validationLibrary}`);
|
|
31
31
|
}
|
|
32
|
-
export async function createStandardSchemaValidatorFile({
|
|
32
|
+
export async function createStandardSchemaValidatorFile({ root, validationLibrary, }) {
|
|
33
33
|
const code = getCode(validationLibrary);
|
|
34
|
-
const srcRoot = (await getRelativeSrcRoot({ cwd })) ?? '.';
|
|
35
|
-
const libDir = path.
|
|
34
|
+
const srcRoot = (await getRelativeSrcRoot({ cwd: root })) ?? '.';
|
|
35
|
+
const libDir = path.resolve(root, srcRoot, 'lib');
|
|
36
|
+
const filePath = path.join(libDir, `${validationLibrary === 'arktype' ? 'withArk' : 'withValibot'}.ts`);
|
|
36
37
|
await fs.mkdir(libDir, { recursive: true });
|
|
37
|
-
await fs.writeFile(
|
|
38
|
+
await fs.writeFile(filePath, code);
|
|
38
39
|
}
|
package/dist/init/index.mjs
CHANGED
|
@@ -18,7 +18,7 @@ import { createStandardSchemaValidatorFile } from './createStandardSchemaValidat
|
|
|
18
18
|
export class Init {
|
|
19
19
|
root;
|
|
20
20
|
log;
|
|
21
|
-
async #init({ configPaths, pkgJson,
|
|
21
|
+
async #init({ configPaths, pkgJson, }, { useNpm, useYarn, usePnpm, useBun, skipInstall, updateTsConfig, updateScripts, validationLibrary, lang, dryRun, channel, }) {
|
|
22
22
|
const { log, root } = this;
|
|
23
23
|
const dependencies = ['vovk', 'vovk-client', 'openapi3-ts', 'vovk-ajv', 'ajv'];
|
|
24
24
|
const devDependencies = ['vovk-cli'];
|
|
@@ -132,7 +132,7 @@ export class Init {
|
|
|
132
132
|
}
|
|
133
133
|
if (validationLibrary === 'valibot' || validationLibrary === 'arktype') {
|
|
134
134
|
createStandardSchemaValidatorFile({
|
|
135
|
-
|
|
135
|
+
root,
|
|
136
136
|
validationLibrary,
|
|
137
137
|
});
|
|
138
138
|
}
|
|
@@ -202,21 +202,21 @@ export class Init {
|
|
|
202
202
|
value: 'class-validator',
|
|
203
203
|
description: 'Use class-validator for data validation',
|
|
204
204
|
},
|
|
205
|
-
{
|
|
206
|
-
name: 'Valibot',
|
|
207
|
-
value: 'valibot',
|
|
208
|
-
description: 'Use valibot for data validation.',
|
|
209
|
-
},
|
|
210
205
|
{
|
|
211
206
|
name: 'ArkType',
|
|
212
207
|
value: 'arktype',
|
|
213
|
-
description: 'Use
|
|
208
|
+
description: 'Use ArkType for data validation.',
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
name: 'Valibot',
|
|
212
|
+
value: 'valibot',
|
|
213
|
+
description: 'Use Valibot for data validation.',
|
|
214
214
|
},
|
|
215
215
|
{ name: 'None', value: null, description: 'Install validation library later' },
|
|
216
216
|
],
|
|
217
217
|
})));
|
|
218
218
|
updateScripts ??= await select({
|
|
219
|
-
message: 'Do you want to update "dev" and "
|
|
219
|
+
message: 'Do you want to update "dev" and add "prebuild" NPM scripts at package.json?',
|
|
220
220
|
default: 'implicit',
|
|
221
221
|
choices: [
|
|
222
222
|
{
|
package/dist/types.d.mts
CHANGED
|
@@ -40,7 +40,8 @@ export interface GenerateOptions {
|
|
|
40
40
|
logLevel?: LogLevelNames;
|
|
41
41
|
}
|
|
42
42
|
export interface BundleOptions extends Partial<Pick<VovkStrictConfig['bundle'], 'prebundleOutDir' | 'keepPrebundleDir' | 'includeSegments' | 'excludeSegments'>> {
|
|
43
|
-
|
|
43
|
+
configPath?: string;
|
|
44
|
+
schemaPath?: string;
|
|
44
45
|
schema?: string;
|
|
45
46
|
outDir?: string;
|
|
46
47
|
origin?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vovk-cli",
|
|
3
|
-
"version": "0.0.1-draft.
|
|
3
|
+
"version": "0.0.1-draft.345",
|
|
4
4
|
"bin": {
|
|
5
5
|
"vovk": "./dist/index.mjs"
|
|
6
6
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://vovk.dev",
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"vovk": "^3.0.0-draft.
|
|
38
|
+
"vovk": "^3.0.0-draft.406"
|
|
39
39
|
},
|
|
40
40
|
"optionalDependencies": {
|
|
41
41
|
"@rolldown/binding-linux-x64-gnu": "1.0.0-beta.31"
|