Skip to content

Commit f916af9

Browse files
authored
Merge pull request #221 from code-collabo/cleanup
Cleanup PR
2 parents 436a2e4 + a5089f0 commit f916af9

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed

dev/cleanup.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
// ------------------------------------

dev/developer.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { basename, resolve, dirname } from 'path';
2+
// file to get and save if user still has the
3+
// Initial settings...
4+
5+
const { chdir } = process;
6+
7+
// Dynamically get current the name of this file you are in, and its parent folder
8+
const developerJsFileName = basename(__filename/*, extname(__filename)*/);
9+
const cleanupFolderPath = dirname(new URL(import.meta.url).pathname);
10+
11+
// Change directory into the dynamically gotten parent folder, then extract folder name from path
12+
chdir(cleanupFolderPath);
13+
const cleanupFolderName = basename(resolve());
14+
15+
// CLI repo's original content config object
16+
export const repo = {
17+
hasOriginalContentOnly: true,
18+
originalContentList: [
19+
cleanupFolderName,
20+
'.all-contributorsrc',
21+
'.babelrc',
22+
'.editorconfig',
23+
'.eslintrc.json',
24+
'.git',
25+
'.github',
26+
'.gitignore',
27+
'.npmrc',
28+
'LICENSE',
29+
'README.md',
30+
'bin',
31+
'cleanup.js',
32+
'node_modules',
33+
'package-lock.json',
34+
'package.json',
35+
'spec',
36+
'src',
37+
'templates'
38+
],
39+
developerJsFileName,
40+
cleanupFolderName,
41+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"test": "npm-run-all --parallel test-message dev-test",
1717
"dev-test": "nodemon --exec babel-node spec/run.js",
1818
"CI-test": "babel-node spec/run.js",
19-
"test-message": "node -r esm src/customize/testMessage"
19+
"test-message": "node -r esm src/customize/testMessage",
20+
"cleanup": "node -r esm dev/cleanup.js"
2021
},
2122
"repository": {
2223
"type": "git",

0 commit comments

Comments
 (0)