refactor: improve the spacing between code lines

This commit is contained in:
Allyedge
2022-05-11 15:20:01 +02:00
parent 59cb125435
commit bfe21818cc
7 changed files with 32 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
//! message for sern devs: ignore this!!!
//! Message for Sern CLI developers. Please ignore this file.
const SpinnerName = [
'dots',

View File

@@ -1,3 +1,3 @@
export function help() {
console.log('This is sern cli help section\n\n' + 'Fill me up later!');
console.log('This is the Sern CLI help section.\n\n' + 'Fill me up later!');
}

View File

@@ -25,12 +25,14 @@ export async function init({ flags }) {
}
const node = await execa('node', ['--version']);
if (/v1(([0-6]\.[2-9])|([0-5]\.[0-9]))/gm.test(node.stdout)) {
console.log(
yellowBright(
`\nYou are using Node ${node.stdout}\nPlease upgrade to Node 16.10.x or higher!\n`
)
);
process.exit(1);
}
@@ -39,7 +41,9 @@ export async function init({ flags }) {
if (Object.keys(data).length < 5) process.exit(1);
await cloneRepo(data.lang, data.name);
const git_init = await prompt([gitInit]);
if (!git_init.gitinit) {
console.log(`\nAlright\n`);
} else {
@@ -47,8 +51,11 @@ export async function init({ flags }) {
text: 'Initializing git...',
spinner: 'aesthetic',
}).start();
const exe = await execa('git', ['init', data.name]);
await wait(300);
if (!exe || exe?.failed) {
spin.fail(
`${redBright('Failed')} to initialize git!` +
@@ -56,17 +63,23 @@ export async function init({ flags }) {
);
process.exit(1);
}
spin.succeed('Git initialized!');
}
const pm = await npm();
let choice = '';
if (pm === 'both') {
const chosen = await prompt([which_manager]);
choice = chosen.manager;
} else choice = pm;
await installDeps(choice, data.name);
await editMain(data.name);
await editDirs(data.main_dir, data.cmds_dir, data.name);
}

View File

@@ -14,6 +14,7 @@ const args = rawArgs
.filter((e) => !/(--|-)\w+/gm.test(e));
const cmdName = args[0];
const commands = new Map([
['help', help],
['', help],

View File

@@ -22,7 +22,6 @@ export const lang = {
export const default_prefix = {
message:
'What is the default prefix for your bot? Type "none" if it is completely Application-Command based',
name: 'prefix',
type: 'text',
initial: '!',
@@ -53,6 +52,7 @@ export const npmInit = {
message: `Do you want to ${blueBright('me')} to initialize npm?`,
initial: true,
};
export const gitInit = {
name: 'gitinit',
type: 'confirm',

View File

@@ -51,6 +51,7 @@ export async function editDirs(
const tsconfig = await findUp('tsconfig.json', {
cwd: process.cwd() + '/' + name,
});
if (tsconfig) {
const output = JSON.parse(await readFile(tsconfig, 'utf8'));
if (!output) throw new Error("Can't read your tsconfig.json.");

View File

@@ -16,18 +16,26 @@ export async function installDeps(choice, name) {
const pkg = await findUp('package.json', {
cwd: process.cwd() + '/' + name,
});
if (!pkg) throw new Error('No package.json found!');
const output = JSON.parse(await readFile(pkg, 'utf8'));
if (!output) throw new Error("Can't read file.");
const deps = output.dependencies;
if (!deps) throw new Error("Can't find dependencies.");
const spin = ora({
text: `Installing dependencies...`,
spinner: 'aesthetic',
}).start();
const result = await execa(choice, ['install'], {
cwd: process.cwd() + '/' + name,
}).catch(() => null);
if (!result || result?.failed) {
spin.fail(`${redBright('Failed')} to install dependencies!`);
return process.exit(1);
@@ -44,7 +52,9 @@ export async function cloneRepo(lang, name) {
'clone',
`https://github.com/sern-handler/templates.git`, // ? See the idea of @Allyedge having templates built in cli
]);
copyRecursiveSync(`templates/templates/${lang}`, name);
fs.rmSync(`templates/`, { recursive: true, force: true });
}
@@ -57,10 +67,14 @@ export async function cloneRepo(lang, name) {
*/
function copyRecursiveSync(src, dest) {
var exists = fs.existsSync(src);
var stats = exists && fs.statSync(src);
var isDirectory = exists && stats.isDirectory();
if (isDirectory) {
fs.mkdirSync(dest);
fs.readdirSync(src).forEach(function (childItemName) {
copyRecursiveSync(
path.join(src, childItemName),