|
| 1 | +import fsExtra from 'fs-extra' |
| 2 | + |
| 3 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)) |
| 4 | +const here = (...p) => path.join(__dirname, ...p) |
| 5 | + |
| 6 | +const workshopRoot = here('..') |
| 7 | +const exercises = (await readDir(here('../exercises'))) |
| 8 | + .map(name => here(`../exercises/${name}`)) |
| 9 | + .filter(filepath => fs.statSync(filepath).isDirectory()) |
| 10 | +const exerciseApps = ( |
| 11 | + await Promise.all( |
| 12 | + exercises.flatMap(async exercise => { |
| 13 | + return (await readDir(exercise)) |
| 14 | + .filter(dir => { |
| 15 | + return /(problem|solution)/.test(dir) |
| 16 | + }) |
| 17 | + .map(dir => path.join(exercise, dir)) |
| 18 | + }), |
| 19 | + ) |
| 20 | +).flat() |
| 21 | + |
| 22 | +const appsWithPkgJson = exerciseApps.filter(app => { |
| 23 | + const pkgjsonPath = path.join(app, 'package.json') |
| 24 | + return exists(pkgjsonPath) |
| 25 | +}) |
| 26 | + |
| 27 | +const tsconfig = { |
| 28 | + files: [], |
| 29 | + exclude: ['node_modules'], |
| 30 | + references: appsWithPkgJson.map(a => ({ |
| 31 | + path: relativeToWorkshopRoot(a).replace(/\\/g, '/'), |
| 32 | + })), |
| 33 | +} |
| 34 | +const written = await writeIfNeeded( |
| 35 | + path.join(workshopRoot, 'tsconfig.json'), |
| 36 | + `${JSON.stringify(tsconfig, null, 2)}\n`, |
| 37 | + { parser: 'json' }, |
| 38 | +) |
| 39 | + |
| 40 | +if (written) { |
| 41 | + // delete node_modules/.cache |
| 42 | + const cacheDir = path.join(workshopRoot, 'node_modules', '.cache') |
| 43 | + if (exists(cacheDir)) { |
| 44 | + await fs.promises.rm(cacheDir, { recursive: true }) |
| 45 | + } |
| 46 | + console.log('all fixed up') |
| 47 | +} |
0 commit comments