vovk-cli 0.0.1-draft.75 → 0.0.1-draft.78
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.
|
@@ -3,6 +3,7 @@ export default function getClientTemplates({ config, cwd, templateNames = [], })
|
|
|
3
3
|
const templatesDir = path.join(import.meta.dirname, '../..', 'client-templates');
|
|
4
4
|
const clientOutDirAbsolutePath = path.resolve(cwd, config.clientOutDir);
|
|
5
5
|
const mapper = (dir) => (name) => ({
|
|
6
|
+
templateName: name,
|
|
6
7
|
templatePath: path.resolve(templatesDir, dir, name),
|
|
7
8
|
outPath: path.join(clientOutDirAbsolutePath, name.replace('.ejs', '')),
|
|
8
9
|
});
|
|
@@ -19,6 +20,7 @@ export default function getClientTemplates({ config, cwd, templateNames = [], })
|
|
|
19
20
|
return [
|
|
20
21
|
...acc,
|
|
21
22
|
{
|
|
23
|
+
templateName: template,
|
|
22
24
|
templatePath: path.resolve(cwd, template),
|
|
23
25
|
outPath: path.join(clientOutDirAbsolutePath, path.basename(template).replace('.ejs', '')),
|
|
24
26
|
},
|
package/dist/generate/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import ejs from 'ejs';
|
|
|
4
4
|
import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
5
5
|
import prettify from '../utils/prettify.mjs';
|
|
6
6
|
import getClientTemplates from './getClientTemplates.mjs';
|
|
7
|
+
import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
|
|
7
8
|
export default async function generate({ projectInfo, segments, segmentsSchema, forceNothingWrittenLog, templates, prettify: prettifyClient, fullSchema, }) {
|
|
8
9
|
templates = templates ?? projectInfo.config.experimental_clientGenerateTemplateNames;
|
|
9
10
|
const noClient = templates?.[0] === 'none';
|
|
@@ -30,7 +31,7 @@ export default async function generate({ projectInfo, segments, segmentsSchema,
|
|
|
30
31
|
// Process each template in parallel
|
|
31
32
|
const processedTemplates = noClient
|
|
32
33
|
? []
|
|
33
|
-
: await Promise.all(templateFiles.map(async ({ templatePath, outPath }) => {
|
|
34
|
+
: await Promise.all(templateFiles.map(async ({ templatePath, outPath, templateName }) => {
|
|
34
35
|
// Read the EJS template
|
|
35
36
|
const templateContent = await fs.readFile(templatePath, 'utf-8');
|
|
36
37
|
// Render the template
|
|
@@ -51,10 +52,12 @@ export default async function generate({ projectInfo, segments, segmentsSchema,
|
|
|
51
52
|
outPath,
|
|
52
53
|
rendered,
|
|
53
54
|
needsWriting,
|
|
55
|
+
templateName,
|
|
54
56
|
};
|
|
55
57
|
}));
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
+
const usedTemplateNames = processedTemplates.filter(({ needsWriting }) => needsWriting).map(({ templateName }) => templateName);
|
|
59
|
+
const unusedTemplateNames = processedTemplates.filter(({ needsWriting }) => !needsWriting).map(({ templateName }) => templateName);
|
|
60
|
+
if (fullSchema || usedTemplateNames.length > 0) {
|
|
58
61
|
// Make sure the output directory exists
|
|
59
62
|
await fs.mkdir(clientOutDirAbsolutePath, { recursive: true });
|
|
60
63
|
}
|
|
@@ -63,7 +66,7 @@ export default async function generate({ projectInfo, segments, segmentsSchema,
|
|
|
63
66
|
await fs.writeFile(fullSchemaOutAbsolutePath, JSON.stringify(segmentsSchema, null, 2));
|
|
64
67
|
log.info(`Full schema has ben written to ${fullSchemaOutAbsolutePath}`);
|
|
65
68
|
}
|
|
66
|
-
if (
|
|
69
|
+
if (usedTemplateNames.length === 0) {
|
|
67
70
|
const logOrDebug = forceNothingWrittenLog ? log.info : log.debug;
|
|
68
71
|
logOrDebug(`Client is up to date and doesn't need to be regenerated (${Date.now() - now}ms)`);
|
|
69
72
|
return { written: false, path: clientOutDirAbsolutePath };
|
|
@@ -75,6 +78,6 @@ export default async function generate({ projectInfo, segments, segmentsSchema,
|
|
|
75
78
|
}
|
|
76
79
|
return null;
|
|
77
80
|
}));
|
|
78
|
-
log.info(`Client generated in ${Date.now() - now}ms`);
|
|
81
|
+
log.info(`Client generated from templates ${chalkHighlightThing(usedTemplateNames.join(', '))}${unusedTemplateNames.length ? ` (files generated from templates ${unusedTemplateNames.join(', ')} are up to date)` : ''} in ${Date.now() - now}ms`);
|
|
79
82
|
return { written: true, path: clientOutDirAbsolutePath };
|
|
80
83
|
}
|