vovk-cli 0.0.1-draft.165 → 0.0.1-draft.166
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 +4 -4
- package/client-templates/cjs/index.d.cts.ejs +3 -3
- package/client-templates/mjs/index.d.mts.ejs +3 -3
- package/client-templates/mjs/index.mjs.ejs +4 -4
- package/client-templates/readme/README.md.ejs +1 -1
- package/client-templates/{fullSchemaCjs/fullSchema.cjs.ejs → schemaCjs/schema.cjs.ejs} +4 -4
- package/client-templates/schemaCjs/schema.d.cts.ejs +10 -0
- package/client-templates/schemaJson/schema.json.ejs +1 -0
- package/client-templates/{fullSchemaTs/fullSchema.ts.ejs → schemaTs/schema.ts.ejs} +4 -4
- package/client-templates/ts/index.ts.ejs +5 -5
- package/dist/bundle/index.d.mts +5 -3
- package/dist/bundle/index.mjs +28 -16
- package/dist/dev/ensureSchemaFiles.mjs +2 -2
- package/dist/dev/index.mjs +32 -27
- package/dist/generate/ensureClient.d.mts +2 -1
- package/dist/generate/ensureClient.mjs +8 -7
- package/dist/generate/getClientTemplateFiles.d.mts +1 -1
- package/dist/generate/getClientTemplateFiles.mjs +13 -16
- package/dist/generate/getFullSchemaFromJSON.d.mts +2 -2
- package/dist/generate/getFullSchemaFromJSON.mjs +3 -4
- package/dist/generate/getTemplateClientImports.d.mts +4 -5
- package/dist/generate/getTemplateClientImports.mjs +3 -3
- package/dist/generate/index.d.mts +5 -3
- package/dist/generate/index.mjs +41 -40
- package/dist/generate/mergePackages.mjs +4 -4
- package/dist/generate/writeOneClientFile.d.mts +5 -3
- package/dist/generate/writeOneClientFile.mjs +12 -8
- package/dist/getProjectInfo/{getRelativeSrcRoot.d.mts → getConfig/getRelativeSrcRoot.d.mts} +1 -1
- package/dist/getProjectInfo/{getRelativeSrcRoot.mjs → getConfig/getRelativeSrcRoot.mjs} +2 -2
- package/dist/getProjectInfo/getConfig/getTemplateDefs.d.mts +3 -3
- package/dist/getProjectInfo/getConfig/getTemplateDefs.mjs +17 -19
- package/dist/getProjectInfo/{getUserConfig.mjs → getConfig/getUserConfig.mjs} +1 -1
- package/dist/getProjectInfo/getConfig/index.d.mts +4 -7
- package/dist/getProjectInfo/getConfig/index.mjs +28 -65
- package/dist/getProjectInfo/index.d.mts +4 -6
- package/dist/getProjectInfo/index.mjs +7 -12
- package/dist/index.mjs +20 -13
- package/dist/init/index.mjs +1 -1
- package/dist/new/newModule.mjs +3 -1
- package/dist/new/newSegment.mjs +7 -5
- package/dist/types.d.mts +7 -8
- package/dist/utils/formatLoggedSegmentName.d.mts +2 -1
- package/dist/utils/formatLoggedSegmentName.mjs +2 -2
- package/dist/utils/getPublicModuleNameFromPath.d.mts +4 -0
- package/dist/utils/getPublicModuleNameFromPath.mjs +9 -0
- package/dist/utils/pickSegmentFullSchema.d.mts +3 -3
- package/dist/utils/pickSegmentFullSchema.mjs +9 -11
- package/dist/utils/resolveAbsoluteModulePath.d.mts +1 -0
- package/dist/utils/resolveAbsoluteModulePath.mjs +17 -5
- package/package.json +1 -1
- package/client-templates/fullSchemaCjs/fullSchema.d.cts.ejs +0 -10
- package/client-templates/fullSchemaJson/full-schema.json.ejs +0 -1
- package/dist/dev/isSegmentSchemaEmpty.d.mts +0 -2
- package/dist/dev/isSegmentSchemaEmpty.mjs +0 -4
- package/dist/enums.d.mts +0 -5
- package/dist/enums.mjs +0 -6
- /package/dist/getProjectInfo/{getConfigAbsolutePaths.d.mts → getConfig/getConfigAbsolutePaths.d.mts} +0 -0
- /package/dist/getProjectInfo/{getConfigAbsolutePaths.mjs → getConfig/getConfigAbsolutePaths.mjs} +0 -0
- /package/dist/getProjectInfo/{getUserConfig.d.mts → getConfig/getUserConfig.d.mts} +0 -0
- /package/dist/getProjectInfo/{importUncachedModule.d.mts → getConfig/importUncachedModule.d.mts} +0 -0
- /package/dist/getProjectInfo/{importUncachedModule.mjs → getConfig/importUncachedModule.mjs} +0 -0
- /package/dist/getProjectInfo/{importUncachedModuleWorker.d.mts → getConfig/importUncachedModuleWorker.d.mts} +0 -0
- /package/dist/getProjectInfo/{importUncachedModuleWorker.mjs → getConfig/importUncachedModuleWorker.mjs} +0 -0
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import type { VovkStrictConfig } from 'vovk';
|
|
2
|
-
import type { Segment } from '../locateSegments.mjs';
|
|
1
|
+
import type { VovkSchema, VovkStrictConfig } from 'vovk';
|
|
3
2
|
export type ClientImports = {
|
|
4
3
|
fetcher: string;
|
|
5
4
|
validateOnClient: string | null;
|
|
6
5
|
createRPC: string;
|
|
7
6
|
};
|
|
8
|
-
export default function getTemplateClientImports({ config,
|
|
7
|
+
export default function getTemplateClientImports({ config, fullSchema, outCwdRelativeDir, }: {
|
|
9
8
|
config: VovkStrictConfig;
|
|
10
|
-
|
|
9
|
+
fullSchema: VovkSchema;
|
|
11
10
|
outCwdRelativeDir: string;
|
|
12
11
|
}): {
|
|
13
|
-
|
|
12
|
+
composedClient: ClientImports & {
|
|
14
13
|
module: ClientImports;
|
|
15
14
|
};
|
|
16
15
|
segmentedClient: Record<string, ClientImports & {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { ROOT_SEGMENT_SCHEMA_NAME } from '../dev/writeOneSegmentSchemaFile.mjs';
|
|
3
|
-
export default function getTemplateClientImports({ config,
|
|
3
|
+
export default function getTemplateClientImports({ config, fullSchema, outCwdRelativeDir, }) {
|
|
4
4
|
const { imports } = config;
|
|
5
5
|
const getImportPath = (p, s = '') => p.startsWith('.') ? path.relative(path.join(outCwdRelativeDir, s), p) : p;
|
|
6
6
|
const clientImports = {
|
|
7
|
-
|
|
7
|
+
composedClient: {
|
|
8
8
|
fetcher: getImportPath(imports.fetcher[0]),
|
|
9
9
|
createRPC: getImportPath(imports.createRPC[0]),
|
|
10
10
|
validateOnClient: imports.validateOnClient ? getImportPath(imports.validateOnClient[0]) : null,
|
|
@@ -16,7 +16,7 @@ export default function getTemplateClientImports({ config, segments, outCwdRelat
|
|
|
16
16
|
: null,
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
|
-
segmentedClient: Object.fromEntries(segments.map((segment) => [
|
|
19
|
+
segmentedClient: Object.fromEntries(Object.values(fullSchema.segments).map((segment) => [
|
|
20
20
|
segment.segmentName,
|
|
21
21
|
{
|
|
22
22
|
fetcher: getImportPath(imports.fetcher[0], segment.segmentName || ROOT_SEGMENT_SCHEMA_NAME),
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { VovkSchema } from 'vovk';
|
|
2
2
|
import type { ProjectInfo } from '../getProjectInfo/index.mjs';
|
|
3
3
|
import type { GenerateOptions } from '../types.mjs';
|
|
4
|
-
|
|
4
|
+
import type { Segment } from '../locateSegments.mts';
|
|
5
|
+
export default function generate({ isEnsuringClient, projectInfo, forceNothingWrittenLog, fullSchema, locatedSegments, cliGenerateOptions, }: {
|
|
5
6
|
isEnsuringClient?: boolean;
|
|
6
7
|
projectInfo: ProjectInfo;
|
|
7
8
|
forceNothingWrittenLog?: boolean;
|
|
8
|
-
fullSchema:
|
|
9
|
+
fullSchema: VovkSchema;
|
|
10
|
+
locatedSegments: Segment[];
|
|
9
11
|
cliGenerateOptions?: GenerateOptions;
|
|
10
12
|
}): Promise<void>;
|
package/dist/generate/index.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import path from 'node:path';
|
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
3
|
import matter from 'gray-matter';
|
|
4
4
|
import _ from 'lodash';
|
|
5
|
-
import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
6
5
|
import getClientTemplateFiles from './getClientTemplateFiles.mjs';
|
|
7
6
|
import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
|
|
8
7
|
import pickSegmentFullSchema from '../utils/pickSegmentFullSchema.mjs';
|
|
@@ -11,29 +10,31 @@ import getTemplateClientImports from './getTemplateClientImports.mjs';
|
|
|
11
10
|
import mergePackages from './mergePackages.mjs';
|
|
12
11
|
import writeOneClientFile from './writeOneClientFile.mjs';
|
|
13
12
|
import { ROOT_SEGMENT_SCHEMA_NAME } from '../dev/writeOneSegmentSchemaFile.mjs';
|
|
14
|
-
const getIncludedSegmentNames = (config,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const getIncludedSegmentNames = (config, fullSchema, configKey, cliGenerateOptions) => {
|
|
14
|
+
const segments = Object.values(fullSchema.segments);
|
|
15
|
+
const includeSegments = cliGenerateOptions?.[configKey === 'segmentedClient' ? 'segmentedIncludeSegments' : 'composedIncludeSegments'] ??
|
|
16
|
+
config[configKey].includeSegments;
|
|
17
|
+
const excludeSegments = cliGenerateOptions?.[configKey === 'segmentedClient' ? 'segmentedExcludeSegments' : 'composedExcludeSegments'] ??
|
|
18
|
+
config[configKey].excludeSegments;
|
|
19
|
+
if (includeSegments?.length && excludeSegments?.length) {
|
|
20
|
+
throw new Error(`Both includeSegments and excludeSegments are set in "${configKey}" config. Please use only one of them.`);
|
|
18
21
|
}
|
|
19
|
-
const includedSegmentNames =
|
|
20
|
-
|
|
21
|
-
? config[configKey].includeSegments.map((segmentName) => {
|
|
22
|
+
const includedSegmentNames = Array.isArray(includeSegments) && includeSegments.length
|
|
23
|
+
? includeSegments.map((segmentName) => {
|
|
22
24
|
const segment = segments.find(({ segmentName: sName }) => sName === segmentName);
|
|
23
25
|
if (!segment) {
|
|
24
|
-
throw new Error(`Segment "${segmentName}" not found in the config for ${configKey}`);
|
|
26
|
+
throw new Error(`Segment "${segmentName}" not found in the config for "${configKey}"`);
|
|
25
27
|
}
|
|
26
28
|
return segment.segmentName;
|
|
27
29
|
})
|
|
28
|
-
:
|
|
29
|
-
Array.isArray(config[configKey].excludeSegments)
|
|
30
|
+
: Array.isArray(excludeSegments) && excludeSegments.length // TODO: Warn if excludeSegments includes a segment name that is not listed at segments
|
|
30
31
|
? segments
|
|
31
|
-
.filter(({ segmentName }) => !
|
|
32
|
+
.filter(({ segmentName }) => !excludeSegments?.includes(segmentName))
|
|
32
33
|
.map(({ segmentName }) => segmentName)
|
|
33
34
|
: segments.map(({ segmentName }) => segmentName);
|
|
34
35
|
return includedSegmentNames;
|
|
35
36
|
};
|
|
36
|
-
function logClientGenerationResults({ results, log, isEnsuringClient = false, forceNothingWrittenLog = false, clientType = '
|
|
37
|
+
function logClientGenerationResults({ results, log, isEnsuringClient = false, forceNothingWrittenLog = false, clientType = 'Composed', startTime, fromTemplates, }) {
|
|
37
38
|
const writtenResults = results.filter(({ written }) => written);
|
|
38
39
|
const duration = Date.now() - startTime;
|
|
39
40
|
if (writtenResults.length) {
|
|
@@ -48,29 +49,27 @@ function logClientGenerationResults({ results, log, isEnsuringClient = false, fo
|
|
|
48
49
|
logOrDebug(`${clientType} client is up to date and doesn't need to be regenerated (${duration}ms)`);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
|
-
export default async function generate({ isEnsuringClient = false, projectInfo, forceNothingWrittenLog, fullSchema, cliGenerateOptions, }) {
|
|
52
|
-
const { config, cwd, log
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
if (config.fullClient.enabled) {
|
|
52
|
+
export default async function generate({ isEnsuringClient = false, projectInfo, forceNothingWrittenLog, fullSchema, locatedSegments, cliGenerateOptions, }) {
|
|
53
|
+
const { config, cwd, log } = projectInfo;
|
|
54
|
+
const isComposedEnabled = cliGenerateOptions?.composedOnly ||
|
|
55
|
+
!!cliGenerateOptions?.composedFrom ||
|
|
56
|
+
!!cliGenerateOptions?.composedOut ||
|
|
57
|
+
(config.composedClient?.enabled && !cliGenerateOptions?.segmentedOnly);
|
|
58
|
+
const isSegmentedEnabled = cliGenerateOptions?.segmentedOnly ||
|
|
59
|
+
!!cliGenerateOptions?.segmentedFrom ||
|
|
60
|
+
!!cliGenerateOptions?.segmentedOut ||
|
|
61
|
+
(config.segmentedClient?.enabled && !cliGenerateOptions?.composedOnly);
|
|
62
|
+
if (isComposedEnabled) {
|
|
64
63
|
const now = Date.now();
|
|
65
|
-
const segmentNames = getIncludedSegmentNames(config,
|
|
66
|
-
const { templateFiles:
|
|
64
|
+
const segmentNames = getIncludedSegmentNames(config, fullSchema, 'composedClient', cliGenerateOptions);
|
|
65
|
+
const { templateFiles: composedClientTemplateFiles, fromTemplates } = await getClientTemplateFiles({
|
|
67
66
|
config,
|
|
68
67
|
cwd,
|
|
69
68
|
log,
|
|
70
69
|
cliGenerateOptions,
|
|
71
|
-
configKey: '
|
|
70
|
+
configKey: 'composedClient',
|
|
72
71
|
});
|
|
73
|
-
const
|
|
72
|
+
const composedClientResults = await Promise.all(composedClientTemplateFiles.map(async (clientTemplateFile) => {
|
|
74
73
|
const { templateFilePath, templateName, templateDef, outCwdRelativeDir } = clientTemplateFile;
|
|
75
74
|
const templateContent = await fs.readFile(templateFilePath, 'utf-8');
|
|
76
75
|
const matterResult = templateFilePath.endsWith('.ejs')
|
|
@@ -78,13 +77,13 @@ export default async function generate({ isEnsuringClient = false, projectInfo,
|
|
|
78
77
|
: { data: { imports: [] }, content: templateContent };
|
|
79
78
|
const clientImports = await getTemplateClientImports({
|
|
80
79
|
config,
|
|
81
|
-
|
|
80
|
+
fullSchema,
|
|
82
81
|
outCwdRelativeDir,
|
|
83
82
|
});
|
|
84
83
|
const packageJson = await mergePackages({
|
|
85
84
|
cwd,
|
|
86
85
|
config,
|
|
87
|
-
packages: [config.
|
|
86
|
+
packages: [config.composedClient.package, templateDef.composedClient?.package],
|
|
88
87
|
});
|
|
89
88
|
const { written } = await writeOneClientFile({
|
|
90
89
|
cwd,
|
|
@@ -93,7 +92,7 @@ export default async function generate({ isEnsuringClient = false, projectInfo,
|
|
|
93
92
|
fullSchema: pickSegmentFullSchema(fullSchema, segmentNames),
|
|
94
93
|
prettifyClient: config.prettifyClient,
|
|
95
94
|
segmentName: null,
|
|
96
|
-
imports: clientImports.
|
|
95
|
+
imports: clientImports.composedClient,
|
|
97
96
|
templateContent,
|
|
98
97
|
matterResult,
|
|
99
98
|
package: packageJson,
|
|
@@ -101,6 +100,7 @@ export default async function generate({ isEnsuringClient = false, projectInfo,
|
|
|
101
100
|
outCwdRelativeDir,
|
|
102
101
|
origin: config.origin ?? templateDef?.origin ?? null,
|
|
103
102
|
templateDef,
|
|
103
|
+
locatedSegments,
|
|
104
104
|
});
|
|
105
105
|
const outAbsoluteDir = path.join(cwd, outCwdRelativeDir);
|
|
106
106
|
return {
|
|
@@ -109,24 +109,24 @@ export default async function generate({ isEnsuringClient = false, projectInfo,
|
|
|
109
109
|
outAbsoluteDir,
|
|
110
110
|
};
|
|
111
111
|
}));
|
|
112
|
-
if (
|
|
112
|
+
if (composedClientTemplateFiles.length) {
|
|
113
113
|
logClientGenerationResults({
|
|
114
|
-
results:
|
|
114
|
+
results: composedClientResults,
|
|
115
115
|
log,
|
|
116
116
|
isEnsuringClient,
|
|
117
117
|
forceNothingWrittenLog,
|
|
118
|
-
clientType: '
|
|
118
|
+
clientType: 'Composed',
|
|
119
119
|
startTime: now,
|
|
120
120
|
fromTemplates,
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
else {
|
|
124
|
-
log.warn('No
|
|
124
|
+
log.warn('No composed client template files found. Skipping composed client generation.');
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
if (
|
|
127
|
+
if (isSegmentedEnabled) {
|
|
128
128
|
const now = Date.now();
|
|
129
|
-
const segmentNames = getIncludedSegmentNames(config,
|
|
129
|
+
const segmentNames = getIncludedSegmentNames(config, fullSchema, 'segmentedClient', cliGenerateOptions);
|
|
130
130
|
const { templateFiles: segmentedClientTemplateFiles, fromTemplates } = await getClientTemplateFiles({
|
|
131
131
|
config,
|
|
132
132
|
cwd,
|
|
@@ -143,7 +143,7 @@ export default async function generate({ isEnsuringClient = false, projectInfo,
|
|
|
143
143
|
const results = await Promise.all(segmentNames.map(async (segmentName) => {
|
|
144
144
|
const clientImports = await getTemplateClientImports({
|
|
145
145
|
config,
|
|
146
|
-
|
|
146
|
+
fullSchema,
|
|
147
147
|
outCwdRelativeDir,
|
|
148
148
|
});
|
|
149
149
|
const packageJson = await mergePackages({
|
|
@@ -169,6 +169,7 @@ export default async function generate({ isEnsuringClient = false, projectInfo,
|
|
|
169
169
|
outCwdRelativeDir,
|
|
170
170
|
origin: config.origin ?? templateDef?.origin ?? null,
|
|
171
171
|
templateDef,
|
|
172
|
+
locatedSegments,
|
|
172
173
|
});
|
|
173
174
|
return {
|
|
174
175
|
written,
|
|
@@ -36,10 +36,10 @@ export default async function mergePackages({ cwd, packages, }) {
|
|
|
36
36
|
import: './index.mjs',
|
|
37
37
|
require: './index.cjs',
|
|
38
38
|
},
|
|
39
|
-
'./
|
|
40
|
-
import: './
|
|
41
|
-
require: './
|
|
42
|
-
types: './
|
|
39
|
+
'./schema': {
|
|
40
|
+
import: './schema.cjs',
|
|
41
|
+
require: './schema.cjs',
|
|
42
|
+
types: './schema.d.cts',
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
45
|
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type VovkSchema, type VovkStrictConfig } from 'vovk';
|
|
2
2
|
import type { ProjectInfo } from '../getProjectInfo/index.mjs';
|
|
3
3
|
import type { ClientTemplateFile } from './getClientTemplateFiles.mjs';
|
|
4
4
|
import type { ClientImports } from './getTemplateClientImports.mjs';
|
|
5
5
|
import type { PackageJson } from 'type-fest';
|
|
6
|
-
|
|
6
|
+
import type { Segment } from '../locateSegments.mjs';
|
|
7
|
+
export default function writeOneClientFile({ cwd, projectInfo, clientTemplateFile, fullSchema, prettifyClient, segmentName, imports, templateContent, matterResult: { data, content }, package: packageJson, isEnsuringClient, outCwdRelativeDir, origin, templateDef, locatedSegments, }: {
|
|
7
8
|
cwd: string;
|
|
8
9
|
projectInfo: ProjectInfo;
|
|
9
10
|
clientTemplateFile: ClientTemplateFile;
|
|
10
|
-
fullSchema:
|
|
11
|
+
fullSchema: VovkSchema;
|
|
11
12
|
prettifyClient: boolean;
|
|
12
13
|
segmentName: string | null;
|
|
13
14
|
imports: ClientImports;
|
|
@@ -23,6 +24,7 @@ export default function writeOneClientFile({ cwd, projectInfo, clientTemplateFil
|
|
|
23
24
|
outCwdRelativeDir: string;
|
|
24
25
|
origin: string | null;
|
|
25
26
|
templateDef: VovkStrictConfig['clientTemplateDefs'][string];
|
|
27
|
+
locatedSegments: Segment[];
|
|
26
28
|
}): Promise<{
|
|
27
29
|
written: boolean;
|
|
28
30
|
}>;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import ejs from 'ejs';
|
|
4
|
-
import _ from 'lodash';
|
|
4
|
+
import _, { keyBy } from 'lodash';
|
|
5
|
+
import { VovkSchemaIdEnum } from 'vovk';
|
|
5
6
|
import prettify from '../utils/prettify.mjs';
|
|
6
7
|
import { ROOT_SEGMENT_SCHEMA_NAME, SEGMENTS_SCHEMA_DIR_NAME } from '../dev/writeOneSegmentSchemaFile.mjs';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const { config, apiRoot, segments } = projectInfo;
|
|
8
|
+
export default async function writeOneClientFile({ cwd, projectInfo, clientTemplateFile, fullSchema, prettifyClient, segmentName, imports, templateContent, matterResult: { data, content }, package: packageJson, isEnsuringClient, outCwdRelativeDir, origin, templateDef, locatedSegments, }) {
|
|
9
|
+
const { config, apiRoot } = projectInfo;
|
|
10
10
|
const { templateFilePath, relativeDir } = clientTemplateFile;
|
|
11
|
+
const locatedSegmentsByName = keyBy(locatedSegments, 'segmentName');
|
|
11
12
|
const outPath = path.resolve(cwd, outCwdRelativeDir, typeof segmentName === 'string' ? segmentName || ROOT_SEGMENT_SCHEMA_NAME : '', relativeDir.replace('[package_name]', packageJson.name ?? 'my-package-name'), path.basename(templateFilePath).replace('.ejs', ''));
|
|
12
13
|
let placeholder = `// This is a temporary placeholder to avoid compilation errors if client is imported before it's generated.
|
|
13
14
|
// If you still see this text, the client is not generated yet because of an unknown problem.
|
|
@@ -21,13 +22,16 @@ export default async function writeOneClientFile({ cwd, projectInfo, clientTempl
|
|
|
21
22
|
SEGMENTS_SCHEMA_DIR_NAME,
|
|
22
23
|
apiRoot: origin ? `${origin}/${config.rootEntry}` : apiRoot,
|
|
23
24
|
imports,
|
|
24
|
-
fullSchema,
|
|
25
|
-
|
|
25
|
+
schema: fullSchema,
|
|
26
|
+
VovkSchemaIdEnum,
|
|
26
27
|
schemaOutDir: typeof segmentName === 'string'
|
|
27
28
|
? path.relative(path.join(outCwdRelativeDir, segmentName || ROOT_SEGMENT_SCHEMA_NAME), config.schemaOutDir)
|
|
28
29
|
: path.relative(outCwdRelativeDir, config.schemaOutDir),
|
|
29
|
-
segmentMeta: Object.fromEntries(segments.map(({ segmentName: sName
|
|
30
|
-
const
|
|
30
|
+
segmentMeta: Object.fromEntries(Object.values(fullSchema.segments).map(({ segmentName: sName }) => {
|
|
31
|
+
const { routeFilePath = null } = locatedSegmentsByName[sName] ?? {};
|
|
32
|
+
const segmentImportPath = routeFilePath
|
|
33
|
+
? path.relative(path.resolve(cwd, outCwdRelativeDir, typeof segmentName === 'string' ? segmentName || ROOT_SEGMENT_SCHEMA_NAME : '.'), path.resolve(cwd, routeFilePath))
|
|
34
|
+
: null;
|
|
31
35
|
const { origin: configOrigin, rootEntry: configRootEntry } = {
|
|
32
36
|
...(config.segmentConfig ? config.segmentConfig[sName] : {}),
|
|
33
37
|
...(templateDef.segmentConfig ? templateDef.segmentConfig[sName] : {}),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import getFileSystemEntryType, { FileSystemEntryType } from '
|
|
2
|
+
import getFileSystemEntryType, { FileSystemEntryType } from '../../utils/getFileSystemEntryType.mjs';
|
|
3
3
|
export default async function getRelativeSrcRoot({ cwd }) {
|
|
4
4
|
// Next.js Docs: src/app or src/pages will be ignored if app or pages are present in the root directory.
|
|
5
5
|
if ((await getFileSystemEntryType(path.join(cwd, 'app'))) === FileSystemEntryType.DIRECTORY) {
|
|
@@ -8,5 +8,5 @@ export default async function getRelativeSrcRoot({ cwd }) {
|
|
|
8
8
|
else if ((await getFileSystemEntryType(path.join(cwd, 'src/app'))) === FileSystemEntryType.DIRECTORY) {
|
|
9
9
|
return './src';
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
return null;
|
|
12
12
|
}
|
|
@@ -3,9 +3,9 @@ export declare enum BuiltInTemplateName {
|
|
|
3
3
|
ts = "ts",
|
|
4
4
|
cjs = "cjs",
|
|
5
5
|
mjs = "mjs",
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
schemaTs = "schemaTs",
|
|
7
|
+
schemaCjs = "schemaCjs",
|
|
8
|
+
schemaJson = "schemaJson",
|
|
9
9
|
readme = "readme",
|
|
10
10
|
packageJson = "packageJson",
|
|
11
11
|
rs = "rs",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
1
|
export var BuiltInTemplateName;
|
|
3
2
|
(function (BuiltInTemplateName) {
|
|
4
3
|
// ts/js
|
|
@@ -6,31 +5,30 @@ export var BuiltInTemplateName;
|
|
|
6
5
|
BuiltInTemplateName["cjs"] = "cjs";
|
|
7
6
|
BuiltInTemplateName["mjs"] = "mjs";
|
|
8
7
|
// schema
|
|
9
|
-
BuiltInTemplateName["
|
|
10
|
-
BuiltInTemplateName["
|
|
11
|
-
BuiltInTemplateName["
|
|
8
|
+
BuiltInTemplateName["schemaTs"] = "schemaTs";
|
|
9
|
+
BuiltInTemplateName["schemaCjs"] = "schemaCjs";
|
|
10
|
+
BuiltInTemplateName["schemaJson"] = "schemaJson";
|
|
12
11
|
// misc
|
|
13
12
|
BuiltInTemplateName["readme"] = "readme";
|
|
14
13
|
BuiltInTemplateName["packageJson"] = "packageJson";
|
|
15
|
-
// other languages
|
|
14
|
+
// other languages (packages installed separately)
|
|
16
15
|
BuiltInTemplateName["rs"] = "rs";
|
|
17
16
|
BuiltInTemplateName["py"] = "py";
|
|
18
17
|
})(BuiltInTemplateName || (BuiltInTemplateName = {}));
|
|
19
|
-
const templatesDir = path.join(import.meta.dirname, '../../..', 'client-templates');
|
|
20
18
|
export default function getTemplateDefs(userTemplateDefs = {}) {
|
|
21
19
|
const defs = {};
|
|
22
20
|
const builtInDefs = {
|
|
23
21
|
[BuiltInTemplateName.ts]: {
|
|
24
22
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.ts}/`,
|
|
25
|
-
requires: { [BuiltInTemplateName.
|
|
23
|
+
requires: { [BuiltInTemplateName.schemaTs]: '.' },
|
|
26
24
|
},
|
|
27
25
|
[BuiltInTemplateName.cjs]: {
|
|
28
26
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.cjs}/`,
|
|
29
|
-
requires: { [BuiltInTemplateName.
|
|
27
|
+
requires: { [BuiltInTemplateName.schemaCjs]: '.' },
|
|
30
28
|
},
|
|
31
29
|
[BuiltInTemplateName.mjs]: {
|
|
32
30
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.mjs}/`,
|
|
33
|
-
requires: { [BuiltInTemplateName.
|
|
31
|
+
requires: { [BuiltInTemplateName.schemaCjs]: '.' },
|
|
34
32
|
},
|
|
35
33
|
[BuiltInTemplateName.readme]: {
|
|
36
34
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.readme}/`,
|
|
@@ -38,31 +36,31 @@ export default function getTemplateDefs(userTemplateDefs = {}) {
|
|
|
38
36
|
[BuiltInTemplateName.packageJson]: {
|
|
39
37
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.packageJson}/`,
|
|
40
38
|
},
|
|
41
|
-
[BuiltInTemplateName.
|
|
42
|
-
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.
|
|
39
|
+
[BuiltInTemplateName.schemaTs]: {
|
|
40
|
+
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.schemaTs}/`,
|
|
43
41
|
},
|
|
44
|
-
[BuiltInTemplateName.
|
|
45
|
-
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.
|
|
42
|
+
[BuiltInTemplateName.schemaCjs]: {
|
|
43
|
+
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.schemaCjs}/`,
|
|
46
44
|
},
|
|
47
|
-
[BuiltInTemplateName.
|
|
48
|
-
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.
|
|
45
|
+
[BuiltInTemplateName.schemaJson]: {
|
|
46
|
+
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.schemaJson}/`,
|
|
49
47
|
},
|
|
50
48
|
[BuiltInTemplateName.rs]: {
|
|
51
49
|
templatePath: 'vovk-rust-client/template/',
|
|
52
|
-
|
|
50
|
+
composedClient: {
|
|
53
51
|
outDir: 'dist_rust',
|
|
54
52
|
},
|
|
55
53
|
requires: {
|
|
56
|
-
|
|
54
|
+
schemaJson: './data',
|
|
57
55
|
},
|
|
58
56
|
},
|
|
59
57
|
[BuiltInTemplateName.py]: {
|
|
60
58
|
templatePath: 'vovk-python-client/template/',
|
|
61
|
-
|
|
59
|
+
composedClient: {
|
|
62
60
|
outDir: 'dist_python',
|
|
63
61
|
},
|
|
64
62
|
requires: {
|
|
65
|
-
|
|
63
|
+
schemaJson: './data',
|
|
66
64
|
},
|
|
67
65
|
},
|
|
68
66
|
};
|
|
@@ -5,7 +5,7 @@ async function getUserConfig({ configPath: givenConfigPath, cwd, }) {
|
|
|
5
5
|
const configAbsolutePaths = await getConfigAbsolutePaths({ configPath: givenConfigPath, cwd });
|
|
6
6
|
let userConfig;
|
|
7
7
|
if (!configAbsolutePaths.length) {
|
|
8
|
-
return { userConfig: null, configAbsolutePaths
|
|
8
|
+
return { userConfig: null, configAbsolutePaths };
|
|
9
9
|
}
|
|
10
10
|
const configPath = configAbsolutePaths[0];
|
|
11
11
|
// TODO explain
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
cliGenerateOptions?: GenerateOptions;
|
|
5
|
-
cliBundleOptions?: BundleOptions;
|
|
1
|
+
import { type VovkStrictConfig } from 'vovk';
|
|
2
|
+
export default function getConfig({ configPath, cwd }: {
|
|
3
|
+
configPath?: string;
|
|
6
4
|
cwd: string;
|
|
7
5
|
}): Promise<{
|
|
8
6
|
config: VovkStrictConfig;
|
|
9
|
-
srcRoot: string;
|
|
7
|
+
srcRoot: string | null;
|
|
10
8
|
configAbsolutePaths: string[];
|
|
11
9
|
userConfig: import("vovk").VovkConfig | null;
|
|
12
|
-
error: Error | undefined;
|
|
13
10
|
log: {
|
|
14
11
|
info: (msg: string) => void;
|
|
15
12
|
warn: (msg: string) => void;
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import
|
|
2
|
+
import { VovkSchemaIdEnum } from 'vovk';
|
|
3
3
|
import getLogger from '../../utils/getLogger.mjs';
|
|
4
|
-
import getUserConfig from '
|
|
5
|
-
import getRelativeSrcRoot from '
|
|
4
|
+
import getUserConfig from './getUserConfig.mjs';
|
|
5
|
+
import getRelativeSrcRoot from './getRelativeSrcRoot.mjs';
|
|
6
6
|
import getTemplateDefs, { BuiltInTemplateName } from './getTemplateDefs.mjs';
|
|
7
|
-
|
|
8
|
-
export default async function getConfig({ cliGenerateOptions, cliBundleOptions, cwd, }) {
|
|
7
|
+
export default async function getConfig({ configPath, cwd }) {
|
|
9
8
|
const { configAbsolutePaths, error, userConfig } = await getUserConfig({
|
|
10
|
-
configPath
|
|
9
|
+
configPath,
|
|
11
10
|
cwd,
|
|
12
11
|
});
|
|
13
12
|
const conf = userConfig ?? {};
|
|
14
13
|
const env = process.env;
|
|
15
14
|
const clientTemplateDefs = getTemplateDefs(conf.clientTemplateDefs);
|
|
16
15
|
const srcRoot = await getRelativeSrcRoot({ cwd });
|
|
17
|
-
const validateOnClientImport =
|
|
18
|
-
const fetcherImport =
|
|
19
|
-
const createRPCImport =
|
|
16
|
+
const validateOnClientImport = conf.imports?.validateOnClient ?? null;
|
|
17
|
+
const fetcherImport = conf.imports?.fetcher ?? 'vovk';
|
|
18
|
+
const createRPCImport = conf.imports?.createRPC ?? 'vovk';
|
|
20
19
|
const imports = {
|
|
21
20
|
fetcher: typeof fetcherImport === 'string' ? [fetcherImport] : fetcherImport,
|
|
22
21
|
validateOnClient: typeof validateOnClientImport === 'string'
|
|
@@ -25,39 +24,38 @@ export default async function getConfig({ cliGenerateOptions, cliBundleOptions,
|
|
|
25
24
|
createRPC: typeof createRPCImport === 'string' ? [createRPCImport] : createRPCImport,
|
|
26
25
|
};
|
|
27
26
|
const config = {
|
|
28
|
-
$schema:
|
|
27
|
+
$schema: VovkSchemaIdEnum.CONFIG,
|
|
29
28
|
clientTemplateDefs,
|
|
30
29
|
imports,
|
|
31
30
|
emitConfig: [],
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
fromTemplates:
|
|
36
|
-
outDir:
|
|
31
|
+
composedClient: {
|
|
32
|
+
...conf.composedClient,
|
|
33
|
+
enabled: conf.composedClient?.enabled ?? true,
|
|
34
|
+
fromTemplates: conf.composedClient?.fromTemplates ?? ['mjs', 'cjs'],
|
|
35
|
+
outDir: conf.composedClient?.outDir ?? './node_modules/.vovk-client',
|
|
37
36
|
},
|
|
38
37
|
segmentedClient: {
|
|
39
|
-
enabled: !!cliGenerateOptions?.segmentedOnly ||
|
|
40
|
-
!!cliGenerateOptions?.segmentedFrom ||
|
|
41
|
-
!!cliGenerateOptions?.segmentedOut,
|
|
42
38
|
...conf.segmentedClient,
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
enabled: conf.segmentedClient?.enabled ?? false,
|
|
40
|
+
fromTemplates: conf.segmentedClient?.fromTemplates ?? ['ts'],
|
|
41
|
+
outDir: conf.segmentedClient?.outDir ?? path.join(srcRoot ?? '.', 'client'),
|
|
45
42
|
},
|
|
46
43
|
bundle: {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
...conf.bundle,
|
|
45
|
+
outDir: conf.bundle?.outDir ?? 'dist',
|
|
46
|
+
tsClientOutDir: conf.bundle?.tsClientOutDir ?? 'tmp_ts_rpc',
|
|
47
|
+
dontDeleteTsClientOutDirAfter: conf.bundle?.dontDeleteTsClientOutDirAfter ?? false,
|
|
48
|
+
sourcemap: conf.bundle?.sourcemap ?? false,
|
|
51
49
|
requires: {
|
|
52
50
|
[BuiltInTemplateName.readme]: '.',
|
|
53
51
|
[BuiltInTemplateName.packageJson]: '.',
|
|
54
52
|
},
|
|
55
53
|
},
|
|
56
|
-
modulesDir:
|
|
54
|
+
modulesDir: conf.modulesDir ?? path.join(srcRoot ?? '.', 'modules'),
|
|
57
55
|
schemaOutDir: env.VOVK_SCHEMA_OUT_DIR ?? conf.schemaOutDir ?? './.vovk-schema',
|
|
58
56
|
origin: (env.VOVK_ORIGIN ?? conf.origin ?? '').replace(/\/$/, ''), // Remove trailing slash
|
|
59
57
|
rootEntry: env.VOVK_ROOT_ENTRY ?? conf.rootEntry ?? 'api',
|
|
60
|
-
rootSegmentModulesDirName:
|
|
58
|
+
rootSegmentModulesDirName: conf.rootSegmentModulesDirName ?? '',
|
|
61
59
|
logLevel: env.VOVK_LOG_LEVEL ?? conf.logLevel ?? 'info',
|
|
62
60
|
prettifyClient: (env.VOVK_PRETTIFY_CLIENT ? !!env.VOVK_PRETTIFY_CLIENT : null) ?? conf.prettifyClient ?? false,
|
|
63
61
|
devHttps: (env.VOVK_DEV_HTTPS ? !!env.VOVK_DEV_HTTPS : null) ?? conf.devHttps ?? false,
|
|
@@ -70,7 +68,7 @@ export default async function getConfig({ cliGenerateOptions, cliBundleOptions,
|
|
|
70
68
|
segmentConfig: {},
|
|
71
69
|
};
|
|
72
70
|
if (typeof conf.emitConfig === 'undefined') {
|
|
73
|
-
config.emitConfig = ['
|
|
71
|
+
config.emitConfig = ['$schema', 'libs'];
|
|
74
72
|
}
|
|
75
73
|
else if (conf.emitConfig === true) {
|
|
76
74
|
config.emitConfig = Object.keys(config);
|
|
@@ -79,42 +77,7 @@ export default async function getConfig({ cliGenerateOptions, cliBundleOptions,
|
|
|
79
77
|
config.emitConfig = conf.emitConfig;
|
|
80
78
|
} // else it's false and emitConfig already is []
|
|
81
79
|
const log = getLogger(config.logLevel);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
.replace(/^VOVK_/, '')
|
|
86
|
-
.split('__')
|
|
87
|
-
.map(camelCase);
|
|
88
|
-
// Parse value
|
|
89
|
-
let value = envValue;
|
|
90
|
-
if (envValue === 'null') {
|
|
91
|
-
value = null;
|
|
92
|
-
}
|
|
93
|
-
else if (envValue === 'true') {
|
|
94
|
-
value = true;
|
|
95
|
-
}
|
|
96
|
-
else if (envValue === 'false') {
|
|
97
|
-
value = false;
|
|
98
|
-
}
|
|
99
|
-
else if (typeof envValue === 'string' && envValue.startsWith('[') && envValue.endsWith(']')) {
|
|
100
|
-
value = envValue
|
|
101
|
-
.slice(1, -1)
|
|
102
|
-
.split(',')
|
|
103
|
-
.map((s) => s.trim())
|
|
104
|
-
.filter(Boolean);
|
|
105
|
-
}
|
|
106
|
-
// Set value in config at the given path
|
|
107
|
-
let target = config;
|
|
108
|
-
for (let i = 0; i < pathArr.length - 1; i++) {
|
|
109
|
-
const key = pathArr[i];
|
|
110
|
-
if (typeof target[key] !== 'object' || target[key] === null) {
|
|
111
|
-
target[key] = {};
|
|
112
|
-
}
|
|
113
|
-
target = target[key];
|
|
114
|
-
}
|
|
115
|
-
target[pathArr[pathArr.length - 1]] = value;
|
|
116
|
-
log.debug(`Set config.${pathArr.join('.')} from env ${envKey}=${envValue}`);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return { config, srcRoot, configAbsolutePaths, userConfig, error, log };
|
|
80
|
+
if (error)
|
|
81
|
+
log.error(`Error reading config: ${String(error)}`);
|
|
82
|
+
return { config, srcRoot, configAbsolutePaths, userConfig, log };
|
|
120
83
|
}
|