-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
4,336 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ node_js: | |
- '4' | ||
- '5' | ||
- '6' | ||
- '7' | ||
after_success: npm run coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
require('../dist/cli') | ||
require('../src/cli') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.