Skip to content

Commit f9e14b6

Browse files
committed
Move console msg and chalk into lib
1 parent e2a3b39 commit f9e14b6

File tree

9 files changed

+29
-29
lines changed

9 files changed

+29
-29
lines changed

dev/cleanup.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readdirSync, rmdirSync } from 'fs';
2-
import chalk from 'chalk';
32
import { repo } from './developer';
43
const { cwd, chdir } = process;
4+
import { success, warning, error, consoleLog } from '../lib/helpers';
55

66
// -------------------------------------------------------------------------------------------------
77
// TODO 1 (after CLI upgrade): Configure cleanup to run using node-mongo command i.e. "node-mongo cleanup" not "npm run cleanup"
@@ -37,15 +37,15 @@ const filterContentToGetTheOnesGeneratedByCLI = repoContent.reduce((acc, curr) =
3737
if (filterContentToGetTheOnesGeneratedByCLI.length) {
3838
try {
3939
filterContentToGetTheOnesGeneratedByCLI.map(folder => {
40-
console.log(chalk.green(`✔ ${folder} folder deleted successfully`));
40+
success(`✔ ${folder} folder deleted successfully`);
4141
return rmdirSync(folder, { recursive: true, force: true });
4242
});
43-
console.log('');
43+
consoleLog('');
4444
} catch (err) {
45-
console.log(chalk.red(err));
45+
error(err);
4646
}
4747
} 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'));
48+
warning('ℹ 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');
4949
}
5050

5151
// ------------------------------------

dev/customize/startMessage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import chalk from 'chalk';/*eslint-disable no-console*/
1+
import { success } from '../../lib/helpers';
22

3-
console.log( chalk.greenBright('\nℹ Collabo Community "Create Collabo App": running in dev mode...\n') );
3+
success('\nℹ Collabo Community "Create Collabo App": running in dev mode...\n');

dev/customize/testMessage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import chalk from 'chalk';/*eslint-disable no-console*/
1+
import { cyanBrightLog } from '../../lib/helpers';
22

3-
console.log( chalk.cyanBright('\nnode-mongo-cli: running jasmine tests...\n') );
3+
cyanBrightLog('\nnode-mongo-cli: running jasmine tests...\n');

src/cli.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import arg from 'arg';
2-
import chalk from 'chalk';
32
import { version } from './version';
43
import { help, notRecognised } from './help';
54
import { folderNameMissingOptionPrompt } from './prompts/foldername';
65
import { templateMissingOptionPrompt } from './prompts/template';
76
import { downloadTemplateKit } from './main';
87
import { Ioptions } from './interfaces';
8+
import { consoleLog, redBoldLog } from '../lib/helpers';
99

1010
let parseArgumentsIntoOptions = (rawArgs: string[]) => {
1111

@@ -76,12 +76,12 @@ let otherOptions = async (options: Ioptions) => {
7676

7777
options = await templateMissingOptionPrompt(updatedOptions, folderNameAnswers, defaultFolderName);
7878

79-
//console.log(options);
79+
// consoleLog(options);
8080

8181
try {
8282
await downloadTemplateKit(options);
8383
} catch (err) {
84-
console.log(chalk.red.bold('ERROR'), err);
84+
redBoldLog('ERROR', err);
8585
}
8686
}
8787

@@ -97,6 +97,6 @@ export let cli = async (args: string[]) => {
9797
await otherOptions(options as Ioptions);
9898
}
9999
} catch (err) {
100-
console.log('');
100+
consoleLog('');
101101
}
102102
}

src/help.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import chalk from 'chalk';
1+
import { warning, consoleLog } from '../lib/helpers';
22

33
export const help = () => {
4-
console.log(
4+
consoleLog(
55
`
66
Usage:
77
node-mongo <folder_name> <template>
@@ -55,7 +55,7 @@ folder name used already exists.
5555
}
5656

5757
export const notRecognised = () => {
58-
console.log(
58+
consoleLog(
5959
`
6060
Flag(s) not recognised. Use any of the help command below for more info:
6161
@@ -68,13 +68,12 @@ nmgo --help`
6868
}
6969

7070
export const userSupport = () => {
71-
console.log (chalk.yellowBright(
71+
warning(
7272
`
7373
It looks like the node-mongo-cli does not work yet for your computer's operating system. Let us know the issue with the CLI on your computer's operating system by reporting it here:
7474
https://github.com/code-collabo/node-mongo-cli/issues/new?assignees=&labels=bug&template=cli-user-error-report.md
7575
7676
Alternatively, you can download and access the API boilerplate templates from the template's github repo:
7777
https://github.com/code-collabo/node-mongo-api-boilerplate-templates
78-
`)
79-
);
78+
`);
8079
}

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import chalk from 'chalk';
21
import fs from 'fs';
32
import ncp from 'ncp';
43
import path from 'path';
@@ -8,6 +7,7 @@ import Listr from 'listr';
87
import { spawn } from 'child_process';
98
import { userSupport } from './help';
109
import { Ioptions, ItemplateOptions } from './interfaces';
10+
import { greenNoConsole, redBoldNoConsole } from '../lib/helpers';
1111

1212
const access = promisify(fs.access);
1313
const copy = promisify(ncp);
@@ -110,7 +110,7 @@ export let downloadTemplateKit = async (options: Ioptions) => {
110110
}).stdout?.pipe(process.stdout);
111111
});
112112
} catch (err) {
113-
console.error(`\n%s Template name or directory path is (probably) incorrect`, chalk.red.bold('ERROR'));
113+
console.error(`\n%s Template name or directory path is (probably) incorrect`, redBoldNoConsole('ERROR'));
114114
userSupport();
115115
process.exit(1);
116116
}
@@ -123,7 +123,7 @@ export let downloadTemplateKit = async (options: Ioptions) => {
123123

124124
const listrTasks = new Listr([
125125
{
126-
title: `${chalk.green(`${options.template} template`)} copied into the generated folder ${chalk.green(`=> ${options.folderName}`)}`,
126+
title: `${greenNoConsole(`${options.template} template`)} copied into the generated folder ${greenNoConsole(`=> ${options.folderName}`)}`,
127127
task: () => copyTemplateFolderContent(options)
128128
},
129129
{

src/prompts/foldername.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import inquirer from 'inquirer';
2-
import chalk from 'chalk';
32
import fs from 'fs';
43
import { IFolderQuestions, Ioptions } from '../interfaces';
4+
import { greenNoConsole, consoleLog, cyanBrightLog, warning } from '../../lib/helpers';
55

66
export const folderNameMissingOptionPrompt = async (options: Ioptions) => {
77
let defaultFolderName = 'nm-kit';
@@ -58,7 +58,7 @@ export const folderNameMissingOptionPrompt = async (options: Ioptions) => {
5858
if (options.folderName && !options.skipPrompts) {
5959
try {
6060
fs.accessSync(`./${options.folderName}`, fs.constants.F_OK);
61-
console.log( chalk.cyanBright(`Folder name ${chalk.green(`${options.folderName}`)} already exists`) );
61+
cyanBrightLog(`Folder name ${greenNoConsole(`${options.folderName}`)} already exists`);
6262
questionPush( 'Enter different folder name:', null);
6363
folderNameAnswers = await inquirer.prompt(folderQuestions);
6464
} catch (err) {
@@ -81,9 +81,9 @@ export const folderNameMissingOptionPrompt = async (options: Ioptions) => {
8181

8282
if (equalToAtLeastOneFolder === true) {
8383
if (folderNameAnswers.folderName !== '') {
84-
console.log( `Folder name ${chalk.green(`${folderNameAnswers.folderName}`)} already exists` );
84+
consoleLog( `Folder name ${greenNoConsole(`${folderNameAnswers.folderName}`)} already exists` );
8585
} else {
86-
console.log( `${chalk.yellowBright(`Folder name cannot be empty`)}` );
86+
warning('Folder name cannot be empty');
8787
}
8888
folderQuestions.push({
8989
type: 'input',

src/prompts/template.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import inquirer from 'inquirer';
2-
import chalk from 'chalk';
32
import { IFoldernameAnswers, Ioptions, ItemplateOptions, TemplateQuestions } from '../interfaces';
3+
import { redBrightNoConsole, consoleLog } from '../../lib/helpers';
44

55
let skipPromptsModified = (options: Ioptions, defaultFolderName: string, notAmongTemplateCollection: boolean, defaultTemplate: ItemplateOptions) => {
66
if (notAmongTemplateCollection && (options.template !== undefined || options.template === undefined)) {
@@ -50,7 +50,7 @@ export const templateMissingOptionPrompt = async (options: Ioptions, folderNameA
5050

5151
const notAmongTemplateCollection = equalToAtLeastOneTemplate === false;
5252

53-
if (notAmongTemplateCollection && options.template !== undefined && !options.skipPrompts) console.log(`${chalk.redBright(`${options.template}`)} is not in the node-mongo template collection`);
53+
if (notAmongTemplateCollection && options.template !== undefined && !options.skipPrompts) consoleLog(`${redBrightNoConsole(`${options.template}`)} is not in the node-mongo template collection`);
5454

5555
if (!options.template || notAmongTemplateCollection) {
5656
templateQuestions.push({

src/version.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import package_json from '../package.json';
2+
import { consoleLog } from '../lib/helpers';
23

34
export const version = () => {
4-
console.log(
5+
consoleLog(
56
`
67
node-mongo-cli v${package_json.version}
78
`

0 commit comments

Comments
 (0)