vovk-cli 0.0.1-draft.68 → 0.0.1-draft.69
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.
|
@@ -9,29 +9,39 @@ import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
|
9
9
|
export default async function ensureSchemaFiles(projectInfo, schemaOutAbsolutePath, segmentNames) {
|
|
10
10
|
const now = Date.now();
|
|
11
11
|
let hasChanged = false;
|
|
12
|
-
const
|
|
12
|
+
const jsContent = `// auto-generated
|
|
13
13
|
${segmentNames
|
|
14
14
|
.map((segmentName) => {
|
|
15
15
|
return `module.exports['${segmentName}'] = require('./${segmentName || ROOT_SEGMENT_SCHEMA_NAME}.json');`;
|
|
16
16
|
})
|
|
17
17
|
.join('\n')}`;
|
|
18
18
|
const dTsContent = `// auto-generated
|
|
19
|
-
import type { VovkSchema } from 'vovk';
|
|
20
19
|
declare const fullSchema: {
|
|
21
20
|
${segmentNames.map((segmentName) => ` '${segmentName}': typeof import('./${segmentName || ROOT_SEGMENT_SCHEMA_NAME}.json');`).join('\n')}
|
|
22
21
|
};
|
|
23
22
|
export default fullSchema;`;
|
|
24
|
-
const
|
|
25
|
-
|
|
23
|
+
const tsContent = `// auto-generated
|
|
24
|
+
${segmentNames.map((segmentName, i) => `import segment${i} from './${segmentName || ROOT_SEGMENT_SCHEMA_NAME}.json';`).join('\n')}
|
|
25
|
+
const fullSchema = {
|
|
26
|
+
${segmentNames.map((segmentName, i) => ` '${segmentName}': segment${i},`).join('\n')}
|
|
27
|
+
};
|
|
28
|
+
export default fullSchema;`;
|
|
29
|
+
const jsAbsolutePath = path.join(schemaOutAbsolutePath, 'main.cjs');
|
|
30
|
+
const dTsAbsolutePath = path.join(schemaOutAbsolutePath, 'main.d.cts');
|
|
31
|
+
const tsAbsolutePath = path.join(schemaOutAbsolutePath, 'index.ts');
|
|
26
32
|
const existingJs = await fs.readFile(jsAbsolutePath, 'utf-8').catch(() => null);
|
|
27
33
|
const existingDTs = await fs.readFile(dTsAbsolutePath, 'utf-8').catch(() => null);
|
|
34
|
+
const existingTs = await fs.readFile(tsAbsolutePath, 'utf-8').catch(() => null);
|
|
28
35
|
await fs.mkdir(schemaOutAbsolutePath, { recursive: true });
|
|
29
|
-
if (existingJs !==
|
|
30
|
-
await fs.writeFile(jsAbsolutePath,
|
|
36
|
+
if (existingJs !== jsContent) {
|
|
37
|
+
await fs.writeFile(jsAbsolutePath, jsContent);
|
|
31
38
|
}
|
|
32
39
|
if (existingDTs !== dTsContent) {
|
|
33
40
|
await fs.writeFile(dTsAbsolutePath, dTsContent);
|
|
34
41
|
}
|
|
42
|
+
if (existingTs !== tsContent) {
|
|
43
|
+
await fs.writeFile(tsAbsolutePath, tsContent);
|
|
44
|
+
}
|
|
35
45
|
// Create JSON files (if not exist) with name [segmentName].json (where segmentName can include /, which means the folder structure can be nested)
|
|
36
46
|
await Promise.all(segmentNames.map(async (segmentName) => {
|
|
37
47
|
const { isCreated } = await writeOneSchemaFile({
|
|
@@ -9,7 +9,7 @@ export default async function getProjectInfo({ port: givenPort, clientOutDir, cw
|
|
|
9
9
|
const apiRoot = `${config.origin ?? ''}/${config.rootEntry}`;
|
|
10
10
|
const apiDir = path.join(srcRoot, 'app', config.rootEntry);
|
|
11
11
|
const schemaOutImportPath = path.relative(config.clientOutDir, config.schemaOutDir).replace(/\\/g, '/') + // windows fix
|
|
12
|
-
'/
|
|
12
|
+
'/main.cjs';
|
|
13
13
|
const log = getLogger(config.logLevel);
|
|
14
14
|
if (configAbsolutePaths.length > 1) {
|
|
15
15
|
log.warn(`Multiple config files found. Using the first one: ${configAbsolutePaths[0]}`);
|
package/dist/index.mjs
CHANGED
|
@@ -83,7 +83,7 @@ program
|
|
|
83
83
|
const { cwd, config, apiDir } = projectInfo;
|
|
84
84
|
const segments = await locateSegments({ dir: apiDir, config });
|
|
85
85
|
const schemaOutAbsolutePath = path.join(cwd, config.schemaOutDir);
|
|
86
|
-
const schemaImportUrl = pathToFileURL(path.join(schemaOutAbsolutePath, '
|
|
86
|
+
const schemaImportUrl = pathToFileURL(path.join(schemaOutAbsolutePath, 'main.cjs')).href;
|
|
87
87
|
const { default: segmentsSchema } = (await import(schemaImportUrl));
|
|
88
88
|
await generate({
|
|
89
89
|
projectInfo,
|