-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (41 loc) · 1.42 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
const frt = require('flow-remove-types');
const [ ,,path ] = process.argv;
const fs = require('fs-extra');
/**
* flowCleanUp
* - Create backup directory
* - Execute flow-remove-types on original director and put output to new directory
* - Merge original directory with flow-remove-types result
* - Remove backup director
* @param {?string} relative path to directory
*/
async function flowCleanUp(dir) {
if (typeof dir !== 'string' || !dir) {
throw new Error(`
Missing directory path.
$ flow-clean-up ./directory
`);
}
const fileInfo = await fs.lstat(dir);
if (!fileInfo.isDirectory()) {
throw new Error(`
Path is not directory
`);
}
const tmpDirPath = `tmp_${dir}`;
const unflowedDirPath = `unflowed_${dir}`;
console.log(`📂 Creating backup folder ${tmpDirPath}`);
await fs.copy(dir, `${tmpDirPath}`);
console.log('💪 tmp directory is ready!');
console.log(`💔 Remove flow types from ${tmpDirPath} to ${unflowedDirPath}`);
const { spawnSync } = require( 'child_process' );
const frtr = spawnSync( 'flow-remove-types', [ dir, '--out-dir', unflowedDirPath ] );
console.log(`💪 Created ${unflowedDirPath}!`);
await fs.copy(unflowedDirPath, dir, {
overwrite: true,
});
console.log('😀 Replaced... removing tmp files');
await fs.remove(unflowedDirPath);
await fs.remove(tmpDirPath);
};
flowCleanUp(path).catch(console.log).then(console.log.bind(console));