Files
pwcli/src/globals.ts
T
724f3905ab Add command to fix templates (#21)
* add command to fix templates

* replaceAll and lint fixes

* fixed menu

* fix lint command and run it

* add basic error handling for listing of templates

* CR suggestions

---------

Co-authored-by: Arwid Thornström <arwidt@gmail.com>
2024-08-16 09:34:15 +02:00

73 lines
1.6 KiB
TypeScript

import chalk = require('chalk');
const os = require('os');
const snakeCase = require('lodash.snakecase');
const { Confirm } = require('enquirer');
export const defaultMenuSettings = {
showHelp: false,
};
export type TConfig = {
gh_token: string;
photowall_repo: string;
mandrill_api_key: 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;
};
export const issueToBranchName = (issue) => {
return `${issue.number}-${snakeCase(issue.title).substr(0, 40)}`;
};
export const confirmMessage = async (message: string) => {
const confirm = new Confirm({
name: 'confirm',
message: message,
});
try {
return await confirm.run();
} catch (e) {
console.error(e);
return false;
}
};
export const sleep = (milliseconds) => {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
};