Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: run prettier on generated output #343

Merged
merged 3 commits into from
Jun 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}