Skip to content

Commit

Permalink
resources: Move mkdirSync into writeGeneratedFile (#3697)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored Aug 15, 2022
1 parent 30d51c3 commit 743f42b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
1 change: 0 additions & 1 deletion resources/build-deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ for (const filepath of srcFiles) {
transformed.dispose();

const destPath = path.join('./denoDist', filepath);
fs.mkdirSync(path.dirname(destPath), { recursive: true });
writeGeneratedFile(destPath, newContent);
}
}
Expand Down
5 changes: 1 addition & 4 deletions resources/build-npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ assert(
);

const tsHost = ts.createCompilerHost(tsOptions);
tsHost.writeFile = (filepath, body) => {
fs.mkdirSync(path.dirname(filepath), { recursive: true });
writeGeneratedFile(filepath, body);
};
tsHost.writeFile = writeGeneratedFile;

const tsProgram = ts.createProgram(['src/index.ts'], tsOptions, tsHost);
const tsResult = tsProgram.emit(undefined, undefined, undefined, undefined, {
Expand Down
10 changes: 3 additions & 7 deletions resources/diff-npm-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';

import { exec, execOutput, localRepoPath } from './utils';
import { exec, execOutput, localRepoPath, writeGeneratedFile } from './utils';

const LOCAL = 'local';
const tmpDir = path.join(os.tmpdir(), 'graphql-js-npm-diff');
Expand Down Expand Up @@ -32,12 +32,8 @@ const diff = execOutput(`npm diff --diff=${fromPackage} --diff=${toPackage}`);
if (diff === '') {
console.log('No changes found!');
} else {
const reportsDir = localRepoPath('reports');
if (!fs.existsSync(reportsDir)) {
fs.mkdirSync(reportsDir);
}
const reportPath = path.join(reportsDir, 'npm-dist-diff.html');
fs.writeFileSync(reportPath, generateReport(diff));
const reportPath = localRepoPath('reports', 'npm-dist-diff.html');
writeGeneratedFile(reportPath, generateReport(diff));
console.log('Report saved to: ', reportPath);
}

Expand Down
1 change: 1 addition & 0 deletions resources/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const prettierConfig = JSON.parse(

export function writeGeneratedFile(filepath: string, body: string): void {
const formatted = prettier.format(body, { filepath, ...prettierConfig });
fs.mkdirSync(path.dirname(filepath), { recursive: true });
fs.writeFileSync(filepath, formatted);
}

Expand Down

0 comments on commit 743f42b

Please sign in to comment.