Skip to content

Commit

Permalink
Run Flow per renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed May 17, 2018
1 parent 42b3fe0 commit 1172221
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 43 deletions.
19 changes: 10 additions & 9 deletions scripts/flow/createFlowConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

const chalk = require('chalk');
const fs = require('fs');
const mkdirp = require('mkdirp');
const {typedRenderers} = require('./typedRenderers');

const config = fs.readFileSync(__dirname + '/config/flowconfig');

function writeConfig(folder) {
mkdirp.sync(folder);

const disclaimer = `
# ---------------------------------------------------------------#
# NOTE: this file is generated. #
Expand All @@ -17,7 +21,7 @@ function writeConfig(folder) {
const configFile = folder + '/.flowconfig';
let oldConfig;
try {
oldConfig = fs.readFileSync(configFile);
oldConfig = fs.readFileSync(configFile).toString();
} catch (err) {
oldConfig = null;
}
Expand All @@ -26,18 +30,15 @@ ${disclaimer}
${config}
${disclaimer}
`.trim();

if (newConfig !== oldConfig) {
fs.writeFileSync(configFile, newConfig);
console.log(chalk.dim('Wrote a Flow config to ' + configFile));
}
}

// Write multiple configs in different folders
// so that we can run those checks in parallel if we want.
writeConfig(__dirname + '/dom');
writeConfig(__dirname + '/fabric');
writeConfig(__dirname + '/native');
writeConfig(__dirname + '/test');

console.log(
chalk.dim('Wrote the Flow configurations to ./scripts/flow/*/.flowconfig'),
);
typedRenderers.forEach(renderer => {
writeConfig(__dirname + '/' + renderer);
});
37 changes: 37 additions & 0 deletions scripts/flow/runFlow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

const chalk = require('chalk');
const spawn = require('child_process').spawn;
const extension = process.platform === 'win32' ? '.cmd' : '';

require('./createFlowConfigs');

async function runFlow(renderer, args) {
return new Promise(resolve => {
console.log(
'Running Flow for the ' + chalk.cyan(renderer) + ' renderer...',
);
spawn('../../../node_modules/.bin/flow' + extension, args, {
// Allow colors to pass through:
stdio: 'inherit',
// Use a specific renderer config:
cwd: process.cwd() + '/scripts/flow/' + renderer + '/',
}).on('close', function(code) {
if (code !== 0) {
console.error(
'Flow failed for the ' + chalk.red(renderer) + ' renderer',
);
console.log();
process.exit(code);
} else {
console.log(
'Flow passed for the ' + chalk.green(renderer) + ' renderer',
);
console.log();
resolve();
}
});
});
}

module.exports = runFlow;
3 changes: 3 additions & 0 deletions scripts/flow/typedRenderers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

exports.typedRenderers = ['dom', 'fabric', 'native', 'test'];
28 changes: 10 additions & 18 deletions scripts/tasks/flow-ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,17 @@

'use strict';

require('../flow/createFlowConfigs');

const spawn = require('child_process').spawn;

const extension = process.platform === 'win32' ? '.cmd' : '';
process.on('unhandledRejection', err => {
throw err;
});

// This script forces a complete check.
// Use it for the CI.
const runFlow = require('../flow/runFlow');
const {typedRenderers} = require('../flow/typedRenderers');

spawn('../../../node_modules/.bin/flow' + extension, ['check', '.'], {
// Allow colors to pass through
stdio: 'inherit',
cwd: process.cwd() + '/scripts/flow/dom/',
}).on('close', function(code) {
if (code !== 0) {
console.error('Flow failed');
} else {
console.log('Flow passed');
async function checkAll() {
for (let renderer of typedRenderers) {
await runFlow(renderer, ['check']);
}
}

process.exit(code);
});
checkAll();
33 changes: 17 additions & 16 deletions scripts/tasks/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@

'use strict';

require('../flow/createFlowConfigs');

const spawn = require('child_process').spawn;
process.on('unhandledRejection', err => {
throw err;
});

const extension = process.platform === 'win32' ? '.cmd' : '';
const runFlow = require('../flow/runFlow');
const {typedRenderers} = require('../flow/typedRenderers');

// This script is using `flow status` for a quick check with a server.
// Use it for local development.

spawn('../../../node_modules/.bin/flow' + extension, ['status', '.'], {
// Allow colors to pass through
stdio: 'inherit',
cwd: process.cwd() + '/scripts/flow/dom/',
}).on('close', function(code) {
if (code !== 0) {
console.error('Flow failed');
} else {
console.log('Flow passed');
}
const primaryRenderer = process.argv[2];
if (typedRenderers.indexOf(primaryRenderer) === -1) {
console.error(
'You need to pass a primary renderer to yarn flow. For example:'
);
typedRenderers.forEach(renderer => {
console.log(' * yarn flow ' + renderer);
});
console.log();
process.exit(1);
}

process.exit(code);
});
runFlow(primaryRenderer, ['status']);

0 comments on commit 1172221

Please sign in to comment.