Skip to content

Commit

Permalink
build: run prettier on generated output
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj committed Jun 22, 2021
1 parent a6596ae commit e9b6e42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions resources/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const path = require('path');
const assert = require('assert');

const babel = require('@babel/core');
const prettier = require('prettier');

const prettierConfig = JSON.parse(
fs.readFileSync(require.resolve('../.prettierrc'), 'utf-8'),
);

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

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

const cjs = babelBuild(srcPath, { envName: 'cjs' });
fs.writeFileSync(destPath, cjs);
writeGeneratedFile(destPath, cjs);
} else if (filepath.endsWith('.d.ts')) {
fs.copyFileSync(srcPath, destPath);
}
Expand Down Expand Up @@ -81,3 +86,8 @@ function buildPackageJSON() {

return packageJSON;
}

function writeGeneratedFile(filepath, body) {
const formatted = prettier.format(body, { filepath, ...prettierConfig });
fs.writeFileSync(filepath, formatted);
}

0 comments on commit e9b6e42

Please sign in to comment.