refactor: removing redundant return process.exit(), more concise cli

messages
This commit is contained in:
Jacob Nguyen
2022-05-08 22:54:26 -05:00
parent e74976a72c
commit 6086af063a
3 changed files with 28 additions and 27 deletions

View File

@@ -18,9 +18,10 @@ const { prompt } = prompts;
// TODO make this functional and better!
export async function init({ flags }) {
if (flags?.includes('y')) {
console.log("I see a flag there! Seems like you're lazy!\nBye!");
console.log("I see the -y flag there! Seems like you're lazy!\nBye!");
process.exit(0);
}
const node = await execa('node', ['--version']);
if ((/v1(([0-6]\.[2-9])|([0-5]\.[0-9]))/gm).test(node.stdout)) {
console.log(
@@ -28,7 +29,7 @@ export async function init({ flags }) {
`\nYou are using Node ${node.stdout}\nPlease upgrade to Node 16.10.x or higher!\n`
)
);
return process.exit(1);
process.exit(1);
}
const pkg = await findUp('package.json');
@@ -40,24 +41,24 @@ export async function init({ flags }) {
`${redBright('Failed')} to initialize Sern!` +
'\nMaybe you should run npm init?'
);
return process.exit(1);
} else {
const spin = ora({
text: 'Initializing npm...',
spinner: 'aesthetic',
}).start();
const exee = await execa('npm', ['init', '-y']).catch(
() => null
); /* .stdout.pipe(process.stdout) */
await wait(300);
if (!exee || exee?.failed) {
spin.fail(
`${redBright('Failed')} to initialize npm!` +
'\nMaybe you should run npm init?'
);
return process.exit(1);
} else spin.succeed('Npm initialized!');
}
process.exit(1);
}
const spin = ora({
text: 'Initializing npm...',
spinner: 'aesthetic',
}).start();
const exee = await execa('npm', ['init', '-y']).catch(
() => null
); /* .stdout.pipe(process.stdout) */
await wait(300);
if (!exee || exee?.failed) {
spin.fail(
`${redBright('Failed')} to initialize npm!` +
'\nMaybe you should run npm init?'
);
process.exit(1);
}
spin.succeed('Npm initialized!');
}
const git = await findUp('.git/config');
if (!git) {
@@ -81,8 +82,9 @@ export async function init({ flags }) {
`${redBright('Failed')} to initialize git!` +
'\nMaybe you should run git init?'
);
return process.exit(1);
} else spin.succeed('Git initialized!');
process.exit(1);
}
spin.succeed('Git initialized!');
return;
}
}

View File

@@ -8,7 +8,7 @@ import { findUp } from 'find-up';
export async function editMain(name) {
const pjLocation = await findUp('package.json');
const output = JSON.parse(await readFile(pjLocation, 'utf8'));
if (!output) throw new Error("Can't read file.");
if (!output) throw new Error("Can't read your package.json.");
output.main = name;

View File

@@ -22,7 +22,7 @@ const Intents = [
].map((i, j) => ({ title: i, value: j, short: `${j}` })); //! bad way
export const lang = {
message: 'What language you want the project to be in?',
message: 'What language do you want the project to be in?',
name: 'lang',
type: 'select',
choices: [
@@ -48,7 +48,7 @@ export const intent = {
export const default_prefix = {
message:
'What is the default prefix for your bot? Type "none" if it is completely based on Application Commands',
'What is the default prefix for your bot? Type "none" if it is completely Application-Command based',
name: 'prefix',
type: 'text',
@@ -59,7 +59,6 @@ export const token = {
message: 'What is your bot token?',
name: 'token',
type: 'password',
validate: (/** @type {string} */ token) =>
(/(?<mfaToken>mfa\.[a-z0-9_-]{20,})|(?<basicToken>[a-z0-9_-]{23,28}\.[a-z0-9_-]{6,7}\.[a-z0-9_-]{27})/i).test(token)
? true
@@ -86,7 +85,7 @@ export const cmds_dir = {
* @type {import('prompts').PromptObject}
*/
export const npmInit = {
name: 'npminit',
name: 'npm_init',
type: 'confirm',
message: `Do you want to ${blueBright('me')} to initialize npm?`,
initial: true,