Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to merge ViewController and PayloadTransport classes #203

Merged
Prev Previous commit
Next Next commit
Fix clean script
  • Loading branch information
smithki committed Sep 2, 2021
commit 557aa124863226a8c7c69f991ddb281d8130259d
38 changes: 24 additions & 14 deletions scripts/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ async function cleanTestArtifacts() {
}

async function cleanNodeModules() {
await Promise.all([
execa('yarn', ['wsrun', '--parallel', '-r', 'rimraf', 'node_modules']),
execa('rimraf', ['node_modules']),
]);
await Promise.all([execa('rimraf', ['**/node_modules'])]);
}

const helpText = `
Expand Down Expand Up @@ -80,34 +77,47 @@ async function main() {
}

const enabledCleaners: string[] = [chalk.rgb(0, 255, 255)('dist')];
const promises: (() => Promise<any>)[] = [cleanDist];
const concurrent: (() => Promise<any>)[] = [cleanDist];
const sequential: (() => Promise<any>)[] = [];

if (cli.flags.cache) {
enabledCleaners.push(chalk.rgb(0, 255, 255)('cache'));
promises.push(cleanCache);
concurrent.push(cleanCache);
}

if (cli.flags.testArtifacts) {
enabledCleaners.push(chalk.rgb(0, 255, 255)('test artifacts'));
promises.push(cleanTestArtifacts);
concurrent.push(cleanTestArtifacts);
}

if (cli.flags.deps) {
enabledCleaners.push(chalk.rgb(0, 255, 255)('node_modules'));
promises.push(cleanNodeModules);
sequential.push(cleanNodeModules);
}

spinner.start(`Cleaning ${enabledCleaners.join(', ')}...`);

Promise.all(promises.map((p) => p()))
const handleError = (err: any) => {
spinner.fail('Failed!');
if (err) console.error(err);
process.exit(1);
}

await Promise.all(concurrent.map((p) => p()))
.catch(handleError)

await new Promise<void>((resolve, reject) => {
sequential
.reduce(async (curr, next) => {
return curr.then(next);
}, Promise.resolve())
.then(() => resolve())
.catch(reject);
})
.then(() => {
spinner.succeed(`Cleaned ${enabledCleaners.join(', ')}!`);
})
.catch((err) => {
spinner.fail('Failed!');
if (err) console.error(err);
process.exit(1);
});
.catch(handleError);
}

runAsyncProcess(main);