vovk-cli 0.0.1-draft.81 → 0.0.1-draft.82
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,5 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import getClientTemplates from './getClientTemplates.mjs';
|
|
3
|
+
import uniq from 'lodash/uniq.js';
|
|
4
|
+
import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
|
|
3
5
|
export default async function ensureClient({ config, cwd, log }) {
|
|
4
6
|
const now = Date.now();
|
|
5
7
|
const { clientOutDirAbsolutePath, templateFiles } = getClientTemplates({
|
|
@@ -7,21 +9,22 @@ export default async function ensureClient({ config, cwd, log }) {
|
|
|
7
9
|
cwd,
|
|
8
10
|
templateNames: config.experimental_clientGenerateTemplateNames,
|
|
9
11
|
});
|
|
12
|
+
let usedTemplateNames = [];
|
|
10
13
|
const text = `// auto-generated ${new Date().toISOString()}
|
|
11
14
|
// This is a temporary placeholder to avoid errors if client is imported before it's generated.
|
|
12
15
|
// If you still see this text, the client is not generated yet because of an unknown problem.
|
|
13
16
|
// Feel free to report an issue at https://github.com/finom/vovk/issues`;
|
|
14
|
-
|
|
15
|
-
for (const { outPath } of templateFiles) {
|
|
17
|
+
for (const { outPath, templateName } of templateFiles) {
|
|
16
18
|
const existing = await fs.readFile(outPath, 'utf-8').catch(() => null);
|
|
17
19
|
if (!existing) {
|
|
18
20
|
await fs.mkdir(clientOutDirAbsolutePath, { recursive: true });
|
|
19
21
|
await fs.writeFile(outPath, text);
|
|
20
|
-
|
|
22
|
+
usedTemplateNames.push(templateName);
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
usedTemplateNames = uniq(usedTemplateNames);
|
|
26
|
+
if (usedTemplateNames.length) {
|
|
27
|
+
log.info(`Placeholder client files for templates ${chalkHighlightThing(usedTemplateNames.join(', '))} are generated at folder ${clientOutDirAbsolutePath} in ${Date.now() - now}ms`);
|
|
25
28
|
}
|
|
26
|
-
return { written, path: clientOutDirAbsolutePath };
|
|
29
|
+
return { written: !!usedTemplateNames.length, path: clientOutDirAbsolutePath };
|
|
27
30
|
}
|