cleanup.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /** @file Remove all smoke tests and may remove extra smoke-test dependencies from `pnpm-lock.yaml`. */
  2. // @ts-check
  3. import { execa } from 'execa';
  4. import { promises as fs } from 'node:fs';
  5. import { fileURLToPath } from 'node:url';
  6. /* Configuration
  7. /* ========================================================================== */
  8. /** URL directory containing this current script. */
  9. const scriptDir = new URL('./', import.meta.url);
  10. /** URL directory containing the entire project. */
  11. const rootDir = new URL('../../', import.meta.url);
  12. /* Application
  13. /* ========================================================================== */
  14. /** Runs all smoke tests. */
  15. async function run() {
  16. const dirs = await getChildDirectories(scriptDir);
  17. if (dirs.length) {
  18. console.log();
  19. for (const dir of await getChildDirectories(scriptDir)) {
  20. console.log('🤖', 'Removing', dir.pathname.split('/').at(-1));
  21. fs.rm(dir, { force: true, recursive: true });
  22. }
  23. }
  24. console.log();
  25. console.log('🤖', 'Resetting', 'pnpm');
  26. await execa('pnpm', ['install'], { cwd: fileURLToPath(rootDir), stdout: 'inherit', stderr: 'inherit' });
  27. }
  28. /* Functionality
  29. /* ========================================================================== */
  30. /** Returns all child directories of the given directory. */
  31. const getChildDirectories = async (/** @type {URL} */ dir) => {
  32. /** @type {URL[]} */
  33. const dirs = [];
  34. for await (const dirent of await fs.opendir(dir)) {
  35. if (dirent.isDirectory()) {
  36. dirs.push(new URL(dirent.name, dir));
  37. }
  38. }
  39. return dirs;
  40. };
  41. /* Execution
  42. /* -------------------------------------------------------------------------- */
  43. run();