2019-06-06 00:59:10 +02:00
|
|
|
import fs from 'fs';
|
2020-02-13 13:20:14 +01:00
|
|
|
import { spawn } from 'child_process';
|
2019-06-06 00:59:10 +02:00
|
|
|
import trash from 'trash';
|
2019-06-06 01:57:31 +02:00
|
|
|
import del from 'del';
|
2019-06-06 00:59:10 +02:00
|
|
|
|
2019-07-01 03:01:26 +03:00
|
|
|
const logger = console;
|
|
|
|
|
2019-06-06 00:59:10 +02:00
|
|
|
fs.writeFileSync('reset.log', '');
|
|
|
|
|
|
|
|
// let results = [];
|
|
|
|
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) {
|
2019-06-17 15:54:31 +08:00
|
|
|
if (
|
|
|
|
uri.match(/node_modules/) ||
|
|
|
|
uri.match(/dist/) ||
|
2020-02-19 01:07:18 -08:00
|
|
|
uri.match(/ts3\.5/) ||
|
2019-06-17 15:54:31 +08:00
|
|
|
uri.match(/\.cache/) ||
|
|
|
|
uri.match(/dll/)
|
|
|
|
) {
|
2019-06-06 01:57:31 +02:00
|
|
|
del(uri).then(() => {
|
2019-07-01 03:01:26 +03:00
|
|
|
logger.log(`deleted ${uri}`);
|
2019-06-06 01:57:31 +02:00
|
|
|
});
|
|
|
|
} else {
|
2019-06-16 21:07:37 +02:00
|
|
|
trash(uri)
|
|
|
|
.then(() => {
|
2019-07-01 03:01:26 +03:00
|
|
|
logger.log(`trashed ${uri}`);
|
2019-06-16 21:07:37 +02:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2019-07-01 03:01:26 +03:00
|
|
|
logger.log('failed to trash, will try permanent delete');
|
2019-06-16 21:07:37 +02:00
|
|
|
trash(uri);
|
|
|
|
});
|
2019-06-06 01:57:31 +02:00
|
|
|
}
|
2019-06-06 00:59:10 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
fs.appendFile('reset.log', data, err => {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
cleaningProcess.on('exit', code => {
|
|
|
|
if (code === 0) {
|
2019-07-01 03:01:26 +03:00
|
|
|
logger.log('all went well, files are being trashed now');
|
2019-06-06 00:59:10 +02:00
|
|
|
} else {
|
2019-07-01 03:01:26 +03:00
|
|
|
logger.error(code);
|
2019-06-06 00:59:10 +02:00
|
|
|
}
|
|
|
|
});
|