Skip to content

Commit

Permalink
fix(scoped-libs): 🐛 resolve scoped libs path
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharkazaz committed Oct 28, 2021
1 parent 725e318 commit c7a701f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion libs/transloco-scoped-libs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}
],
"dependencies": {
"@ngneat/transloco-utils": "^3.0.1",
"@ngneat/transloco-utils": "^3.0.2",
"chalk": "^4.1.2",
"chokidar": "^3.5.2",
"command-line-args": "^5.1.1",
Expand Down
2 changes: 1 addition & 1 deletion libs/transloco-scoped-libs/src/lib/scoped-libs.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export interface SetTranslationOptions
}

export interface CopyScopeTranslationsOptions extends CopyScopeOptions {
fileExtention: `${string}json`;
fileExtension: `${string}json`;
}
24 changes: 17 additions & 7 deletions libs/transloco-scoped-libs/src/lib/transloco-scoped-libs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import glob from 'glob';
import chokidar from 'chokidar';
import fsExtra from 'fs-extra';
import {
coerceArray,
cutPath,
getPackageJson,
insertPathToGitIgnore,
isString,
readJson,
writeJson,
} from './scoped-libs.utils';
Expand All @@ -16,6 +18,7 @@ import {
ScopedLibsOptions,
SetTranslationOptions,
} from './scoped-libs.types';
import { TranslocoGlobalConfig } from '@ngneat/transloco-utils';

const libSrcExample = `
e.g:
Expand Down Expand Up @@ -129,8 +132,11 @@ export default function run({
}
}

function coerceScopedLibs(scopedLibs: string[], defaultPath: string) {
if (!scopedLibs || scopedLibs.length === 0) {
function coerceScopedLibs(
scopedLibs: TranslocoGlobalConfig['scopedLibs'],
defaultPath: TranslocoGlobalConfig['rootTranslationsPath']
) {
if (!scopedLibs?.length) {
console.log(
chalk.red(
'Please add "scopedLibs" configuration in transloco.config.js file.',
Expand All @@ -141,17 +147,21 @@ function coerceScopedLibs(scopedLibs: string[], defaultPath: string) {
return [];
}

return scopedLibs.map((lib) => ({ src: lib, dist: [defaultPath] }));
return scopedLibs.map((lib) => {
return isString(lib)
? { src: lib, dist: [defaultPath] }
: { ...lib, dist: coerceArray(lib.dist) };
});
}

function copyScopes(options: CopyScopeOptions) {
const resolvedOptions: CopyScopeTranslationsOptions = {
...options,
fileExtention: 'json',
fileExtension: 'json',
};

if (resolvedOptions.strategy === 'join') {
resolvedOptions.fileExtention = 'vendor.json';
resolvedOptions.fileExtension = 'vendor.json';
} else {
resolvedOptions.outputDir = path.join(
resolvedOptions.outputDir,
Expand All @@ -166,7 +176,7 @@ function copyScopes(options: CopyScopeOptions) {
function copyScopeTranslationFiles(options: CopyScopeTranslationsOptions) {
const {
files,
fileExtention,
fileExtension,
outputDir,
skipGitIgnoreUpdate,
strategy,
Expand All @@ -177,7 +187,7 @@ function copyScopeTranslationFiles(options: CopyScopeTranslationsOptions) {
translationFilePath = path.normalize(translationFilePath);
const [lang] = path.basename(translationFilePath).split('.');

const fileName = `${lang}.${fileExtention}`;
const fileName = `${lang}.${fileExtension}`;
const outputFilePath = path.join(outputDir, fileName);

console.log(
Expand Down

0 comments on commit c7a701f

Please sign in to comment.