Skip to content

Commit

Permalink
chore: parallel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
molant committed Oct 4, 2021
1 parent 93473e9 commit 5cfc0d1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 9 deletions.
12 changes: 6 additions & 6 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ module.exports = {
i18n: {
defaultLocale: 'en',
locales: [
// 'de-de',
'en',
'de-de',
'es-es',
// 'fr-fr',
// 'ja-jp',
// 'pt-br',
// 'ru-ru',
// 'zh-cn',
'fr-fr',
'ja-jp',
'pt-br',
'ru-ru',
'zh-cn',
],
},
themeConfig: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"update-l10n-sources": "node scripts/update-l10n-sources.js",
"lint": "prettier -c ./scripts/**/*.js",
"test": "yarn lint && jest",
"prebuild": "node ./scripts/pre-build.js",
"pre-build": "node ./scripts/pre-build.js",
"process-docs-changes": "node ./scripts/process-docs-changes.js",
"update-pinned-version": "node ./scripts/update-pinned-version.js",
"prepare": "husky install"
Expand Down Expand Up @@ -69,6 +69,7 @@
"json5": "^2.2.0",
"latest-version": "^5.1.0",
"make-dir": "^3.1.0",
"p-limit": "^3.1.0",
"prettier": "^2.2.1",
"tar-stream": "^2.2.0",
"unist-util-visit-parents": "^3.1.1"
Expand Down
45 changes: 45 additions & 0 deletions scripts/parallel-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const plimit = require('p-limit');
const limit = plimit(1);

const { execute } = require('./utils/execute');
const { prebuild } = require('./pre-build');
const {
i18n: { locales },
} = require('../docusaurus.config');

const processLocale = (locale) => {
return limit(async () => {
const start = Date.now();
const outdir = locale.includes('-') ? `--out-dir build/${locale}` : '';
await execute(`yarn build --locale ${locale} ${outdir}`);
console.log(`Locale ${locale} finished in ${(Date.now() - start) / 1000}s`);
});
};

const start = async () => {
const start = Date.now();

await prebuild();

console.log('Building the locales');

const parallelLocales = locales.filter(locale => locale !== 'en');

await processLocale('en');

const localeProcesses = parallelLocales.map((locale) => {
return processLocale(locale);
});

await Promise.all(localeProcesses);

console.log(`Process finished in ${(Date.now() - start) / 1000}s`);
};

process.on('unhandledRejection', (e) => {
console.error(e);

process.exit(-1);
});

start();
10 changes: 9 additions & 1 deletion scripts/pre-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ const start = async (source) => {
console.log('Updating sidebar.js');
await createSidebar('docs', path.join(process.cwd(), 'sidebars.js'));

// All this should be replaced with the crowdin CLI and just download once
// everything this repo is the source of truth
console.log('Downloading translations');
const locales = await downloadTranslations(I18N_FOLDER);

Expand Down Expand Up @@ -117,4 +119,10 @@ process.on('unhandledRejection', (error) => {
process.exit(1);
});

start(process.argv[2]);
if (require.main === module) {
start(process.argv[2]);
}

module.exports = {
prebuild: start,
};
2 changes: 1 addition & 1 deletion scripts/tasks/add-frontmatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const descriptionFromContent = (content) => {

// The content of structures is often only bullet lists and no general description
if (trimmedLine.startsWith('#') || trimmedLine.startsWith('*')) {
if (subHeader) {
if (subHeader && description.length > 0) {
return cleanUpMarkdown(description.trim());
} else {
subHeader = true;
Expand Down

0 comments on commit 5cfc0d1

Please sign in to comment.