2022-02-15 15:51:12 +00:00
|
|
|
/** @file Remove all smoke tests and may remove extra smoke-test dependencies from `yarn.lock`. */
|
|
|
|
|
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
import { execa } from 'execa';
|
2022-03-07 21:36:22 +00:00
|
|
|
import { polyfill } from '@astrojs/webapi';
|
2022-02-15 15:51:12 +00:00
|
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
import { promises as fs } from 'node:fs';
|
|
|
|
|
|
|
|
polyfill(globalThis, { exclude: 'window document' });
|
|
|
|
|
|
|
|
/* Configuration
|
|
|
|
/* ========================================================================== */
|
|
|
|
|
|
|
|
/** URL directory containing this current script. */
|
|
|
|
const scriptDir = new URL('./', import.meta.url);
|
|
|
|
|
|
|
|
/** URL directory containing the entire project. */
|
|
|
|
const rootDir = new URL('../../', import.meta.url);
|
|
|
|
|
|
|
|
/* Application
|
|
|
|
/* ========================================================================== */
|
|
|
|
|
|
|
|
/** Runs all smoke tests. */
|
|
|
|
async function run() {
|
2022-02-15 15:52:31 +00:00
|
|
|
const dirs = await getChildDirectories(scriptDir);
|
2022-02-15 15:51:12 +00:00
|
|
|
|
|
|
|
if (dirs.length) {
|
2022-02-15 15:52:31 +00:00
|
|
|
console.log();
|
2022-02-15 15:51:12 +00:00
|
|
|
|
|
|
|
for (const dir of await getChildDirectories(scriptDir)) {
|
|
|
|
console.log('🤖', 'Removing', dir.pathname.split('/').at(-1));
|
|
|
|
|
2022-02-15 15:52:31 +00:00
|
|
|
fs.rm(dir, { force: true, recursive: true });
|
2022-02-15 15:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-15 15:52:31 +00:00
|
|
|
console.log();
|
2022-02-15 15:51:12 +00:00
|
|
|
|
|
|
|
console.log('🤖', 'Resetting', 'yarn');
|
|
|
|
|
|
|
|
await execa('yarn', [], { cwd: fileURLToPath(rootDir), stdout: 'inherit', stderr: 'inherit' });
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Functionality
|
|
|
|
/* ========================================================================== */
|
|
|
|
|
|
|
|
/** Returns all child directories of the given directory. */
|
|
|
|
const getChildDirectories = async (/** @type {URL} */ dir) => {
|
|
|
|
/** @type {URL[]} */
|
|
|
|
const dirs = [];
|
|
|
|
|
|
|
|
for await (const dirent of await fs.opendir(dir)) {
|
|
|
|
if (dirent.isDirectory()) {
|
|
|
|
dirs.push(new URL(dirent.name, dir));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dirs;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Execution
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
run();
|