-
-
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
1 parent
e535591
commit 47c24bf
Showing
10 changed files
with
203 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
lib | ||
coverage | ||
__snapshots__ | ||
node_modules | ||
npm-debug.log* | ||
yarn-debug.log* | ||
|
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,60 +1,4 @@ | ||
#!/usr/bin/env node | ||
|
||
|
||
var read = require('fs').createReadStream | ||
var write = require('fs').createWriteStream | ||
|
||
var banner = require('../') | ||
|
||
var args = process.argv.slice(2) | ||
var help = false | ||
var multi = false | ||
var one = false | ||
|
||
args = args.filter(function (arg) { | ||
if (arg === '-h' || arg === '--help') { | ||
help = true | ||
return false | ||
} else if (arg === '-m' || arg === '--multi') { | ||
multi = true | ||
return false | ||
} else if (arg === '-o' || arg === '--one') { | ||
one = true | ||
return false | ||
} | ||
return true | ||
}) | ||
|
||
|
||
if (help){ | ||
|
||
console.log('Usage: bannerjs') | ||
console.log('') | ||
console.log('Pipe Usage: bannerjs') | ||
console.log('') | ||
console.log('Options:') | ||
console.log('') | ||
console.log(' -m --multi Output multi-line results') | ||
console.log(' -o --one Output one-line results') | ||
console.log('') | ||
if (!help) process.exit(1) | ||
|
||
}else { | ||
|
||
var banner_str = ''; | ||
|
||
if(multi){ | ||
banner_str = banner.multibanner() | ||
}else{ | ||
banner_str = banner.onebanner() | ||
} | ||
|
||
|
||
var dest = args[2] ? write(args[2]) : process.stdout | ||
var source = args[1] ? read(args[1]) : process.stdin | ||
|
||
dest.write(banner_str+'\n') | ||
source.on('end', function () { | ||
dest.write('\n') | ||
}).pipe(dest, {end: false}) | ||
} | ||
const bannerjs = require('../lib'); | ||
bannerjs.run(); |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env node | ||
|
||
import { createReadStream, createWriteStream } from 'fs'; | ||
import { onebanner, multibanner } from './'; | ||
|
||
export function run() { | ||
let args = process.argv.slice(2) | ||
let help = false; | ||
let multi = false; | ||
let one = false; | ||
|
||
args = args.filter(function (arg) { | ||
if (arg === '-h' || arg === '--help') { | ||
help = true | ||
return false | ||
} else if (arg === '-m' || arg === '--multi') { | ||
multi = true | ||
return false | ||
} else if (arg === '-o' || arg === '--one') { | ||
one = true | ||
return false | ||
} | ||
return true | ||
}); | ||
|
||
if (help) { | ||
console.log('Usage: bannerjs'); | ||
console.log(''); | ||
console.log('Pipe Usage: bannerjs'); | ||
console.log(''); | ||
console.log('Options:'); | ||
console.log(''); | ||
console.log(' -m --multi Output multi-line results'); | ||
console.log(' -o --one Output one-line results'); | ||
console.log(''); | ||
if (!help) process.exit(1); | ||
} else { | ||
let bannerStr = ''; | ||
if (multi) { | ||
bannerStr = multibanner(); | ||
} else { | ||
bannerStr = onebanner(); | ||
} | ||
|
||
let dest = args[2] ? createWriteStream(args[2]) : process.stdout; | ||
let source = args[1] ? createReadStream(args[1]) : process.stdin; | ||
|
||
dest.write(`${bannerStr}\n`); | ||
source.on('end', () => { | ||
dest.write('\n'); | ||
}) | ||
.pipe(dest, { end: true }); | ||
} | ||
} |
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,59 @@ | ||
import path from 'path'; | ||
import { PackageJson } from 'types-package-json'; | ||
|
||
export * from './cli'; | ||
|
||
/** | ||
* Get package.json Object | ||
*/ | ||
export function getPackage(rootPath: string = process.cwd()): PackageJson { | ||
const pkgPath = path.resolve(rootPath, 'package.json'); | ||
const pkg: PackageJson = require(pkgPath); | ||
pkg.author = pkg.author; | ||
if (pkg.author && typeof pkg.author === 'object' && pkg.author.name) { | ||
pkg.author = pkg.author.name; | ||
} | ||
|
||
if (!pkg.homepage && pkg.repository && pkg.repository.url) { | ||
pkg.homepage = pkg.repository.url; | ||
} | ||
if (!pkg.homepage) { | ||
pkg.homepage = ''; | ||
} | ||
|
||
pkg.description = pkg.description; | ||
if (!pkg.description) { | ||
pkg.description = ''; | ||
} | ||
|
||
return pkg; | ||
} | ||
|
||
export function onebanner(option?: PackageJson) { | ||
let bn = getPackage(); | ||
if (option) { | ||
bn = Object.assign(bn, option); | ||
} | ||
return ['/*! ', bn.name, ' v', bn.version, | ||
' | ', bn.license, ' (c) ', | ||
new Date().getFullYear(), ' ', bn.author, | ||
' | ', bn.homepage, | ||
' */', | ||
].filter(Boolean).join(''); | ||
} | ||
|
||
export function multibanner(option?: PackageJson) { | ||
let bn = getPackage(); | ||
if (option) bn = Object.assign(bn, option); | ||
const result: string[] = []; | ||
result.push('/**!'); | ||
result.push(`\n * ${bn.name} v${bn.version}`); | ||
result.push(`\n * ${bn.description}`); | ||
result.push(`\n * `); | ||
result.push(`\n * Copyright (c) ${new Date().getFullYear()} ${bn.author}`); | ||
result.push(`\n * ${bn.homepage}`); | ||
result.push(`\n * `); | ||
result.push(`\n * Licensed under the ${bn.license} license.`); | ||
result.push(`\n */\n`); | ||
return result.filter(Boolean).join(''); | ||
} |
Oops, something went wrong.