|
| 1 | +import { readdirSync, rmdirSync } from 'fs'; |
| 2 | +import { repo } from './developer'; |
| 3 | +const { cwd, chdir } = process; |
| 4 | + |
| 5 | +// ------------------------------------------------------------------------------------------------- |
| 6 | +// TODO 1 (after CLI upgrade): Configure cleanup to run using node-mongo command i.e. "node-mongo cleanup" not "npm run cleanup" |
| 7 | +// TODO 2 (if possible): (I don't think you will need this TODO when this is done using the "node-mongo cleanup" command - or it might need slight modification) |
| 8 | + // update package.json cleanup script dynamically with the cleanup file path. |
| 9 | + // This means you will have to get the cleanup file name/path dynamically too... |
| 10 | +// Or... (instead) should cleanup script be handled a pre-commit hook or pre-push hook or something? - We'll see... |
| 11 | +// ------------------------------------------------------------------------------------------------- |
| 12 | + |
| 13 | +// cd into repo root |
| 14 | +chdir('../'); |
| 15 | + |
| 16 | +// use repo root |
| 17 | +const rootDir = cwd(); |
| 18 | + |
| 19 | +// return all files and folders in repo root i.e. original + node-mongo generated |
| 20 | + const repoContent = readdirSync(rootDir, (err, filesAndFolders) => { |
| 21 | + if (err) { |
| 22 | + throw err; |
| 23 | + } |
| 24 | + |
| 25 | + return filesAndFolders; |
| 26 | +}); |
| 27 | + |
| 28 | +console.log(repoContent); |
| 29 | + |
| 30 | +const filterContentToGetTheOnesGeneratedByCLI = repoContent.reduce((acc, curr) => { |
| 31 | + if (!repo.originalContentList.includes(curr)) { |
| 32 | + acc.push(curr); |
| 33 | + } |
| 34 | + return acc; |
| 35 | +}, []); |
| 36 | + |
| 37 | +console.log(filterContentToGetTheOnesGeneratedByCLI); |
| 38 | + |
| 39 | +// delete folders generated by CLI |
| 40 | +try { |
| 41 | + filterContentToGetTheOnesGeneratedByCLI.map(folder => { |
| 42 | + console.log(`${folder} folder deleted successfully`); |
| 43 | + return rmdirSync(folder, { recursive: true, force: true }); |
| 44 | + }); |
| 45 | +} catch (err) { |
| 46 | + console.log(err); |
| 47 | +} |
| 48 | + |
| 49 | +console.log(repoContent); |
| 50 | + |
| 51 | +// ------------------------------------ |
| 52 | +// TODO: Write another script at the end of this file |
| 53 | +// that updates this repoContent list back when done. |
| 54 | +// Is this TODO even needed? - We'll see. For now the |
| 55 | +// solution ending here works fine. |
| 56 | +// ------------------------------------ |
0 commit comments