Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
sadorlovsky committed Dec 15, 2016
2 parents 0e613b7 + c313308 commit f6287b3
Show file tree
Hide file tree
Showing 15 changed files with 4,336 additions and 212 deletions.
8 changes: 7 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"presets": ["es2015"],
"presets": [
["env", {
"targets": {
"node": 4
}
}]
],
"env": {
"test": {
"plugins": ["istanbul"]
Expand Down
6 changes: 5 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"extends": [
"@sadorlovsky",
"@sadorlovsky/eslint-config/ava"
]
],
"rules": {
"ava/max-asserts": "off",
"import/no-commonjs": "off"
}
}
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_js:
- '4'
- '5'
- '6'
- '7'
after_success: npm run coveralls
2 changes: 1 addition & 1 deletion bin/lissie.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node

require('../dist/cli')
require('../src/cli')
55 changes: 28 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
{
"name": "lissie",
"version": "0.2.0",
"description": "tool for generate LICENSE",
"version": "0.3.0",
"description": "CLI tool for generate LICENSE",
"main": "dist/lissie.js",
"bin": {
"lissie": "bin/lissie.js"
"license": "bin/lissie.js"
},
"preferGlobal": true,
"scripts": {
"lint": "eslint src test",
"pretest": "npm run build && rimraf coverage",
"test": "NODE_ENV=test nyc --check-coverage --lines 100 ava",
"lint": "eslint src",
"test": "NODE_ENV=test nyc ava",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"clean": "rimraf dist",
"prebuild": "npm run clean",
"build": "babel src -d dist",
"prepublish": "npm run lint && npm run test && npm run build"
"pretest": "del coverage",
"prebuild": "del dist",
"build": "babel src -d dist --ignore \"**/*.test.js\""
},
"ava": {
"require": [
Expand Down Expand Up @@ -56,31 +54,34 @@
},
"homepage": "https://github.com/sadorlovsky/lissie",
"devDependencies": {
"@sadorlovsky/eslint-config": "^0.12.0",
"ava": "^0.16.0",
"@sadorlovsky/eslint-config": "^0.13.0",
"ava": "^0.17.0",
"babel-cli": "^6.11.4",
"babel-eslint": "^6.1.2",
"babel-plugin-istanbul": "^2.0.0",
"babel-preset-es2015": "^6.13.2",
"babel-eslint": "^7.1.1",
"babel-plugin-istanbul": "^3.0.0",
"babel-preset-env": "^1.1.1",
"babel-register": "^6.11.6",
"common-tags": "^1.3.1",
"coveralls": "^2.11.12",
"eslint": "^3.3.0",
"eslint-plugin-ava": "^2.5.0",
"eslint-plugin-fp": "^1.3.0",
"eslint-plugin-import": "^1.13.0",
"execa": "^0.4.0",
"nyc": "^8.1.0",
"rimraf": "^2.5.4"
"common-tags": "^1.4.0",
"coveralls": "^2.11.15",
"del-cli": "^0.2.1",
"eslint": "^3.12.2",
"eslint-plugin-ava": "^4.0.0",
"eslint-plugin-fp": "^2.2.0",
"eslint-plugin-import": "^2.2.0",
"execa": "^0.5.0",
"nyc": "^10.0.0"
},
"dependencies": {
"assign-defined": "^1.0.5",
"bluebird": "^3.4.1",
"chalk": "^1.1.3",
"fullname": "^3.1.0",
"lodash": "^4.17.2",
"meow": "^3.7.0",
"pify": "^2.3.0",
"project-name": "^0.2.6",
"promise.any": "^0.1.0",
"read-pkg": "^2.0.0",
"read-pkg-up": "^2.0.0",
"user-email": "^1.0.1",
"user-fullname": "^0.1.7"
"user-fullname": "^0.3.0"
}
}
78 changes: 12 additions & 66 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,18 @@
import fs from 'fs'
import path from 'path'
import meow from 'meow'
import pify from 'pify'
import userFullname from 'user-fullname'
import userEmail from 'user-email'
import projectName from 'project-name'
import lissie from './lissie'
const meow = require('meow')
const chalk = require('chalk')
const lissie = require('./lissie')

const cli = meow(`
Usage
$ lissie <license> Show text of given license
$ lissie ls List of available licenses
$ lissie <license>
`)

Options
-a, --author "<your name>"
-y, --year <year>
-e, --email "<your email>"
-p, --project "<project name>"
-v, --version
-h, --help
Examples
$ lissie mit
$ lissie mit -a "Zach Orlovsky" -y 2016
$ lissie mit -a "Zach Orlovsky" -e "sadorlovsky@gmail.com"
`,
{
alias: {
a: 'author',
y: 'year',
e: 'email',
p: 'project',
v: 'version',
h: 'help'
}
}
const highlight = text => text.replace(
/\{year\}|\{author\}|\{project\}|\{email\}/gi,
matched => chalk.black.bgYellow(matched)
)

const ls = () => {
return pify(fs.readdir)(path.resolve(__dirname, '..', 'licenses'))
.then(licenses => licenses.join('\n'))
}

if (cli.input[0] === 'ls') {
ls().then(list => {
console.log(list)
process.exit()
}).catch(error => {
console.log(error)
process.exit(1)
})
}

Promise.all([
userFullname(),
userEmail()
]).then(results => {
const [author, email] = results
const project = projectName()
const year = new Date().getFullYear()
return lissie({
license: cli.input[0],
author: cli.flags.author || author,
year: cli.flags.year || year,
email: cli.flags.email || email,
project: cli.flags.project || project
})
}).then(license => {
console.log(license)
process.exit()
})
lissie(cli.input[0] || 'mit')
.then(highlight)
.then(text => console.log(text))
.catch(({ message }) => console.log(message))
18 changes: 18 additions & 0 deletions src/cli.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import test from 'ava'
import execa from 'execa'
import lissie from './lissie'

test('MIT without params', async t => {
const { stdout } = await execa('bin/lissie.js')
t.is(stdout, await lissie('mit'))
})

test('MIT', async t => {
const { stdout } = await execa('bin/lissie.js', ['mit'])
t.is(stdout, await lissie('mit'))
})

test('Error message if license not exists', async t => {
const { stdout } = await execa('bin/lissie.js', ['no-exist'])
t.is(stdout, 'There is not that license')
})
39 changes: 20 additions & 19 deletions src/lissie.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import path from 'path'
import fs from 'fs'
import pify from 'pify'
import assign from 'assign-defined'
import template from './template'
const fs = require('fs')
const path = require('path')
const pify = require('pify')
const { isString, get } = require('lodash')

const getLicenseText = license => {
return pify(fs.readFile)(
path.resolve(__dirname, '..', 'licenses', `${license}`), 'utf8'
)
const lissie = options => {
const license = isString(options) ? options : get(options, 'license')
return pify(fs)
.readFile(path.join('licenses', license), { encoding: 'utf8' })
.then(text => {
return text.replace(
/\{year\}|\{author\}|\{project\}|\{email\}/gi,
matched => options[matched.replace(/\{|\}/gi, '')] || matched
)
})
.catch(({ code }) => {
if (code === 'ENOENT') {
throw new Error('There is not that license')
}
})
}

const lissie = props => {
const options = typeof props === 'string'
? { license: props }
: assign({}, props)
return getLicenseText(options.license || 'mit').then(text => {
return template(text, options)
})
}

export default lissie
module.exports = lissie
32 changes: 32 additions & 0 deletions src/lissie.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import fs from 'fs'
import path from 'path'
import pify from 'pify'
import test from 'ava'
import { take } from 'lodash'
import { stripIndent } from 'common-tags'
import lissie from './lissie'

test('returns license text', async t => {
const expected = await pify(fs).readFile(path.join('licenses', 'mit'), { encoding: 'utf8' })
t.is(await lissie('mit'), expected)
t.is(await lissie({ license: 'mit' }), expected)
})

test('pass options', async t => {
const mit = await lissie({
license: 'mit',
year: 2016,
author: 'Zach Orlovsky'
})
const expected = stripIndent`
The MIT License (MIT)
Copyright (c) 2016 Zach Orlovsky
`
const head = take(mit.split('\n'), 3).join('\n')
t.is(head, expected)
})

test('throws if no license found', t => {
t.throws(lissie('no-exist'))
})
10 changes: 0 additions & 10 deletions src/template.js

This file was deleted.

16 changes: 0 additions & 16 deletions test/cli.test.js

This file was deleted.

14 changes: 0 additions & 14 deletions test/helpers/strip.js

This file was deleted.

33 changes: 0 additions & 33 deletions test/lissie.test.js

This file was deleted.

24 changes: 0 additions & 24 deletions test/template.test.js

This file was deleted.

Loading

0 comments on commit f6287b3

Please sign in to comment.