Skip to content

Commit

Permalink
scripts(tools-scripts): 🛠️ scripts for sort Jest config
Browse files Browse the repository at this point in the history
  • Loading branch information
linbudu599 committed Sep 19, 2021
1 parent d8e339c commit 0343862
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ module.exports = {
"<rootDir>/packages/nx-plugin-esbuild",
"<rootDir>/packages/nx-plugin-workspace",
"<rootDir>/packages/nx-plugin-vite",
"<rootDir>/e2e/nx-plugin-vite-e2e",
"<rootDir>/packages/nx-plugin-snowpack",
"<rootDir>/e2e/nx-plugin-snowpack-e2e",
"<rootDir>/packages/nx-plugin-prisma",
"<rootDir>/e2e/nx-plugin-prisma-e2e",
"<rootDir>/packages/nx-plugin-swc",
"<rootDir>/e2e/nx-plugin-swc-e2e",
"<rootDir>/packages/esbuild-plugin-decorator",
"<rootDir>/packages/esbuild-plugin-alias-path",
"<rootDir>/packages/esbuild-plugin-node-externals",
Expand All @@ -26,6 +22,10 @@ module.exports = {
"<rootDir>/packages/snowpack-plugin-execa",
"<rootDir>/packages/snowpack-plugin-serve",
"<rootDir>/packages/snowpack-plugin-markdown-import",
"<rootDir>/e2e/nx-plugin-vite-e2e",
"<rootDir>/e2e/nx-plugin-snowpack-e2e",
"<rootDir>/e2e/nx-plugin-prisma-e2e",
"<rootDir>/e2e/nx-plugin-swc-e2e",
"<rootDir>/e2e/node-playground",
"<rootDir>/e2e/react-playground",
],
Expand Down
70 changes: 36 additions & 34 deletions scripts/sort-configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,49 +199,51 @@ function sortPluginInWorkspaceJson() {
}

function sortPluginInJestConfigFile() {
const jestConfigFileContent: {
const {
projects,
}: {
projects: string[];
} = require(jestConfigFilePath);

const nxProjects: string[] = [];
const esbuildProjects: string[] = [];
const viteProjects: string[] = [];
const snowpackProjects: string[] = [];
const rollupProjects: string[] = [];
const parcelProjects: string[] = [];
const otherProjects: string[] = [];

for (const project of jestConfigFileContent.projects.map((p) =>
p.replace('\\', '/')
)) {
if (project.includes('nx-plugin-')) {
nxProjects.push(project);
} else if (project.includes('esbuild-plugin-')) {
esbuildProjects.push(project);
} else if (project.includes('vite-plugin-')) {
viteProjects.push(project);
} else if (project.includes('snowpack-plugin-')) {
snowpackProjects.push(project);
} else if (project.includes('rollup-plugin-')) {
rollupProjects.push(project);
} else if (project.includes('parcel-plugin-')) {
parcelProjects.push(project);
const projectMap: Record<string, string[]> = {
packages: [],
playground: [],
};

for (const k of projects.map((p) => p.replace('\\', '/'))) {
const key = k.includes('/packages/')
? k.split('/packages/')[1].split('-')[0]
: 'playground';

if (k.endsWith('-app') || k.endsWith('-playground')) {
projectMap['playground'].push(k);
} else {
otherProjects.push(project);
if (!projectMap[key]) {
projectMap[key] = [];
}
projectMap[key].push(k);
}
}
const sortedProjectMap: Record<string, string[]> = {
nx: projectMap['nx'],
esbuild: projectMap['esbuild'],
snowpack: projectMap['snowpack'],
vite: projectMap['vite'] ?? [],
gatsby: projectMap['gatsby'] ?? [],
playground: projectMap['playground'],
...projectMap,
};

const sortedProjects = [
...nxProjects,
...esbuildProjects,
...viteProjects,
...snowpackProjects,
...rollupProjects,
...parcelProjects,
...otherProjects,
const tmpProjects: string[] = [
...sortedProjectMap['nx'],
...sortedProjectMap['esbuild'],
...sortedProjectMap['snowpack'],
...sortedProjectMap['vite'],
...sortedProjectMap['gatsby'],
...sortedProjectMap['playground'],
].map((p) => `"${p}"`);

const updatedContent = `module.exports = { projects:[${sortedProjects}] }`;
const updatedContent = `module.exports = { projects:[${tmpProjects}]}`;

fs.writeFileSync(
jestConfigFilePath,
Expand Down

0 comments on commit 0343862

Please sign in to comment.