diff --git a/cli.js b/cli.js
index 70def98..80eee6c 100644
--- a/cli.js
+++ b/cli.js
@@ -27,6 +27,7 @@ if (argv.h || argv.help) {
-a, --author Define author
-y, --year Define year
-l, --license Define license
+ --template Define template
-h, --help Display help information
-v, --version Output version
@@ -34,6 +35,7 @@ if (argv.h || argv.help) {
$ banner-cli dist/**/*.js
$ banner-cli dist/**/*.css --author 'CJ Patoilo' --license MIT --site https://milligram.io
+ $ banner-cli dist/**/*.css --template '/*
[name]
[tag]
[site]
[author]
[year]
[license]
[time] */'
`)
process.exit(0)
}
@@ -86,6 +88,10 @@ if (argv.y && argv.y !== true) {
options.year = argv.y
}
+if (argv.template && argv.template !== true) {
+ options.template = argv.template
+}
+
if (argv._[0]) {
options.source = argv._[0]
banner(options)
diff --git a/index.js b/index.js
index 1f9a1cb..23cb6f5 100644
--- a/index.js
+++ b/index.js
@@ -10,29 +10,48 @@ const getAuthorName = value => {
}
const unlicense = 'This is free and unencumbered software'
+const defaultTemplate =
+`/*!
+ * [name] v[tag]
+ * [homepage]
+ *
+ * Copyright (c) [year] [author]
+ * [license]
+ */
+`
+
+function getBanner(template, options) {
+ return template
+ .replace('[name]', options.name.charAt(0).toUpperCase() + options.name.slice(1))
+ .replace('[tag]', options.tag)
+ .replace('[homepage]', options.homepage)
+ .replace('[license]', options.license)
+ .replace('[author]', options.author)
+ .replace('[year]', options.year)
+ .replace('[time]', Date.now())
+ .split('
')
+ .join("\n")
+
+}
function banner (options = {}) {
options.name = options.name || pkg.name || 'unknown'
options.tag = options.tag || pkg.version || '0.0.0'
options.homepage = options.homepage || pkg.homepage || `https://npm.com/${options.name}`
options.license = options.license || pkg.license
+ options.license = options.license ? `Licensed under the ${options.license} license` : unlicense
options.author = options.author || getAuthorName(pkg.author)
options.year = options.year || new Date().getFullYear()
- const template = options.template || `/*!
- * ${options.name.charAt(0).toUpperCase() + options.name.slice(1)} v${options.tag}
- * ${options.homepage}
- *
- * Copyright (c) ${options.year} ${options.author}
- * ${options.license ? `Licensed under the ${options.license} license\n *` : unlicense}/\n
-`
+ let template = options.template || defaultTemplate;
+ let bannerText = getBanner(template, options)
if (!options.source) {
throw new Error(`File not found!`)
} else {
glob(options.source, (err, files) => {
if (err) throw err
- files.map(file => prependFile.sync(file, template))
+ files.map(file => prependFile.sync(file, bannerText))
process.exit(0)
})
}
diff --git a/readme.md b/readme.md
index 14078d5..14508db 100644
--- a/readme.md
+++ b/readme.md
@@ -89,6 +89,7 @@ $ banner-cli --help
-a, --author Define author
-y, --year Define year
-l, --license Define license
+ --template Define template
-h, --help Display help information
-v, --version Output version
@@ -96,6 +97,7 @@ $ banner-cli --help
$ banner-cli dist/**/*.js
$ banner-cli dist/**/*.css --author 'CJ Patoilo' --license MIT --site https://milligram.io
+ $ banner-cli dist/**/*.css --template '/*
[name]
[tag]
[site]
[author]
[year]
[license]
[time] */'
```