Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to set a proxy in the command line. #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 136 additions & 4 deletions bin/gitignore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,137 @@
#!/usr/bin/env node
var path = require('path');
var fs = require('fs');
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib/main.js');
require(lib);

const fs = require("fs");
const OS = require("os");
const commandLineArgs = require("command-line-args");
const commandLineUsage = require("command-line-usage");
const globalTunnel = require("global-tunnel-ng");
const GitIgnore = require("../lib/library");

const args = [
{
name: "type",
alias: "t",
type: String,
multiple: true,
defaultOption: true,
typeLabel: "[PROJECT TYPE]"
},
{
name: "types",
type: Boolean,
defaultValue: false,
description: "Retreive a list of available project types"
},
{
name: "proxy",
alias: "p",
type: String,
typeLabel: "[URL]",
description: "The URL of a proxy server to use"
},
{
name: "help",
alias: "h",
type: Boolean,
description: "Display this help message"
}
];

const help = args =>
console.log(
commandLineUsage([
{
header: "Usage",
content:
"gitignore [PROJECT TYPE]\n\n" +
"Available project types can be found by running `gitignore --types` or at https://github.com/github/gitignore"
},
{
header: "Example",
content: "gitignore rails"
},
{
header: "Options",
optionList: args.map(arg => ({
name: arg.name,
typeLabel: arg.typeLabel,
description: arg.description
}))
}
])
);

var options = {};

try {
options = commandLineArgs(args);
} catch (err) {
if (err.name == "UNKNOWN_OPTION") {
console.error("\n >>> %s <<<", err.message);
help(args);
} else {
console.error(err);
}

return;
}

if (options.proxy) {
process.env.HTTP_PROXY = options.proxy;
process.env.HTTPS_PROXY = options.proxy;

globalTunnel.initialize();
}

if (options.types) {
console.log("Fetching available types...");

GitIgnore.getTypes((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 if (Array.isArray(options.type)) {
options.type.map(type => {
type = type.charAt(0).toUpperCase() + type.slice(1);

GitIgnore.writeFile(
{
type: type,
file: fs.createWriteStream(".gitignore", { flags: "a" })
},
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 + " :)");
}
);
});
} else {
help(args);
}
55 changes: 0 additions & 55 deletions lib/main.js

This file was deleted.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
"author": "Michael Feldstein",
"name": "gitignore",
"description": "Automatically fetch gitignore files for any project type from github into your new project",
"version": "0.5.0",
"version": "1.0.0",
"license": "MIT",
"repository": {
"url": "https://github.com/msfeldstein/gitignore"
},
"main": "./lib/library.js",
"bin": {
"gitignore": "./bin/gitignore.js"
},
"dependencies": {},
"dependencies": {
"command-line-args": "^5.0.2",
"command-line-usage": "^5.0.5",
"global-tunnel-ng": "^2.6.0"
},
"devDependencies": {},
"optionalDependencies": {},
"engines": {
Expand Down