Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Add ability to set global packages #74

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules/
*.bcup
*.git-label-maker-config
38 changes: 37 additions & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// EXTERNAL DEPENDENCIES
const fs = require("fs"),
iq = require("inquirer"),
pathTool = require("path"),
gitLabel = require("git-label");
// UTILS ARE STANDALONE METHODS WITH NO DEPENDENCIES
const alertDeletes = require("./utils/alertDeletes"),
Expand Down Expand Up @@ -103,6 +104,20 @@ const addFromPackage = (repo, token, path) => {
.catch(console.warn);
};

const setGlobalPackage = (path, token) => {
fs.writeFile('.git-label-maker-config', pathTool.resolve(__dirname, '..', path), (err) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EmmaRamirez "labelmaker" should match the name of the repo, like .git-labelmaker-config' 👍

if (err) throw err;
console.log("\n");
console.log("Saved " + path + " as global. When you specify no file when adding from a package, the global will be used instead.");
console.log("\n");
gitLabelmaker(token);
});
};

const getGlobalPackage = () => {
return fs.readFileSync('.git-label-maker-config', 'utf-8');
}

// removeLabels function
const removeLabels = (repo, token, answers) => {
// Tell the user what they're about to lose
Expand Down Expand Up @@ -145,7 +160,28 @@ const handleMainPrompts = (repo, token, ans) => {
validate: validateAddPackages
}])
.then((ans)=>{
return addFromPackage( repo, token, ans.path );
if (ans.path !== "") {
return addFromPackage( repo, token, ans.path );
} else {
try {
addFromPackage( repo, token, getGlobalPackage() );
} catch (e) {
console.log("Either an incorrect global was used or no global package has been set yet.");
}
}
})
.catch(console.warn);
break;

case "add global package":
prompt([{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can break off this array for the prompt and put it in the ./bin/prompts/ directory 👍

name: "path",
type: "input",
message: "What is the pathname you want to use for your package? (Must be valid json)",
validate: validateAddPackages
}])
.then((ans)=>{
return setGlobalPackage( ans.path, token );
})
.catch(console.warn);
break;
Expand Down
2 changes: 2 additions & 0 deletions bin/modules/validateAddPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const isJsonString = require("../utils/isJsonString");
module.exports = function (jsonPath) {
// Declare function as asynchronous, and save the done callback
let done = this.async();
// this is clunky, but this way we can just use a default
if (jsonPath === "") done(true);
try {
if (jsonPath.indexOf(".json") < 0) {
done("Not a JSON file");
Expand Down
2 changes: 1 addition & 1 deletion bin/prompts/mainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = [
type: "list",
name: "main",
message: "Welcome to git-labelmaker!\nWhat would you like to do?",
choices: [ "Add Custom Labels", "Add Labels From Package", "Create a Package From Labels", "Remove Labels", "Remove All Labels", "Reset Token", "Quit" ]
choices: [ "Add Custom Labels", "Add Labels From Package", "Add Global Package", "Create a Package From Labels", "Remove Labels", "Remove All Labels", "Reset Token", "Quit" ]
}
];
1 change: 1 addition & 0 deletions bin/utils/banners.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
welcome: printBanner(" Welcome to git-labelmaker "),
addCustom: printBanner(" Adding Custom Labels "),
addFromPackage: printBanner(" Adding Labels From Package "),
addGlobalPackage: printBanner(" Add Global Package "),
createPkgFromLabels: printBanner(" Creating Package From Labels "),
removeLabels: printBanner(" Removing Labels "),
resetToken: printBanner(" Resetting Token "),
Expand Down