vovk-cli 0.0.1-draft.39 → 0.0.1-draft.390
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/LICENSE +1 -1
- package/README.md +31 -1
- package/client-templates/cjs/index.cjs.ejs +20 -0
- package/client-templates/cjs/index.d.cts.ejs +22 -0
- package/client-templates/mixins/mixins.d.ts.ejs +64 -0
- package/client-templates/mixins/mixins.json.ejs +1 -0
- package/client-templates/mjs/index.d.mts.ejs +22 -0
- package/client-templates/mjs/index.mjs.ejs +19 -0
- package/client-templates/openapiCjs/openapi.cjs.ejs +4 -0
- package/client-templates/openapiCjs/openapi.d.cts.ejs +4 -0
- package/client-templates/openapiJson/openapi.json.ejs +1 -0
- package/client-templates/openapiTs/openapi.ts.ejs +4 -0
- package/client-templates/packageJson/package.json.ejs +1 -0
- package/client-templates/readme/README.md.ejs +39 -0
- package/client-templates/schemaCjs/schema.cjs.ejs +24 -0
- package/client-templates/schemaCjs/schema.d.cts.ejs +10 -0
- package/client-templates/schemaJson/schema.json.ejs +1 -0
- package/client-templates/schemaTs/schema.ts.ejs +28 -0
- package/client-templates/ts/index.ts.ejs +33 -0
- package/dist/bundle/index.d.mts +8 -0
- package/dist/bundle/index.mjs +74 -0
- package/dist/dev/diffSegmentSchema.d.mts +36 -0
- package/dist/dev/{diffSchema.mjs → diffSegmentSchema.mjs} +3 -11
- package/dist/dev/ensureSchemaFiles.d.mts +4 -1
- package/dist/dev/ensureSchemaFiles.mjs +15 -31
- package/dist/dev/index.d.mts +5 -1
- package/dist/dev/index.mjs +141 -66
- package/dist/dev/logDiffResult.d.mts +1 -1
- package/dist/dev/logDiffResult.mjs +6 -43
- package/dist/dev/writeMetaJson.d.mts +2 -0
- package/dist/dev/writeMetaJson.mjs +20 -0
- package/dist/dev/writeOneSegmentSchemaFile.d.mts +12 -0
- package/dist/dev/{writeOneSchemaFile.mjs → writeOneSegmentSchemaFile.mjs} +10 -6
- package/dist/generate/ensureClient.d.mts +3 -0
- package/dist/generate/ensureClient.mjs +28 -0
- package/dist/generate/generate.d.mts +13 -0
- package/dist/generate/generate.mjs +307 -0
- package/dist/generate/getClientTemplateFiles.d.mts +20 -0
- package/dist/generate/getClientTemplateFiles.mjs +85 -0
- package/dist/generate/getProjectFullSchema.d.mts +8 -0
- package/dist/generate/getProjectFullSchema.mjs +66 -0
- package/dist/generate/getTemplateClientImports.d.mts +20 -0
- package/dist/generate/getTemplateClientImports.mjs +54 -0
- package/dist/generate/index.d.mts +33 -0
- package/dist/generate/index.mjs +186 -0
- package/dist/generate/writeOneClientFile.d.mts +42 -0
- package/dist/generate/writeOneClientFile.mjs +151 -0
- package/dist/getProjectInfo/getConfig/getConfigAbsolutePaths.d.mts +5 -0
- package/dist/getProjectInfo/{getConfigAbsolutePaths.mjs → getConfig/getConfigAbsolutePaths.mjs} +4 -1
- 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 +24 -0
- package/dist/getProjectInfo/getConfig/getTemplateDefs.mjs +165 -0
- package/dist/getProjectInfo/{getUserConfig.d.mts → getConfig/getUserConfig.d.mts} +3 -2
- package/dist/getProjectInfo/{getUserConfig.mjs → getConfig/getUserConfig.mjs} +3 -3
- package/dist/getProjectInfo/{importUncachedModule.mjs → getConfig/importUncachedModule.mjs} +1 -4
- package/dist/getProjectInfo/getConfig/index.d.mts +91 -0
- package/dist/getProjectInfo/getConfig/index.mjs +92 -0
- package/dist/getProjectInfo/getMetaSchema.d.mts +8 -0
- package/dist/getProjectInfo/getMetaSchema.mjs +27 -0
- package/dist/getProjectInfo/index.d.mts +14 -9
- package/dist/getProjectInfo/index.mjs +24 -22
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +116 -35
- package/dist/init/createConfig.d.mts +2 -2
- package/dist/init/createConfig.mjs +40 -13
- package/dist/init/createStandardSchemaValidatorFile.d.mts +4 -0
- package/dist/init/createStandardSchemaValidatorFile.mjs +52 -0
- package/dist/init/getTemplateFilesFromPackage.mjs +10 -5
- package/dist/init/index.d.mts +2 -2
- package/dist/init/index.mjs +121 -72
- package/dist/init/installDependencies.mjs +4 -2
- package/dist/init/logUpdateDependenciesError.d.mts +3 -1
- package/dist/init/logUpdateDependenciesError.mjs +7 -1
- package/dist/init/updateDependenciesWithoutInstalling.mjs +39 -9
- package/dist/init/updateNPMScripts.mjs +1 -1
- package/dist/init/updateTypeScriptConfig.d.mts +4 -1
- package/dist/init/updateTypeScriptConfig.mjs +11 -7
- package/dist/initProgram.d.mts +1 -1
- package/dist/initProgram.mjs +17 -17
- package/dist/locateSegments.d.mts +8 -1
- package/dist/locateSegments.mjs +13 -3
- package/dist/new/addClassToSegmentCode.d.mts +1 -2
- package/dist/new/addClassToSegmentCode.mjs +3 -3
- package/dist/new/index.d.mts +2 -1
- package/dist/new/index.mjs +5 -3
- package/dist/new/newModule.d.mts +5 -2
- package/dist/new/newModule.mjs +26 -24
- package/dist/new/newSegment.d.mts +4 -1
- package/dist/new/newSegment.mjs +20 -12
- package/dist/new/render.d.mts +7 -3
- package/dist/new/render.mjs +31 -10
- package/dist/types.d.mts +66 -44
- package/dist/utils/compileJSONSchemaToTypeScriptType.d.mts +5 -0
- package/dist/utils/compileJSONSchemaToTypeScriptType.mjs +9 -0
- package/dist/utils/compileTs.d.mts +12 -0
- package/dist/utils/compileTs.mjs +261 -0
- package/dist/utils/debounceWithArgs.d.mts +1 -1
- package/dist/utils/deepExtend.d.mts +54 -0
- package/dist/utils/deepExtend.mjs +129 -0
- package/dist/utils/formatLoggedSegmentName.d.mts +3 -1
- package/dist/utils/formatLoggedSegmentName.mjs +3 -2
- package/dist/utils/generateFnName.d.mts +23 -0
- package/dist/utils/generateFnName.mjs +76 -0
- package/dist/utils/getPackageJson.d.mts +3 -0
- package/dist/utils/getPackageJson.mjs +22 -0
- package/dist/utils/getPublicModuleNameFromPath.d.mts +4 -0
- package/dist/utils/getPublicModuleNameFromPath.mjs +9 -0
- package/dist/utils/normalizeOpenAPIMixin.d.mts +14 -0
- package/dist/utils/normalizeOpenAPIMixin.mjs +114 -0
- package/dist/utils/pickSegmentFullSchema.d.mts +3 -0
- package/dist/utils/pickSegmentFullSchema.mjs +15 -0
- package/dist/utils/removeUnlistedDirectories.d.mts +10 -0
- package/dist/utils/removeUnlistedDirectories.mjs +61 -0
- package/dist/utils/resolveAbsoluteModulePath.d.mts +2 -0
- package/dist/utils/resolveAbsoluteModulePath.mjs +32 -0
- package/module-templates/arktype/controller.ts.ejs +78 -0
- package/module-templates/type/controller.ts.ejs +64 -0
- package/module-templates/type/service.ts.ejs +37 -0
- package/module-templates/valibot/controller.ts.ejs +78 -0
- package/package.json +39 -22
- package/dist/dev/diffSchema.d.mts +0 -43
- package/dist/dev/ensureClient.d.mts +0 -5
- package/dist/dev/ensureClient.mjs +0 -31
- package/dist/dev/isMetadataEmpty.d.mts +0 -2
- package/dist/dev/isMetadataEmpty.mjs +0 -4
- package/dist/dev/writeOneSchemaFile.d.mts +0 -11
- package/dist/generateClient.d.mts +0 -7
- package/dist/generateClient.mjs +0 -97
- package/dist/getProjectInfo/getConfig.d.mts +0 -11
- package/dist/getProjectInfo/getConfig.mjs +0 -29
- package/dist/getProjectInfo/getConfigAbsolutePaths.d.mts +0 -4
- package/dist/postinstall.d.mts +0 -1
- package/dist/postinstall.mjs +0 -24
- package/templates/controller.ejs +0 -52
- package/templates/service.ejs +0 -27
- package/templates/worker.ejs +0 -24
- /package/dist/getProjectInfo/{importUncachedModule.d.mts → getConfig/importUncachedModule.d.mts} +0 -0
- /package/dist/getProjectInfo/{importUncachedModuleWorker.d.mts → getConfig/importUncachedModuleWorker.d.mts} +0 -0
- /package/dist/getProjectInfo/{importUncachedModuleWorker.mjs → getConfig/importUncachedModuleWorker.mjs} +0 -0
package/dist/locateSegments.mjs
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import getFileSystemEntryType from './utils/getFileSystemEntryType.mjs';
|
|
4
|
-
export
|
|
4
|
+
export async function locateSegments({ dir, rootDir, config, log, }) {
|
|
5
5
|
let results = [];
|
|
6
|
+
if (!dir)
|
|
7
|
+
return results; // If dir is null, return empty results because this isn't a Next.js app
|
|
8
|
+
rootDir = rootDir ?? dir;
|
|
9
|
+
let list = [];
|
|
6
10
|
// Read the contents of the directory
|
|
7
|
-
|
|
11
|
+
try {
|
|
12
|
+
list = (await fs.readdir(dir)).toSorted();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// do nothing
|
|
16
|
+
return results;
|
|
17
|
+
}
|
|
8
18
|
// Iterate through each item in the directory
|
|
9
19
|
for (const file of list) {
|
|
10
20
|
const filePath = path.join(dir, file);
|
|
@@ -21,7 +31,7 @@ export default async function locateSegments(dir, rootDir = dir) {
|
|
|
21
31
|
}
|
|
22
32
|
}
|
|
23
33
|
// Recursively search inside subdirectories
|
|
24
|
-
const subDirResults = await locateSegments(filePath, rootDir);
|
|
34
|
+
const subDirResults = await locateSegments({ dir: filePath, rootDir, config, log });
|
|
25
35
|
results = results.concat(subDirResults);
|
|
26
36
|
}
|
|
27
37
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export default function addClassToSegmentCode(segmentSourceCode: string, { sourceName, compiledName,
|
|
1
|
+
export default function addClassToSegmentCode(segmentSourceCode: string, { sourceName, compiledName, importPath, }: {
|
|
2
2
|
sourceName: string;
|
|
3
3
|
compiledName: string;
|
|
4
|
-
type: 'worker' | 'controller';
|
|
5
4
|
importPath: string;
|
|
6
5
|
}): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Project, QuoteKind, SyntaxKind } from 'ts-morph';
|
|
2
|
-
export default function addClassToSegmentCode(segmentSourceCode, { sourceName, compiledName,
|
|
2
|
+
export default function addClassToSegmentCode(segmentSourceCode, { sourceName, compiledName, importPath, }) {
|
|
3
3
|
const project = new Project({
|
|
4
4
|
manipulationSettings: {
|
|
5
5
|
quoteKind: QuoteKind.Single,
|
|
@@ -16,8 +16,8 @@ export default function addClassToSegmentCode(segmentSourceCode, { sourceName, c
|
|
|
16
16
|
moduleSpecifier: importPath,
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
// Get the variable declaration for controllers
|
|
20
|
-
const variableDeclaration = sourceFile.getVariableDeclaration(
|
|
19
|
+
// Get the variable declaration for controllers
|
|
20
|
+
const variableDeclaration = sourceFile.getVariableDeclaration('controllers');
|
|
21
21
|
if (variableDeclaration) {
|
|
22
22
|
const initializer = variableDeclaration.getInitializer();
|
|
23
23
|
if (initializer && initializer.getKind() === SyntaxKind.ObjectLiteralExpression) {
|
package/dist/new/index.d.mts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { NewOptions } from '../types.mjs';
|
|
2
|
-
|
|
2
|
+
import type { ProjectInfo } from '../getProjectInfo/index.mts';
|
|
3
|
+
export declare function newComponents(components: string[], projectInfo: ProjectInfo, { dryRun, outDir, templates, overwrite, noSegmentUpdate, empty, static: isStaticSegment }: NewOptions): Promise<void>;
|
package/dist/new/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import newModule from './newModule.mjs';
|
|
2
2
|
import newSegment from './newSegment.mjs';
|
|
3
|
-
export
|
|
3
|
+
export async function newComponents(components, projectInfo, { dryRun, outDir, templates, overwrite, noSegmentUpdate, empty, static: isStaticSegment }) {
|
|
4
4
|
if (components[0] === 'segment' || components[0] === 'segments') {
|
|
5
5
|
// vovk new segment [segmentName]
|
|
6
6
|
let segmentNames = components
|
|
@@ -10,7 +10,7 @@ export default async function newComponents(components, { dryRun, dir, templates
|
|
|
10
10
|
segmentNames = [''];
|
|
11
11
|
}
|
|
12
12
|
for (const segmentName of segmentNames) {
|
|
13
|
-
await newSegment({ segmentName, overwrite, dryRun });
|
|
13
|
+
await newSegment({ projectInfo, segmentName, isStaticSegment, overwrite, dryRun });
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
@@ -24,13 +24,15 @@ export default async function newComponents(components, { dryRun, dir, templates
|
|
|
24
24
|
throw new Error('A module name with an optional segment cannot be empty');
|
|
25
25
|
}
|
|
26
26
|
await newModule({
|
|
27
|
+
projectInfo,
|
|
27
28
|
what,
|
|
28
29
|
moduleNameWithOptionalSegment,
|
|
29
|
-
|
|
30
|
+
outDir,
|
|
30
31
|
templates,
|
|
31
32
|
overwrite,
|
|
32
33
|
noSegmentUpdate,
|
|
33
34
|
dryRun,
|
|
35
|
+
empty,
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
38
|
}
|
package/dist/new/newModule.d.mts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ProjectInfo } from '../getProjectInfo/index.mjs';
|
|
2
|
+
export default function newModule({ projectInfo, what, moduleNameWithOptionalSegment, dryRun, outDir: outDirFlag, templates: templatesFlag, noSegmentUpdate, overwrite, empty, }: {
|
|
3
|
+
projectInfo: ProjectInfo;
|
|
2
4
|
what: string[];
|
|
3
5
|
moduleNameWithOptionalSegment: string;
|
|
4
6
|
dryRun?: boolean;
|
|
5
|
-
|
|
7
|
+
outDir?: string;
|
|
6
8
|
templates?: string[];
|
|
7
9
|
noSegmentUpdate?: boolean;
|
|
8
10
|
overwrite?: boolean;
|
|
11
|
+
empty?: boolean;
|
|
9
12
|
}): Promise<void>;
|
package/dist/new/newModule.mjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { getTsconfig } from 'get-tsconfig';
|
|
3
5
|
import render from './render.mjs';
|
|
4
6
|
import addClassToSegmentCode from './addClassToSegmentCode.mjs';
|
|
5
|
-
import getProjectInfo from '../getProjectInfo/index.mjs';
|
|
6
|
-
import locateSegments from '../locateSegments.mjs';
|
|
7
7
|
import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
|
|
8
8
|
import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
9
9
|
import getFileSystemEntryType from '../utils/getFileSystemEntryType.mjs';
|
|
10
10
|
import prettify from '../utils/prettify.mjs';
|
|
11
|
+
import resolveAbsoluteModulePath from '../utils/resolveAbsoluteModulePath.mjs';
|
|
12
|
+
import { locateSegments } from '../locateSegments.mjs';
|
|
11
13
|
function splitByLast(str, delimiter = '/') {
|
|
12
14
|
const index = str.lastIndexOf(delimiter);
|
|
13
15
|
if (index === -1) {
|
|
@@ -18,19 +20,19 @@ function splitByLast(str, delimiter = '/') {
|
|
|
18
20
|
const after = str.substring(index + delimiter.length);
|
|
19
21
|
return [before, after];
|
|
20
22
|
}
|
|
21
|
-
export default async function newModule({ what, moduleNameWithOptionalSegment, dryRun,
|
|
22
|
-
const { config, log,
|
|
23
|
-
|
|
23
|
+
export default async function newModule({ projectInfo, what, moduleNameWithOptionalSegment, dryRun, outDir: outDirFlag, templates: templatesFlag, noSegmentUpdate, overwrite, empty, }) {
|
|
24
|
+
const { config, log, cwd, apiDirAbsolutePath } = projectInfo;
|
|
25
|
+
const segments = await locateSegments({ dir: apiDirAbsolutePath, config, log });
|
|
26
|
+
const isNodeNextResolution = ['node16', 'nodenext'].includes((await getTsconfig(cwd)?.config?.compilerOptions?.moduleResolution?.toLowerCase()) ?? '');
|
|
27
|
+
let templates = config.moduleTemplates;
|
|
24
28
|
const [segmentName, moduleName] = splitByLast(moduleNameWithOptionalSegment);
|
|
25
|
-
// replace c by controller, s by service,
|
|
29
|
+
// replace c by controller, s by service, everything else keeps the same
|
|
26
30
|
what = what.map((s) => {
|
|
27
31
|
switch (s) {
|
|
28
32
|
case 'c':
|
|
29
33
|
return 'controller';
|
|
30
34
|
case 's':
|
|
31
35
|
return 'service';
|
|
32
|
-
case 'w':
|
|
33
|
-
return 'worker';
|
|
34
36
|
default:
|
|
35
37
|
return s;
|
|
36
38
|
}
|
|
@@ -49,66 +51,66 @@ export default async function newModule({ what, moduleNameWithOptionalSegment, d
|
|
|
49
51
|
throw new Error(`Template for "${type}" not found`);
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
|
-
const segments = await locateSegments(apiDir);
|
|
53
54
|
const segment = segments.find((s) => s.segmentName === segmentName);
|
|
54
55
|
if (!segment) {
|
|
55
56
|
throw new Error(`Unable to create module. Segment "${segmentName}" not found. Run "vovk new segment ${segmentName}" to create it`);
|
|
56
57
|
}
|
|
57
58
|
for (const type of what) {
|
|
58
59
|
const templatePath = templates[type];
|
|
59
|
-
const templateAbsolutePath = templatePath
|
|
60
|
-
? path.resolve(cwd, templatePath)
|
|
61
|
-
: path.resolve(cwd, './node_modules', templatePath);
|
|
60
|
+
const templateAbsolutePath = resolveAbsoluteModulePath(templatePath, cwd);
|
|
62
61
|
const templateCode = await fs.readFile(templateAbsolutePath, 'utf-8');
|
|
63
|
-
const {
|
|
62
|
+
const { outDir: renderedOutDir, fileName, sourceName, compiledName, code, } = await render(templateCode, {
|
|
64
63
|
cwd,
|
|
65
64
|
config,
|
|
66
65
|
withService: what.includes('service'),
|
|
67
66
|
segmentName,
|
|
68
67
|
moduleName,
|
|
68
|
+
empty,
|
|
69
|
+
templateFileName: templateAbsolutePath,
|
|
70
|
+
isNodeNextResolution,
|
|
69
71
|
});
|
|
70
|
-
const
|
|
71
|
-
if (!
|
|
72
|
-
throw new Error(`The template for "${type}" does not provide a
|
|
72
|
+
const outDir = outDirFlag ?? renderedOutDir;
|
|
73
|
+
if (!outDir) {
|
|
74
|
+
throw new Error(`The template for "${type}" does not provide a outDir`);
|
|
73
75
|
}
|
|
74
76
|
if (!fileName) {
|
|
75
77
|
throw new Error(`The template for "${type}" does not provide a fileName`);
|
|
76
78
|
}
|
|
77
|
-
const absoluteModuleDir = path.join(cwd,
|
|
79
|
+
const absoluteModuleDir = path.join(cwd, outDir);
|
|
78
80
|
const absoluteModulePath = path.join(absoluteModuleDir, fileName);
|
|
79
81
|
const prettiedCode = await prettify(code, absoluteModulePath);
|
|
80
82
|
if (!dryRun) {
|
|
81
83
|
if (!overwrite && (await getFileSystemEntryType(absoluteModulePath))) {
|
|
82
|
-
log.warn(`File ${chalkHighlightThing(absoluteModulePath)} already exists, skipping this "${type}"
|
|
84
|
+
log.warn(`File ${chalkHighlightThing(absoluteModulePath)} already exists, skipping this "${chalkHighlightThing(type)}". You can use --overwrite flag to overwrite it.`);
|
|
83
85
|
}
|
|
84
86
|
else {
|
|
85
87
|
await fs.mkdir(absoluteModuleDir, { recursive: true });
|
|
86
88
|
await fs.writeFile(absoluteModulePath, prettiedCode);
|
|
87
|
-
log.info(
|
|
89
|
+
log.info(`${chalk.green('Created')}${empty ? ' empty' : ''} ${chalkHighlightThing(absoluteModulePath)} using ${chalkHighlightThing(`"${type}"`)} template for ${formatLoggedSegmentName(segmentName)}`);
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
|
-
if (type === 'controller'
|
|
92
|
+
if (type === 'controller') {
|
|
91
93
|
if (!sourceName) {
|
|
92
94
|
throw new Error(`The template for "${type}" does not provide a sourceName`);
|
|
93
95
|
}
|
|
94
96
|
if (!compiledName) {
|
|
95
|
-
throw new Error(
|
|
97
|
+
throw new Error(`The template for "${type}" does not provide a compiledName`);
|
|
96
98
|
}
|
|
97
99
|
const { routeFilePath } = segment;
|
|
98
100
|
const segmentSourceCode = await fs.readFile(routeFilePath, 'utf-8');
|
|
99
|
-
|
|
101
|
+
let importPath = path.relative(path.dirname(routeFilePath) + '/', absoluteModulePath).replace(/\.(ts|tsx)$/, '');
|
|
102
|
+
importPath += isNodeNextResolution ? '.ts' : '';
|
|
100
103
|
if (!noSegmentUpdate) {
|
|
101
104
|
const newSegmentCode = await prettify(addClassToSegmentCode(segmentSourceCode, {
|
|
102
105
|
sourceName,
|
|
103
106
|
compiledName,
|
|
104
|
-
type,
|
|
105
107
|
importPath,
|
|
106
108
|
}), routeFilePath);
|
|
107
109
|
if (!dryRun) {
|
|
108
110
|
await fs.writeFile(routeFilePath, newSegmentCode);
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
|
-
log.info(
|
|
113
|
+
log.info(`${chalk.green('Added')} ${chalkHighlightThing(sourceName)} ${type} as ${chalkHighlightThing(compiledName)} to ${formatLoggedSegmentName(segmentName)}`);
|
|
112
114
|
}
|
|
113
115
|
}
|
|
114
116
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ProjectInfo } from '../getProjectInfo/index.mjs';
|
|
2
|
+
export default function newSegment({ projectInfo, segmentName, isStaticSegment, overwrite, dryRun, }: {
|
|
3
|
+
projectInfo: ProjectInfo;
|
|
2
4
|
segmentName: string;
|
|
5
|
+
isStaticSegment?: boolean;
|
|
3
6
|
overwrite?: boolean;
|
|
4
7
|
dryRun?: boolean;
|
|
5
8
|
}): Promise<void>;
|
package/dist/new/newSegment.mjs
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
|
-
import getProjectInfo from '../getProjectInfo/index.mjs';
|
|
4
3
|
import getFileSystemEntryType from '../utils/getFileSystemEntryType.mjs';
|
|
5
4
|
import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
|
|
6
5
|
import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
7
6
|
import prettify from '../utils/prettify.mjs';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
export default async function newSegment({ projectInfo, segmentName, isStaticSegment, overwrite, dryRun, }) {
|
|
9
|
+
const { apiDirAbsolutePath, log, config } = projectInfo;
|
|
10
|
+
if (!apiDirAbsolutePath) {
|
|
11
|
+
throw new Error('No API directory found. Please ensure you are in a Nest.js project.');
|
|
12
|
+
}
|
|
13
|
+
const absoluteSegmentRoutePath = path.join(apiDirAbsolutePath, segmentName, '[[...vovk]]/route.ts');
|
|
11
14
|
if (!overwrite && (await getFileSystemEntryType(absoluteSegmentRoutePath))) {
|
|
12
|
-
throw new Error(`Unable to create new segment. ${formatLoggedSegmentName(segmentName, { upperFirst: true })} already exists.`);
|
|
15
|
+
throw new Error(`Unable to create new segment. ${formatLoggedSegmentName(segmentName, { upperFirst: true })} already exists. You can use --overwrite flag to overwrite it.`);
|
|
13
16
|
}
|
|
14
|
-
const code = await prettify(`import {
|
|
17
|
+
const code = await prettify(`import { initSegment${isStaticSegment ? ', generateStaticAPI' : ''} } from 'vovk';
|
|
15
18
|
|
|
16
19
|
const controllers = {};
|
|
17
|
-
const workers = {};
|
|
18
20
|
|
|
19
21
|
export type Controllers = typeof controllers;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export
|
|
22
|
+
${isStaticSegment
|
|
23
|
+
? `
|
|
24
|
+
export function generateStaticParams() {
|
|
25
|
+
return generateStaticAPI(controllers);
|
|
26
|
+
}
|
|
27
|
+
`
|
|
28
|
+
: ''}
|
|
29
|
+
export const { GET${isStaticSegment ? '' : ', POST, PATCH, PUT, HEAD, OPTIONS, DELETE'} } = initSegment({
|
|
23
30
|
${segmentName ? ` segmentName: '${segmentName}',\n` : ''} emitSchema: true,
|
|
24
|
-
workers,
|
|
25
31
|
controllers,
|
|
26
32
|
});
|
|
27
33
|
`, absoluteSegmentRoutePath);
|
|
@@ -29,5 +35,7 @@ ${segmentName ? ` segmentName: '${segmentName}',\n` : ''} emitSchema: true,
|
|
|
29
35
|
await fs.mkdir(path.dirname(absoluteSegmentRoutePath), { recursive: true });
|
|
30
36
|
await fs.writeFile(absoluteSegmentRoutePath, code);
|
|
31
37
|
}
|
|
32
|
-
log.info(`${formatLoggedSegmentName(segmentName, {
|
|
38
|
+
log.info(`${chalk.green('Created')} ${formatLoggedSegmentName(segmentName, { isStatic: isStaticSegment })} at ${absoluteSegmentRoutePath}.`);
|
|
39
|
+
const dir = chalk.cyanBright([segmentName, 'thing'].filter(Boolean).join('/'));
|
|
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`);
|
|
33
41
|
}
|
package/dist/new/render.d.mts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { VovkStrictConfig } from 'vovk';
|
|
2
|
+
import type { VovkModuleRenderResult } from '../types.mjs';
|
|
3
|
+
export default function render(codeTemplate: string, { config, withService, segmentName, moduleName, empty, templateFileName, isNodeNextResolution, }: {
|
|
3
4
|
cwd: string;
|
|
4
|
-
config:
|
|
5
|
+
config: VovkStrictConfig;
|
|
5
6
|
withService: boolean;
|
|
6
7
|
segmentName: string;
|
|
7
8
|
moduleName: string;
|
|
9
|
+
empty?: boolean;
|
|
10
|
+
templateFileName: string;
|
|
11
|
+
isNodeNextResolution: boolean;
|
|
8
12
|
}): Promise<VovkModuleRenderResult>;
|
package/dist/new/render.mjs
CHANGED
|
@@ -4,27 +4,48 @@ import _ from 'lodash';
|
|
|
4
4
|
import pluralize from 'pluralize';
|
|
5
5
|
import addCommonTerms from './addCommonTerms.mjs';
|
|
6
6
|
addCommonTerms();
|
|
7
|
-
export default async function render(codeTemplate, { config, withService, segmentName, moduleName, }) {
|
|
7
|
+
export default async function render(codeTemplate, { config, withService, segmentName, moduleName, empty, templateFileName, isNodeNextResolution, }) {
|
|
8
8
|
const getModuleDirName = (givenSegmentName, givenModuleName) => [config.modulesDir, givenSegmentName || config.rootSegmentModulesDirName, _.camelCase(givenModuleName)]
|
|
9
9
|
.filter(Boolean)
|
|
10
10
|
.join('/');
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const theThing = _.camelCase(moduleName);
|
|
12
|
+
const TheThing = _.upperFirst(theThing);
|
|
13
|
+
const the_thing = _.snakeCase(moduleName);
|
|
14
|
+
const THE_THING = _.toUpper(the_thing);
|
|
15
|
+
const the__thing = _.kebabCase(moduleName);
|
|
16
|
+
const t = {
|
|
17
|
+
// module name variations
|
|
18
|
+
moduleName,
|
|
19
|
+
theThing,
|
|
20
|
+
theThings: pluralize(theThing),
|
|
21
|
+
TheThing,
|
|
22
|
+
TheThings: pluralize(TheThing),
|
|
23
|
+
the_thing,
|
|
24
|
+
the_things: pluralize(the_thing),
|
|
25
|
+
THE_THING,
|
|
26
|
+
THE_THINGS: pluralize(THE_THING),
|
|
27
|
+
'the-thing': the__thing,
|
|
28
|
+
'the-things': pluralize(the__thing),
|
|
29
|
+
// data
|
|
13
30
|
config,
|
|
14
31
|
withService,
|
|
15
32
|
segmentName,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
33
|
+
nodeNextResolutionExt: {
|
|
34
|
+
ts: isNodeNextResolution ? '.ts' : '',
|
|
35
|
+
js: isNodeNextResolution ? '.js' : '',
|
|
36
|
+
cjs: isNodeNextResolution ? '.cjs' : '',
|
|
37
|
+
mjs: isNodeNextResolution ? '.mjs' : '',
|
|
38
|
+
},
|
|
39
|
+
defaultOutDir: getModuleDirName(segmentName, theThing),
|
|
19
40
|
// libraries
|
|
20
41
|
_, // lodash
|
|
21
42
|
pluralize,
|
|
22
43
|
};
|
|
23
|
-
const parsed = matter((await ejs.render(codeTemplate,
|
|
24
|
-
const {
|
|
25
|
-
const code = parsed.content;
|
|
44
|
+
const parsed = matter((await ejs.render(codeTemplate, { t }, { async: true, filename: templateFileName })).trim());
|
|
45
|
+
const { outDir, fileName, sourceName, compiledName } = parsed.data;
|
|
46
|
+
const code = empty ? (sourceName ? `export default class ${sourceName} {}` : '') : parsed.content;
|
|
26
47
|
return {
|
|
27
|
-
|
|
48
|
+
outDir,
|
|
28
49
|
fileName,
|
|
29
50
|
sourceName,
|
|
30
51
|
compiledName,
|
package/dist/types.d.mts
CHANGED
|
@@ -1,58 +1,61 @@
|
|
|
1
1
|
import type { LogLevelNames } from 'loglevel';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
PORT?: string;
|
|
5
|
-
VOVK_CLIENT_OUT_DIR?: string;
|
|
6
|
-
VOVK_SCHEMA_OUT_DIR?: string;
|
|
7
|
-
VOVK_FETCHER?: string;
|
|
8
|
-
VOVK_VALIDATE_ON_CLIENT?: string;
|
|
9
|
-
VOVK_MODULES_DIR?: string;
|
|
10
|
-
VOVK_VALIDATION_LIBRARY?: string;
|
|
11
|
-
VOVK_ORIGIN?: string;
|
|
12
|
-
VOVK_ROOT_ENTRY?: string;
|
|
13
|
-
VOVK_API_ENTRY_POINT?: string;
|
|
14
|
-
VOVK_ROOT_SEGMENT_MODULES_DIR_NAME?: string;
|
|
15
|
-
VOVK_LOG_LEVEL?: LogLevelNames;
|
|
16
|
-
VOVK_PRETTIFY_CLIENT?: string;
|
|
17
|
-
VOVK_DEV_HTTPS?: string;
|
|
18
|
-
__VOVK_START_WATCHER_IN_STANDALONE_MODE__?: 'true';
|
|
19
|
-
};
|
|
20
|
-
export type VovkConfig = {
|
|
21
|
-
clientOutDir?: string;
|
|
22
|
-
schemaOutDir?: string;
|
|
23
|
-
fetcher?: string;
|
|
24
|
-
validateOnClient?: string | null;
|
|
25
|
-
modulesDir?: string;
|
|
26
|
-
validationLibrary?: string | null;
|
|
27
|
-
rootEntry?: string;
|
|
28
|
-
origin?: string;
|
|
29
|
-
rootSegmentModulesDirName?: string;
|
|
30
|
-
logLevel?: LogLevelNames;
|
|
31
|
-
prettifyClient?: boolean;
|
|
32
|
-
devHttps?: boolean;
|
|
33
|
-
templates?: {
|
|
34
|
-
service?: string;
|
|
35
|
-
controller?: string;
|
|
36
|
-
worker?: string;
|
|
37
|
-
[key: string]: string | undefined;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
2
|
+
import type { build } from 'tsdown';
|
|
3
|
+
import type { VovkStrictConfig } from 'vovk';
|
|
40
4
|
export type VovkModuleRenderResult = {
|
|
41
5
|
fileName: string;
|
|
42
|
-
|
|
6
|
+
outDir: string;
|
|
43
7
|
sourceName?: string;
|
|
44
8
|
compiledName?: string;
|
|
45
9
|
code: string;
|
|
46
10
|
};
|
|
47
11
|
export interface DevOptions {
|
|
12
|
+
schemaOut?: string;
|
|
48
13
|
nextDev?: boolean;
|
|
14
|
+
exit?: boolean;
|
|
15
|
+
devHttps?: boolean;
|
|
16
|
+
logLevel?: LogLevelNames;
|
|
49
17
|
}
|
|
50
18
|
export interface GenerateOptions {
|
|
51
|
-
|
|
19
|
+
prettify?: boolean;
|
|
20
|
+
configPath?: string;
|
|
21
|
+
schemaPath?: string;
|
|
22
|
+
origin?: string;
|
|
23
|
+
openapiSpec?: string[];
|
|
24
|
+
openapiGetModuleName?: string[];
|
|
25
|
+
openapiGetMethodName?: string[];
|
|
26
|
+
openapiRootUrl?: string[];
|
|
27
|
+
openapiMixinName?: string[];
|
|
28
|
+
openapiFallback?: string[];
|
|
29
|
+
watch?: boolean | string;
|
|
30
|
+
composedFrom?: string[];
|
|
31
|
+
composedOut?: string;
|
|
32
|
+
composedOnly?: boolean;
|
|
33
|
+
composedIncludeSegments?: string[];
|
|
34
|
+
composedExcludeSegments?: string[];
|
|
35
|
+
segmentedFrom?: string[];
|
|
36
|
+
segmentedOut?: string;
|
|
37
|
+
segmentedOnly?: boolean;
|
|
38
|
+
segmentedIncludeSegments?: string[];
|
|
39
|
+
segmentedExcludeSegments?: string[];
|
|
40
|
+
logLevel?: LogLevelNames;
|
|
41
|
+
}
|
|
42
|
+
export interface BundleOptions extends Partial<Pick<VovkStrictConfig['bundle'], 'prebundleOutDir' | 'keepPrebundleDir' | 'includeSegments' | 'excludeSegments'>> {
|
|
43
|
+
bundler?: 'tsdown' | 'ncc';
|
|
44
|
+
configPath?: string;
|
|
45
|
+
schemaPath?: string;
|
|
46
|
+
schema?: string;
|
|
47
|
+
outDir?: string;
|
|
48
|
+
origin?: string;
|
|
49
|
+
openapiSpec?: string[];
|
|
50
|
+
openapiGetModuleName?: string[];
|
|
51
|
+
openapiGetMethodName?: string[];
|
|
52
|
+
openapiRootUrl?: string[];
|
|
53
|
+
openapiMixinName?: string[];
|
|
54
|
+
logLevel?: LogLevelNames;
|
|
52
55
|
}
|
|
53
56
|
export interface InitOptions {
|
|
57
|
+
prefix?: string;
|
|
54
58
|
yes?: boolean;
|
|
55
|
-
logLevel: LogLevelNames;
|
|
56
59
|
useNpm?: boolean;
|
|
57
60
|
useYarn?: boolean;
|
|
58
61
|
usePnpm?: boolean;
|
|
@@ -60,15 +63,34 @@ export interface InitOptions {
|
|
|
60
63
|
skipInstall?: boolean;
|
|
61
64
|
updateTsConfig?: boolean;
|
|
62
65
|
updateScripts?: 'implicit' | 'explicit';
|
|
63
|
-
validationLibrary?:
|
|
64
|
-
validateOnClient?: boolean;
|
|
66
|
+
validationLibrary?: 'zod' | 'yup' | 'class-validator' | 'valibot' | 'arktype' | null;
|
|
65
67
|
dryRun?: boolean;
|
|
68
|
+
lang?: string[];
|
|
66
69
|
channel?: 'latest' | 'beta' | 'draft';
|
|
70
|
+
logLevel?: LogLevelNames;
|
|
67
71
|
}
|
|
68
72
|
export interface NewOptions {
|
|
69
73
|
dryRun?: boolean;
|
|
70
74
|
templates?: string[];
|
|
71
|
-
|
|
75
|
+
outDir?: string;
|
|
72
76
|
overwrite?: boolean;
|
|
73
77
|
noSegmentUpdate?: boolean;
|
|
78
|
+
empty?: boolean;
|
|
79
|
+
static?: boolean;
|
|
80
|
+
logLevel?: LogLevelNames;
|
|
81
|
+
}
|
|
82
|
+
export type VovkEnv = {
|
|
83
|
+
PORT?: string;
|
|
84
|
+
VOVK_SCHEMA_OUT_DIR?: string;
|
|
85
|
+
VOVK_ORIGIN?: string;
|
|
86
|
+
VOVK_ROOT_ENTRY?: string;
|
|
87
|
+
VOVK_API_ENTRY_POINT?: string;
|
|
88
|
+
__VOVK_START_WATCHER_IN_STANDALONE_MODE__?: 'true';
|
|
89
|
+
__VOVK_SCHEMA_OUT_FLAG__?: string;
|
|
90
|
+
__VOVK_DEV_HTTPS_FLAG__?: 'true' | 'false';
|
|
91
|
+
__VOVK_EXIT__?: 'true' | 'false';
|
|
92
|
+
__VOVK_LOG_LEVEL__?: LogLevelNames;
|
|
93
|
+
};
|
|
94
|
+
declare global {
|
|
95
|
+
var TSdownBuildOptions: Parameters<typeof build>[0];
|
|
74
96
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OpenAPIObject } from 'openapi3-ts/oas31';
|
|
2
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
3
|
+
export declare function compileJSONSchemaToTypeScriptType(schema: JSONSchema7, typeName: string, components?: NonNullable<OpenAPIObject['components']>, options?: {
|
|
4
|
+
dontCreateRefTypes?: boolean;
|
|
5
|
+
}): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { compileTs } from './compileTs.mjs';
|
|
2
|
+
export function compileJSONSchemaToTypeScriptType(schema, typeName, components = {}, options = {}) {
|
|
3
|
+
if (!schema)
|
|
4
|
+
return '';
|
|
5
|
+
if ('tsType' in schema && typeof schema.tsType === 'string')
|
|
6
|
+
return `export type ${typeName} = ${schema.tsType};\n`;
|
|
7
|
+
const tsType = compileTs({ schema: { ...schema, components }, name: typeName, ...options });
|
|
8
|
+
return tsType;
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { JSONSchema7 } from 'json-schema';
|
|
2
|
+
import { OpenAPIObject } from 'openapi3-ts/oas31';
|
|
3
|
+
interface CompileOptions {
|
|
4
|
+
name: string;
|
|
5
|
+
schema: JSONSchema7 & {
|
|
6
|
+
components?: OpenAPIObject['components'];
|
|
7
|
+
};
|
|
8
|
+
refs?: Map<string, JSONSchema7>;
|
|
9
|
+
dontCreateRefTypes?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function compileTs(options: CompileOptions): string;
|
|
12
|
+
export {};
|