Skip to content

Commit cd6f3f4

Browse files
authored
Merge pull request #220 from code-collabo/qa-ing
QA-ing next fixes for new release
2 parents 5460a51 + 433c06c commit cd6f3f4

File tree

5 files changed

+159
-46
lines changed

5 files changed

+159
-46
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 chalk from 'chalk';
3+
import { repo } from './developer';
4+
const { cwd, chdir } = process;
5+
6+
// -------------------------------------------------------------------------------------------------
7+
// TODO 1 (after CLI upgrade): Configure cleanup to run using node-mongo command i.e. "node-mongo cleanup" not "npm run cleanup"
8+
// 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)
9+
// update package.json cleanup script dynamically with the cleanup file path.
10+
// This means you will have to get the cleanup file name/path dynamically too...
11+
// Or... (instead) should cleanup script be handled a pre-commit hook or pre-push hook or something? - We'll see...
12+
// -------------------------------------------------------------------------------------------------
13+
14+
// cd into repo root
15+
chdir('../');
16+
17+
// use repo root
18+
const rootDir = cwd();
19+
20+
// return all files and folders in repo root i.e. original + node-mongo generated
21+
const repoContent = readdirSync(rootDir, (err, filesAndFolders) => {
22+
if (err) {
23+
throw err;
24+
}
25+
26+
return filesAndFolders;
27+
});
28+
29+
const filterContentToGetTheOnesGeneratedByCLI = repoContent.reduce((acc, curr) => {
30+
if (!repo.originalContentList.includes(curr)) {
31+
acc.push(curr);
32+
}
33+
return acc;
34+
}, []);
35+
36+
// delete folders generated by CLI
37+
if (filterContentToGetTheOnesGeneratedByCLI.length) {
38+
try {
39+
filterContentToGetTheOnesGeneratedByCLI.map(folder => {
40+
console.log(chalk.green(`✔ ${folder} folder deleted successfully`));
41+
return rmdirSync(folder, { recursive: true, force: true });
42+
});
43+
console.log('');
44+
} catch (err) {
45+
console.log(chalk.red(err));
46+
}
47+
} else {
48+
console.log(chalk.yellowBright('ℹ There are no folders to delete yet. Generate folder(s) using the "node-mongo" command, then run the cleanup script after you are done developing, and are ready to add and push your changes/fixes.\n'));
49+
}
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-lock.json

Lines changed: 43 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "src/cli.js",
66
"bin": {
77
"@code-collabo/node-mongo-cli": "bin/create-node-mongo-project",
8-
"node-mongo": "bin/create-node-mongo-project"
8+
"node-mongo": "bin/create-node-mongo-project",
9+
"nmgo": "bin/create-node-mongo-project"
910
},
1011
"scripts": {
1112
"prestart": "node -r esm src/customize/startMessage.js",
@@ -15,7 +16,8 @@
1516
"test": "npm-run-all --parallel test-message dev-test",
1617
"dev-test": "nodemon --exec babel-node spec/run.js",
1718
"CI-test": "babel-node spec/run.js",
18-
"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"
1921
},
2022
"repository": {
2123
"type": "git",

src/help.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,25 @@ console.log(
66
Usage:
77
node-mongo <folder_name> <template>
88
9+
Usage (for shorter command alternative):
10+
nmgo <folder_name> <template>
11+
912
Command:
1013
node-mongo
1114
15+
Command (shorter command alternative):
16+
nmgo
17+
1218
Arguments:
1319
<folder_name> Replace this with your folder name
1420
<template> Available templates: ts, esm and cjs
1521
1622
Usage example:
1723
node-mongo test-folder ts
1824
25+
Usage example (for shorter command alternative):
26+
nmgo test-folder ts
27+
1928
The above example bootstraps the ts template i.e.
2029
the typescript template into a folder named test-folder.
2130
@@ -48,9 +57,13 @@ folder name used already exists.
4857
export const notRecognised = () => {
4958
console.log(
5059
`
51-
Flag(s) not recognised. Use the help command below for more info:
60+
Flag(s) not recognised. Use any of the help command below for more info:
61+
62+
Help command:
63+
node-mongo --help
5264
53-
node-mongo --help`
65+
Help command (for shorter command alternative):
66+
nmgo --help`
5467
);
5568
}
5669

0 commit comments

Comments
 (0)