-
Notifications
You must be signed in to change notification settings - Fork 10
/
flow-typed-update.js
38 lines (29 loc) · 1.63 KB
/
flow-typed-update.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* eslint-disable no-console */
import path from 'path';
import { execa } from 'execa';
import { createRequire } from 'module';
// TODO use project resolver
import { setup, getProjects, getPackageName } from './workspaces.js';
import { rootResolve, dirname } from './shared/utils.js';
const importMetaUrl = import/*:: ("") */.meta.url;
const require = createRequire(importMetaUrl);
const ROOT_RESOLVE = rootResolve();
const SHARED_RESOLVE = path.resolve(ROOT_RESOLVE, 'shared');
const FLOW_DEPS_RESOLVE = path.resolve(SHARED_RESOLVE, 'flow-deps');
const FLOW_DEPS_LINK_RESOLVE = path.resolve(ROOT_RESOLVE, 'flow-deps-modules');
const libdefDir = path.relative(dirname(importMetaUrl), path.resolve(SHARED_RESOLVE, 'flow-typed'));
const command = async (args, cwd) => execa('yarn', args, { stdio: 'inherit', cwd }); // TODO handle stderr
const flowTypedCmd = ['node', require.resolve('flow-typed'), 'update', '--libdefDir', libdefDir, '-s', '--skipFlowRestart', '-i', 'dev'];
console.log('Linking Flow Dependencies...');
await (command(['install'], FLOW_DEPS_RESOLVE));
await (command(['symlink-dir', path.resolve(ROOT_RESOLVE, FLOW_DEPS_RESOLVE, 'node_modules'), FLOW_DEPS_LINK_RESOLVE]));
console.log('\nChecking flow types for shared/flow-deps');
await (command([...flowTypedCmd, '-p', ROOT_RESOLVE], FLOW_DEPS_RESOLVE));
await (setup());
const projects = await (getProjects());
/* eslint-disable no-await-in-loop, no-restricted-syntax */
for (const [cwd] of projects) {
const name = await (getPackageName(cwd));
console.log(`\nChecking flow types for [${name}]`);
await (command(['workspace', name, 'exec', ...flowTypedCmd, '-p', ROOT_RESOLVE]));
}