vovk-cli 0.0.1-draft.297 → 0.0.1-draft.299
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 +1 -1
- package/client-templates/readme/README.md.ejs +2 -1
- package/dist/generate/generate.mjs +4 -1
- package/dist/generate/getProjectFullSchema.d.mts +5 -1
- package/dist/generate/getProjectFullSchema.mjs +4 -3
- package/dist/generate/index.mjs +6 -2
- package/dist/getProjectInfo/index.d.mts +1 -0
- package/dist/getProjectInfo/index.mjs +2 -0
- package/dist/index.mjs +6 -2
- package/dist/utils/normalizeOpenAPIMixins.mjs +2 -1
- package/package.json +2 -2
|
@@ -5,7 +5,7 @@ const { schema } = require('./schema.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(([reExportWhat, reExportFrom]) => { %>
|
|
8
|
-
exports[<%= reExportWhat.split(/\s+as\s+/)[1] ?? reExportWhat %>] = require('<%= reExportFrom %>')[<%= reExportWhat.split(/\s+as\s+/)[0] %>];
|
|
8
|
+
exports['<%= reExportWhat.split(/\s+as\s+/)[1] ?? reExportWhat %>'] = require('<%= reExportFrom %>')['<%= reExportWhat.split(/\s+as\s+/)[0] %>'];
|
|
9
9
|
<% }) %>
|
|
10
10
|
<% Object.keys(segment.controllers).forEach((rpcModuleName) => { %>
|
|
11
11
|
exports.<%= rpcModuleName %> = createRPC(
|
|
@@ -22,7 +22,8 @@ npm install <%= t.package.name %>
|
|
|
22
22
|
|
|
23
23
|
<%- handlerSchema.openapi?.description ? `${handlerSchema.openapi.description}` : '' %>
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
<% const forceApiRoot = t.segmentMeta[segment.segmentName].forceApiRoot ?? controllerSchema.forceApiRoot; %>
|
|
26
|
+
`<%= handlerSchema.httpMethod %> <%= [...(forceApiRoot ? [forceApiRoot] : [t.apiRoot, segmentName]), controllerSchema.prefix, handlerSchema.path].map((part, i) => i > 0 ? t._.trim(part, '/') : part).filter(Boolean).join('/') %>`
|
|
26
27
|
|
|
27
28
|
```ts
|
|
28
29
|
<%- t.createCodeExamples({
|
|
@@ -221,12 +221,15 @@ export async function generate({ isEnsuringClient = false, projectInfo, forceNot
|
|
|
221
221
|
log,
|
|
222
222
|
rootPackageJson,
|
|
223
223
|
packages: [
|
|
224
|
+
fullSchema.segments[segmentName]?.meta?.package,
|
|
224
225
|
config.segmentedClient.packages?.[segmentName],
|
|
225
226
|
templateDef.segmentedClient?.packages?.[segmentName],
|
|
226
227
|
argPackageJson,
|
|
227
228
|
],
|
|
228
229
|
});
|
|
229
|
-
const readme = Object.assign({},
|
|
230
|
+
const readme = Object.assign({},
|
|
231
|
+
// TODO fullSchema.segments[segmentName]?.meta?.readme,
|
|
232
|
+
config.segmentedClient.readmes?.[segmentName], templateDef.segmentedClient?.readmes?.[segmentName], argReadme);
|
|
230
233
|
const segmentedFullSchema = pickSegmentFullSchema(fullSchema, [segmentName]);
|
|
231
234
|
const hasMixins = Object.values(segmentedFullSchema.segments).some((segment) => segment.segmentType === 'mixin');
|
|
232
235
|
if (templateName === BuiltInTemplateName.mixins && !hasMixins) {
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { type VovkSchema } from 'vovk';
|
|
2
2
|
import type { ProjectInfo } from '../getProjectInfo/index.mjs';
|
|
3
|
-
export declare function getProjectFullSchema(schemaOutAbsolutePath
|
|
3
|
+
export declare function getProjectFullSchema({ schemaOutAbsolutePath, isNextInstalled, log, }: {
|
|
4
|
+
schemaOutAbsolutePath: string;
|
|
5
|
+
isNextInstalled: boolean;
|
|
6
|
+
log: ProjectInfo['log'];
|
|
7
|
+
}): Promise<VovkSchema>;
|
|
@@ -3,7 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
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
|
-
export async function getProjectFullSchema(schemaOutAbsolutePath, log) {
|
|
6
|
+
export async function getProjectFullSchema({ schemaOutAbsolutePath, isNextInstalled, log, }) {
|
|
7
7
|
const result = {
|
|
8
8
|
$schema: VovkSchemaIdEnum.SCHEMA,
|
|
9
9
|
segments: {},
|
|
@@ -14,6 +14,7 @@ export async function getProjectFullSchema(schemaOutAbsolutePath, log) {
|
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
};
|
|
17
|
+
const isEmptyLogOrWarn = isNextInstalled ? log.warn : log.debug;
|
|
17
18
|
// Handle config.json
|
|
18
19
|
const metaPath = path.join(schemaOutAbsolutePath, `${META_FILE_NAME}.json`);
|
|
19
20
|
try {
|
|
@@ -21,7 +22,7 @@ export async function getProjectFullSchema(schemaOutAbsolutePath, log) {
|
|
|
21
22
|
result.meta = JSON.parse(metaContent);
|
|
22
23
|
}
|
|
23
24
|
catch {
|
|
24
|
-
|
|
25
|
+
isEmptyLogOrWarn(`${META_FILE_NAME}.json not found at ${metaPath}. Using empty meta as fallback.`);
|
|
25
26
|
}
|
|
26
27
|
// Handle segments directory
|
|
27
28
|
const segmentsDir = path.join(schemaOutAbsolutePath);
|
|
@@ -57,7 +58,7 @@ export async function getProjectFullSchema(schemaOutAbsolutePath, log) {
|
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
catch {
|
|
60
|
-
|
|
61
|
+
isEmptyLogOrWarn(`Segments directory not found at ${segmentsDir}. Using empty segments as fallback.`);
|
|
61
62
|
result.segments = {};
|
|
62
63
|
}
|
|
63
64
|
return result;
|
package/dist/generate/index.mjs
CHANGED
|
@@ -37,9 +37,13 @@ export class VovkGenerate {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
async getFullSchema() {
|
|
40
|
-
const { log, config, cwd } = this.#projectInfo;
|
|
40
|
+
const { log, config, cwd, isNextInstalled } = this.#projectInfo;
|
|
41
41
|
const { schemaPath } = this.#cliGenerateOptions;
|
|
42
|
-
const fullSchema = await getProjectFullSchema(
|
|
42
|
+
const fullSchema = await getProjectFullSchema({
|
|
43
|
+
schemaOutAbsolutePath: path.resolve(cwd, schemaPath ?? config.schemaOutDir),
|
|
44
|
+
isNextInstalled,
|
|
45
|
+
log,
|
|
46
|
+
});
|
|
43
47
|
return fullSchema;
|
|
44
48
|
}
|
|
45
49
|
watch({ throttleDelay }) {
|
|
@@ -15,6 +15,7 @@ export default function getProjectInfo({ port: givenPort, cwd, configPath, srcRo
|
|
|
15
15
|
};
|
|
16
16
|
config: import("vovk").VovkStrictConfig;
|
|
17
17
|
packageJson: import("type-fest").PackageJson;
|
|
18
|
+
isNextInstalled: boolean;
|
|
18
19
|
log: {
|
|
19
20
|
info: (msg: string) => void;
|
|
20
21
|
warn: (msg: string) => void;
|
|
@@ -11,6 +11,7 @@ export default async function getProjectInfo({ port: givenPort, cwd = process.cw
|
|
|
11
11
|
cwd,
|
|
12
12
|
});
|
|
13
13
|
const packageJson = await getPackageJson(cwd, log);
|
|
14
|
+
const isNextInstalled = !!packageJson?.dependencies?.next || !!packageJson?.devDependencies?.next;
|
|
14
15
|
if (srcRootRequired && !srcRoot) {
|
|
15
16
|
throw new Error(`Could not find app router directory at ${cwd}. Check Next.js docs for more info.`);
|
|
16
17
|
}
|
|
@@ -29,6 +30,7 @@ export default async function getProjectInfo({ port: givenPort, cwd = process.cw
|
|
|
29
30
|
vovkCliPackage,
|
|
30
31
|
config,
|
|
31
32
|
packageJson,
|
|
33
|
+
isNextInstalled,
|
|
32
34
|
log,
|
|
33
35
|
};
|
|
34
36
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -121,8 +121,12 @@ program
|
|
|
121
121
|
.option('--openapi-root-url <urls...>', 'root URLs corresponding to the index of --openapi option')
|
|
122
122
|
.action(async (cliBundleOptions) => {
|
|
123
123
|
const projectInfo = await getProjectInfo({ configPath: cliBundleOptions.config, srcRootRequired: false });
|
|
124
|
-
const { cwd, config, log } = projectInfo;
|
|
125
|
-
const fullSchema = await getProjectFullSchema(
|
|
124
|
+
const { cwd, config, log, isNextInstalled } = projectInfo;
|
|
125
|
+
const fullSchema = await getProjectFullSchema({
|
|
126
|
+
schemaOutAbsolutePath: path.resolve(cwd, cliBundleOptions?.schema ?? config.schemaOutDir),
|
|
127
|
+
log,
|
|
128
|
+
isNextInstalled,
|
|
129
|
+
});
|
|
126
130
|
await bundle({
|
|
127
131
|
projectInfo,
|
|
128
132
|
fullSchema,
|
|
@@ -37,7 +37,7 @@ async function getOpenApiSpecRemote({ cwd, url, fallback, log, }) {
|
|
|
37
37
|
}
|
|
38
38
|
export async function normalizeOpenAPIMixins({ mixinModules, log, cwd = process.cwd(), }) {
|
|
39
39
|
if (mixinModules) {
|
|
40
|
-
const modules = await Promise.all(Object.entries(mixinModules).map(async ([mixinName, { source, apiRoot, getModuleName, getMethodName, errorMessageKey }]) => {
|
|
40
|
+
const modules = await Promise.all(Object.entries(mixinModules).map(async ([mixinName, { source, apiRoot, getModuleName, getMethodName, errorMessageKey, package: packageJson },]) => {
|
|
41
41
|
let openAPIObject;
|
|
42
42
|
if ('url' in source) {
|
|
43
43
|
openAPIObject = await getOpenApiSpecRemote({ url: source.url, fallback: source.fallback, log, cwd });
|
|
@@ -57,6 +57,7 @@ export async function normalizeOpenAPIMixins({ mixinModules, log, cwd = process.
|
|
|
57
57
|
getModuleName,
|
|
58
58
|
getMethodName,
|
|
59
59
|
errorMessageKey,
|
|
60
|
+
package: packageJson,
|
|
60
61
|
mixinName,
|
|
61
62
|
};
|
|
62
63
|
}));
|
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.299",
|
|
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.324"
|
|
39
39
|
},
|
|
40
40
|
"optionalDependencies": {
|
|
41
41
|
"vovk-python": "^0.0.1-draft.53"
|