Skip to content

Commit b2caf98

Browse files
committed
Add support for external templates
1 parent 9375ef6 commit b2caf98

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

index.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ async function run(rootDir, options = {}) {
3636
let ignoredAppFiles = config.ignoredAppFiles || [];
3737
let customHelpers = config.helpers || [];
3838
let includeGtsExtension = userExtensions.includes('.gts');
39+
let externalTemplatesPaths = config.externalTemplatesPaths || [];
3940

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

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

56-
log(`${step(2)} 🔍 Searching for translations keys in JS and HBS files...`);
57-
let usedTranslationKeys = await analyzeFiles(rootDir, files, analyzeOptions);
57+
let externalFiles = await findExternalFiles(rootDir, externalTemplatesPaths, userExtensions);
58+
59+
60+
log(`${step(2)} 🔍 Searching for translations keys in your files...`);
61+
let localTranslationKeys = await analyzeFiles(rootDir, files, analyzeOptions);
62+
let externalTranslationKeys = await analyzeFiles('', externalFiles, analyzeOptions);
63+
let usedTranslationKeys = new Map([...localTranslationKeys, ...externalTranslationKeys]);
5864

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

@@ -173,6 +179,23 @@ async function findInRepoFiles(cwd, userExtensions) {
173179
return globby(joinPaths(inRepoFolders, pathsWithExtensions), { cwd });
174180
}
175181

182+
async function findExternalFiles(cwd, externalTemplatesPaths, userExtensions) {
183+
if (externalTemplatesPaths.length === 0) return [];
184+
185+
let baseUrl = path.join(cwd.split('qonto-web')[0], "qonto-web");
186+
let extensions = [...DEFAULT_EXTENSIONS, ...userExtensions];
187+
188+
let files = []
189+
for (let externalTemplatesPath of externalTemplatesPaths) {
190+
let templatePath = path.join(baseUrl, externalTemplatesPath);
191+
let pathsWithExtensions = extensions.map(extension => `{app,src}/**/*${extension}`);
192+
193+
let fullPaths = await globby(joinPaths(templatePath, pathsWithExtensions))
194+
files.push(...fullPaths);
195+
}
196+
return files;
197+
}
198+
176199
async function findOwnTranslationFiles(cwd, config) {
177200
return findTranslationFiles(cwd, ['', ...findInRepoPaths(cwd)], config);
178201
}

0 commit comments

Comments
 (0)