added support for current branch, and some cleanup

This commit is contained in:
Arwid Thornström
2022-01-21 15:23:19 +01:00
parent fda1b42e9f
commit c00be4305e
5 changed files with 78 additions and 38 deletions
+32
View File
@@ -1,4 +1,36 @@
import chalk = require("chalk");
const os = require("os");
export const defaultMenuSettings = {
showHelp: false
};
export type TConfig = {
gh_token: string;
photowall_repo: string;
};
export const getSettings = async (toolbox): Promise<TConfig | null> => {
const { filesystem, print } = toolbox;
try {
return await filesystem.readAsync(`${os.homedir()}/.pwcli_settings`, "json");
} catch {
print.error(`
No config found, please run [ ${chalk.cyan('pwcli s se')} ] or setup > settings from the menu.
`);
return null;
}
};
export const getCurrentBranch = async (path: string, toolbox): Promise<string | null> => {
const { system } = toolbox;
const config = await getSettings(toolbox);
if (config.photowall_repo) {
// git rev-parse --abbrev-ref HEAD
const branch = await system.run('git rev-parse --abbrev-ref HEAD', {cwd: config.photowall_repo, trim: true});
console.log(`branch`, branch);
return branch;
}
return null;
};