vovk-cli 0.0.1-draft.54 → 0.0.1-draft.56

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.
@@ -1,30 +1,27 @@
1
- import path from 'node:path';
2
1
  import fs from 'node:fs/promises';
2
+ import getClientTemplates from '../generate/getClientTemplates.mjs';
3
3
  export default async function ensureClient({ config, cwd, log }) {
4
4
  const now = Date.now();
5
- const clientoOutDirAbsolutePath = path.join(cwd, config.clientOutDir);
6
- const dts = `// auto-generated
5
+ const { clientOutDirAbsolutePath, templateFiles } = getClientTemplates({
6
+ config,
7
+ cwd,
8
+ templateNames: config.experimental_clientGenerateTemplateNames,
9
+ });
10
+ const text = `// auto-generated
7
11
  // This is a temporary placeholder to avoid errors if client is imported before it's generated.
8
12
  // If you still see this text, the client is not generated yet because of an unknown problem.
9
13
  // 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 };
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
+ }
20
22
  }
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 };
23
+ if (written) {
24
+ log.info(`Empty client files are generated in ${Date.now() - now}ms`);
25
+ }
26
+ return { written, path: clientOutDirAbsolutePath };
30
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
- }): ClientTemplate[];
10
+ }): {
11
+ clientOutDirAbsolutePath: string;
12
+ templateFiles: ClientTemplate[];
13
+ };
11
14
  export {};
@@ -24,5 +24,5 @@ export default function getClientTemplates({ config, cwd, templateNames = [], })
24
24
  },
25
25
  ];
26
26
  }, []);
27
- return templateFiles;
27
+ return { clientOutDirAbsolutePath, templateFiles };
28
28
  }
@@ -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 = path.resolve(cwd, config.clientOutDir);
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];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk-cli",
3
- "version": "0.0.1-draft.54",
3
+ "version": "0.0.1-draft.56",
4
4
  "bin": {
5
5
  "vovk": "./dist/index.mjs"
6
6
  },