vovk-cli 0.0.1-draft.1 → 0.0.1-draft.100
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/README.md +29 -1
- package/client-templates/main/main.cjs.ejs +15 -0
- package/client-templates/main/main.d.cts.ejs +14 -0
- package/client-templates/module/module.d.mts.ejs +14 -0
- package/client-templates/module/module.mjs.ejs +24 -0
- package/client-templates/python/__init__.py +276 -0
- package/client-templates/ts/index.ts.ejs +25 -0
- package/dist/dev/diffSchema.d.mts +36 -0
- package/dist/{watcher → dev}/diffSchema.mjs +3 -11
- package/dist/{watcher → dev}/ensureSchemaFiles.d.mts +3 -0
- package/dist/{watcher → dev}/ensureSchemaFiles.mjs +43 -16
- package/dist/dev/index.d.mts +6 -0
- package/dist/{watcher → dev}/index.mjs +138 -69
- package/dist/{watcher/isMetadataEmpty.mjs → dev/isSchemaEmpty.mjs} +1 -1
- package/dist/{watcher → dev}/logDiffResult.d.mts +2 -2
- package/dist/dev/logDiffResult.mjs +57 -0
- package/dist/{watcher → dev}/writeOneSchemaFile.d.mts +2 -1
- package/dist/{watcher → dev}/writeOneSchemaFile.mjs +6 -4
- package/dist/generate/ensureClient.d.mts +5 -0
- package/dist/generate/ensureClient.mjs +30 -0
- package/dist/generate/getClientTemplates.d.mts +16 -0
- package/dist/generate/getClientTemplates.mjs +42 -0
- package/dist/generate/index.d.mts +13 -0
- package/dist/generate/index.mjs +94 -0
- package/dist/getProjectInfo/getConfig.d.mts +3 -3
- package/dist/getProjectInfo/getConfig.mjs +11 -5
- package/dist/getProjectInfo/getConfigAbsolutePaths.mjs +2 -2
- package/dist/getProjectInfo/getRelativeSrcRoot.mjs +4 -4
- package/dist/getProjectInfo/getUserConfig.mjs +4 -2
- package/dist/getProjectInfo/importUncachedModule.mjs +0 -1
- package/dist/getProjectInfo/importUncachedModuleWorker.mjs +0 -1
- package/dist/getProjectInfo/index.d.mts +14 -5
- package/dist/getProjectInfo/index.mjs +21 -13
- package/dist/index.d.mts +1 -23
- package/dist/index.mjs +58 -60
- package/dist/init/checkTSConfigForExperimentalDecorators.mjs +2 -2
- package/dist/init/createConfig.d.mts +3 -4
- package/dist/init/createConfig.mjs +9 -8
- package/dist/init/getTemplateFilesFromPackage.d.mts +2 -1
- package/dist/init/getTemplateFilesFromPackage.mjs +4 -5
- package/dist/init/index.d.mts +2 -3
- package/dist/init/index.mjs +61 -97
- package/dist/init/installDependencies.d.mts +4 -1
- package/dist/init/installDependencies.mjs +2 -2
- package/dist/init/logUpdateDependenciesError.d.mts +11 -0
- package/dist/init/logUpdateDependenciesError.mjs +45 -0
- package/dist/init/updateDependenciesWithoutInstalling.d.mts +3 -2
- package/dist/init/updateDependenciesWithoutInstalling.mjs +13 -8
- package/dist/init/updateNPMScripts.d.mts +3 -1
- package/dist/init/updateNPMScripts.mjs +10 -6
- package/dist/init/updateTypeScriptConfig.mjs +2 -2
- package/dist/initProgram.d.mts +2 -0
- package/dist/initProgram.mjs +22 -0
- package/dist/locateSegments.d.mts +7 -1
- package/dist/locateSegments.mjs +9 -6
- package/dist/new/addClassToSegmentCode.d.mts +1 -2
- package/dist/new/addClassToSegmentCode.mjs +9 -5
- package/dist/new/addCommonTerms.mjs +1 -0
- package/dist/new/index.d.mts +2 -2
- package/dist/new/index.mjs +14 -3
- package/dist/new/newModule.d.mts +7 -2
- package/dist/new/newModule.mjs +54 -31
- package/dist/new/newSegment.d.mts +3 -2
- package/dist/new/newSegment.mjs +10 -8
- package/dist/new/render.d.mts +6 -8
- package/dist/new/render.mjs +40 -13
- package/dist/postinstall.mjs +16 -17
- package/dist/types.d.mts +63 -8
- package/dist/utils/debounceWithArgs.d.mts +1 -1
- package/dist/utils/debounceWithArgs.mjs +24 -9
- package/dist/utils/formatLoggedSegmentName.mjs +1 -1
- package/dist/utils/getAvailablePort.mjs +3 -2
- package/dist/utils/getFileSystemEntryType.mjs +1 -1
- package/package.json +21 -18
- package/templates/controller.ejs +23 -23
- package/templates/service.ejs +24 -4
- package/dist/generateClient.d.mts +0 -7
- package/dist/generateClient.mjs +0 -97
- package/dist/getProjectInfo/directoryExists.d.mts +0 -1
- package/dist/getProjectInfo/directoryExists.mjs +0 -10
- package/dist/watcher/diffSchema.d.mts +0 -43
- package/dist/watcher/index.d.mts +0 -6
- package/dist/watcher/logDiffResult.mjs +0 -90
- package/templates/worker.ejs +0 -1
- package/templates_old/MyThingController.c.only.template.ts +0 -32
- package/templates_old/MyThingController.c.template.ts +0 -34
- package/templates_old/MyThingService.s.template.ts +0 -18
- package/templates_old/controller.ejs +0 -85
- package/templates_old/service.ejs +0 -9
- package/templates_old/worker.ejs +0 -9
- package/templates_old/zod/MyThingController.c.only.template.ts +0 -32
- package/templates_old/zod/MyThingController.c.template.ts +0 -39
- package/templates_old/zod/MyThingService.s.template.ts +0 -18
- /package/dist/{watcher/isMetadataEmpty.d.mts → dev/isSchemaEmpty.d.mts} +0 -0
package/dist/new/newModule.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs/promises';
|
|
3
|
-
import getProjectInfo from '../getProjectInfo/index.mjs';
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
4
3
|
import render from './render.mjs';
|
|
4
|
+
import addClassToSegmentCode from './addClassToSegmentCode.mjs';
|
|
5
|
+
import getProjectInfo from '../getProjectInfo/index.mjs';
|
|
6
|
+
import locateSegments from '../locateSegments.mjs';
|
|
5
7
|
import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
|
|
6
8
|
import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
7
|
-
import locateSegments from '../locateSegments.mjs';
|
|
8
|
-
import addClassToSegmentCode from './addClassToSegmentCode.mjs';
|
|
9
9
|
import getFileSystemEntryType from '../utils/getFileSystemEntryType.mjs';
|
|
10
10
|
import prettify from '../utils/prettify.mjs';
|
|
11
11
|
function splitByLast(str, delimiter = '/') {
|
|
@@ -18,33 +18,39 @@ function splitByLast(str, delimiter = '/') {
|
|
|
18
18
|
const after = str.substring(index + delimiter.length);
|
|
19
19
|
return [before, after];
|
|
20
20
|
}
|
|
21
|
-
export default async function newModule({ what, moduleNameWithOptionalSegment, dryRun, }) {
|
|
21
|
+
export default async function newModule({ what, moduleNameWithOptionalSegment, dryRun, dir: dirFlag, templates: templatesFlag, noSegmentUpdate, overwrite, empty, }) {
|
|
22
22
|
const { config, log, apiDir, cwd } = await getProjectInfo();
|
|
23
|
-
|
|
23
|
+
let templates = config.templates;
|
|
24
24
|
const [segmentName, moduleName] = splitByLast(moduleNameWithOptionalSegment);
|
|
25
|
-
// replace c by controller, s by service,
|
|
25
|
+
// replace c by controller, s by service, everything else keeps the same
|
|
26
26
|
what = what.map((s) => {
|
|
27
27
|
switch (s) {
|
|
28
28
|
case 'c':
|
|
29
29
|
return 'controller';
|
|
30
30
|
case 's':
|
|
31
31
|
return 'service';
|
|
32
|
-
case 'w':
|
|
33
|
-
return 'worker';
|
|
34
32
|
default:
|
|
35
33
|
return s;
|
|
36
34
|
}
|
|
37
35
|
});
|
|
38
|
-
|
|
36
|
+
if (templatesFlag) {
|
|
37
|
+
if (templatesFlag.length > what.length) {
|
|
38
|
+
throw new Error('Too many templates provided');
|
|
39
|
+
}
|
|
40
|
+
templates = templatesFlag.reduce((acc, templatePath, index) => ({
|
|
41
|
+
...acc,
|
|
42
|
+
[what[index]]: templatePath,
|
|
43
|
+
}), templates);
|
|
44
|
+
}
|
|
39
45
|
for (const type of what) {
|
|
40
46
|
if (!templates[type]) {
|
|
41
|
-
throw new Error(`Template for ${type} not found
|
|
47
|
+
throw new Error(`Template for "${type}" not found`);
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
|
-
const segments = await locateSegments(apiDir);
|
|
50
|
+
const segments = await locateSegments({ dir: apiDir, config });
|
|
45
51
|
const segment = segments.find((s) => s.segmentName === segmentName);
|
|
46
52
|
if (!segment) {
|
|
47
|
-
throw new Error(`Segment ${segmentName} not found`);
|
|
53
|
+
throw new Error(`Unable to create module. Segment "${segmentName}" not found. Run "vovk new segment ${segmentName}" to create it`);
|
|
48
54
|
}
|
|
49
55
|
for (const type of what) {
|
|
50
56
|
const templatePath = templates[type];
|
|
@@ -52,39 +58,56 @@ export default async function newModule({ what, moduleNameWithOptionalSegment, d
|
|
|
52
58
|
? path.resolve(cwd, templatePath)
|
|
53
59
|
: path.resolve(cwd, './node_modules', templatePath);
|
|
54
60
|
const templateCode = await fs.readFile(templateAbsolutePath, 'utf-8');
|
|
55
|
-
const {
|
|
61
|
+
const { dir: renderedDir, fileName, sourceName, compiledName, code, } = await render(templateCode, {
|
|
62
|
+
cwd,
|
|
56
63
|
config,
|
|
57
64
|
withService: what.includes('service'),
|
|
58
65
|
segmentName,
|
|
59
66
|
moduleName,
|
|
67
|
+
empty,
|
|
68
|
+
templateFileName: templateAbsolutePath,
|
|
60
69
|
});
|
|
61
|
-
const
|
|
62
|
-
|
|
70
|
+
const dir = dirFlag || renderedDir;
|
|
71
|
+
if (!dir) {
|
|
72
|
+
throw new Error(`The template for "${type}" does not provide a dir`);
|
|
73
|
+
}
|
|
74
|
+
if (!fileName) {
|
|
75
|
+
throw new Error(`The template for "${type}" does not provide a fileName`);
|
|
76
|
+
}
|
|
77
|
+
const absoluteModuleDir = path.join(cwd, dir);
|
|
78
|
+
const absoluteModulePath = path.join(absoluteModuleDir, fileName);
|
|
63
79
|
const prettiedCode = await prettify(code, absoluteModulePath);
|
|
64
80
|
if (!dryRun) {
|
|
65
|
-
if (await getFileSystemEntryType(absoluteModulePath)) {
|
|
81
|
+
if (!overwrite && (await getFileSystemEntryType(absoluteModulePath))) {
|
|
66
82
|
log.warn(`File ${chalkHighlightThing(absoluteModulePath)} already exists, skipping this "${type}"`);
|
|
67
83
|
}
|
|
68
84
|
else {
|
|
69
|
-
await fs.mkdir(
|
|
85
|
+
await fs.mkdir(absoluteModuleDir, { recursive: true });
|
|
70
86
|
await fs.writeFile(absoluteModulePath, prettiedCode);
|
|
87
|
+
log.info(`Created ${chalkHighlightThing(fileName)} using ${chalkHighlightThing(`"${type}"`)} template for ${formatLoggedSegmentName(segmentName)}`);
|
|
71
88
|
}
|
|
72
89
|
}
|
|
73
|
-
if (type === 'controller'
|
|
90
|
+
if (type === 'controller') {
|
|
91
|
+
if (!sourceName) {
|
|
92
|
+
throw new Error(`The template for "${type}" does not provide a sourceName`);
|
|
93
|
+
}
|
|
94
|
+
if (!compiledName) {
|
|
95
|
+
throw new Error(`The template for "${type}" does not provide a compiledName`);
|
|
96
|
+
}
|
|
74
97
|
const { routeFilePath } = segment;
|
|
75
98
|
const segmentSourceCode = await fs.readFile(routeFilePath, 'utf-8');
|
|
76
|
-
const importPath = path.relative(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
99
|
+
const importPath = path.relative(path.dirname(routeFilePath), absoluteModulePath).replace(/\.(ts|tsx)$/, '');
|
|
100
|
+
if (!noSegmentUpdate) {
|
|
101
|
+
const newSegmentCode = await prettify(addClassToSegmentCode(segmentSourceCode, {
|
|
102
|
+
sourceName,
|
|
103
|
+
compiledName,
|
|
104
|
+
importPath,
|
|
105
|
+
}), routeFilePath);
|
|
106
|
+
if (!dryRun) {
|
|
107
|
+
await fs.writeFile(routeFilePath, newSegmentCode);
|
|
108
|
+
}
|
|
85
109
|
}
|
|
86
|
-
log.info(`Added ${chalkHighlightThing(sourceName)} ${type}
|
|
110
|
+
log.info(`Added ${chalkHighlightThing(sourceName)} ${type} as ${chalkHighlightThing(compiledName)} to ${formatLoggedSegmentName(segmentName)}`);
|
|
87
111
|
}
|
|
88
|
-
log.info(`Created ${chalkHighlightThing(sourceName)} with ${chalkHighlightThing(type)} template for ${formatLoggedSegmentName(segmentName)}`);
|
|
89
112
|
}
|
|
90
113
|
}
|
package/dist/new/newSegment.mjs
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs/promises';
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
3
|
import getProjectInfo from '../getProjectInfo/index.mjs';
|
|
4
4
|
import getFileSystemEntryType from '../utils/getFileSystemEntryType.mjs';
|
|
5
5
|
import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
|
|
6
6
|
import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
7
7
|
import prettify from '../utils/prettify.mjs';
|
|
8
|
-
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
export default async function newSegment({ segmentName, overwrite, dryRun, }) {
|
|
9
10
|
const { apiDir, cwd, log } = await getProjectInfo();
|
|
10
11
|
const absoluteSegmentRoutePath = path.join(cwd, apiDir, segmentName, '[[...vovk]]/route.ts');
|
|
11
|
-
if (await getFileSystemEntryType(absoluteSegmentRoutePath)) {
|
|
12
|
+
if (!overwrite && (await getFileSystemEntryType(absoluteSegmentRoutePath))) {
|
|
12
13
|
throw new Error(`Unable to create new segment. ${formatLoggedSegmentName(segmentName, { upperFirst: true })} already exists.`);
|
|
13
14
|
}
|
|
14
15
|
const code = await prettify(`import { initVovk } from 'vovk';
|
|
15
16
|
|
|
17
|
+
export const runtime = 'edge';
|
|
18
|
+
|
|
16
19
|
const controllers = {};
|
|
17
|
-
const workers = {};
|
|
18
20
|
|
|
19
21
|
export type Controllers = typeof controllers;
|
|
20
|
-
export type Workers = typeof workers;
|
|
21
22
|
|
|
22
23
|
export const { GET, POST, PATCH, PUT, HEAD, OPTIONS, DELETE } = initVovk({
|
|
23
24
|
${segmentName ? ` segmentName: '${segmentName}',\n` : ''} emitSchema: true,
|
|
24
|
-
workers,
|
|
25
25
|
controllers,
|
|
26
26
|
});
|
|
27
27
|
`, absoluteSegmentRoutePath);
|
|
@@ -29,5 +29,7 @@ ${segmentName ? ` segmentName: '${segmentName}',\n` : ''} emitSchema: true,
|
|
|
29
29
|
await fs.mkdir(path.dirname(absoluteSegmentRoutePath), { recursive: true });
|
|
30
30
|
await fs.writeFile(absoluteSegmentRoutePath, code);
|
|
31
31
|
}
|
|
32
|
-
log.info(`${formatLoggedSegmentName(segmentName, { upperFirst: true })} created at ${absoluteSegmentRoutePath}
|
|
32
|
+
log.info(`${formatLoggedSegmentName(segmentName, { upperFirst: true })} created at ${absoluteSegmentRoutePath}.`);
|
|
33
|
+
const dir = chalk.cyanBright([segmentName, 'thing'].filter(Boolean).join('/'));
|
|
34
|
+
log.info(`Run ${chalkHighlightThing(`npx vovk new service controller ${dir}`)} to create a new controller with a service at modules/${dir} folder for this segment`);
|
|
33
35
|
}
|
package/dist/new/render.d.mts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type { VovkConfig } from '../types.mjs';
|
|
2
|
-
export default function render(codeTemplate: string, { config, withService, segmentName, moduleName, }: {
|
|
1
|
+
import type { VovkConfig, VovkModuleRenderResult } from '../types.mjs';
|
|
2
|
+
export default function render(codeTemplate: string, { config, withService, segmentName, moduleName, empty, templateFileName, }: {
|
|
3
|
+
cwd: string;
|
|
3
4
|
config: VovkConfig;
|
|
4
5
|
withService: boolean;
|
|
5
6
|
segmentName: string;
|
|
6
7
|
moduleName: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
compiledName: string;
|
|
11
|
-
code: string;
|
|
12
|
-
}>;
|
|
8
|
+
empty?: boolean;
|
|
9
|
+
templateFileName: string;
|
|
10
|
+
}): Promise<VovkModuleRenderResult>;
|
package/dist/new/render.mjs
CHANGED
|
@@ -4,26 +4,53 @@ 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, }) {
|
|
8
|
-
const
|
|
7
|
+
export default async function render(codeTemplate, { config, withService, segmentName, moduleName, empty, templateFileName, }) {
|
|
8
|
+
const getModuleDirName = (givenSegmentName, givenModuleName) => [config.modulesDir, givenSegmentName || config.rootSegmentModulesDirName, _.camelCase(givenModuleName)]
|
|
9
9
|
.filter(Boolean)
|
|
10
10
|
.join('/');
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/*
|
|
12
|
+
<% var modulePascalName = _.upperFirst(_.camelCase(moduleName)); %>
|
|
13
|
+
<% var modulePascalNamePlural = pluralize(modulePascalName); %>
|
|
14
|
+
<% var controllerName = modulePascalName + 'Controller'; %>
|
|
15
|
+
<% var compiledName = modulePascalName + 'RPC'; %>
|
|
16
|
+
<% var serviceName = modulePascalName + 'Service'; %>
|
|
17
|
+
<% var prefix = pluralize(_.kebabCase(moduleName).toLowerCase()); %>
|
|
18
|
+
*/
|
|
19
|
+
const theThing = _.camelCase(moduleName);
|
|
20
|
+
const TheThing = _.upperFirst(theThing);
|
|
21
|
+
const the_thing = _.snakeCase(moduleName);
|
|
22
|
+
const THE_THING = _.toUpper(the_thing);
|
|
23
|
+
const the__thing = _.kebabCase(moduleName);
|
|
24
|
+
const t = {
|
|
25
|
+
// module name variations
|
|
26
|
+
moduleName,
|
|
27
|
+
theThing,
|
|
28
|
+
theThings: pluralize(theThing),
|
|
29
|
+
TheThing,
|
|
30
|
+
TheThings: pluralize(TheThing),
|
|
31
|
+
the_thing,
|
|
32
|
+
the_things: pluralize(the_thing),
|
|
33
|
+
THE_THING,
|
|
34
|
+
THE_THINGS: pluralize(THE_THING),
|
|
35
|
+
'the-thing': the__thing,
|
|
36
|
+
'the-things': pluralize(the__thing),
|
|
37
|
+
// data
|
|
13
38
|
config,
|
|
14
39
|
withService,
|
|
15
40
|
segmentName,
|
|
16
|
-
|
|
17
|
-
// utils
|
|
18
|
-
getModulePath,
|
|
41
|
+
defaultDir: getModuleDirName(segmentName, theThing),
|
|
19
42
|
// libraries
|
|
20
43
|
_, // lodash
|
|
21
44
|
pluralize,
|
|
22
45
|
};
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
46
|
+
const parsed = matter((await ejs.render(codeTemplate, { t }, { async: true, filename: templateFileName })).trim());
|
|
47
|
+
const { dir, fileName, sourceName, compiledName } = parsed.data;
|
|
48
|
+
const code = empty ? (sourceName ? `export default class ${sourceName} {}` : '') : parsed.content;
|
|
49
|
+
return {
|
|
50
|
+
dir,
|
|
51
|
+
fileName,
|
|
52
|
+
sourceName,
|
|
53
|
+
compiledName,
|
|
54
|
+
code,
|
|
55
|
+
};
|
|
29
56
|
}
|
package/dist/postinstall.mjs
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
* Checks if a file exists at the given path.
|
|
5
|
-
* @param {string} filePath - The path to the file.
|
|
6
|
-
* @returns {Promise<boolean>} - A promise that resolves to true if the file exists, false otherwise.
|
|
7
|
-
*/
|
|
8
|
-
const getFileSystemEntryType = async (filePath) => !!(await fs.stat(filePath).catch(() => false));
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import getFileSystemEntryType from './utils/getFileSystemEntryType.mjs';
|
|
9
4
|
async function postinstall() {
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
5
|
+
// TODO: The function doesn't consider client templates, how to do that?
|
|
6
|
+
const vovk = path.join(import.meta.dirname, '../../.vovk-client');
|
|
7
|
+
const js = path.join(vovk, 'compiled.js');
|
|
8
|
+
const ts = path.join(vovk, 'compiled.d.ts');
|
|
13
9
|
const index = path.join(vovk, 'index.ts');
|
|
14
|
-
if ((await getFileSystemEntryType(js)) || (await getFileSystemEntryType(ts)) || (await getFileSystemEntryType(index))) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
10
|
await fs.mkdir(vovk, { recursive: true });
|
|
18
|
-
await
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
if (!(await getFileSystemEntryType(js))) {
|
|
12
|
+
await fs.writeFile(js, '/* postinstall */');
|
|
13
|
+
}
|
|
14
|
+
if (!(await getFileSystemEntryType(ts))) {
|
|
15
|
+
await fs.writeFile(ts, '/* postinstall */');
|
|
16
|
+
}
|
|
17
|
+
if (!(await getFileSystemEntryType(index))) {
|
|
18
|
+
await fs.writeFile(index, '/* postinstall */');
|
|
19
|
+
}
|
|
21
20
|
}
|
|
22
21
|
void postinstall();
|
package/dist/types.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { LogLevelNames } from 'loglevel';
|
|
1
|
+
import type { LogLevelNames } from 'loglevel';
|
|
2
2
|
export type KnownAny = any;
|
|
3
3
|
export type VovkEnv = {
|
|
4
4
|
PORT?: string;
|
|
5
5
|
VOVK_CLIENT_OUT_DIR?: string;
|
|
6
6
|
VOVK_SCHEMA_OUT_DIR?: string;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
VOVK_FETCHER_PATH?: string;
|
|
8
|
+
VOVK_VALIDATE_ON_CLIENT_PATH?: string;
|
|
9
|
+
VOVK_CREATE_RPC_PATH?: string;
|
|
9
10
|
VOVK_MODULES_DIR?: string;
|
|
10
|
-
VOVK_VALIDATION_LIBRARY?: string;
|
|
11
11
|
VOVK_ORIGIN?: string;
|
|
12
12
|
VOVK_ROOT_ENTRY?: string;
|
|
13
13
|
VOVK_API_ENTRY_POINT?: string;
|
|
@@ -16,24 +16,79 @@ export type VovkEnv = {
|
|
|
16
16
|
VOVK_PRETTIFY_CLIENT?: string;
|
|
17
17
|
VOVK_DEV_HTTPS?: string;
|
|
18
18
|
__VOVK_START_WATCHER_IN_STANDALONE_MODE__?: 'true';
|
|
19
|
+
__VOVK_EXIT__?: 'true' | 'false';
|
|
19
20
|
};
|
|
21
|
+
type GenerateFrom = (string | {
|
|
22
|
+
templatePath: string;
|
|
23
|
+
outDir?: string;
|
|
24
|
+
templateName?: string;
|
|
25
|
+
fullSchema?: string | boolean;
|
|
26
|
+
})[];
|
|
20
27
|
export type VovkConfig = {
|
|
21
28
|
clientOutDir?: string;
|
|
22
29
|
schemaOutDir?: string;
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
fetcherImport?: string | string[];
|
|
31
|
+
validateOnClientImport?: string | string[] | null;
|
|
32
|
+
createRPCImport?: string | string[];
|
|
25
33
|
modulesDir?: string;
|
|
26
|
-
validationLibrary?: string | null;
|
|
27
34
|
rootEntry?: string;
|
|
28
35
|
origin?: string;
|
|
29
36
|
rootSegmentModulesDirName?: string;
|
|
30
37
|
logLevel?: LogLevelNames;
|
|
31
38
|
prettifyClient?: boolean;
|
|
32
39
|
devHttps?: boolean;
|
|
40
|
+
generateFrom?: GenerateFrom | ((value: GenerateFrom) => GenerateFrom);
|
|
33
41
|
templates?: {
|
|
34
42
|
service?: string;
|
|
35
43
|
controller?: string;
|
|
36
|
-
worker?: string;
|
|
37
44
|
[key: string]: string | undefined;
|
|
38
45
|
};
|
|
39
46
|
};
|
|
47
|
+
export type VovkStrictConfig = Required<Omit<VovkConfig, 'validateOnClientImport' | 'fetcherImport' | 'createRPCImport' | 'generateFrom'>> & {
|
|
48
|
+
validateOnClientImport: string[] | null;
|
|
49
|
+
fetcherImport: string[];
|
|
50
|
+
createRPCImport: string[];
|
|
51
|
+
generateFrom: GenerateFrom;
|
|
52
|
+
};
|
|
53
|
+
export type VovkModuleRenderResult = {
|
|
54
|
+
fileName: string;
|
|
55
|
+
dir: string;
|
|
56
|
+
sourceName?: string;
|
|
57
|
+
compiledName?: string;
|
|
58
|
+
code: string;
|
|
59
|
+
};
|
|
60
|
+
export interface DevOptions {
|
|
61
|
+
nextDev?: boolean;
|
|
62
|
+
exit?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface GenerateOptions {
|
|
65
|
+
clientOutDir?: string;
|
|
66
|
+
templates?: string[];
|
|
67
|
+
prettify?: boolean;
|
|
68
|
+
fullSchema?: string | boolean;
|
|
69
|
+
}
|
|
70
|
+
export interface InitOptions {
|
|
71
|
+
yes?: boolean;
|
|
72
|
+
logLevel: LogLevelNames;
|
|
73
|
+
useNpm?: boolean;
|
|
74
|
+
useYarn?: boolean;
|
|
75
|
+
usePnpm?: boolean;
|
|
76
|
+
useBun?: boolean;
|
|
77
|
+
skipInstall?: boolean;
|
|
78
|
+
updateTsConfig?: boolean;
|
|
79
|
+
updateScripts?: 'implicit' | 'explicit';
|
|
80
|
+
validationLibrary?: string | null;
|
|
81
|
+
reactQuery?: boolean;
|
|
82
|
+
validateOnClient?: boolean;
|
|
83
|
+
dryRun?: boolean;
|
|
84
|
+
channel?: 'latest' | 'beta' | 'draft';
|
|
85
|
+
}
|
|
86
|
+
export interface NewOptions {
|
|
87
|
+
dryRun?: boolean;
|
|
88
|
+
templates?: string[];
|
|
89
|
+
dir?: string;
|
|
90
|
+
overwrite?: boolean;
|
|
91
|
+
noSegmentUpdate?: boolean;
|
|
92
|
+
empty?: boolean;
|
|
93
|
+
}
|
|
94
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { KnownAny } from '../types.mjs';
|
|
2
|
-
export default function debounceWithArgs<
|
|
2
|
+
export default function debounceWithArgs<Callback extends (...args: KnownAny[]) => KnownAny>(callback: Callback, wait: number): (...args: Parameters<Callback>) => Promise<Awaited<ReturnType<Callback>>>;
|
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
1
|
+
export default function debounceWithArgs(callback, wait) {
|
|
2
|
+
// Stores timeouts keyed by the stringified arguments
|
|
3
|
+
const timeouts = new Map();
|
|
4
4
|
return (...args) => {
|
|
5
|
+
// Convert arguments to a JSON string (or any other stable key generation)
|
|
5
6
|
const key = JSON.stringify(args);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const debouncedFn = debouncedFunctions.get(key);
|
|
10
|
-
if (debouncedFn) {
|
|
11
|
-
debouncedFn(...args);
|
|
7
|
+
// Clear any existing timer for this specific key
|
|
8
|
+
if (timeouts.has(key)) {
|
|
9
|
+
clearTimeout(timeouts.get(key));
|
|
12
10
|
}
|
|
11
|
+
// Return a promise that resolves/rejects after the debounce delay
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const timeoutId = setTimeout(async () => {
|
|
14
|
+
try {
|
|
15
|
+
const result = await callback(...args);
|
|
16
|
+
resolve(result);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
reject(error);
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
// Remove the entry once the callback is invoked
|
|
23
|
+
timeouts.delete(key);
|
|
24
|
+
}
|
|
25
|
+
}, wait);
|
|
26
|
+
timeouts.set(key, timeoutId);
|
|
27
|
+
});
|
|
13
28
|
};
|
|
14
29
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import chalkHighlightThing from './chalkHighlightThing.mjs';
|
|
2
1
|
import upperFirstLodash from 'lodash/upperFirst.js';
|
|
2
|
+
import chalkHighlightThing from './chalkHighlightThing.mjs';
|
|
3
3
|
export default function formatLoggedSegmentName(segmentName, { withChalk = true, upperFirst = false } = {}) {
|
|
4
4
|
let text = segmentName ? `segment "${segmentName}"` : 'the root segment';
|
|
5
5
|
text = upperFirst ? upperFirstLodash(text) : text;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import net from 'net';
|
|
1
|
+
import net from 'node:net';
|
|
2
|
+
// Created with AI
|
|
2
3
|
/**
|
|
3
4
|
* Checks if a port is available.
|
|
4
5
|
* @param {number} port - The port to check.
|
|
@@ -34,7 +35,7 @@ function getAvailablePort(startPort, maxAttempts, attempt, onWarning) {
|
|
|
34
35
|
getAvailablePort(startPort + 1, maxAttempts, attempt + 1, onWarning).then(resolve, reject);
|
|
35
36
|
}
|
|
36
37
|
else {
|
|
37
|
-
reject('No available ports found');
|
|
38
|
+
reject(new Error('No available ports found'));
|
|
38
39
|
}
|
|
39
40
|
});
|
|
40
41
|
});
|
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.100",
|
|
4
4
|
"bin": {
|
|
5
5
|
"vovk": "./dist/index.mjs"
|
|
6
6
|
},
|
|
@@ -10,10 +10,13 @@
|
|
|
10
10
|
"prefix": ".",
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "rm -rf dist tsconfig.build.tsbuildinfo && tsc -P tsconfig.build.json",
|
|
13
|
+
"postbuild": "chmod +x ./dist/index.mjs",
|
|
13
14
|
"build-test": "rm -rf test_dist && tsc -P tsconfig.test.json",
|
|
14
|
-
"test": "npm run build &&
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"pre-test": "npm run build && npm run build-test",
|
|
16
|
+
"test-only": "npm run pre-test && node --test --test-only test_dist/test/**/*.mjs",
|
|
17
|
+
"test": "npm run pre-test && node --test --test-concurrency=1 test_dist/test/**/*.mjs",
|
|
18
|
+
"tsc": "tsc --noEmit",
|
|
19
|
+
"ncu": "npm-check-updates -u -x commander",
|
|
17
20
|
"npm-publish": "npm publish"
|
|
18
21
|
},
|
|
19
22
|
"repository": {
|
|
@@ -33,27 +36,27 @@
|
|
|
33
36
|
},
|
|
34
37
|
"homepage": "https://vovk.dev",
|
|
35
38
|
"peerDependencies": {
|
|
36
|
-
"vovk": "^3.0.0-draft.
|
|
39
|
+
"vovk": "^3.0.0-draft.87"
|
|
37
40
|
},
|
|
38
41
|
"dependencies": {
|
|
39
|
-
"@inquirer/prompts": "^7.
|
|
40
|
-
"@npmcli/package-json": "^6.
|
|
41
|
-
"chalk": "^5.
|
|
42
|
-
"chokidar": "^4.0.
|
|
43
|
-
"commander": "^
|
|
44
|
-
"concurrently": "^9.
|
|
45
|
-
"dotenv": "^16.4.
|
|
42
|
+
"@inquirer/prompts": "^7.3.1",
|
|
43
|
+
"@npmcli/package-json": "^6.1.1",
|
|
44
|
+
"chalk": "^5.4.1",
|
|
45
|
+
"chokidar": "^4.0.3",
|
|
46
|
+
"commander": "^13.1.0",
|
|
47
|
+
"concurrently": "^9.1.2",
|
|
48
|
+
"dotenv": "^16.4.7",
|
|
46
49
|
"ejs": "^3.1.10",
|
|
47
50
|
"gray-matter": "^4.0.3",
|
|
48
|
-
"inflection": "^3.0.
|
|
51
|
+
"inflection": "^3.0.2",
|
|
49
52
|
"jsonc-parser": "^3.3.1",
|
|
50
53
|
"lodash": "^4.17.21",
|
|
51
54
|
"loglevel": "^1.9.2",
|
|
52
55
|
"pluralize": "^8.0.0",
|
|
53
|
-
"prettier": "^3.
|
|
56
|
+
"prettier": "^3.4.2",
|
|
54
57
|
"tar-stream": "^3.1.7",
|
|
55
|
-
"ts-morph": "^
|
|
56
|
-
"undici": "^
|
|
58
|
+
"ts-morph": "^25.0.0",
|
|
59
|
+
"undici": "^7.3.0"
|
|
57
60
|
},
|
|
58
61
|
"devDependencies": {
|
|
59
62
|
"@types/concat-stream": "^2.0.3",
|
|
@@ -62,8 +65,8 @@
|
|
|
62
65
|
"@types/pluralize": "^0.0.33",
|
|
63
66
|
"@types/tar-stream": "^3.1.3",
|
|
64
67
|
"concat-stream": "^2.0.0",
|
|
65
|
-
"create-next-app": "^15.
|
|
68
|
+
"create-next-app": "^15.1.6",
|
|
66
69
|
"node-pty": "^1.0.0",
|
|
67
|
-
"type-fest": "^4.
|
|
70
|
+
"type-fest": "^4.33.0"
|
|
68
71
|
}
|
|
69
72
|
}
|
package/templates/controller.ejs
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
<%
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
<% var ServiceName = modulePascalName + 'Service'; %>
|
|
1
|
+
<% const vars = {
|
|
2
|
+
ControllerName: t.TheThing + 'Controller',
|
|
3
|
+
ServiceName: t.TheThing + 'Service',
|
|
4
|
+
}; %>
|
|
6
5
|
---
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
dir: <%= t.defaultDir %>
|
|
7
|
+
fileName: <%= vars.ControllerName + '.ts' %>
|
|
8
|
+
sourceName: <%= vars.ControllerName %>
|
|
9
|
+
compiledName: <%= t.TheThing + 'RPC' %>
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
import { prefix, get, put, post, del
|
|
13
|
-
<% if(withService) { %>
|
|
14
|
-
import <%= ServiceName %> from './<%= ServiceName %>';
|
|
12
|
+
import { prefix, get, put, post, del, type VovkRequest } from 'vovk';
|
|
13
|
+
<% if(t.withService) { %>
|
|
14
|
+
import <%= vars.ServiceName %> from './<%= vars.ServiceName %>';
|
|
15
15
|
<% } %>
|
|
16
16
|
|
|
17
|
-
@prefix('<%=
|
|
18
|
-
export default class <%= ControllerName %> {
|
|
17
|
+
@prefix('<%= t['the-things'] %>')
|
|
18
|
+
export default class <%= vars.ControllerName %> {
|
|
19
19
|
@get()
|
|
20
|
-
static get<%=
|
|
21
|
-
const
|
|
22
|
-
<% if(withService) { %>
|
|
23
|
-
return <%= ServiceName %>.
|
|
20
|
+
static get<%= t.TheThings %> = async (req: VovkRequest<null, { search: string }>) => {
|
|
21
|
+
const search = req.nextUrl.searchParams.get('search');
|
|
22
|
+
<% if(t.withService) { %>
|
|
23
|
+
return <%= vars.ServiceName %>.get<%= t.TheThings %>(search);
|
|
24
24
|
<% } else { %>
|
|
25
|
-
return {
|
|
25
|
+
return { results: [], search };
|
|
26
26
|
<% } %>
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
@put(':id')
|
|
30
|
-
static update<%=
|
|
30
|
+
static update<%= t.TheThing %> = async (req: VovkRequest<{ foo: 'bar' | 'baz' }, { q: string }>, params: { id: string }) => {
|
|
31
31
|
const { id } = params;
|
|
32
32
|
const body = await req.json();
|
|
33
33
|
const q = req.nextUrl.searchParams.get('q');
|
|
34
|
-
<% if(withService) { %>
|
|
35
|
-
return
|
|
34
|
+
<% if(t.withService) { %>
|
|
35
|
+
return <%= vars.ServiceName %>.update<%= t.TheThing %>(id, q, body);
|
|
36
36
|
<% } else { %>
|
|
37
37
|
return { id, body, q };
|
|
38
38
|
<% } %>
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
@post()
|
|
42
|
-
static create<%=
|
|
42
|
+
static create<%= t.TheThing %> = () => {
|
|
43
43
|
// ...
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
@del(':id')
|
|
47
|
-
static delete<%=
|
|
47
|
+
static delete<%= t.TheThing %> = () => {
|
|
48
48
|
// ...
|
|
49
49
|
};
|
|
50
50
|
}
|