Skip to content

Commit

Permalink
fix: Fix translation schemas resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Mar 25, 2024
1 parent 5afbd8d commit c9c5436
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions scripts/build.cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const {compilerOptions: {target}} = require('../tsconfig.json');

const commonConfig = {
tsconfig: './tsconfig.json',
// packages: 'external',
platform: 'node',
target: target,
format: 'cjs',
Expand Down Expand Up @@ -45,7 +44,10 @@ Promise.all(builds.map(([entries, outfile]) => {
};
}

currentConfig.external = Object.keys(dependencies);
currentConfig.external = [
...Object.keys(dependencies),
'@diplodoc/cli',
];

return esbuild.build(currentConfig);
})).then(() => {
Expand Down
11 changes: 7 additions & 4 deletions src/cmd/translate/utils/fs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {JSONValue, resolveRefs} from '@diplodoc/translation';
import {dirname, join} from 'node:path';
import {readFile, writeFile} from 'node:fs/promises';
import {dump, load} from 'js-yaml';
import {readFile, writeFile} from 'fs/promises';

const ROOT = dirname(require.resolve('@diplodoc/cli/package.json'));

function last<T>(array: T[]): T | undefined {
return array[array.length - 1];
Expand Down Expand Up @@ -74,15 +77,15 @@ export async function dumpFile(path: string, content: string | JSONValue) {
*/
export async function resolveSchemas(path: string) {
if (path.endsWith('toc.yaml')) {
return [await loadFile('schemas/toc-schema.yaml', false)];
return [await loadFile(join(ROOT, 'toc-schema.yaml'), false)];
}

if (path.endsWith('index.yaml')) {
return [await loadFile('schemas/leading-schema.yaml', false)];
return [await loadFile(join(ROOT, 'leading-schema.yaml'), false)];
}

if (path.endsWith('presets.yaml')) {
return [await loadFile('schemas/presets-schema.yaml', false)];
return [await loadFile(join(ROOT, 'presets-schema.yaml'), false)];
}

return [await loadFile('schemas/toc-schema.yaml', false)];
Expand Down

0 comments on commit c9c5436

Please sign in to comment.