Skip to content

Commit 14753dd

Browse files
build: run prettier on generated output (#343)
Co-authored-by: Ivan Goncharov <[email protected]>
1 parent a6596ae commit 14753dd

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

resources/build.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ const path = require('path');
55
const assert = require('assert');
66

77
const babel = require('@babel/core');
8+
const prettier = require('prettier');
9+
10+
const prettierConfig = JSON.parse(
11+
fs.readFileSync(require.resolve('../.prettierrc'), 'utf-8'),
12+
);
813

914
const { readdirRecursive, showDirStats } = require('./utils');
1015

@@ -20,10 +25,10 @@ if (require.main === module) {
2025
fs.mkdirSync(path.dirname(destPath), { recursive: true });
2126
if (filepath.endsWith('.js')) {
2227
const flowBody = '// @flow strict\n' + fs.readFileSync(srcPath, 'utf-8');
23-
fs.writeFileSync(destPath + '.flow', flowBody);
28+
writeGeneratedFile(destPath + '.flow', flowBody);
2429

2530
const cjs = babelBuild(srcPath, { envName: 'cjs' });
26-
fs.writeFileSync(destPath, cjs);
31+
writeGeneratedFile(destPath, cjs);
2732
} else if (filepath.endsWith('.d.ts')) {
2833
fs.copyFileSync(srcPath, destPath);
2934
}
@@ -81,3 +86,8 @@ function buildPackageJSON() {
8186

8287
return packageJSON;
8388
}
89+
90+
function writeGeneratedFile(filepath, body) {
91+
const formatted = prettier.format(body, { filepath, ...prettierConfig });
92+
fs.writeFileSync(filepath, formatted);
93+
}

0 commit comments

Comments
 (0)