Skip to content

Commit

Permalink
build: improve pnpm run generate performance (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix authored Nov 9, 2024
1 parent 64ab321 commit 66f9fa1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
11 changes: 6 additions & 5 deletions scripts/config-generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writeFileSync } from 'node:fs';
import { writeFile } from 'node:fs/promises';
import path from 'node:path';
import type { Rule } from './traverse-rules.js';
import { camelCase, kebabCase, pascalCase } from 'scule';
Expand Down Expand Up @@ -40,7 +40,7 @@ export class ConfigGenerator {
return map;
}

public async generateRulesCode() {
public generateRulesCode() {
console.log(`Generating config, grouped by ${this.rulesGrouping}`);

const rulesGrouping = this.rulesGrouping;
Expand Down Expand Up @@ -78,9 +78,10 @@ export class ConfigGenerator {
return code;
}

public async generateRules(folderPath: string) {
const output = await this.generateRulesCode();
writeFileSync(
public async generateRules(folderPath: string): Promise<void> {
const output = this.generateRulesCode();

return writeFile(
path.resolve(folderPath, `configs-by-${this.rulesGrouping}.ts`),
output
);
Expand Down
16 changes: 10 additions & 6 deletions scripts/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ if (!fs.existsSync(generateFolder)) {
fs.mkdirSync(generateFolder);
}

for (const generator of [rulesGenerator, configGenerator]) {
generator.setRulesGrouping(RulesGrouping.SCOPE);
await generator.generateRules(generateFolder);
generator.setRulesGrouping(RulesGrouping.CATEGORY);
await generator.generateRules(generateFolder);
}
const promises = [rulesGenerator, configGenerator].map(
(generator) => async () => {
generator.setRulesGrouping(RulesGrouping.SCOPE);
await generator.generateRules(generateFolder);
generator.setRulesGrouping(RulesGrouping.CATEGORY);
await generator.generateRules(generateFolder);
}
);

await Promise.all(promises);
11 changes: 6 additions & 5 deletions scripts/rules-generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writeFileSync } from 'node:fs';
import { writeFile } from 'node:fs/promises';
import path from 'node:path';
import type { Rule } from './traverse-rules.js';
import { camelCase } from 'scule';
Expand Down Expand Up @@ -40,7 +40,7 @@ export class RulesGenerator {
return map;
}

public async generateRulesCode() {
public generateRulesCode() {
console.log(`Generating rules, grouped by ${this.rulesGrouping}`);

const rulesGrouping = this.rulesGrouping;
Expand Down Expand Up @@ -77,9 +77,10 @@ export class RulesGenerator {
return code;
}

public async generateRules(folderPath: string) {
const output = await this.generateRulesCode();
writeFileSync(
public generateRules(folderPath: string): Promise<void> {
const output = this.generateRulesCode();

return writeFile(
path.resolve(folderPath, `rules-by-${this.rulesGrouping}.ts`),
output
);
Expand Down

0 comments on commit 66f9fa1

Please sign in to comment.