vovk-cli 0.0.1-draft.39 → 0.0.1-draft.392
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 +300 -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 +21 -0
- package/dist/generate/getTemplateClientImports.mjs +56 -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/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://vovk.dev">
|
|
3
|
+
<picture>
|
|
4
|
+
<source width="300" media="(prefers-color-scheme: dark)" srcset="https://vovk.dev/vovk-logo-white.svg">
|
|
5
|
+
<source width="300" media="(prefers-color-scheme: light)" srcset="https://vovk.dev/vovk-logo.svg">
|
|
6
|
+
<img width="300" alt="vovk" src="https://vovk.dev/vovk-logo.svg">
|
|
7
|
+
</picture>
|
|
8
|
+
</a>
|
|
9
|
+
<br>
|
|
10
|
+
<strong>Back-end for <a href="https://nextjs.org/">Next.js</a></strong>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## vovk-cli [](https://www.npmjs.com/package/vovk-cli)
|
|
16
|
+
|
|
17
|
+
The Vovk.ts [CLI](https://vovk.dev/cli) that will be used as a devDependency in a Vovk.ts app.
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install -D vovk-cli
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- [vovk dev](https://vovk.dev/dev) - starts the development script that watches the changes in [controllers](https://vovk.dev/controller) and regenerates the [schema](https://vovk.dev/schema) and [client](https://vovk.dev/typescript).
|
|
24
|
+
- [vovk generate](https://vovk.dev/generate) - generates the client based on the schema.
|
|
25
|
+
- [vovk bundle](https://vovk.dev/bundle) - bundles the client with [tsdown](https://tsdown.dev/).
|
|
26
|
+
- [vovk init](https://vovk.dev/init) - initializes Vovk.ts project.
|
|
27
|
+
- [vovk new](https://vovk.dev/new) - generates a new controller, service or a custom module.
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npx vovk-cli --help
|
|
31
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<%- t.getFirstLineBanner() %>
|
|
2
|
+
const { createRPC } = require('<%= t.commonImports.createRPC %>');
|
|
3
|
+
const { schema } = require('./schema.cjs');
|
|
4
|
+
const { openapi } = require('./openapi.cjs');
|
|
5
|
+
<% Object.entries(t.reExports).forEach(([reExportWhatCommaDivisible, reExportFrom]) => {
|
|
6
|
+
reExportWhatCommaDivisible.split(/\s*,\s*/).forEach((reExportWhat) => { %>
|
|
7
|
+
exports['<%= reExportWhat.split(/\s+as\s+/)[1] ?? reExportWhat %>'] = require('<%= reExportFrom %>')['<%= reExportWhat.split(/\s+as\s+/)[0] %>'];
|
|
8
|
+
<% })
|
|
9
|
+
}) %>
|
|
10
|
+
<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment) => { %>
|
|
11
|
+
<% Object.keys(segment.controllers).forEach((rpcModuleName) => {
|
|
12
|
+
const apiRoot = t.segmentMeta[segment.segmentName].forceApiRoot ?? t.apiRoot; %>
|
|
13
|
+
exports.<%= rpcModuleName %> = createRPC(
|
|
14
|
+
schema, '<%= segment.segmentName %>', '<%= rpcModuleName %>', require('<%= t.segmentImports[segment.segmentName].fetcher %>').fetcher,
|
|
15
|
+
{ validateOnClient: <%- t.segmentImports[segment.segmentName].validateOnClient ? `require('${t.segmentImports[segment.segmentName].validateOnClient}').validateOnClient` : 'undefined' %>, <%- typeof t.segmentMeta[segment.segmentName].segmentNameOverride === 'string' ? `segmentNameOverride: '${t.segmentMeta[segment.segmentName].segmentNameOverride}', ` : '' %><%- segment.segmentType === 'mixin' ? '' : apiRoot ? `apiRoot: '${apiRoot}'` : '' %> }
|
|
16
|
+
);
|
|
17
|
+
<% })
|
|
18
|
+
}) %>
|
|
19
|
+
exports.schema = schema;
|
|
20
|
+
exports.openapi = openapi;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<%- t.getFirstLineBanner() %>
|
|
2
|
+
import type { VovkFetcher } from 'vovk';
|
|
3
|
+
import type { createRPC } from '<%= t.commonImports.module.createRPC %>';
|
|
4
|
+
<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { if(segment.segmentType !== 'mixin') { %>
|
|
5
|
+
import type { Controllers as Controllers<%= i %> } from "<%= t.segmentMeta[segment.segmentName].segmentImportPath %>";
|
|
6
|
+
<% }}) %>
|
|
7
|
+
<% if (t.hasMixins) { %>
|
|
8
|
+
import type { Controllers as MixinControllers, Mixins } from "./mixins";
|
|
9
|
+
<% } %>
|
|
10
|
+
<% Object.entries(t.reExports).forEach(([reExportWhat, reExportFrom]) => { %>
|
|
11
|
+
export { <%= reExportWhat %> } from '<%= reExportFrom %>';
|
|
12
|
+
<% }) %>
|
|
13
|
+
<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { %>
|
|
14
|
+
<% Object.keys(segment.controllers).forEach((rpcModuleName) => { %>
|
|
15
|
+
export const <%= rpcModuleName %>: ReturnType<typeof createRPC<<%= segment.segmentType === 'mixin' ? `MixinControllers` : `Controllers${i}` %>["<%= rpcModuleName %>"], typeof import('<%- t.segmentImports[segment.segmentName].module.fetcher %>').fetcher extends VovkFetcher<infer U> ? U : never>>;
|
|
16
|
+
<% })
|
|
17
|
+
}) %>
|
|
18
|
+
export { schema } from './schema.cjs';
|
|
19
|
+
export { openapi } from './openapi.cjs';
|
|
20
|
+
<% if (t.hasMixins) { %>
|
|
21
|
+
export { Mixins };
|
|
22
|
+
<% } %>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<%- t.getFirstLineBanner() %>
|
|
2
|
+
import type { VovkRequest, VovkStreamAsyncIterable, KnownAny } from 'vovk';
|
|
3
|
+
|
|
4
|
+
<% const mixins = Object.values(t.schema.segments).filter((segment) => segment.emitSchema && segment.segmentType === 'mixin'); %>
|
|
5
|
+
|
|
6
|
+
export namespace Mixins {
|
|
7
|
+
<% for (const segment of mixins) { %>
|
|
8
|
+
<% if(segment.meta?.openAPIObject?.components?.schemas) { %>
|
|
9
|
+
export namespace <%= t._.upperFirst(t._.camelCase(segment.segmentName)) %> {
|
|
10
|
+
<% for (const [componentName, componentSchema] of Object.entries(segment.meta.openAPIObject.components.schemas)) { %>
|
|
11
|
+
<%- t.compileJSONSchemaToTypeScriptType(componentSchema, componentName, segment.meta.openAPIObject.components, { dontCreateRefTypes: true }) %>
|
|
12
|
+
<% } %>
|
|
13
|
+
}
|
|
14
|
+
<% } %>
|
|
15
|
+
<% } %>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export namespace Types {
|
|
19
|
+
<% for (const segment of mixins) { %>
|
|
20
|
+
export namespace <%= t._.upperFirst(t._.camelCase(segment.segmentName)) %> {
|
|
21
|
+
<% for (const [controllerName, controllerSchema] of Object.entries(segment.controllers)) { %>
|
|
22
|
+
export namespace <%= controllerSchema.rpcModuleName %> {
|
|
23
|
+
<% for (const [handlerName, handlerSchema] of Object.entries(controllerSchema.handlers)) { %>
|
|
24
|
+
export namespace <%= t._.upperFirst(handlerName) %> {
|
|
25
|
+
<%- t.compileJSONSchemaToTypeScriptType(handlerSchema.validation?.body, 'Body') %>
|
|
26
|
+
<%- t.compileJSONSchemaToTypeScriptType(handlerSchema.validation?.query, 'Query') %>
|
|
27
|
+
<%- t.compileJSONSchemaToTypeScriptType(handlerSchema.validation?.params, 'Params') %>
|
|
28
|
+
<%- t.compileJSONSchemaToTypeScriptType(handlerSchema.validation?.output, 'Output') %>
|
|
29
|
+
<%- t.compileJSONSchemaToTypeScriptType(handlerSchema.validation?.iteration, 'Iteration') %>
|
|
30
|
+
}
|
|
31
|
+
<% } %>
|
|
32
|
+
}
|
|
33
|
+
<% } %>
|
|
34
|
+
}
|
|
35
|
+
<% } %>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
<% const getType = (segment, controllerSchema, handlerName, validationType) => {
|
|
39
|
+
const segmentNs = t._.upperFirst(t._.camelCase(segment.segmentName));
|
|
40
|
+
const controllerNs = controllerSchema.rpcModuleName;
|
|
41
|
+
const handlerNs = t._.upperFirst(handlerName);
|
|
42
|
+
const typeName = t._.upperFirst(validationType);
|
|
43
|
+
const handlerSchema = controllerSchema.handlers[handlerName];
|
|
44
|
+
if(handlerSchema.validation?.[validationType] ) {
|
|
45
|
+
return 'Types.' + segmentNs + '.' + controllerNs + '.' + handlerNs + '.' + typeName;
|
|
46
|
+
}
|
|
47
|
+
return 'null';
|
|
48
|
+
} %>
|
|
49
|
+
|
|
50
|
+
export type Controllers = {
|
|
51
|
+
<% for (const segment of Object.values(t.schema.segments).filter((segment) => segment.emitSchema && segment.segmentType === 'mixin')) { %>
|
|
52
|
+
<% for (const controllerSchema of Object.values(segment.controllers)) { %>
|
|
53
|
+
<%= controllerSchema.rpcModuleName %>: {
|
|
54
|
+
<% for (const [handlerName, handlerSchema] of Object.entries(controllerSchema.handlers)) { %>
|
|
55
|
+
<%= handlerName %>: (req: VovkRequest<
|
|
56
|
+
<%- getType(segment, controllerSchema, handlerName, 'body') %>,
|
|
57
|
+
<%- getType(segment, controllerSchema, handlerName, 'query') %>,
|
|
58
|
+
<%- getType(segment, controllerSchema, handlerName, 'params') %>
|
|
59
|
+
>) => <%- handlerSchema.validation?.output ? `Promise<${getType(segment, controllerSchema, handlerName, 'output')}>` : handlerSchema.validation?.iteration ? `Promise<VovkStreamAsyncIterable<${getType(segment, controllerSchema, handlerName, 'iteration')}>>` : 'Promise<KnownAny>' %>,
|
|
60
|
+
<% } %>
|
|
61
|
+
};
|
|
62
|
+
<% } %>
|
|
63
|
+
<% } %>
|
|
64
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%- JSON.stringify(t._.pickBy(t.schema.segments, (segment) => segment.segmentType === 'mixin'), null, 2) %>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<%- t.getFirstLineBanner() %>
|
|
2
|
+
import type { VovkFetcher } from 'vovk';
|
|
3
|
+
import type { createRPC } from '<%= t.commonImports.module.createRPC %>';
|
|
4
|
+
<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { if(segment.segmentType !== 'mixin') { %>
|
|
5
|
+
import type { Controllers as Controllers<%= i %> } from "<%= t.segmentMeta[segment.segmentName].segmentImportPath %>";
|
|
6
|
+
<% }}) %>
|
|
7
|
+
<% if (t.hasMixins) { %>
|
|
8
|
+
import type { Controllers as MixinControllers, Mixins } from "./mixins";
|
|
9
|
+
<% } %>
|
|
10
|
+
<% Object.entries(t.reExports).forEach(([reExportWhat, reExportFrom]) => { %>
|
|
11
|
+
export { <%= reExportWhat %> } from '<%= reExportFrom %>';
|
|
12
|
+
<% }) %>
|
|
13
|
+
<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { %>
|
|
14
|
+
<% Object.keys(segment.controllers).forEach((rpcModuleName) => { %>
|
|
15
|
+
export const <%= rpcModuleName %>: ReturnType<typeof createRPC<<%= segment.segmentType === 'mixin' ? `MixinControllers` : `Controllers${i}` %>["<%= rpcModuleName %>"], typeof import('<%- t.segmentImports[segment.segmentName].module.fetcher %>').fetcher extends VovkFetcher<infer U> ? U : never>>;
|
|
16
|
+
<% })
|
|
17
|
+
}) %>
|
|
18
|
+
export { schema } from './schema.cjs';
|
|
19
|
+
export { openapi } from './openapi.cjs';
|
|
20
|
+
<% if (t.hasMixins) { %>
|
|
21
|
+
export { Mixins };
|
|
22
|
+
<% } %>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<%- t.getFirstLineBanner() %>
|
|
2
|
+
import { createRPC } from '<%= t.commonImports.module.createRPC %>';
|
|
3
|
+
import { schema } from './schema.cjs';
|
|
4
|
+
import { openapi } from './openapi.cjs';
|
|
5
|
+
<% Object.entries(t.reExports).forEach(([reExportWhat, reExportFrom]) => { %>
|
|
6
|
+
export { <%= reExportWhat %> } from '<%= reExportFrom %>';
|
|
7
|
+
<% }) %>
|
|
8
|
+
<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { %>
|
|
9
|
+
<% Object.keys(segment.controllers).forEach((rpcModuleName) => {
|
|
10
|
+
const apiRoot = t.segmentMeta[segment.segmentName].forceApiRoot ?? t.apiRoot; %>
|
|
11
|
+
export const <%= rpcModuleName %> = createRPC(
|
|
12
|
+
schema, '<%= segment.segmentName %>', '<%= rpcModuleName %>', import('<%- t.segmentImports[segment.segmentName].module.fetcher %>'),
|
|
13
|
+
{ validateOnClient: <%- t.segmentImports[segment.segmentName].module.validateOnClient ? `import('${t.segmentImports[segment.segmentName].validateOnClient}')` : 'undefined' %>, <%- typeof t.segmentMeta[segment.segmentName].segmentNameOverride === 'string' ? `segmentNameOverride: '${t.segmentMeta[segment.segmentName].segmentNameOverride}', ` : '' %><%- segment.segmentType === 'mixin' ? '' : apiRoot ? `apiRoot: '${apiRoot}'` : '' %> }
|
|
14
|
+
);
|
|
15
|
+
<%
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
%>
|
|
19
|
+
export { schema, openapi };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%- JSON.stringify(t.openapi, null, 2) %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%- JSON.stringify(t.package, null, 2) %>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<%- t.getFirstLineBanner('html') %>
|
|
2
|
+
<%- t.readme.banner %>
|
|
3
|
+
|
|
4
|
+
# <%= t.package.name %> v<%= t.package.version %> [](https://www.typescriptlang.org/) [](https://vovk.dev)
|
|
5
|
+
|
|
6
|
+
<%- t.readme.description ?? (`${t.package.description ? `> ${t.package.description}` : ''}`) %>
|
|
7
|
+
|
|
8
|
+
<%- t.package.license ? `License: **${t.package.license}**` : '' %>
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
# Install the package
|
|
12
|
+
<%= t.readme.installCommand ?? `npm install ${t.package.name}` %>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
<% Object.entries(t.schema.segments).forEach(([segmentName, segment]) => {
|
|
16
|
+
Object.values(segment.controllers).forEach((controllerSchema) => { %>
|
|
17
|
+
|
|
18
|
+
## <%= controllerSchema.rpcModuleName %>
|
|
19
|
+
<% Object.entries(controllerSchema.handlers).forEach(([handlerName, handlerSchema]) => { %>
|
|
20
|
+
### <%= controllerSchema.rpcModuleName %>.<%= handlerName %>
|
|
21
|
+
<%- handlerSchema.operationObject?.summary ? `> ${handlerSchema.operationObject.summary}` : '' %>
|
|
22
|
+
|
|
23
|
+
<%- handlerSchema.operationObject?.description ? `${handlerSchema.operationObject.description}` : '' %>
|
|
24
|
+
|
|
25
|
+
<% const forceApiRoot = t.segmentMeta[segment.segmentName].forceApiRoot ?? controllerSchema.forceApiRoot; %>
|
|
26
|
+
`<%= handlerSchema.httpMethod %> <%= [...(forceApiRoot ? [forceApiRoot] : [t.apiRoot, segmentName]), controllerSchema.prefix, handlerSchema.path].map((part, i) => i > 0 ? t._.trim(part, '/') : part).filter(Boolean).join('/') %>`
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
<%- t.createCodeSamples({
|
|
30
|
+
handlerSchema,
|
|
31
|
+
handlerName,
|
|
32
|
+
controllerSchema,
|
|
33
|
+
package: t.package,
|
|
34
|
+
config: t.samples,
|
|
35
|
+
}).ts %>
|
|
36
|
+
```
|
|
37
|
+
<% }) %>
|
|
38
|
+
<% }) %>
|
|
39
|
+
<% }) %>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<%- t.getFirstLineBanner() %>
|
|
2
|
+
<% if(t.isVovkProject) { %>
|
|
3
|
+
const meta = require('./<%= t.schemaOutDir %>/_meta.json');
|
|
4
|
+
<% } else { %>
|
|
5
|
+
const meta = <%- JSON.stringify(t.publicMeta, null, 2) %>;
|
|
6
|
+
<% } %>
|
|
7
|
+
|
|
8
|
+
<% if(t.hasMixins) { %>
|
|
9
|
+
const mixins = require('./mixins.json');
|
|
10
|
+
<% } %>
|
|
11
|
+
const segments = {<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema && segment.segmentType !== 'mixin').forEach((segment) => { %>
|
|
12
|
+
'<%= segment.segmentName %>': require('./<%= t.schemaOutDir %>/<%= segment.segmentName || t.ROOT_SEGMENT_FILE_NAME %>.json'),
|
|
13
|
+
<% }) %>
|
|
14
|
+
<% if(t.hasMixins) { %>
|
|
15
|
+
...mixins,
|
|
16
|
+
<% } %>
|
|
17
|
+
};
|
|
18
|
+
const schema = {
|
|
19
|
+
$schema: '<%- t.VovkSchemaIdEnum.SCHEMA %>',
|
|
20
|
+
segments,
|
|
21
|
+
meta,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
module.exports.schema = schema;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<%- t.getFirstLineBanner() %>
|
|
2
|
+
import type { VovkMetaSchema, VovkSegmentSchema } from 'vovk';
|
|
3
|
+
|
|
4
|
+
export const schema: {
|
|
5
|
+
$schema: '<%- t.VovkSchemaIdEnum.SCHEMA %>';
|
|
6
|
+
meta: VovkMetaSchema;
|
|
7
|
+
segments: {<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment) => { %>
|
|
8
|
+
'<%= segment.segmentName %>': VovkSegmentSchema;<% }) %>
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%- JSON.stringify(t.schema, null, 2) %>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<%- t.getFirstLineBanner() %>
|
|
2
|
+
<% if(t.hasMixins) { %>
|
|
3
|
+
import mixins from './mixins.json' with { type: "json" };
|
|
4
|
+
import type { Mixins } from './mixins.d.ts';
|
|
5
|
+
<% } %>
|
|
6
|
+
<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema && segment.segmentType !== 'mixin').forEach((segment, i) => { %>
|
|
7
|
+
import segment<%= i %> from './<%= t.schemaOutDir %>/<%= segment.segmentName || t.ROOT_SEGMENT_FILE_NAME %>.json' with { type: "json" };
|
|
8
|
+
<% }); %>
|
|
9
|
+
<% if(t.isVovkProject) { %>
|
|
10
|
+
import meta from './<%= t.schemaOutDir %>/_meta.json' with { type: "json" };
|
|
11
|
+
<% } else { %>
|
|
12
|
+
const meta = <%- JSON.stringify(t.publicMeta, null, 2) %>;
|
|
13
|
+
<% } %>
|
|
14
|
+
const segments = {<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema && segment.segmentType !== 'mixin').forEach((segment, i) => { %>
|
|
15
|
+
'<%= segment.segmentName %>': segment<%= i %>,<% }) %>
|
|
16
|
+
<% if(t.hasMixins) { %>
|
|
17
|
+
...mixins,
|
|
18
|
+
<% } %>
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const schema = {
|
|
22
|
+
$schema: '<%- t.VovkSchemaIdEnum.SCHEMA %>',
|
|
23
|
+
segments,
|
|
24
|
+
meta,
|
|
25
|
+
};
|
|
26
|
+
<% if (t.hasMixins) { %>
|
|
27
|
+
export { Mixins };
|
|
28
|
+
<% } %>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<%- t.getFirstLineBanner() %>
|
|
2
|
+
import type { VovkFetcher } from 'vovk';
|
|
3
|
+
import { createRPC } from '<%= t.commonImports.module.createRPC %>';
|
|
4
|
+
import { schema } from './schema<%= t.nodeNextResolutionExt.ts %>';
|
|
5
|
+
<% if(t.isBundle) { %>
|
|
6
|
+
import { openapi } from './openapi<%= t.nodeNextResolutionExt.ts %>';
|
|
7
|
+
<% } else { %>
|
|
8
|
+
// TODO: This is a temporary fix https://github.com/rolldown/tsdown/issues/528#issuecomment-3476284358
|
|
9
|
+
import openapi from './openapi.json' with { type: "json" };
|
|
10
|
+
<% } %>
|
|
11
|
+
<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { if(segment.segmentType !== 'mixin') { %>
|
|
12
|
+
import type { Controllers as Controllers<%= i %> } from "<%= t.segmentMeta[segment.segmentName].segmentImportPath %>";
|
|
13
|
+
<% }
|
|
14
|
+
});
|
|
15
|
+
if (t.hasMixins) { %>
|
|
16
|
+
import type { Controllers as MixinControllers, Mixins } from "./mixins.d.ts";
|
|
17
|
+
<% } %>
|
|
18
|
+
<% Object.entries(t.reExports).forEach(([reExportWhat, reExportFrom]) => { %>
|
|
19
|
+
export { <%= reExportWhat %> } from '<%= reExportFrom %>';
|
|
20
|
+
<% }) %>
|
|
21
|
+
<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => {
|
|
22
|
+
Object.keys(segment.controllers).forEach((rpcModuleName) => {
|
|
23
|
+
const apiRoot = t.segmentMeta[segment.segmentName].forceApiRoot ?? t.apiRoot; %>
|
|
24
|
+
export const <%= rpcModuleName %> = createRPC<<%= segment.segmentType === 'mixin' ? `MixinControllers` : `Controllers${i}` %>["<%= rpcModuleName %>"], typeof import('<%- t.segmentImports[segment.segmentName].module.fetcher %>').fetcher extends VovkFetcher<infer U> ? U : never>(
|
|
25
|
+
schema, '<%= segment.segmentName %>', '<%= rpcModuleName %>', import('<%- t.segmentImports[segment.segmentName].module.fetcher %>'),
|
|
26
|
+
{ validateOnClient: <%- t.segmentImports[segment.segmentName].module.validateOnClient ? `import('${t.segmentImports[segment.segmentName].validateOnClient}')` : 'undefined' %>, <%- typeof t.segmentMeta[segment.segmentName].segmentNameOverride === 'string' ? `segmentNameOverride: '${t.segmentMeta[segment.segmentName].segmentNameOverride}', ` : '' %><%- segment.segmentType === 'mixin' ? '' : apiRoot ? `apiRoot: '${apiRoot}'` : '' %> }
|
|
27
|
+
);
|
|
28
|
+
<% })
|
|
29
|
+
}) %>
|
|
30
|
+
export { schema, openapi };
|
|
31
|
+
<% if (t.hasMixins) { %>
|
|
32
|
+
export { Mixins };
|
|
33
|
+
<% } %>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { VovkSchema } from 'vovk';
|
|
2
|
+
import type { ProjectInfo } from '../getProjectInfo/index.mjs';
|
|
3
|
+
import type { BundleOptions } from '../types.mjs';
|
|
4
|
+
export declare function bundle({ projectInfo, fullSchema, cliBundleOptions, }: {
|
|
5
|
+
projectInfo: ProjectInfo;
|
|
6
|
+
fullSchema: VovkSchema;
|
|
7
|
+
cliBundleOptions: BundleOptions;
|
|
8
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import groupBy from 'lodash/groupBy.js';
|
|
4
|
+
import { generate } from '../generate/generate.mjs';
|
|
5
|
+
import { BuiltInTemplateName } from '../getProjectInfo/getConfig/getTemplateDefs.mjs';
|
|
6
|
+
import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
|
|
7
|
+
import { locateSegments } from '../locateSegments.mjs';
|
|
8
|
+
export async function bundle({ projectInfo, fullSchema, cliBundleOptions, }) {
|
|
9
|
+
const { config, log, cwd, apiDirAbsolutePath } = projectInfo;
|
|
10
|
+
const locatedSegments = await locateSegments({ dir: apiDirAbsolutePath, config, log });
|
|
11
|
+
const { bundle: bundleConfig } = config;
|
|
12
|
+
const keepPrebundleDir = cliBundleOptions?.keepPrebundleDir ?? bundleConfig?.keepPrebundleDir ?? false;
|
|
13
|
+
const prebundleOutDirAbsolute = path.resolve(cwd, cliBundleOptions?.prebundleOutDir ?? bundleConfig.prebundleOutDir);
|
|
14
|
+
const entry = path.join(prebundleOutDirAbsolute, 'index.ts');
|
|
15
|
+
const outDir = cliBundleOptions?.outDir ?? bundleConfig.outDir;
|
|
16
|
+
if (!outDir) {
|
|
17
|
+
throw new Error('No output directory specified for bundling');
|
|
18
|
+
}
|
|
19
|
+
const outDirAbsolute = path.resolve(cwd, outDir);
|
|
20
|
+
await generate({
|
|
21
|
+
isEnsuringClient: false,
|
|
22
|
+
isBundle: true,
|
|
23
|
+
projectInfo,
|
|
24
|
+
forceNothingWrittenLog: true,
|
|
25
|
+
fullSchema,
|
|
26
|
+
locatedSegments,
|
|
27
|
+
cliGenerateOptions: {
|
|
28
|
+
schemaPath: cliBundleOptions?.schemaPath,
|
|
29
|
+
origin: cliBundleOptions?.origin,
|
|
30
|
+
openapiSpec: cliBundleOptions?.openapiSpec,
|
|
31
|
+
openapiGetModuleName: cliBundleOptions?.openapiGetModuleName,
|
|
32
|
+
openapiGetMethodName: cliBundleOptions?.openapiGetMethodName,
|
|
33
|
+
openapiRootUrl: cliBundleOptions?.openapiRootUrl,
|
|
34
|
+
composedFrom: [BuiltInTemplateName.ts],
|
|
35
|
+
composedOut: prebundleOutDirAbsolute,
|
|
36
|
+
composedOnly: true,
|
|
37
|
+
composedIncludeSegments: cliBundleOptions.includeSegments ?? bundleConfig.includeSegments,
|
|
38
|
+
composedExcludeSegments: cliBundleOptions.excludeSegments ?? bundleConfig.excludeSegments,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
log.debug(`Bundling ${chalkHighlightThing(entry)} to ${chalkHighlightThing(outDirAbsolute)}`);
|
|
42
|
+
await bundleConfig.build({
|
|
43
|
+
outDir: outDirAbsolute,
|
|
44
|
+
prebundleDir: prebundleOutDirAbsolute,
|
|
45
|
+
entry,
|
|
46
|
+
});
|
|
47
|
+
log.debug(`Bundled index.ts to ${chalkHighlightThing(outDirAbsolute)}`);
|
|
48
|
+
const requiresGroup = groupBy(Object.entries(bundleConfig.requires), ([, relativePath]) => relativePath);
|
|
49
|
+
for (const [relativePath, group] of Object.entries(requiresGroup)) {
|
|
50
|
+
await generate({
|
|
51
|
+
isEnsuringClient: false,
|
|
52
|
+
isBundle: true,
|
|
53
|
+
projectInfo,
|
|
54
|
+
forceNothingWrittenLog: true,
|
|
55
|
+
fullSchema,
|
|
56
|
+
locatedSegments,
|
|
57
|
+
cliGenerateOptions: {
|
|
58
|
+
schemaPath: cliBundleOptions?.schemaPath,
|
|
59
|
+
origin: cliBundleOptions?.origin,
|
|
60
|
+
composedFrom: group.map(([templateName]) => templateName),
|
|
61
|
+
composedOut: path.resolve(outDirAbsolute, relativePath),
|
|
62
|
+
composedOnly: true,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (!keepPrebundleDir) {
|
|
67
|
+
await fs.rm(prebundleOutDirAbsolute, { recursive: true, force: true });
|
|
68
|
+
log.debug(`Deleted temporary TypeScript client output directory: ${chalkHighlightThing(prebundleOutDirAbsolute)}`);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
log.debug(`Temporary TypeScript client output directory not deleted because it is marked to keep: ${chalkHighlightThing(prebundleOutDirAbsolute)}`);
|
|
72
|
+
}
|
|
73
|
+
log.info(`Bundled TypeScript client to ${chalkHighlightThing(outDirAbsolute)}`);
|
|
74
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { VovkControllerSchema, VovkSegmentSchema } from 'vovk';
|
|
2
|
+
interface HandlersDiff {
|
|
3
|
+
nameOfClass: string;
|
|
4
|
+
added: string[];
|
|
5
|
+
removed: string[];
|
|
6
|
+
changed: string[];
|
|
7
|
+
}
|
|
8
|
+
interface ControllersDiff {
|
|
9
|
+
added: string[];
|
|
10
|
+
removed: string[];
|
|
11
|
+
handlers: HandlersDiff[];
|
|
12
|
+
}
|
|
13
|
+
export interface DiffResult {
|
|
14
|
+
controllers: ControllersDiff;
|
|
15
|
+
}
|
|
16
|
+
export declare function diffHandlers<T extends VovkControllerSchema['handlers']>(oldHandlers: T, newHandlers: T, nameOfClass: string): HandlersDiff;
|
|
17
|
+
export declare function diffControllers<T extends VovkSegmentSchema['controllers']>(oldItems: T, newItems: T): ControllersDiff;
|
|
18
|
+
/**
|
|
19
|
+
example output:
|
|
20
|
+
{
|
|
21
|
+
controllers: {
|
|
22
|
+
added: ["ControllerC"],
|
|
23
|
+
removed: ["ControllerB"],
|
|
24
|
+
handlers: [
|
|
25
|
+
{
|
|
26
|
+
nameOfClass: "ControllerA",
|
|
27
|
+
added: ["handlerF"],
|
|
28
|
+
removed: [],
|
|
29
|
+
changed: ["handlerD"]
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
*/
|
|
35
|
+
export default function diffSegmentSchema(oldJson: VovkSegmentSchema, newJson: VovkSegmentSchema): DiffResult;
|
|
36
|
+
export {};
|
|
@@ -18,7 +18,7 @@ export function diffHandlers(oldHandlers, newHandlers, nameOfClass) {
|
|
|
18
18
|
}
|
|
19
19
|
return { nameOfClass, added, removed, changed };
|
|
20
20
|
}
|
|
21
|
-
export function
|
|
21
|
+
export function diffControllers(oldItems, newItems) {
|
|
22
22
|
const added = [];
|
|
23
23
|
const removed = [];
|
|
24
24
|
const handlersDiff = [];
|
|
@@ -43,11 +43,6 @@ export function diffWorkersOrControllers(oldItems, newItems) {
|
|
|
43
43
|
/**
|
|
44
44
|
example output:
|
|
45
45
|
{
|
|
46
|
-
workers: {
|
|
47
|
-
added: ["WorkerC"],
|
|
48
|
-
removed: ["WorkerA"],
|
|
49
|
-
handlers: []
|
|
50
|
-
},
|
|
51
46
|
controllers: {
|
|
52
47
|
added: ["ControllerC"],
|
|
53
48
|
removed: ["ControllerB"],
|
|
@@ -62,11 +57,8 @@ example output:
|
|
|
62
57
|
}
|
|
63
58
|
}
|
|
64
59
|
*/
|
|
65
|
-
export default function
|
|
66
|
-
const workersDiff = diffWorkersOrControllers(oldJson.workers ?? {}, newJson.workers ?? {});
|
|
67
|
-
const controllersDiff = diffWorkersOrControllers(oldJson.controllers ?? {}, newJson.controllers ?? {});
|
|
60
|
+
export default function diffSegmentSchema(oldJson, newJson) {
|
|
68
61
|
return {
|
|
69
|
-
|
|
70
|
-
controllers: controllersDiff,
|
|
62
|
+
controllers: diffControllers(oldJson.controllers ?? {}, newJson.controllers ?? {}),
|
|
71
63
|
};
|
|
72
64
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { ProjectInfo } from '../getProjectInfo/index.mjs';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Ensure that the schema files are created to avoid any import errors.
|
|
4
|
+
*/
|
|
5
|
+
export default function ensureSchemaFiles(projectInfo: ProjectInfo, schemaOutAbsolutePath: string, segmentNames: string[]): Promise<void>;
|
|
3
6
|
export declare const debouncedEnsureSchemaFiles: import("lodash").DebouncedFunc<typeof ensureSchemaFiles>;
|
|
@@ -1,44 +1,28 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import debounce from 'lodash/debounce.js';
|
|
4
|
-
import
|
|
4
|
+
import { VovkSchemaIdEnum } from 'vovk';
|
|
5
|
+
import writeOneSegmentSchemaFile, { META_FILE_NAME, ROOT_SEGMENT_FILE_NAME } from './writeOneSegmentSchemaFile.mjs';
|
|
5
6
|
import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
7
|
+
import writeMetaJson from './writeMetaJson.mjs';
|
|
8
|
+
/**
|
|
9
|
+
* Ensure that the schema files are created to avoid any import errors.
|
|
10
|
+
*/
|
|
6
11
|
export default async function ensureSchemaFiles(projectInfo, schemaOutAbsolutePath, segmentNames) {
|
|
7
12
|
const now = Date.now();
|
|
8
13
|
let hasChanged = false;
|
|
9
|
-
// Create index.js file
|
|
10
|
-
const indexContent = `// auto-generated
|
|
11
|
-
${segmentNames
|
|
12
|
-
.map((segmentName) => {
|
|
13
|
-
return `module.exports['${segmentName}'] = require('./${segmentName || ROOT_SEGMENT_SCHEMA_NAME}.json');`;
|
|
14
|
-
})
|
|
15
|
-
.join('\n')}`;
|
|
16
|
-
const dTsContent = `// auto-generated
|
|
17
|
-
import type { VovkSchema } from 'vovk';
|
|
18
|
-
declare const segmentSchema: {
|
|
19
|
-
${segmentNames.map((segmentName) => ` '${segmentName}': VovkSchema;`).join('\n')}
|
|
20
|
-
};
|
|
21
|
-
export default segmentSchema;`;
|
|
22
|
-
const jsAbsolutePath = path.join(schemaOutAbsolutePath, 'index.js');
|
|
23
|
-
const dTsAbsolutePath = path.join(schemaOutAbsolutePath, 'index.d.ts');
|
|
24
|
-
const existingJs = await fs.readFile(jsAbsolutePath, 'utf-8').catch(() => null);
|
|
25
|
-
const existingDTs = await fs.readFile(dTsAbsolutePath, 'utf-8').catch(() => null);
|
|
26
14
|
await fs.mkdir(schemaOutAbsolutePath, { recursive: true });
|
|
27
|
-
|
|
28
|
-
await fs.writeFile(jsAbsolutePath, indexContent);
|
|
29
|
-
}
|
|
30
|
-
if (existingDTs !== dTsContent) {
|
|
31
|
-
await fs.writeFile(dTsAbsolutePath, dTsContent);
|
|
32
|
-
}
|
|
15
|
+
await writeMetaJson(schemaOutAbsolutePath, projectInfo);
|
|
33
16
|
// Create JSON files (if not exist) with name [segmentName].json (where segmentName can include /, which means the folder structure can be nested)
|
|
34
17
|
await Promise.all(segmentNames.map(async (segmentName) => {
|
|
35
|
-
const { isCreated } = await
|
|
18
|
+
const { isCreated } = await writeOneSegmentSchemaFile({
|
|
36
19
|
schemaOutAbsolutePath,
|
|
37
|
-
|
|
20
|
+
segmentSchema: {
|
|
21
|
+
$schema: VovkSchemaIdEnum.SEGMENT,
|
|
38
22
|
emitSchema: false,
|
|
39
23
|
segmentName,
|
|
24
|
+
segmentType: 'segment',
|
|
40
25
|
controllers: {},
|
|
41
|
-
workers: {},
|
|
42
26
|
},
|
|
43
27
|
skipIfExists: true,
|
|
44
28
|
});
|
|
@@ -48,7 +32,7 @@ export default segmentSchema;`;
|
|
|
48
32
|
}
|
|
49
33
|
}));
|
|
50
34
|
// Recursive function to delete unnecessary JSON files and folders
|
|
51
|
-
async function deleteUnnecessaryJsonFiles(dirPath) {
|
|
35
|
+
async function deleteUnnecessaryJsonFiles(dirPath, allow = [`${META_FILE_NAME}.json`]) {
|
|
52
36
|
const entries = await fs.readdir(dirPath, { withFileTypes: true });
|
|
53
37
|
await Promise.all(entries.map(async (entry) => {
|
|
54
38
|
const absolutePath = path.join(dirPath, entry.name);
|
|
@@ -67,7 +51,8 @@ export default segmentSchema;`;
|
|
|
67
51
|
const relativePath = path.relative(schemaOutAbsolutePath, absolutePath);
|
|
68
52
|
const segmentName = relativePath.replace(/\\/g, '/').slice(0, -5); // Remove '.json' extension
|
|
69
53
|
if (!segmentNames.includes(segmentName) &&
|
|
70
|
-
!segmentNames.includes(segmentName.replace(
|
|
54
|
+
!segmentNames.includes(segmentName.replace(ROOT_SEGMENT_FILE_NAME, '')) &&
|
|
55
|
+
!allow.includes(entry.name)) {
|
|
71
56
|
await fs.unlink(absolutePath);
|
|
72
57
|
projectInfo?.log.debug(`Deleted unnecessary schema file for ${formatLoggedSegmentName(segmentName)}`);
|
|
73
58
|
hasChanged = true;
|
|
@@ -75,9 +60,8 @@ export default segmentSchema;`;
|
|
|
75
60
|
}
|
|
76
61
|
}));
|
|
77
62
|
}
|
|
78
|
-
// Start the recursive deletion from the root directory
|
|
79
63
|
await deleteUnnecessaryJsonFiles(schemaOutAbsolutePath);
|
|
80
64
|
if (hasChanged)
|
|
81
|
-
projectInfo?.log.info(`
|
|
65
|
+
projectInfo?.log.info(`Created empty schema files in ${Date.now() - now}ms`);
|
|
82
66
|
}
|
|
83
67
|
export const debouncedEnsureSchemaFiles = debounce(ensureSchemaFiles, 1000);
|
package/dist/dev/index.d.mts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import type { DevOptions } from '../types.mjs';
|
|
1
2
|
export declare class VovkDev {
|
|
2
3
|
#private;
|
|
3
|
-
|
|
4
|
+
constructor({ schemaOut, devHttps, logLevel }: Pick<DevOptions, 'schemaOut' | 'devHttps' | 'logLevel'>);
|
|
5
|
+
start({ exit }: {
|
|
6
|
+
exit: boolean;
|
|
7
|
+
}): Promise<void>;
|
|
4
8
|
}
|