Skip to content

Commit

Permalink
Merge pull request #28 from sunesimonsen/feature/modernise
Browse files Browse the repository at this point in the history
Modernise magicpen repository
  • Loading branch information
sunesimonsen committed Dec 16, 2019
2 parents 9501ee5 + c5d8e13 commit 4d713f8
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 186 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
@@ -0,0 +1,12 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
indent_size = 4
indent_style = space

[*.{json,yml}]
indent_size = 2
2 changes: 2 additions & 0 deletions .eslintignore
@@ -0,0 +1,2 @@
magicpen.js
magicpen.esm.js
16 changes: 16 additions & 0 deletions .eslintrc
@@ -0,0 +1,16 @@
{
"extends": ["standard", "prettier", "prettier/standard"],
"plugins": ["import", "mocha"],
"env": {
"mocha": true
},
"rules": {
"camelcase": "off",
"dot-notation": "off",
"no-useless-escape": "off",
"spaced-comment": "off",
"mocha/no-exclusive-tests": "error",
"mocha/no-nested-tests": "error",
"mocha/no-identical-title": "error"
}
}
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,3 +1,6 @@
/node_modules/
/.nyc_output/
/coverage/
magicpen.js
magicpen.esm.js
magicpen.esm.js.map
3 changes: 0 additions & 3 deletions .jshintignore

This file was deleted.

154 changes: 0 additions & 154 deletions .jshintrc

This file was deleted.

24 changes: 22 additions & 2 deletions .travis.yml
@@ -1,9 +1,29 @@
language: node_js

env:
- TARGET=test-node

node_js:
- "6"
- "7"
- "8.4.0"
- "8.10.0"
- "9"
- "10"

script: "npm run-script travis"
matrix:
include:
- name: Lint
node_js: '8.10.0'
env:
- TARGET=lint
- name: Coverage
node_js: '8.10.0'
env:
- TARGET=coverage
- name: Pseudo Browser
node_js: '8.10.0'
env:
- TARGET=test-browser

script: "npm run $TARGET"
after_success: '<coverage/lcov.info ./node_modules/coveralls/bin/coveralls.js'
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -5,10 +5,10 @@
Create composable extensible styled text in both consoles and
browsers.

[![NPM version](https://badge.fury.io/js/magicpen.png)](http://badge.fury.io/js/magicpen)
[![Build Status](https://travis-ci.org/sunesimonsen/magicpen.png)](https://travis-ci.org/sunesimonsen/magicpen)
[![Coverage Status](https://coveralls.io/repos/sunesimonsen/magicpen/badge.png)](https://coveralls.io/r/sunesimonsen/magicpen)
[![Dependency Status](https://david-dm.org/sunesimonsen/magicpen.png)](https://david-dm.org/sunesimonsen/magicpen)
[![NPM version](https://img.shields.io/npm/v/magicpen.svg)](https://www.npmjs.com/package/magicpen)
[![Build Status](https://img.shields.io/travis/sunesimonsen/magicpen/master.svg)](https://travis-ci.org/sunesimonsen/magicpen)
[![Coverage Status](https://img.shields.io/coveralls/sunesimonsen/magicpen.svg)](https://coveralls.io/r/sunesimonsen/magicpen)
[![Dependency Status](https://david-dm.org/sunesimonsen/magicpen.svg)](https://david-dm.org/sunesimonsen/magicpen)

## Installation

Expand Down
4 changes: 2 additions & 2 deletions lib/MagicPen.js
Expand Up @@ -428,7 +428,7 @@ MagicPen.prototype.prependLinesWith = function () {
var output = this.clone();
output.block(function () {
for (var i = 0; i < height; i += 1) {
if (0 < i) {
if (i > 0) {
this.nl();
}
this.append(pen);
Expand Down Expand Up @@ -563,7 +563,7 @@ MagicPen.prototype.installPlugin = MagicPen.prototype.use; // Legacy alias
function replaceText(output, outputArray, regexp, cb) {
var replacedOutput = output;
outputArray.forEach(function (line, i) {
if (0 < i) {
if (i > 0) {
replacedOutput.nl();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/supportsColor.js
Expand Up @@ -12,7 +12,7 @@ var hasFlag = function hasFlag(flag, argv) {
// Fork from https://github.com/chalk/supports-color
var env = platform.env;

var forceColor = void 0;
var forceColor;
if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) {
forceColor = 0;
} else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/themeMapper.js
Expand Up @@ -7,7 +7,7 @@ module.exports = function (theme, styles) {
while(typeof themeMapping === 'string' && themeStyles[themeMapping]) {
themeMapping = themeStyles[themeMapping];
count += 1;
if (100 < count) {
if (count > 100) {
var index = stack.indexOf(themeMapping);
stack.push(themeMapping);
if (index !== -1) {
Expand Down
33 changes: 21 additions & 12 deletions package.json
Expand Up @@ -11,21 +11,30 @@
"url": "https://github.com/sunesimonsen/magicpen.git"
},
"scripts": {
"lint": "jshint .",
"test": "npm run lint && mocha -R spec",
"travis": "npm test && npm run coverage && (<coverage/lcov.info coveralls || true)",
"prepublish": "(echo '/*!' && <LICENSE sed -e's/^/ * /' | sed -e's/\\s+$//' && echo ' */' && browserify -p bundle-collapser/plugin -e lib/MagicPen -s weknowhow.MagicPen) > magicpen.js",
"coverage": "NODE_ENV=development istanbul cover _mocha --report text --report lcov -- --reporter dot && echo google-chrome coverage/lcov-report/index.html"
"coverage": "nyc --reporter=lcov --reporter=text npm run test-node",
"lint": "eslint .",
"test": "npm run lint && npm run test-node && npm run test-browser",
"test-browser": "npm run prepublish && PSEUDO_BROWSER=yes mocha",
"test-node": "mocha",
"prepublish": "rollup -c"
},
"author": "Sune Simonsen",
"devDependencies": {
"browserify": "8.1.0",
"bundle-collapser": "1.1.1",
"coveralls": "2.11.1",
"del": "0.1.1",
"istanbul": "0.3.17",
"jshint": "*",
"mocha": "1.20.1",
"coveralls": "^3.0.9",
"eslint": "^6.0.0",
"eslint-config-prettier": "^6.0.0",
"eslint-config-standard": "^14.0.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-mocha": "^6.0.0",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.0",
"mocha": "^6.0.2",
"nyc": "^14.1.1",
"rollup": "^1.0.2",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-node-resolve": "^5.0.0",
"sinon": "1.9.1",
"unexpected": "9.5.0",
"unexpected-sinon": "6.4.2"
Expand Down
49 changes: 49 additions & 0 deletions rollup.config.js
@@ -0,0 +1,49 @@
const fs = require('fs');
const path = require('path');

const commonjs = require('rollup-plugin-commonjs');
const nodeResolve = require('rollup-plugin-node-resolve');
const nodeGlobals = require('rollup-plugin-node-globals');

const plugins = [
commonjs({ ignore: ['os'] }),
nodeResolve({ preferBuiltins: true }),
nodeGlobals()
];

const banner =
'/*!\n' +
fs
.readFileSync(path.resolve(__dirname, 'LICENSE'), 'utf-8')
.replace(/^/gm, ' * ')
.replace(/\s+$/g, '') +
'/\n';

module.exports = [
{
input: 'lib/MagicPen.js',
output: {
banner,
file: 'magicpen.js',
name: 'weknowhow.MagicPen',
exports: 'default',
format: 'umd',
esModule: false,
sourcemap: false,
strict: false
},
plugins
},
{
input: 'lib/MagicPen.js',
output: {
banner,
file: 'magicpen.esm.js',
exports: 'default',
format: 'esm',
sourcemap: true,
strict: false
},
plugins
}
];
10 changes: 3 additions & 7 deletions test/magicpen.spec.js
@@ -1,5 +1,6 @@
/*global describe, it, beforeEach*/
var magicpen = require('..');
var magicpen = process.env.PSEUDO_BROWSER ? require('..') : require('../lib/MagicPen');

var expect = require('unexpected');
var sinon = require('sinon');
expect.use(require('unexpected-sinon'));
Expand Down Expand Up @@ -1330,12 +1331,7 @@ describe('magicpen', function () {
if (obj && typeof obj === 'object') {
this.text('{').nl()
.indentLines();
var keys = [];
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
keys.push(prop);
}
}
var keys = Object.keys(obj);
for (var i = 0; i < keys.length; i += 1) {
var key = keys[i];
this.i().cyan(key).text(': ').object(obj[key]);
Expand Down

0 comments on commit 4d713f8

Please sign in to comment.