Skip to content

Commit a6fcaeb

Browse files
committed
Run Flow per renderer
1 parent 42b3fe0 commit a6fcaeb

File tree

5 files changed

+75
-43
lines changed

5 files changed

+75
-43
lines changed

scripts/flow/createFlowConfigs.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const chalk = require('chalk');
44
const fs = require('fs');
5+
const {typedRenderers} = require('./typedRenderers');
56

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

@@ -17,7 +18,7 @@ function writeConfig(folder) {
1718
const configFile = folder + '/.flowconfig';
1819
let oldConfig;
1920
try {
20-
oldConfig = fs.readFileSync(configFile);
21+
oldConfig = fs.readFileSync(configFile).toString();
2122
} catch (err) {
2223
oldConfig = null;
2324
}
@@ -26,18 +27,15 @@ ${disclaimer}
2627
${config}
2728
${disclaimer}
2829
`.trim();
30+
2931
if (newConfig !== oldConfig) {
3032
fs.writeFileSync(configFile, newConfig);
33+
console.log(chalk.dim('Wrote a Flow config to ' + configFile));
3134
}
3235
}
3336

3437
// Write multiple configs in different folders
3538
// so that we can run those checks in parallel if we want.
36-
writeConfig(__dirname + '/dom');
37-
writeConfig(__dirname + '/fabric');
38-
writeConfig(__dirname + '/native');
39-
writeConfig(__dirname + '/test');
40-
41-
console.log(
42-
chalk.dim('Wrote the Flow configurations to ./scripts/flow/*/.flowconfig'),
43-
);
39+
typedRenderers.forEach(renderer => {
40+
writeConfig(__dirname + '/' + renderer);
41+
});

scripts/flow/runFlow.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
const chalk = require('chalk');
4+
const spawn = require('child_process').spawn;
5+
const extension = process.platform === 'win32' ? '.cmd' : '';
6+
7+
require('./createFlowConfigs');
8+
9+
async function runFlow(renderer, args) {
10+
return new Promise(resolve => {
11+
console.log(
12+
'Running Flow for the ' + chalk.cyan(renderer) + ' renderer...',
13+
);
14+
console.log();
15+
spawn('../../../node_modules/.bin/flow' + extension, args, {
16+
// Allow colors to pass through:
17+
stdio: 'inherit',
18+
// Use a specific renderer config:
19+
cwd: process.cwd() + '/scripts/flow/' + renderer + '/',
20+
}).on('close', function(code) {
21+
if (code !== 0) {
22+
console.error(
23+
'Flow failed for the ' + chalk.red(renderer) + ' renderer',
24+
);
25+
console.log();
26+
process.exit(code);
27+
} else {
28+
console.log(
29+
'Flow passed for the ' + chalk.green(renderer) + ' renderer',
30+
);
31+
console.log();
32+
resolve();
33+
}
34+
});
35+
});
36+
}
37+
38+
module.exports = runFlow;

scripts/flow/typedRenderers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
exports.typedRenderers = ['dom', 'fabric', 'native', 'test'];

scripts/tasks/flow-ci.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,17 @@
77

88
'use strict';
99

10-
require('../flow/createFlowConfigs');
11-
12-
const spawn = require('child_process').spawn;
13-
14-
const extension = process.platform === 'win32' ? '.cmd' : '';
10+
process.on('unhandledRejection', err => {
11+
throw err;
12+
});
1513

16-
// This script forces a complete check.
17-
// Use it for the CI.
14+
const runFlow = require('../flow/runFlow');
15+
const {typedRenderers} = require('../flow/typedRenderers');
1816

19-
spawn('../../../node_modules/.bin/flow' + extension, ['check', '.'], {
20-
// Allow colors to pass through
21-
stdio: 'inherit',
22-
cwd: process.cwd() + '/scripts/flow/dom/',
23-
}).on('close', function(code) {
24-
if (code !== 0) {
25-
console.error('Flow failed');
26-
} else {
27-
console.log('Flow passed');
17+
async function checkAll() {
18+
for (let renderer of typedRenderers) {
19+
await runFlow(renderer, ['check']);
2820
}
21+
}
2922

30-
process.exit(code);
31-
});
23+
checkAll();

scripts/tasks/flow.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,26 @@
77

88
'use strict';
99

10-
require('../flow/createFlowConfigs');
11-
12-
const spawn = require('child_process').spawn;
10+
process.on('unhandledRejection', err => {
11+
throw err;
12+
});
1313

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

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

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

30-
process.exit(code);
31-
});
32+
runFlow(primaryRenderer, ['status']);

0 commit comments

Comments
 (0)