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 { BundleOptions, GenerateOptions } from '../types.mjs';
|
|
2
1
|
export type ProjectInfo = Awaited<ReturnType<typeof getProjectInfo>>;
|
|
3
|
-
export default function getProjectInfo({ port: givenPort, cwd,
|
|
2
|
+
export default function getProjectInfo({ port: givenPort, cwd, configPath, srcRootRequired, }?: {
|
|
4
3
|
port?: number;
|
|
5
4
|
cwd?: string;
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
configPath?: string;
|
|
6
|
+
srcRootRequired?: boolean;
|
|
8
7
|
}): Promise<{
|
|
9
8
|
cwd: string;
|
|
10
9
|
port: string;
|
|
11
10
|
apiRoot: string;
|
|
12
11
|
apiDir: string;
|
|
13
|
-
srcRoot: string;
|
|
12
|
+
srcRoot: string | null;
|
|
14
13
|
config: import("vovk").VovkStrictConfig;
|
|
15
14
|
log: {
|
|
16
15
|
info: (msg: string) => void;
|
|
@@ -19,5 +18,4 @@ export default function getProjectInfo({ port: givenPort, cwd, cliGenerateOption
|
|
|
19
18
|
debug: (msg: string) => void;
|
|
20
19
|
raw: import("loglevel").RootLogger;
|
|
21
20
|
};
|
|
22
|
-
segments: import("../locateSegments.mjs").Segment[];
|
|
23
21
|
}>;
|
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import getConfig from './getConfig/index.mjs';
|
|
3
|
-
|
|
4
|
-
export default async function getProjectInfo({ port: givenPort, cwd = process.cwd(), cliGenerateOptions, cliBundleOptions, } = {}) {
|
|
3
|
+
export default async function getProjectInfo({ port: givenPort, cwd = process.cwd(), configPath, srcRootRequired = true, } = {}) {
|
|
5
4
|
const port = givenPort?.toString() ?? process.env.PORT ?? '3000';
|
|
6
5
|
// Make PORT available to the config file at getConfig
|
|
7
6
|
process.env.PORT = port;
|
|
8
|
-
const { config, srcRoot, configAbsolutePaths,
|
|
9
|
-
|
|
10
|
-
cliBundleOptions,
|
|
7
|
+
const { config, srcRoot, configAbsolutePaths, log } = await getConfig({
|
|
8
|
+
configPath,
|
|
11
9
|
cwd,
|
|
12
10
|
});
|
|
11
|
+
if (srcRootRequired && !srcRoot) {
|
|
12
|
+
throw new Error(`Could not find app router directory at ${cwd}. Check Next.js docs for more info.`);
|
|
13
|
+
}
|
|
13
14
|
const apiRoot = `${config.origin ?? ''}/${config.rootEntry}`;
|
|
14
|
-
const apiDir = path.join(srcRoot, 'app', config.rootEntry);
|
|
15
|
+
const apiDir = path.join(srcRoot ?? '.', 'app', config.rootEntry);
|
|
15
16
|
if (configAbsolutePaths.length > 1) {
|
|
16
17
|
log.warn(`Multiple config files found. Using the first one: ${configAbsolutePaths[0]}`);
|
|
17
18
|
}
|
|
18
|
-
if (!userConfig && configAbsolutePaths.length > 0) {
|
|
19
|
-
log.error(`Error reading config file at ${configAbsolutePaths[0]}: ${error?.message ?? 'Unknown Error'}`);
|
|
20
|
-
}
|
|
21
|
-
const apiDirAbsolutePath = path.join(cwd, apiDir);
|
|
22
|
-
const segments = await locateSegments({ dir: apiDirAbsolutePath, config, log });
|
|
23
19
|
return {
|
|
24
20
|
cwd,
|
|
25
21
|
port,
|
|
@@ -28,6 +24,5 @@ export default async function getProjectInfo({ port: givenPort, cwd = process.cw
|
|
|
28
24
|
srcRoot,
|
|
29
25
|
config,
|
|
30
26
|
log,
|
|
31
|
-
segments,
|
|
32
27
|
};
|
|
33
28
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { VovkDev } from './dev/index.mjs';
|
|
|
12
12
|
import newComponents from './new/index.mjs';
|
|
13
13
|
import initProgram from './initProgram.mjs';
|
|
14
14
|
import { getFullSchemaFromJSON } from './generate/getFullSchemaFromJSON.mjs';
|
|
15
|
+
import locateSegments from './locateSegments.mjs';
|
|
15
16
|
const program = new Command();
|
|
16
17
|
const packageJSON = JSON.parse(readFileSync(path.join(import.meta.dirname, '../package.json'), 'utf-8'));
|
|
17
18
|
program.name('vovk').description('Vovk CLI').version(packageJSON.version);
|
|
@@ -73,24 +74,30 @@ program
|
|
|
73
74
|
.command('generate')
|
|
74
75
|
.alias('g')
|
|
75
76
|
.description('Generate RPC client from schema')
|
|
76
|
-
.option('--out, --
|
|
77
|
-
.option('--from, --
|
|
78
|
-
.option('--
|
|
79
|
-
.option('--
|
|
77
|
+
.option('--out, --composed-out <path>', 'path to output directory for composed client')
|
|
78
|
+
.option('--from, --composed-from <templates...>', 'client template names for composed client')
|
|
79
|
+
.option('--include, --composed-include-segments <segments...>', 'include segments in composed client')
|
|
80
|
+
.option('--exclude, --composed-exclude-segments <segments...>', 'exclude segments in composed client')
|
|
81
|
+
.option('--composed-only', 'generate only composed client even if segmented client is enabled')
|
|
82
|
+
.option('--segmented-only', 'generate only segmented client even if composed client is enabled')
|
|
80
83
|
.option('--segmented-out <path>', 'path to output directory for segmented client')
|
|
81
84
|
.option('--segmented-from <templates...>', 'client template names for segmented client')
|
|
85
|
+
.option('--segmented-include-segments <segments...>', 'include segments in segmented client')
|
|
86
|
+
.option('--segmented-exclude-segments <segments...>', 'exclude segments in segmented client')
|
|
82
87
|
.option('--prettify', 'prettify output files')
|
|
83
88
|
.option('--config <config>', 'path to config file')
|
|
84
89
|
.action(async (cliGenerateOptions) => {
|
|
85
|
-
const projectInfo = await getProjectInfo({ cliGenerateOptions });
|
|
86
|
-
const { cwd, config } = projectInfo;
|
|
90
|
+
const projectInfo = await getProjectInfo({ configPath: cliGenerateOptions.config, srcRootRequired: false });
|
|
91
|
+
const { cwd, config, log, apiDir } = projectInfo;
|
|
92
|
+
const locatedSegments = await locateSegments({ dir: path.join(cwd, apiDir), config, log });
|
|
87
93
|
const schemaOutAbsolutePath = path.join(cwd, config.schemaOutDir);
|
|
88
|
-
const fullSchema = await getFullSchemaFromJSON(schemaOutAbsolutePath,
|
|
94
|
+
const fullSchema = await getFullSchemaFromJSON(schemaOutAbsolutePath, log);
|
|
89
95
|
await generate({
|
|
90
96
|
projectInfo,
|
|
91
97
|
fullSchema,
|
|
92
98
|
forceNothingWrittenLog: true,
|
|
93
99
|
cliGenerateOptions,
|
|
100
|
+
locatedSegments,
|
|
94
101
|
});
|
|
95
102
|
});
|
|
96
103
|
program
|
|
@@ -98,20 +105,20 @@ program
|
|
|
98
105
|
.alias('b')
|
|
99
106
|
.description('Generate TypeScrtipt RPC and bundle it')
|
|
100
107
|
.option('--out, --out-dir <path>', 'path to output directory for bundle')
|
|
108
|
+
.option('--include, --include-segments <segments...>', 'include segments')
|
|
109
|
+
.option('--exclude, --exclude-segments <segments...>', 'exclude segments')
|
|
101
110
|
.option('--ts-client-out-dir <path>', 'path to output directory for TypeScript client')
|
|
102
|
-
.option('--no-readme', 'do not generate README file')
|
|
103
|
-
.option('--no-package', 'do not generate package.json file')
|
|
104
111
|
.option('--dont-delete-ts-client-out-dir-after', 'do not delete TypeScript client output directory after bundling')
|
|
105
112
|
.option('--config <config>', 'path to config file')
|
|
106
113
|
.option('--sourcemap', 'generate sourcemaps')
|
|
107
114
|
.action(async (cliBundleOptions) => {
|
|
108
|
-
const projectInfo = await getProjectInfo({ cliBundleOptions });
|
|
109
|
-
const { cwd, config } = projectInfo;
|
|
110
|
-
const
|
|
111
|
-
const fullSchema = await getFullSchemaFromJSON(schemaOutAbsolutePath, projectInfo);
|
|
115
|
+
const projectInfo = await getProjectInfo({ configPath: cliBundleOptions.config, srcRootRequired: false });
|
|
116
|
+
const { cwd, config, log } = projectInfo;
|
|
117
|
+
const fullSchema = await getFullSchemaFromJSON(path.resolve(cwd, config.schemaOutDir), log);
|
|
112
118
|
await bundle({
|
|
113
119
|
projectInfo,
|
|
114
120
|
fullSchema,
|
|
121
|
+
cliBundleOptions,
|
|
115
122
|
});
|
|
116
123
|
});
|
|
117
124
|
program
|
package/dist/init/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { confirm, select } from '@inquirer/prompts';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import fs from 'node:fs/promises';
|
|
4
|
-
import getConfigPaths from '../getProjectInfo/getConfigAbsolutePaths.mjs';
|
|
4
|
+
import getConfigPaths from '../getProjectInfo/getConfig/getConfigAbsolutePaths.mjs';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
import getFileSystemEntryType from '../utils/getFileSystemEntryType.mjs';
|
|
7
7
|
import installDependencies, { getPackageManager } from './installDependencies.mjs';
|
package/dist/new/newModule.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
|
8
8
|
import getFileSystemEntryType from '../utils/getFileSystemEntryType.mjs';
|
|
9
9
|
import prettify from '../utils/prettify.mjs';
|
|
10
10
|
import resolveAbsoluteModulePath from '../utils/resolveAbsoluteModulePath.mjs';
|
|
11
|
+
import locateSegments from '../locateSegments.mjs';
|
|
11
12
|
function splitByLast(str, delimiter = '/') {
|
|
12
13
|
const index = str.lastIndexOf(delimiter);
|
|
13
14
|
if (index === -1) {
|
|
@@ -19,7 +20,8 @@ function splitByLast(str, delimiter = '/') {
|
|
|
19
20
|
return [before, after];
|
|
20
21
|
}
|
|
21
22
|
export default async function newModule({ what, moduleNameWithOptionalSegment, dryRun, dir: dirFlag, templates: templatesFlag, noSegmentUpdate, overwrite, empty, }) {
|
|
22
|
-
const { config, log, cwd,
|
|
23
|
+
const { config, log, cwd, apiDir } = await getProjectInfo();
|
|
24
|
+
const segments = await locateSegments({ dir: path.join(cwd, apiDir), config, log });
|
|
23
25
|
let templates = config.moduleTemplates;
|
|
24
26
|
const [segmentName, moduleName] = splitByLast(moduleNameWithOptionalSegment);
|
|
25
27
|
// replace c by controller, s by service, everything else keeps the same
|
package/dist/new/newSegment.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
|
7
7
|
import prettify from '../utils/prettify.mjs';
|
|
8
8
|
import chalk from 'chalk';
|
|
9
9
|
export default async function newSegment({ segmentName, isStaticSegment, overwrite, dryRun, }) {
|
|
10
|
-
const { apiDir, cwd, log } = await getProjectInfo();
|
|
10
|
+
const { apiDir, cwd, log, config } = await getProjectInfo();
|
|
11
11
|
const absoluteSegmentRoutePath = path.join(cwd, apiDir, segmentName, '[[...vovk]]/route.ts');
|
|
12
12
|
if (!overwrite && (await getFileSystemEntryType(absoluteSegmentRoutePath))) {
|
|
13
13
|
throw new Error(`Unable to create new segment. ${formatLoggedSegmentName(segmentName, { upperFirst: true })} already exists.`);
|
|
@@ -20,9 +20,11 @@ const controllers = {};
|
|
|
20
20
|
|
|
21
21
|
export type Controllers = typeof controllers;
|
|
22
22
|
${isStaticSegment
|
|
23
|
-
? `
|
|
23
|
+
? `
|
|
24
|
+
export function generateStaticParams() {
|
|
24
25
|
return generateStaticAPI(controllers);
|
|
25
|
-
}
|
|
26
|
+
}
|
|
27
|
+
`
|
|
26
28
|
: ''}
|
|
27
29
|
export const { GET${isStaticSegment ? '' : ', POST, PATCH, PUT, HEAD, OPTIONS, DELETE'} } = initVovk({
|
|
28
30
|
${segmentName ? ` segmentName: '${segmentName}',\n` : ''} emitSchema: true,
|
|
@@ -33,7 +35,7 @@ ${segmentName ? ` segmentName: '${segmentName}',\n` : ''} emitSchema: true,
|
|
|
33
35
|
await fs.mkdir(path.dirname(absoluteSegmentRoutePath), { recursive: true });
|
|
34
36
|
await fs.writeFile(absoluteSegmentRoutePath, code);
|
|
35
37
|
}
|
|
36
|
-
log.info(`${formatLoggedSegmentName(segmentName, { upperFirst: true })} created at ${absoluteSegmentRoutePath}.`);
|
|
38
|
+
log.info(`${formatLoggedSegmentName(segmentName, { upperFirst: true, isStatic: isStaticSegment })} created at ${absoluteSegmentRoutePath}.`);
|
|
37
39
|
const dir = chalk.cyanBright([segmentName, 'thing'].filter(Boolean).join('/'));
|
|
38
|
-
log.info(`Run ${chalkHighlightThing(`npx vovk new service controller ${dir}`)} to create a new controller with a service at
|
|
40
|
+
log.info(`Run ${chalkHighlightThing(`npx vovk new service controller ${dir}`)} to create a new controller with a service at ${path.join(config.modulesDir, dir)} folder for this segment`);
|
|
39
41
|
}
|
package/dist/types.d.mts
CHANGED
|
@@ -14,12 +14,16 @@ export interface DevOptions {
|
|
|
14
14
|
export interface GenerateOptions {
|
|
15
15
|
prettify?: boolean;
|
|
16
16
|
config?: string;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
composedFrom?: string[];
|
|
18
|
+
composedOut?: string;
|
|
19
|
+
composedOnly?: boolean;
|
|
20
|
+
composedIncludeSegments?: string[];
|
|
21
|
+
composedExcludeSegments?: string[];
|
|
20
22
|
segmentedFrom?: string[];
|
|
21
23
|
segmentedOut?: string;
|
|
22
24
|
segmentedOnly?: boolean;
|
|
25
|
+
segmentedIncludeSegments?: string[];
|
|
26
|
+
segmentedExcludeSegments?: string[];
|
|
23
27
|
}
|
|
24
28
|
export interface BundleOptions extends Partial<Omit<VovkStrictConfig['bundle'], 'requires'>> {
|
|
25
29
|
config?: string;
|
|
@@ -51,14 +55,9 @@ export interface NewOptions {
|
|
|
51
55
|
export type VovkEnv = {
|
|
52
56
|
PORT?: string;
|
|
53
57
|
VOVK_SCHEMA_OUT_DIR?: string;
|
|
54
|
-
VOVK_IMPORTS_FETCHER?: string;
|
|
55
|
-
VOVK_IMPORTS_VALIDATE_ON_CLIENT?: string;
|
|
56
|
-
VOVK_IMPORTS_CREATE_RPC?: string;
|
|
57
|
-
VOVK_MODULES_DIR?: string;
|
|
58
58
|
VOVK_ORIGIN?: string;
|
|
59
59
|
VOVK_ROOT_ENTRY?: string;
|
|
60
60
|
VOVK_API_ENTRY_POINT?: string;
|
|
61
|
-
VOVK_ROOT_SEGMENT_MODULES_DIR_NAME?: string;
|
|
62
61
|
VOVK_LOG_LEVEL?: LogLevelNames;
|
|
63
62
|
VOVK_PRETTIFY_CLIENT?: string;
|
|
64
63
|
VOVK_DEV_HTTPS?: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export default function formatLoggedSegmentName(segmentName: string, { withChalk, upperFirst }?: {
|
|
1
|
+
export default function formatLoggedSegmentName(segmentName: string, { withChalk, upperFirst, isStatic, }?: {
|
|
2
2
|
withChalk?: boolean;
|
|
3
3
|
upperFirst?: boolean;
|
|
4
|
+
isStatic?: boolean;
|
|
4
5
|
}): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import upperFirstLodash from 'lodash/upperFirst.js';
|
|
2
2
|
import chalkHighlightThing from './chalkHighlightThing.mjs';
|
|
3
|
-
export default function formatLoggedSegmentName(segmentName, { withChalk = true, upperFirst = false } = {}) {
|
|
4
|
-
let text = segmentName ?
|
|
3
|
+
export default function formatLoggedSegmentName(segmentName, { withChalk = true, upperFirst = false, isStatic = false, } = {}) {
|
|
4
|
+
let text = segmentName ? `${isStatic ? 'static ' : ''}segment "${segmentName}"` : 'the root segment';
|
|
5
5
|
text = upperFirst ? upperFirstLodash(text) : text;
|
|
6
6
|
return withChalk ? chalkHighlightThing(text) : text;
|
|
7
7
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default function getPublicModuleNameFromPath(modulePath) {
|
|
2
|
+
if (modulePath && !modulePath.startsWith('.') && !modulePath.startsWith('/')) {
|
|
3
|
+
const pathParts = modulePath.split('/');
|
|
4
|
+
const moduleName = pathParts[0].startsWith('@') ? `${pathParts[0]}/${pathParts[1]}` : pathParts[0];
|
|
5
|
+
const restPath = pathParts.slice(pathParts[0].startsWith('@') ? 2 : 1).join('/');
|
|
6
|
+
return { moduleName, restPath };
|
|
7
|
+
}
|
|
8
|
+
return { moduleName: null, restPath: modulePath };
|
|
9
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export default function pickSegmentFullSchema(
|
|
3
|
-
export declare function omitSegmentFullSchema(
|
|
1
|
+
import { type VovkSchema } from 'vovk';
|
|
2
|
+
export default function pickSegmentFullSchema(schema: VovkSchema, segmentNames: string[]): VovkSchema;
|
|
3
|
+
export declare function omitSegmentFullSchema(schema: VovkSchema, segmentNames: string[]): VovkSchema;
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function pickSegmentFullSchema(
|
|
1
|
+
import { VovkSchemaIdEnum } from 'vovk';
|
|
2
|
+
export default function pickSegmentFullSchema(schema, segmentNames) {
|
|
3
3
|
return {
|
|
4
|
-
$schema:
|
|
5
|
-
config:
|
|
6
|
-
segments:
|
|
7
|
-
...Object.fromEntries(segmentNames.map((segmentName) => [segmentName, fullSchema.segments[segmentName]])),
|
|
8
|
-
},
|
|
4
|
+
$schema: VovkSchemaIdEnum.SCHEMA,
|
|
5
|
+
config: schema.config,
|
|
6
|
+
segments: Object.fromEntries(segmentNames.map((segmentName) => [segmentName, schema.segments[segmentName]])),
|
|
9
7
|
};
|
|
10
8
|
}
|
|
11
|
-
export function omitSegmentFullSchema(
|
|
9
|
+
export function omitSegmentFullSchema(schema, segmentNames) {
|
|
12
10
|
return {
|
|
13
|
-
$schema:
|
|
14
|
-
config:
|
|
15
|
-
segments: Object.fromEntries(Object.entries(
|
|
11
|
+
$schema: VovkSchemaIdEnum.SCHEMA,
|
|
12
|
+
config: schema.config,
|
|
13
|
+
segments: Object.fromEntries(Object.entries(schema.segments).filter(([segmentName]) => !segmentNames.includes(segmentName))),
|
|
16
14
|
};
|
|
17
15
|
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
|
+
import getPublicModuleNameFromPath from './getPublicModuleNameFromPath.mjs';
|
|
4
|
+
// Returns the path up to and including the last occurrence of the given module name
|
|
5
|
+
export function getPathUpToModule(moduleName, fullPath) {
|
|
6
|
+
const idx = fullPath.lastIndexOf(moduleName);
|
|
7
|
+
if (idx === -1)
|
|
8
|
+
return moduleName;
|
|
9
|
+
return fullPath.slice(0, idx + moduleName.length);
|
|
10
|
+
}
|
|
3
11
|
export default function resolveAbsoluteModulePath(modulePath, cwd) {
|
|
4
12
|
// If it's an absolute path or starts with '.' (relative), resolve it directly
|
|
5
13
|
if (modulePath.startsWith('/') || modulePath.startsWith('.')) {
|
|
@@ -7,12 +15,16 @@ export default function resolveAbsoluteModulePath(modulePath, cwd) {
|
|
|
7
15
|
}
|
|
8
16
|
// For npm package names, use Node's module resolution algorithm
|
|
9
17
|
try {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
const { moduleName, restPath } = getPublicModuleNameFromPath(modulePath);
|
|
19
|
+
if (!moduleName) {
|
|
20
|
+
throw new Error(`Invalid module path: ${modulePath}`);
|
|
21
|
+
}
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
const resolved = require.resolve(moduleName);
|
|
24
|
+
return path.resolve(getPathUpToModule(moduleName, path.dirname(resolved)), restPath);
|
|
14
25
|
}
|
|
15
|
-
catch {
|
|
26
|
+
catch (e) {
|
|
27
|
+
console.error(`Error resolving module path: ${modulePath}`, e);
|
|
16
28
|
// If resolution fails, fall back to the original behavior
|
|
17
29
|
return path.resolve(cwd, './node_modules', modulePath);
|
|
18
30
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
<%- `// auto-generated ${new Date().toISOString()}\n/* eslint-disable */` %>
|
|
2
|
-
import type { VovkStrictConfig, VovkSegmentSchema } from 'vovk';
|
|
3
|
-
|
|
4
|
-
export const fullSchema: {
|
|
5
|
-
$schema: string;
|
|
6
|
-
config: Partial<VovkStrictConfig>;
|
|
7
|
-
segments: {<% Object.values(t.fullSchema.segments).filter((segment) => segment.emitSchema).forEach((segment) => { %>
|
|
8
|
-
'<%= segment.segmentName %>': VovkSegmentSchema;<% }) %>
|
|
9
|
-
};
|
|
10
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<%- JSON.stringify(t.fullSchema, null, 2) %>
|
package/dist/enums.d.mts
DELETED
package/dist/enums.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export var SchemaIdEnum;
|
|
2
|
-
(function (SchemaIdEnum) {
|
|
3
|
-
SchemaIdEnum["CONFIG"] = "https://vovk.dev/api/schema/v3/config.json";
|
|
4
|
-
SchemaIdEnum["SEGMENT"] = "https://vovk.dev/api/schema/v3/segment.json";
|
|
5
|
-
SchemaIdEnum["FULL"] = "https://vovk.dev/api/schema/v3/full.json";
|
|
6
|
-
})(SchemaIdEnum || (SchemaIdEnum = {}));
|
/package/dist/getProjectInfo/{getConfigAbsolutePaths.d.mts → getConfig/getConfigAbsolutePaths.d.mts}
RENAMED
|
File without changes
|
/package/dist/getProjectInfo/{getConfigAbsolutePaths.mjs → getConfig/getConfigAbsolutePaths.mjs}
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/getProjectInfo/{importUncachedModule.d.mts → getConfig/importUncachedModule.d.mts}
RENAMED
|
File without changes
|
/package/dist/getProjectInfo/{importUncachedModule.mjs → getConfig/importUncachedModule.mjs}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|