Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async function run(rootDir, options = {}) {
let ignoredAppFiles = config.ignoredAppFiles || [];
let customHelpers = config.helpers || [];
let includeGtsExtension = userExtensions.includes('.gts');
let externalTemplatesPaths = config.externalTemplatesPaths || [];

userExtensions = userExtensions.map(extension =>
extension.startsWith('.') ? extension : `.${extension}`
Expand All @@ -48,13 +49,18 @@ async function run(rootDir, options = {}) {
helpers: customHelpers,
};

log(`${step(1)} 🔍 Finding JS and HBS files...`);
log(`${step(1)} 🔍 Finding files containing translations...`);
let appFiles = await findAppFiles(rootDir, userExtensions, ignoredAppFiles);
let inRepoFiles = await findInRepoFiles(rootDir, userExtensions);
let files = [...appFiles, ...inRepoFiles];

log(`${step(2)} 🔍 Searching for translations keys in JS and HBS files...`);
let usedTranslationKeys = await analyzeFiles(rootDir, files, analyzeOptions);
let externalFiles = await findExternalFiles(rootDir, externalTemplatesPaths, userExtensions);


log(`${step(2)} 🔍 Searching for translations keys in your files...`);
let localTranslationKeys = await analyzeFiles(rootDir, files, analyzeOptions);
let externalTranslationKeys = await analyzeFiles('', externalFiles, analyzeOptions);
let usedTranslationKeys = new Map([...localTranslationKeys, ...externalTranslationKeys]);

log(`${step(3)} ⚙️ Checking for unused translations...`);

Expand Down Expand Up @@ -173,6 +179,23 @@ async function findInRepoFiles(cwd, userExtensions) {
return globby(joinPaths(inRepoFolders, pathsWithExtensions), { cwd });
}

async function findExternalFiles(cwd, externalTemplatesPaths, userExtensions) {
if (externalTemplatesPaths.length === 0) return [];

let baseUrl = path.join(cwd.split('qonto-web')[0], "qonto-web");
let extensions = [...DEFAULT_EXTENSIONS, ...userExtensions];

let files = []
for (let externalTemplatesPath of externalTemplatesPaths) {
let templatePath = path.join(baseUrl, externalTemplatesPath);
let pathsWithExtensions = extensions.map(extension => `{app,src}/**/*${extension}`);

let fullPaths = await globby(joinPaths(templatePath, pathsWithExtensions))
files.push(...fullPaths);
}
return files;
}

async function findOwnTranslationFiles(cwd, config) {
return findTranslationFiles(cwd, ['', ...findInRepoPaths(cwd)], config);
}
Expand Down