Comparing version 1.0.2 to 1.0.3
#! /usr/bin/env node | ||
'use strict'; | ||
(function () { | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var colors = require('colors'); | ||
'use strict'; | ||
var tplDir = path.join(getUserHome(), '.templates'); | ||
var BR = "\r\n"; | ||
var fs = require('fs'), | ||
path = require('path'), | ||
colors = require('colors'), | ||
omelette = require("omelette"); | ||
if (process.argv[2] === 'list') { | ||
return list(tplDir); | ||
} else if (process.argv[2] === 'help') { | ||
return usage(); | ||
} else { | ||
return mk(tplDir); | ||
} | ||
var complete = omelette("mkhere <action>"); | ||
function getUserHome() { | ||
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; | ||
} | ||
function list(dir) { | ||
var tpls = fs.readdirSync(dir); | ||
tpls.forEach(function (file) { | ||
console.log(file); | ||
complete.on("action", function () { | ||
return this.reply(["list", "help"]); | ||
}); | ||
} | ||
complete.init(); | ||
function usage() { | ||
console.log( | ||
BR + "mkhere: Create files based on predefined emplates".inverse + BR + BR + | ||
"mkhere list ".green.bold + BR + | ||
"\t List all templates in " + tplDir.italic + BR + | ||
"mkhere tplname.html newname ".green.bold + BR + | ||
"\t Will create new file " + "newname.html".italic + " based on " + path.join(tplDir, "tplname.html").italic + " in current directory" | ||
); | ||
} | ||
var tplDir = path.join(getUserHome(), '.templates'); | ||
var BR = "\r\n"; | ||
function mk(tplDir) { | ||
var CWD = process.cwd(); | ||
var tplFile = process.argv[2]; | ||
var tplName = path.join(tplDir, tplFile); | ||
var newFileExt = tplFile.slice(tplFile.indexOf('.')); | ||
var newFile = process.argv[3] + newFileExt; | ||
fs.readFile(tplName, 'utf8', function (err, data) { | ||
if (err) { | ||
return console.log( | ||
'Error! No such template file '.red + tplFile.red.bold + ' in '.red + tplDir.red + BR + | ||
if (process.argv[2] === 'list') { | ||
return list(tplDir); | ||
} else if (process.argv[2] === 'help' || !process.argv[2]) { | ||
return usage(); | ||
} else { | ||
return mk(tplDir); | ||
} | ||
function getUserHome() { | ||
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; | ||
} | ||
function list(dir) { | ||
var tpls = fs.readdirSync(dir); | ||
tpls.forEach(function (file) { | ||
console.log(file); | ||
}); | ||
} | ||
function usage() { | ||
console.log( | ||
"--------------------------------------------------" + BR + | ||
"mkhere: Create files based on predefined templates".white.bold + BR + | ||
"--------------------------------------------------" + BR + | ||
"Run: ".white + "mkhere list ".green.bold + BR + | ||
"\t To list all templates in " + tplDir.italic + BR + | ||
"Run: ".white + "mkhere tplname.html newname ".green.bold + BR + | ||
"\t This will create new file " + "newname.html".italic + " based on " + path.join(tplDir, "tplname.html").italic + " in current directory" + BR + BR + | ||
"------------------Auto-completion-----------------" + BR + BR + | ||
"Run: " + "mkhere --completion >> ~/.mkhere.completion.sh && echo 'source ~/.mkhere.completion.sh' >> .bash_profile".green.bold + BR + | ||
"\tIn order to enable auto-completion in your `BASH` terminal" + BR + | ||
"Or: " + "echo '. <(./githubber --completion)' >> .zshrc".green.bold + BR + | ||
"\tif you're using `ZSH`" | ||
); | ||
} | ||
function mk(tplDir) { | ||
var CWD = process.cwd(); | ||
var tplFile = process.argv[2]; | ||
var tplName = path.join(tplDir, tplFile); | ||
var newFileExt = tplFile.slice(tplFile.indexOf('.')); | ||
var newFile = process.argv[3] + newFileExt; | ||
fs.readFile(tplName, 'utf8', function (err, data) { | ||
if (err) { | ||
return console.log( | ||
'Error! No such template file '.red + tplFile.red.bold + ' in '.red + tplDir.red + BR + | ||
"For usage see: " + "mkhere help".bold | ||
); | ||
} | ||
fs.writeFile(path.join(CWD,newFile), data); | ||
}); | ||
} | ||
); | ||
} | ||
fs.writeFile(path.join(CWD, newFile), data); | ||
}); | ||
} | ||
}).call(this); |
{ | ||
"name": "mkhere", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Make files based on template", | ||
@@ -37,3 +37,3 @@ "main": "lib/mkhere.js", | ||
"colors": "~0.6.2", | ||
"path": "~0.4.9" | ||
"omelette": "~0.1.0" | ||
}, | ||
@@ -40,0 +40,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62
6453
5
+ Addedomelette@~0.1.0
+ Addedomelette@0.1.0(transitive)
- Removedpath@~0.4.9
- Removedpath@0.4.10(transitive)