Initial Commit
This commit is contained in:
51
node_modules/gitignore/lib/library.js
generated
vendored
Normal file
51
node_modules/gitignore/lib/library.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
|
||||
var https = require('https');
|
||||
|
||||
var GitIgnore = {};
|
||||
|
||||
GitIgnore.getTypes = function(callback){
|
||||
var types = [];
|
||||
https.get({host: "api.github.com", path: "/repos/github/gitignore/contents", headers: {"User-Agent": "gitignore node app"}}, function(res) {
|
||||
if (res.statusCode !== 200) {
|
||||
var err = new Error("somethingWentWrong");
|
||||
err.statusCode = res.statusCode;
|
||||
return callback(err);
|
||||
}
|
||||
var body = "";
|
||||
res.on("data", function(chunk) {
|
||||
body += chunk;
|
||||
});
|
||||
res.on("end", function() {
|
||||
var json = JSON.parse(body);
|
||||
for(var i = 0; i < json.length; ++i) {
|
||||
var name = json[i].name;
|
||||
var cleanName = name.substr(0, name.indexOf('.'));
|
||||
if (cleanName.length > 0 && name.match(/\.gitignore$/)){
|
||||
types.push(cleanName);
|
||||
}
|
||||
}
|
||||
callback(null, types);
|
||||
});
|
||||
}).on("error", callback);
|
||||
};
|
||||
|
||||
GitIgnore.writeFile = function(options, callback){
|
||||
if(!options.type){
|
||||
return callback(new Error("noTypeProvided"));
|
||||
}
|
||||
if(!options.file && !options.writable){
|
||||
return callback(new Error("noWritableProvided"));
|
||||
}
|
||||
https.get("https://raw.githubusercontent.com/github/gitignore/master/" + options.type + ".gitignore", function(res) {
|
||||
if (res.statusCode !== 200) {
|
||||
var err = new Error("typeDoesNotExist");
|
||||
err.statusCode = res.statusCode;
|
||||
return callback(err);
|
||||
}
|
||||
res.pipe(options.file || options.writable);
|
||||
return callback();
|
||||
}).on("error", callback);
|
||||
};
|
||||
|
||||
module.exports = GitIgnore;
|
||||
55
node_modules/gitignore/lib/main.js
generated
vendored
Normal file
55
node_modules/gitignore/lib/main.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
|
||||
var GitIgnore = require('./library');
|
||||
var fs = require('fs');
|
||||
var OS = require('os');
|
||||
|
||||
(function() {
|
||||
var types = process.argv.slice(2);
|
||||
|
||||
if (!types || types.length === 0) {
|
||||
console.log("Usage: gitignore [PROJECT TYPE]");
|
||||
console.log("Example: gitignore rails");
|
||||
console.log("Available project types can be found by running `gitignore -types` or at https://github.com/github/gitignore");
|
||||
return;
|
||||
}
|
||||
|
||||
if (/^((--?)?types|-t)$/i.test(types.join())) {
|
||||
console.log("Fetching available types...");
|
||||
GitIgnore.getTypes(function(err, types){
|
||||
if(err){
|
||||
if(err.statusCode){
|
||||
console.error("Could not access file from GitHub. Recieved status code "+err.statusCode);
|
||||
} else {
|
||||
console.error("An unexpected error occurred.");
|
||||
console.error(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
console.log(types.join(OS.EOL));
|
||||
});
|
||||
} else {
|
||||
types.forEach(function(type) {
|
||||
type = type.charAt(0).toUpperCase() + type.slice(1);
|
||||
var file = fs.createWriteStream(".gitignore", {'flags': 'a'});
|
||||
GitIgnore.writeFile({
|
||||
type: type,
|
||||
file: file
|
||||
}, function(err){
|
||||
if(err){
|
||||
if(err.statusCode){
|
||||
console.log("There is no gitignore for " + type);
|
||||
console.log("Available project types can be found by running `gitignore -types` or at https://github.com/github/gitignore");
|
||||
console.error("Recieved status code "+err.statusCode);
|
||||
} else {
|
||||
console.error("An unexpected error occurred.");
|
||||
console.error(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
console.log("Created .gitignore file for type "+type+" :)");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}).call(this);
|
||||
Reference in New Issue
Block a user