vovk-cli 0.0.1-draft.55 → 0.0.1-draft.58
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/dist/dev/index.mjs +1 -1
- package/dist/generate/ensureClient.mjs +27 -0
- package/dist/generate/getClientTemplates.d.mts +4 -1
- package/dist/generate/getClientTemplates.mjs +1 -1
- package/dist/generate/index.mjs +1 -2
- package/dist/getProjectInfo/getConfig.mjs +2 -2
- package/dist/getProjectInfo/index.mjs +2 -1
- package/package.json +1 -1
- package/dist/dev/ensureClient.mjs +0 -30
- /package/dist/{dev → generate}/ensureClient.d.mts +0 -0
package/dist/dev/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import once from 'lodash/once.js';
|
|
|
10
10
|
import { debouncedEnsureSchemaFiles } from './ensureSchemaFiles.mjs';
|
|
11
11
|
import writeOneSchemaFile from './writeOneSchemaFile.mjs';
|
|
12
12
|
import logDiffResult from './logDiffResult.mjs';
|
|
13
|
-
import ensureClient from '
|
|
13
|
+
import ensureClient from '../generate/ensureClient.mjs';
|
|
14
14
|
import getProjectInfo from '../getProjectInfo/index.mjs';
|
|
15
15
|
import generate from '../generate/index.mjs';
|
|
16
16
|
import locateSegments from '../locateSegments.mjs';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import getClientTemplates from './getClientTemplates.mjs';
|
|
3
|
+
export default async function ensureClient({ config, cwd, log }) {
|
|
4
|
+
const now = Date.now();
|
|
5
|
+
const { clientOutDirAbsolutePath, templateFiles } = getClientTemplates({
|
|
6
|
+
config,
|
|
7
|
+
cwd,
|
|
8
|
+
templateNames: config.experimental_clientGenerateTemplateNames,
|
|
9
|
+
});
|
|
10
|
+
const text = `// auto-generated
|
|
11
|
+
// This is a temporary placeholder to avoid errors if client is imported before it's generated.
|
|
12
|
+
// If you still see this text, the client is not generated yet because of an unknown problem.
|
|
13
|
+
// Feel free to report an issue at https://github.com/finom/vovk/issues`;
|
|
14
|
+
let written = false;
|
|
15
|
+
for (const { outPath } of templateFiles) {
|
|
16
|
+
const existing = await fs.readFile(outPath, 'utf-8').catch(() => null);
|
|
17
|
+
if (!existing) {
|
|
18
|
+
await fs.mkdir(clientOutDirAbsolutePath, { recursive: true });
|
|
19
|
+
await fs.writeFile(outPath, text);
|
|
20
|
+
written = true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (written) {
|
|
24
|
+
log.info(`Empty client files are generated in ${Date.now() - now}ms`);
|
|
25
|
+
}
|
|
26
|
+
return { written, path: clientOutDirAbsolutePath };
|
|
27
|
+
}
|
|
@@ -7,5 +7,8 @@ export default function getClientTemplates({ config, cwd, templateNames, }: {
|
|
|
7
7
|
config: Required<VovkConfig>;
|
|
8
8
|
cwd: string;
|
|
9
9
|
templateNames?: string[];
|
|
10
|
-
}):
|
|
10
|
+
}): {
|
|
11
|
+
clientOutDirAbsolutePath: string;
|
|
12
|
+
templateFiles: ClientTemplate[];
|
|
13
|
+
};
|
|
11
14
|
export {};
|
package/dist/generate/index.mjs
CHANGED
|
@@ -8,8 +8,7 @@ export default async function generate({ projectInfo, segments, segmentsSchema,
|
|
|
8
8
|
templates = templates ?? projectInfo.config.experimental_clientGenerateTemplateNames;
|
|
9
9
|
const noClient = templates?.[0] === 'none';
|
|
10
10
|
const { config, cwd, log, validateOnClientImportPath, apiRoot, fetcherClientImportPath, createRPCImportPath, schemaOutImportPath, } = projectInfo;
|
|
11
|
-
const clientOutDirAbsolutePath =
|
|
12
|
-
const templateFiles = getClientTemplates({ config, cwd, templateNames: templates });
|
|
11
|
+
const { clientOutDirAbsolutePath, templateFiles } = getClientTemplates({ config, cwd, templateNames: templates });
|
|
13
12
|
// Ensure that each segment has a matching schema if it needs to be emitted:
|
|
14
13
|
for (let i = 0; i < segments.length; i++) {
|
|
15
14
|
const { segmentName } = segments[i];
|
|
@@ -8,8 +8,8 @@ export default async function getConfig({ clientOutDir, cwd }) {
|
|
|
8
8
|
const config = {
|
|
9
9
|
modulesDir: env.VOVK_MODULES_DIR ?? conf.modulesDir ?? './' + [srcRoot, 'modules'].filter(Boolean).join('/'),
|
|
10
10
|
validateOnClientPath: env.VOVK_VALIDATE_ON_CLIENT_PATH ?? conf.validateOnClientPath ?? null,
|
|
11
|
-
fetcherPath: env.VOVK_FETCHER_PATH ?? conf.fetcherPath ?? 'vovk/dist/client/defaultFetcher',
|
|
12
|
-
createRPCPath: env.VOVK_CREATE_RPC_PATH ?? conf.createRPCPath ?? 'vovk/dist/client/createRPC',
|
|
11
|
+
fetcherPath: env.VOVK_FETCHER_PATH ?? conf.fetcherPath ?? 'vovk/dist/client/defaultFetcher.js',
|
|
12
|
+
createRPCPath: env.VOVK_CREATE_RPC_PATH ?? conf.createRPCPath ?? 'vovk/dist/client/createRPC.js',
|
|
13
13
|
schemaOutDir: env.VOVK_SCHEMA_OUT_DIR ?? conf.schemaOutDir ?? './.vovk-schema',
|
|
14
14
|
clientOutDir: clientOutDir ?? env.VOVK_CLIENT_OUT_DIR ?? conf.clientOutDir ?? './node_modules/.vovk-client',
|
|
15
15
|
origin: (env.VOVK_ORIGIN ?? conf.origin ?? '').replace(/\/$/, ''), // Remove trailing slash
|
|
@@ -8,7 +8,8 @@ export default async function getProjectInfo({ port: givenPort, clientOutDir, cw
|
|
|
8
8
|
const { config, srcRoot, configAbsolutePaths, userConfig, error } = await getConfig({ clientOutDir, cwd });
|
|
9
9
|
const apiRoot = `${config.origin ?? ''}/${config.rootEntry}`;
|
|
10
10
|
const apiDir = path.join(srcRoot, 'app', config.rootEntry);
|
|
11
|
-
const schemaOutImportPath = path.relative(config.clientOutDir, config.schemaOutDir).replace(/\\/g, '/')
|
|
11
|
+
const schemaOutImportPath = path.relative(config.clientOutDir, config.schemaOutDir).replace(/\\/g, '/') + // windows fix
|
|
12
|
+
'index.js';
|
|
12
13
|
const fetcherClientImportPath = config.fetcherPath.startsWith('.')
|
|
13
14
|
? path.relative(config.clientOutDir, config.fetcherPath)
|
|
14
15
|
: config.fetcherPath;
|
package/package.json
CHANGED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fs from 'node:fs/promises';
|
|
3
|
-
export default async function ensureClient({ config, cwd, log }) {
|
|
4
|
-
const now = Date.now();
|
|
5
|
-
const clientoOutDirAbsolutePath = path.join(cwd, config.clientOutDir);
|
|
6
|
-
const dts = `// auto-generated
|
|
7
|
-
// This is a temporary placeholder to avoid errors if client is imported before it's generated.
|
|
8
|
-
// If you still see this text, the client is not generated yet because of an unknown problem.
|
|
9
|
-
// Feel free to report an issue at https://github.com/finom/vovk/issues`;
|
|
10
|
-
const js = dts;
|
|
11
|
-
const ts = dts;
|
|
12
|
-
const localJsAbsolutePath = path.join(clientoOutDirAbsolutePath, 'compiled.js');
|
|
13
|
-
const localDtsAbsolutePath = path.join(clientoOutDirAbsolutePath, 'compiled.d.ts');
|
|
14
|
-
const localTsAbsolutePath = path.join(clientoOutDirAbsolutePath, 'index.ts');
|
|
15
|
-
const existingJs = await fs.readFile(localJsAbsolutePath, 'utf-8').catch(() => null);
|
|
16
|
-
const existingDts = await fs.readFile(localDtsAbsolutePath, 'utf-8').catch(() => null);
|
|
17
|
-
const existingTs = await fs.readFile(localTsAbsolutePath, 'utf-8').catch(() => null);
|
|
18
|
-
if (existingJs && existingDts && existingTs) {
|
|
19
|
-
return { written: false, path: clientoOutDirAbsolutePath };
|
|
20
|
-
}
|
|
21
|
-
await fs.mkdir(clientoOutDirAbsolutePath, { recursive: true });
|
|
22
|
-
if (!existingJs)
|
|
23
|
-
await fs.writeFile(localJsAbsolutePath, js);
|
|
24
|
-
if (!existingDts)
|
|
25
|
-
await fs.writeFile(localDtsAbsolutePath, dts);
|
|
26
|
-
if (!existingTs)
|
|
27
|
-
await fs.writeFile(localTsAbsolutePath, ts);
|
|
28
|
-
log.info(`Empty client files are generated in ${Date.now() - now}ms`);
|
|
29
|
-
return { written: true, path: clientoOutDirAbsolutePath };
|
|
30
|
-
}
|
|
File without changes
|