Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: commonjs to modules #231

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"parserOptions": {
"ecmaVersion": 2015,
"requireConfigFile": false,
"sourceType": "script",
"sourceType": "module",
"babelOptions": {
"plugins": [
"@babel/plugin-syntax-dynamic-import"
Expand Down
19 changes: 8 additions & 11 deletions lib/reporters/dots.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';
const chalk = require('chalk'),
_ = require('lodash'),
term = require('terminal-logger')('dots');
import * as chalk from 'chalk';
import * as _ from 'lodash';
import * as termConfig from 'terminal-logger';

const term = termConfig('dots');

term.level = 'debug'; // log everything
chalk.enabled = true;
Expand All @@ -11,15 +12,15 @@ chalk.level = 1;
* log simple messages
* @param {string} message
*/
function log(message) {
export function log(message) {
term.status.info(message);
}

/**
* log each operation as it happens
* @param {object} action
*/
function logAction(action) {
export function logAction(action) {
if (action.type === 'success') {
process.stderr.write(chalk.green('.'));
} else if (action.type === 'error') {
Expand All @@ -32,7 +33,7 @@ function logAction(action) {
* @param {function} summary that returns { success, message }
* @param {array} results
*/
function logSummary(summary, results) {
export function logSummary(summary, results) {
const successes = _.filter(results, { type: 'success' }),
warnings = _.filter(results, { type: 'warning' }),
errors = _.filter(results, { type: 'error' }),
Expand Down Expand Up @@ -68,7 +69,3 @@ function logSummary(summary, results) {
}
});
}

module.exports.log = log;
module.exports.logAction = logAction;
module.exports.logSummary = logSummary;
24 changes: 10 additions & 14 deletions lib/reporters/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
const _ = require('lodash'),
dots = require('./dots'),
pretty = require('./pretty'),
json = require('./json'),
nyan = require('./nyan'),
reporters = { dots, pretty, json, nyan };
import * as _ from 'lodash';
import * as dots from './dots.js';
import * as pretty from './pretty.js';
import * as json from './json.js';
import * as nyan from './nyan.js';

const reporters = { dots, pretty, json, nyan };

/**
* reporter is passed in via argument, or env variable, or defaults to 'dots'
Expand All @@ -21,7 +21,7 @@ function getReporter(reporter) {
* @param {string} command e.g. 'lint'
* @return {function}
*/
function log(reporter, command) {
export function log(reporter, command) {
reporter = getReporter(reporter);

return (message) => {
Expand All @@ -37,7 +37,7 @@ function log(reporter, command) {
* @param {string} command e.g. lint
* @return {function} that each action is passed into
*/
function logAction(reporter, command) {
export function logAction(reporter, command) {
reporter = getReporter(reporter);

return (action) => {
Expand All @@ -56,7 +56,7 @@ function logAction(reporter, command) {
* @param {function} summary function that returns { success: boolean, message: string }
* @return {function} that array of results is passed into
*/
function logSummary(reporter, command, summary) {
export function logSummary(reporter, command, summary) {
reporter = getReporter(reporter);

return (results) => {
Expand All @@ -65,7 +65,3 @@ function logSummary(reporter, command, summary) {
}
};
}

module.exports.log = log;
module.exports.logAction = logAction;
module.exports.logSummary = logSummary;
17 changes: 6 additions & 11 deletions lib/reporters/json.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const _ = require('lodash'),
clayLog = require('clay-log'),
pkg = require('../../package.json');
import * as _ from 'lodash';
import * as clayLog from 'clay-log';
import * as pkg from '../../package.json';

let logger = clayLog.init({
name: 'claycli',
Expand All @@ -14,7 +13,7 @@ let logger = clayLog.init({
* @param {string} message
* @param {string} command
*/
function log(message, command) {
export function log(message, command) {
logger('info', message, { command, type: 'info' });
}

Expand All @@ -23,7 +22,7 @@ function log(message, command) {
* @param {object} action
* @param {string} command
*/
function logAction(action, command) {
export function logAction(action, command) {
const message = action.message;

delete action.message; // remove duplicate property
Expand All @@ -43,7 +42,7 @@ function logAction(action, command) {
* @param {array} results
* @param {string} command
*/
function logSummary(summary, results, command) {
export function logSummary(summary, results, command) {
const successes = _.filter(results, { type: 'success' }),
errors = _.filter(results, { type: 'error' }),
sum = summary(successes.length, errors.length);
Expand All @@ -54,7 +53,3 @@ function logSummary(summary, results, command) {
logger('error', sum.message, { command, type: 'info' });
}
}

module.exports.log = log;
module.exports.logAction = logAction;
module.exports.logSummary = logSummary;
21 changes: 9 additions & 12 deletions lib/reporters/nyan.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
'use strict';
const _ = require('lodash'),
chalk = require('chalk'),
NyanCat = require('nyansole'),
term = require('terminal-logger')('nyan');
import * as chalk from 'chalk';
import * as _ from 'lodash';
import * as termConfig from 'terminal-logger';
import * as NyanCat from 'nyansole';

const term = termConfig('nyan');

let cat;

/**
* log simple messages and reset the cat
* @param {string} message
*/
function log(message) {
export function log(message) {
term.status.info(message);

if (!cat) {
Expand All @@ -24,7 +25,7 @@ function log(message) {
* move the cat!
* @param {object} action
*/
function logAction(action) {
export function logAction(action) {
if (!cat) {
cat = new NyanCat();
cat.reset();
Expand All @@ -41,7 +42,7 @@ function logAction(action) {
* @param {function} summary that returns { success, message }
* @param {array} results
*/
function logSummary(summary, results) {
export function logSummary(summary, results) {
const successes = _.filter(results, { action: 'success' }),
warnings = _.filter(results, { action: 'warning' }),
errors = _.filter(results, { action: 'error' }),
Expand Down Expand Up @@ -83,7 +84,3 @@ function logSummary(summary, results) {
}
});
}

module.exports.log = log;
module.exports.logAction = logAction;
module.exports.logSummary = logSummary;
19 changes: 8 additions & 11 deletions lib/reporters/pretty.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
'use strict';
const chalk = require('chalk'),
_ = require('lodash'),
term = require('terminal-logger')('pretty');
import * as chalk from 'chalk';
import * as _ from 'lodash';
import * as termConfig from 'terminal-logger';

const term = termConfig('pretty');

term.level = 'debug'; // log everything

/**
* log simple messages
* @param {string} message
*/
function log(message) {
export function log(message) {
term.status.info(message);
}

/**
* log each operation as it happens
* @param {object} action
*/
function logAction(action) {
export function logAction(action) {
let details = action.details && _.isString(action.details) ? ` ${chalk.grey('(' + action.details + ')')}` : '',
message = `${action.message}${details}`;

Expand All @@ -35,7 +36,7 @@ function logAction(action) {
* @param {function} summary that returns { success, message }
* @param {array} results
*/
function logSummary(summary, results) {
export function logSummary(summary, results) {
const successes = _.filter(results, { type: 'success' }),
errors = _.filter(results, { type: 'error' }),
sum = summary(successes.length, errors.length);
Expand All @@ -47,7 +48,3 @@ function logSummary(summary, results) {
term.cross(sum.message);
}
}

module.exports.log = log;
module.exports.logAction = logAction;
module.exports.logSummary = logSummary;
Loading