mirror of
https://github.com/harish2704/file-header.git
synced 2026-09-10 07:01:07 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
|
||||
module.exports = {
|
||||
user: process.env.USER,
|
||||
email: process.env.USER + '@' + process.env.HOST,
|
||||
date: new Date(),
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* <%- filename %>
|
||||
*
|
||||
* Copyright <%- new Date().getFullYear() %> <%- user %> <<%- email %>>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var path = require('path');
|
||||
var os = require('os');
|
||||
var fs = require('fs');
|
||||
var ejs = require('ejs');
|
||||
var configDir = path.join( process.env.HOME, '.file-headers' );
|
||||
|
||||
|
||||
function cp( src, dest ){
|
||||
var data = fs.readFileSync(src);
|
||||
fs.writeFileSync( dest, data);
|
||||
}
|
||||
|
||||
function initialize(){
|
||||
if( !fs.existsSync( configDir )){
|
||||
fs.mkdirSync( configDir );
|
||||
cp( path.join( __dirname, 'default-template' ), path.join( configDir, 'default' ) );
|
||||
cp( path.join( __dirname, 'default-data.js' ), path.join( configDir, 'template_data.js' ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getTemplate( fname ){
|
||||
var ext = path.extname(fname).slice(1) || 'default';
|
||||
|
||||
if( fs.existsSync( path.join(configDir, ext ) ) ){
|
||||
return fs.readFileSync( path.join(configDir, ext ), 'utf-8' );
|
||||
} else {
|
||||
return fs.readFileSync( path.join(configDir, 'default' ), 'utf-8' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getConfig(){
|
||||
try{
|
||||
return require( path.join(configDir, 'template_data' ) );
|
||||
} catch(e){
|
||||
return { date: new Date(), user: process.env.USER, email: process.env.USER + '@' + os.hostname() };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getHeader( fname ){
|
||||
var template = getTemplate( fname );
|
||||
var config = getConfig();
|
||||
var data = Object.assign({ filename: fname }, config );
|
||||
return ejs.render( template, data );
|
||||
}
|
||||
|
||||
|
||||
function printHeader( fname ){
|
||||
var header = getHeader( fname );
|
||||
console.log( header );
|
||||
}
|
||||
|
||||
|
||||
if( require.main === module ){
|
||||
var fname = process.argv[2];
|
||||
initialize();
|
||||
|
||||
if( !fname ){
|
||||
console.log( 'file-header <filename>');
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
printHeader( fname );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "file-header",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"bin": {
|
||||
"file-header": "./main.js"
|
||||
},
|
||||
"author": {
|
||||
"name": "Harish.K",
|
||||
"email": "harish2704@gmail.com"
|
||||
},
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"ejs": "^2.5.3"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/harish2704/file-header.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/harish2704/file-header/issues"
|
||||
},
|
||||
"homepage": "https://github.com/harish2704/file-header#readme"
|
||||
}
|
||||
Reference in New Issue
Block a user