mirror of
https://github.com/SrIzan10/sern-cli.git
synced 2026-05-01 11:05:17 +00:00
feat(init): add --sync flag (#53)
This commit is contained in:
@@ -19,6 +19,9 @@ import { editDirs, editMain } from '../utilities/edits.js';
|
||||
import { writeFile } from 'fs/promises';
|
||||
const { prompt } = prompts;
|
||||
|
||||
/**
|
||||
* @param {{ y: string; sync: string; }} flags
|
||||
*/
|
||||
export async function init(flags) {
|
||||
// * Check if node version is valid
|
||||
const node = await execa('node', ['--version']);
|
||||
@@ -46,6 +49,8 @@ export async function init(flags) {
|
||||
main_dir: 'src',
|
||||
cmds_dir: 'commands',
|
||||
};
|
||||
} else if (flags.sync) {
|
||||
data = await prompt([lang, main_dir, cmds_dir]);
|
||||
} else {
|
||||
data = await prompt([name, lang, main_dir, cmds_dir]);
|
||||
git_init = (await prompt([gitInit])).gitinit;
|
||||
@@ -59,22 +64,32 @@ export async function init(flags) {
|
||||
commands: data.cmds_dir,
|
||||
},
|
||||
};
|
||||
|
||||
const file = JSON.stringify(config, null, 2);
|
||||
|
||||
if (Object.keys(data).length < 4) process.exit(1);
|
||||
const requiredData = flags.sync !== undefined ? 3 : 4;
|
||||
const receivedData = Object.keys(data).length;
|
||||
const hasRequiredData = receivedData < requiredData;
|
||||
|
||||
await cloneRepo(data.lang, data.name);
|
||||
if (hasRequiredData) process.exit(1);
|
||||
|
||||
if (!flags.sync) await cloneRepo(data.lang, data.name);
|
||||
|
||||
const pkg = await findUp('package.json', {
|
||||
cwd: process.cwd() + '/' + data.name,
|
||||
});
|
||||
|
||||
if (!pkg) throw new Error('No package.json found! Clone Failed');
|
||||
if (!pkg) throw new Error('No package.json found!');
|
||||
|
||||
if (pkg) {
|
||||
await writeFile(pkg.replace('package.json', 'sern.config.json'), file);
|
||||
}
|
||||
|
||||
if (flags.sync) {
|
||||
console.log('Project was successfully synced!');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
git_init ? await git(data) : console.log(`Skipping git init...\n`);
|
||||
|
||||
let choice;
|
||||
|
||||
@@ -19,6 +19,7 @@ program
|
||||
.command(init.name)
|
||||
.description('Quickest way to scaffold a new project')
|
||||
.option('-y', 'Finishes setup as default')
|
||||
.option('-s, --sync', 'Syncs the project and generates sern.config.json')
|
||||
.action(init);
|
||||
|
||||
program
|
||||
|
||||
Reference in New Issue
Block a user