vovk-cli 0.0.1-draft.5 → 0.0.1-draft.52
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/compiled/compiled.d.ts.ejs +15 -0
- package/client-templates/compiled/compiled.js.ejs +16 -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/dev/ensureClient.d.mts +5 -0
- package/dist/dev/ensureClient.mjs +30 -0
- package/dist/{watcher → dev}/ensureSchemaFiles.d.mts +3 -0
- package/dist/{watcher → dev}/ensureSchemaFiles.mjs +6 -4
- package/dist/dev/index.d.mts +6 -0
- package/dist/{watcher → dev}/index.mjs +128 -62
- package/dist/{watcher → dev}/isMetadataEmpty.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 +1 -1
- package/dist/{watcher → dev}/writeOneSchemaFile.mjs +3 -3
- package/dist/generate/getClientTemplates.d.mts +11 -0
- package/dist/generate/getClientTemplates.mjs +27 -0
- package/dist/generate/index.d.mts +12 -0
- package/dist/generate/index.mjs +79 -0
- package/dist/getProjectInfo/getConfig.mjs +5 -5
- package/dist/getProjectInfo/getConfigAbsolutePaths.mjs +2 -2
- package/dist/getProjectInfo/getRelativeSrcRoot.mjs +3 -3
- package/dist/getProjectInfo/getUserConfig.mjs +3 -1
- package/dist/getProjectInfo/importUncachedModule.mjs +0 -1
- package/dist/getProjectInfo/importUncachedModuleWorker.mjs +0 -1
- package/dist/getProjectInfo/index.d.mts +2 -1
- package/dist/getProjectInfo/index.mjs +14 -10
- package/dist/index.d.mts +1 -27
- package/dist/index.mjs +47 -60
- package/dist/init/checkTSConfigForExperimentalDecorators.mjs +2 -2
- package/dist/init/createConfig.d.mts +3 -4
- package/dist/init/createConfig.mjs +6 -8
- package/dist/init/getTemplateFilesFromPackage.d.mts +2 -1
- package/dist/init/getTemplateFilesFromPackage.mjs +4 -5
- package/dist/init/index.d.mts +1 -2
- package/dist/init/index.mjs +46 -93
- 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 +21 -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 +4 -4
- package/dist/new/newModule.d.mts +4 -4
- package/dist/new/newModule.mjs +45 -33
- package/dist/new/newSegment.mjs +6 -6
- package/dist/new/render.mjs +2 -5
- package/dist/postinstall.mjs +16 -17
- package/dist/types.d.mts +42 -9
- 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 +19 -16
- package/templates/controller.ejs +12 -11
- package/templates/service.ejs +6 -6
- package/dist/generateClient.d.mts +0 -7
- package/dist/generateClient.mjs +0 -97
- 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/dist/{watcher → dev}/isMetadataEmpty.d.mts +0 -0
|
@@ -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.52",
|
|
4
4
|
"bin": {
|
|
5
5
|
"vovk": "./dist/index.mjs"
|
|
6
6
|
},
|
|
@@ -10,9 +10,12 @@
|
|
|
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
|
-
"
|
|
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",
|
|
16
19
|
"ncu": "npm-check-updates -u",
|
|
17
20
|
"npm-publish": "npm publish"
|
|
18
21
|
},
|
|
@@ -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.57"
|
|
37
40
|
},
|
|
38
41
|
"dependencies": {
|
|
39
|
-
"@inquirer/prompts": "^7.
|
|
40
|
-
"@npmcli/package-json": "^6.
|
|
41
|
-
"chalk": "^5.
|
|
42
|
-
"chokidar": "^4.0.
|
|
42
|
+
"@inquirer/prompts": "^7.3.1",
|
|
43
|
+
"@npmcli/package-json": "^6.1.1",
|
|
44
|
+
"chalk": "^5.4.1",
|
|
45
|
+
"chokidar": "^4.0.3",
|
|
43
46
|
"commander": "^12.1.0",
|
|
44
|
-
"concurrently": "^9.
|
|
45
|
-
"dotenv": "^16.4.
|
|
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
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
<% var controllerName = modulePascalName + 'Controller'; %>
|
|
4
4
|
<% var compiledName = modulePascalName + 'RPC'; %>
|
|
5
5
|
<% var serviceName = modulePascalName + 'Service'; %>
|
|
6
|
+
<% var prefix = pluralize(_.kebabCase(moduleName).toLowerCase()); %>
|
|
6
7
|
---
|
|
7
|
-
|
|
8
|
+
dir: <%= getModuleDirName(segmentName, moduleName) %>
|
|
8
9
|
fileName: <%= controllerName + '.ts' %>
|
|
9
|
-
sourceName: <%= controllerName %>
|
|
10
|
-
compiledName: <%= compiledName %>
|
|
10
|
+
sourceName: <%= controllerName %>
|
|
11
|
+
compiledName: <%= compiledName %>
|
|
11
12
|
---
|
|
12
13
|
|
|
13
14
|
import { prefix, get, put, post, del, type VovkRequest } from 'vovk';
|
|
@@ -15,15 +16,15 @@ import { prefix, get, put, post, del, type VovkRequest } from 'vovk';
|
|
|
15
16
|
import <%= serviceName %> from './<%= serviceName %>';
|
|
16
17
|
<% } %>
|
|
17
18
|
|
|
18
|
-
@prefix('<%=
|
|
19
|
+
@prefix('<%= prefix %>')
|
|
19
20
|
export default class <%= controllerName %> {
|
|
20
21
|
@get()
|
|
21
|
-
static get<%= modulePascalNamePlural %> = async (req: VovkRequest<null, {
|
|
22
|
-
const
|
|
22
|
+
static get<%= modulePascalNamePlural %> = async (req: VovkRequest<null, { search: string }>) => {
|
|
23
|
+
const search = req.nextUrl.searchParams.get('search');
|
|
23
24
|
<% if(withService) { %>
|
|
24
|
-
return <%= serviceName %>.get<%= modulePascalNamePlural %>(
|
|
25
|
+
return <%= serviceName %>.get<%= modulePascalNamePlural %>(search);
|
|
25
26
|
<% } else { %>
|
|
26
|
-
return {
|
|
27
|
+
return { results: [], search };
|
|
27
28
|
<% } %>
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -33,19 +34,19 @@ export default class <%= controllerName %> {
|
|
|
33
34
|
const body = await req.json();
|
|
34
35
|
const q = req.nextUrl.searchParams.get('q');
|
|
35
36
|
<% if(withService) { %>
|
|
36
|
-
return
|
|
37
|
+
return <%= serviceName %>.update<%= modulePascalName %>(id, q, body);
|
|
37
38
|
<% } else { %>
|
|
38
39
|
return { id, body, q };
|
|
39
40
|
<% } %>
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
@post()
|
|
43
|
-
static create<%=
|
|
44
|
+
static create<%= modulePascalName %> = () => {
|
|
44
45
|
// ...
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
@del(':id')
|
|
48
|
-
static delete<%=
|
|
49
|
+
static delete<%= modulePascalName %> = () => {
|
|
49
50
|
// ...
|
|
50
51
|
};
|
|
51
52
|
}
|
package/templates/service.ejs
CHANGED
|
@@ -3,22 +3,22 @@
|
|
|
3
3
|
<% var serviceName = modulePascalName + 'Service'; %>
|
|
4
4
|
<% var controllerName = modulePascalName + 'Controller'; %>
|
|
5
5
|
---
|
|
6
|
-
|
|
6
|
+
dir: <%= getModuleDirName(segmentName, moduleName) %>
|
|
7
7
|
fileName: <%= serviceName + '.ts' %>
|
|
8
8
|
---
|
|
9
9
|
|
|
10
10
|
import type { VovkControllerBody, VovkControllerQuery } from 'vovk';
|
|
11
|
-
import <%= controllerName %> from './<%= controllerName %>';
|
|
11
|
+
import type <%= controllerName %> from './<%= controllerName %>';
|
|
12
12
|
|
|
13
13
|
export default class <%= serviceName %> {
|
|
14
|
-
static get<%= modulePascalNamePlural %> = (
|
|
15
|
-
return [];
|
|
14
|
+
static get<%= modulePascalNamePlural %> = (search: VovkControllerQuery<typeof <%= controllerName %>.get<%= modulePascalNamePlural %>>['search']) => {
|
|
15
|
+
return { results: [], search };
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
static update<%= modulePascalName %> = (
|
|
19
19
|
id: string,
|
|
20
|
-
q: VovkControllerQuery<typeof <%= controllerName %>.
|
|
21
|
-
body: VovkControllerBody<typeof <%= controllerName %>.
|
|
20
|
+
q: VovkControllerQuery<typeof <%= controllerName %>.update<%= modulePascalName %>>['q'],
|
|
21
|
+
body: VovkControllerBody<typeof <%= controllerName %>.update<%= modulePascalName %>>
|
|
22
22
|
) => {
|
|
23
23
|
return { id, q, body };
|
|
24
24
|
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { ProjectInfo } from './getProjectInfo/index.mjs';
|
|
2
|
-
import type { Segment } from './locateSegments.mjs';
|
|
3
|
-
import type { VovkSchema } from 'vovk';
|
|
4
|
-
export default function generateClient(projectInfo: ProjectInfo, segments: Segment[], segmentsSchema: Record<string, VovkSchema>): Promise<{
|
|
5
|
-
written: boolean;
|
|
6
|
-
path: string;
|
|
7
|
-
}>;
|
package/dist/generateClient.mjs
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs/promises';
|
|
3
|
-
import formatLoggedSegmentName from './utils/formatLoggedSegmentName.mjs';
|
|
4
|
-
import prettify from './utils/prettify.mjs';
|
|
5
|
-
export default async function generateClient(projectInfo, segments, segmentsSchema) {
|
|
6
|
-
const { config, cwd, log, validateOnClientImportPath, apiEntryPoint, fetcherClientImportPath, schemaOutImportPath } = projectInfo;
|
|
7
|
-
const now = Date.now();
|
|
8
|
-
const clientoOutDirAbsolutePath = path.join(cwd, config.clientOutDir);
|
|
9
|
-
let dts = `// auto-generated
|
|
10
|
-
/* eslint-disable */
|
|
11
|
-
import type { clientizeController } from 'vovk/client';
|
|
12
|
-
import type { promisifyWorker } from 'vovk/worker';
|
|
13
|
-
import type { VovkClientFetcher } from 'vovk/client';
|
|
14
|
-
import type fetcher from '${fetcherClientImportPath}';
|
|
15
|
-
|
|
16
|
-
`;
|
|
17
|
-
let js = `// auto-generated
|
|
18
|
-
/* eslint-disable */
|
|
19
|
-
const { clientizeController } = require('vovk/client');
|
|
20
|
-
const { promisifyWorker } = require('vovk/worker');
|
|
21
|
-
const { default: fetcher } = require('${fetcherClientImportPath}');
|
|
22
|
-
const schema = require('${schemaOutImportPath}');
|
|
23
|
-
`;
|
|
24
|
-
let ts = `// auto-generated
|
|
25
|
-
/* eslint-disable */
|
|
26
|
-
import { clientizeController } from 'vovk/client';
|
|
27
|
-
import { promisifyWorker } from 'vovk/worker';
|
|
28
|
-
import type { VovkClientFetcher } from 'vovk/client';
|
|
29
|
-
import fetcher from '${fetcherClientImportPath}';
|
|
30
|
-
import schema from '${schemaOutImportPath}';
|
|
31
|
-
|
|
32
|
-
`;
|
|
33
|
-
for (let i = 0; i < segments.length; i++) {
|
|
34
|
-
const { routeFilePath, segmentName } = segments[i];
|
|
35
|
-
const schema = segmentsSchema[segmentName];
|
|
36
|
-
if (!schema) {
|
|
37
|
-
throw new Error(`Unable to generate client. No schema found for ${formatLoggedSegmentName(segmentName)}`);
|
|
38
|
-
}
|
|
39
|
-
if (!schema.emitSchema)
|
|
40
|
-
continue;
|
|
41
|
-
const importRouteFilePath = path.relative(config.clientOutDir, routeFilePath);
|
|
42
|
-
dts += `import type { Controllers as Controllers${i}, Workers as Workers${i} } from "${importRouteFilePath}";\n`;
|
|
43
|
-
ts += `import type { Controllers as Controllers${i}, Workers as Workers${i} } from "${importRouteFilePath}";\n`;
|
|
44
|
-
}
|
|
45
|
-
dts += `
|
|
46
|
-
type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
|
|
47
|
-
`;
|
|
48
|
-
ts += `
|
|
49
|
-
${validateOnClientImportPath ? `import validateOnClient from '${validateOnClientImportPath}';\n` : '\nconst validateOnClient = undefined;'}
|
|
50
|
-
type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
|
|
51
|
-
const prefix = '${apiEntryPoint}';
|
|
52
|
-
`;
|
|
53
|
-
js += `
|
|
54
|
-
const { default: validateOnClient = null } = ${validateOnClientImportPath ? `require('${validateOnClientImportPath}')` : '{}'};
|
|
55
|
-
const prefix = '${apiEntryPoint}';
|
|
56
|
-
`;
|
|
57
|
-
for (let i = 0; i < segments.length; i++) {
|
|
58
|
-
const { segmentName } = segments[i];
|
|
59
|
-
const schema = segmentsSchema[segmentName];
|
|
60
|
-
if (!schema) {
|
|
61
|
-
throw new Error(`Unable to generate client. No schema found for ${formatLoggedSegmentName(segmentName)}`);
|
|
62
|
-
}
|
|
63
|
-
if (!schema.emitSchema)
|
|
64
|
-
continue;
|
|
65
|
-
for (const key of Object.keys(schema.controllers)) {
|
|
66
|
-
dts += `export const ${key}: ReturnType<typeof clientizeController<Controllers${i}["${key}"], Options>>;\n`;
|
|
67
|
-
js += `exports.${key} = clientizeController(schema['${segmentName}'].controllers.${key}, '${segmentName}', { fetcher, validateOnClient, defaultOptions: { prefix } });\n`;
|
|
68
|
-
ts += `export const ${key} = clientizeController<Controllers${i}["${key}"], Options>(schema['${segmentName}'].controllers.${key}, '${segmentName}', { fetcher, validateOnClient, defaultOptions: { prefix } });\n`;
|
|
69
|
-
}
|
|
70
|
-
for (const key of Object.keys(schema.workers)) {
|
|
71
|
-
dts += `export const ${key}: ReturnType<typeof promisifyWorker<Workers${i}["${key}"]>>;\n`;
|
|
72
|
-
js += `exports.${key} = promisifyWorker(null, schema['${segmentName}'].workers.${key});\n`;
|
|
73
|
-
ts += `export const ${key} = promisifyWorker<Workers${i}["${key}"]>(null, schema['${segmentName}'].workers.${key});\n`;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const localJsAbsolutePath = path.join(clientoOutDirAbsolutePath, 'client.js');
|
|
77
|
-
const localDtsAbsolutePath = path.join(clientoOutDirAbsolutePath, 'client.d.ts');
|
|
78
|
-
const localTsAbsolutePath = path.join(clientoOutDirAbsolutePath, 'index.ts');
|
|
79
|
-
const existingJs = await fs.readFile(localJsAbsolutePath, 'utf-8').catch(() => '');
|
|
80
|
-
const existingDts = await fs.readFile(localDtsAbsolutePath, 'utf-8').catch(() => '');
|
|
81
|
-
const existingTs = await fs.readFile(localTsAbsolutePath, 'utf-8').catch(() => '');
|
|
82
|
-
if (config.prettifyClient) {
|
|
83
|
-
js = await prettify(js, localJsAbsolutePath);
|
|
84
|
-
dts = await prettify(dts, localDtsAbsolutePath);
|
|
85
|
-
ts = await prettify(ts, localTsAbsolutePath);
|
|
86
|
-
}
|
|
87
|
-
if (existingJs === js && existingDts === dts && existingTs === ts) {
|
|
88
|
-
log.debug(`Client is up to date and doesn't need to be regenerated (${Date.now() - now}ms)`);
|
|
89
|
-
return { written: false, path: clientoOutDirAbsolutePath };
|
|
90
|
-
}
|
|
91
|
-
await fs.mkdir(clientoOutDirAbsolutePath, { recursive: true });
|
|
92
|
-
await fs.writeFile(localJsAbsolutePath, js);
|
|
93
|
-
await fs.writeFile(localDtsAbsolutePath, dts);
|
|
94
|
-
await fs.writeFile(localTsAbsolutePath, ts);
|
|
95
|
-
log.info(`Client generated in ${Date.now() - now}ms`);
|
|
96
|
-
return { written: true, path: clientoOutDirAbsolutePath };
|
|
97
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { VovkSchema } from 'vovk';
|
|
2
|
-
import { _VovkControllerSchema, _VovkWorkerSchema } from 'vovk/types';
|
|
3
|
-
interface HandlersDiff {
|
|
4
|
-
nameOfClass: string;
|
|
5
|
-
added: string[];
|
|
6
|
-
removed: string[];
|
|
7
|
-
changed: string[];
|
|
8
|
-
}
|
|
9
|
-
interface WorkersOrControllersDiff {
|
|
10
|
-
added: string[];
|
|
11
|
-
removed: string[];
|
|
12
|
-
handlers: HandlersDiff[];
|
|
13
|
-
}
|
|
14
|
-
export interface DiffResult {
|
|
15
|
-
workers: WorkersOrControllersDiff;
|
|
16
|
-
controllers: WorkersOrControllersDiff;
|
|
17
|
-
}
|
|
18
|
-
export declare function diffHandlers<T extends _VovkWorkerSchema['_handlers'] | _VovkControllerSchema['_handlers']>(oldHandlers: T, newHandlers: T, nameOfClass: string): HandlersDiff;
|
|
19
|
-
export declare function diffWorkersOrControllers<T extends VovkSchema['controllers'] | VovkSchema['workers']>(oldItems: T, newItems: T): WorkersOrControllersDiff;
|
|
20
|
-
/**
|
|
21
|
-
example output:
|
|
22
|
-
{
|
|
23
|
-
workers: {
|
|
24
|
-
added: ["WorkerC"],
|
|
25
|
-
removed: ["WorkerA"],
|
|
26
|
-
handlers: []
|
|
27
|
-
},
|
|
28
|
-
controllers: {
|
|
29
|
-
added: ["ControllerC"],
|
|
30
|
-
removed: ["ControllerB"],
|
|
31
|
-
handlers: [
|
|
32
|
-
{
|
|
33
|
-
nameOfClass: "ControllerA",
|
|
34
|
-
added: ["handlerF"],
|
|
35
|
-
removed: [],
|
|
36
|
-
changed: ["handlerD"]
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
*/
|
|
42
|
-
export default function diffSchema(oldJson: VovkSchema, newJson: VovkSchema): DiffResult;
|
|
43
|
-
export {};
|
package/dist/watcher/index.d.mts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
2
|
-
import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
|
|
3
|
-
export default function logDiffResult(segmentName, diffResult, projectInfo) {
|
|
4
|
-
const diffNormalized = [];
|
|
5
|
-
diffResult.workers.added.forEach((name) => {
|
|
6
|
-
diffNormalized.push({ what: 'worker', type: 'added', name });
|
|
7
|
-
});
|
|
8
|
-
diffResult.workers.removed.forEach((name) => {
|
|
9
|
-
diffNormalized.push({ what: 'worker', type: 'removed', name });
|
|
10
|
-
});
|
|
11
|
-
diffResult.workers.handlers.forEach((handler) => {
|
|
12
|
-
handler.added.forEach((name) => {
|
|
13
|
-
diffNormalized.push({ what: 'workerHandler', type: 'added', name: `${handler.nameOfClass}.${name}` });
|
|
14
|
-
});
|
|
15
|
-
handler.removed.forEach((name) => {
|
|
16
|
-
diffNormalized.push({ what: 'workerHandler', type: 'removed', name: `${handler.nameOfClass}.${name}` });
|
|
17
|
-
});
|
|
18
|
-
handler.changed.forEach((name) => {
|
|
19
|
-
diffNormalized.push({ what: 'workerHandler', type: 'changed', name: `${handler.nameOfClass}.${name}` });
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
diffResult.controllers.added.forEach((name) => {
|
|
23
|
-
diffNormalized.push({ what: 'controller', type: 'added', name });
|
|
24
|
-
});
|
|
25
|
-
diffResult.controllers.removed.forEach((name) => {
|
|
26
|
-
diffNormalized.push({ what: 'controller', type: 'removed', name });
|
|
27
|
-
});
|
|
28
|
-
diffResult.controllers.handlers.forEach((handler) => {
|
|
29
|
-
handler.added.forEach((name) => {
|
|
30
|
-
diffNormalized.push({ what: 'controllerHandler', type: 'added', name: `${handler.nameOfClass}.${name}` });
|
|
31
|
-
});
|
|
32
|
-
handler.removed.forEach((name) => {
|
|
33
|
-
diffNormalized.push({ what: 'controllerHandler', type: 'removed', name: `${handler.nameOfClass}.${name}` });
|
|
34
|
-
});
|
|
35
|
-
handler.changed.forEach((name) => {
|
|
36
|
-
diffNormalized.push({ what: 'controllerHandler', type: 'changed', name: `${handler.nameOfClass}.${name}` });
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
const LIMIT = diffNormalized.length < 12 ? diffNormalized.length : 10;
|
|
40
|
-
for (const diffNormalizedItem of diffNormalized.slice(0, LIMIT)) {
|
|
41
|
-
switch (diffNormalizedItem.what) {
|
|
42
|
-
case 'worker':
|
|
43
|
-
switch (diffNormalizedItem.type) {
|
|
44
|
-
case 'added':
|
|
45
|
-
projectInfo.log.info(`Schema for worker ${chalkHighlightThing(diffNormalizedItem.name)} has been added at ${formatLoggedSegmentName(segmentName)}`);
|
|
46
|
-
break;
|
|
47
|
-
case 'removed':
|
|
48
|
-
projectInfo.log.info(`Schema for worker ${chalkHighlightThing(diffNormalizedItem.name)} has been removed from ${formatLoggedSegmentName(segmentName)}`);
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
break;
|
|
52
|
-
case 'controller':
|
|
53
|
-
switch (diffNormalizedItem.type) {
|
|
54
|
-
case 'added':
|
|
55
|
-
projectInfo.log.info(`Schema for controller ${chalkHighlightThing(diffNormalizedItem.name)} has been added at ${formatLoggedSegmentName(segmentName)}`);
|
|
56
|
-
break;
|
|
57
|
-
case 'removed':
|
|
58
|
-
projectInfo.log.info(`Schema for controller ${chalkHighlightThing(diffNormalizedItem.name)} has been removed from ${formatLoggedSegmentName(segmentName)}`);
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
case 'workerHandler':
|
|
63
|
-
switch (diffNormalizedItem.type) {
|
|
64
|
-
case 'added':
|
|
65
|
-
projectInfo.log.info(`Schema for worker method ${chalkHighlightThing(diffNormalizedItem.name)} has been added at ${formatLoggedSegmentName(segmentName)}`);
|
|
66
|
-
break;
|
|
67
|
-
case 'removed':
|
|
68
|
-
projectInfo.log.info(`Schema for worker method ${chalkHighlightThing(diffNormalizedItem.name)} has been removed from ${formatLoggedSegmentName(segmentName)}`);
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
case 'controllerHandler':
|
|
73
|
-
switch (diffNormalizedItem.type) {
|
|
74
|
-
case 'added':
|
|
75
|
-
projectInfo.log.info(`Schema for controller method ${chalkHighlightThing(diffNormalizedItem.name)} has been added at ${formatLoggedSegmentName(segmentName)}`);
|
|
76
|
-
break;
|
|
77
|
-
case 'removed':
|
|
78
|
-
projectInfo.log.info(`Schema for controller method ${chalkHighlightThing(diffNormalizedItem.name)} has been removed from ${formatLoggedSegmentName(segmentName)}`);
|
|
79
|
-
break;
|
|
80
|
-
case 'changed':
|
|
81
|
-
projectInfo.log.info(`Schema for controller method ${chalkHighlightThing(diffNormalizedItem.name)} has been changed at ${formatLoggedSegmentName(segmentName)}`);
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (diffNormalized.length > LIMIT) {
|
|
88
|
-
projectInfo.log.info(`... and ${diffNormalized.length - LIMIT} more changes`);
|
|
89
|
-
}
|
|
90
|
-
}
|
package/templates/worker.ejs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// TODO
|
|
File without changes
|