forked from storybookjs/storybook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset.js
62 lines (57 loc) · 1.39 KB
/
reset.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import fs from 'fs';
import { remove } from 'fs-extra';
import { spawn } from 'child_process';
import trash from 'trash';
const logger = console;
fs.writeFileSync('reset.log', '');
const cleaningProcess = spawn('git', [
'clean',
'-xdf',
'-n',
'--exclude=".vscode"',
'--exclude=".idea"',
]);
cleaningProcess.stdout.on('data', (data) => {
if (data && data.toString()) {
const l = data
.toString()
.split(/\n/)
.forEach((i) => {
const [, uri] = i.match(/Would remove (.*)$/) || [];
if (uri) {
if (
uri.match(/node_modules/) ||
uri.match(/dist/) ||
uri.match(/ts3\.4/) ||
uri.match(/\.cache/) ||
uri.match(/dll/)
) {
remove(uri).then(() => {
logger.log(`deleted ${uri}`);
});
} else {
trash(uri)
.then(() => {
logger.log(`trashed ${uri}`);
})
.catch((e) => {
logger.log('failed to trash, will try permanent delete');
remove(uri);
});
}
}
});
}
fs.appendFile('reset.log', data, (err) => {
if (err) {
throw err;
}
});
});
cleaningProcess.on('exit', (code) => {
if (code === 0) {
logger.log('all went well, files are being trashed now');
} else {
logger.error(code);
}
});