mirror of
https://github.com/sern-handler/cli
synced 2026-06-06 01:16:53 +00:00
feat: add sern.config.json (#38)
This commit is contained in:
@@ -2,6 +2,7 @@ import prompts from 'prompts';
|
||||
import ora from 'ora';
|
||||
import { redBright, yellowBright } from 'colorette';
|
||||
import { execa } from 'execa';
|
||||
import { findUp } from 'find-up';
|
||||
import {
|
||||
cmds_dir,
|
||||
default_prefix,
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
import { npm } from '../utilities/npm.js';
|
||||
import { cloneRepo, installDeps } from '../utilities/install.js';
|
||||
import { editDirs, editMain } from '../utilities/edits.js';
|
||||
import { writeFile } from 'fs/promises';
|
||||
const { prompt } = prompts;
|
||||
|
||||
export async function init(flags, options) {
|
||||
@@ -34,6 +36,7 @@ export async function init(flags, options) {
|
||||
let data;
|
||||
let git_init;
|
||||
let pm;
|
||||
|
||||
if (flags.y) {
|
||||
const projectName = await prompt([name]);
|
||||
git_init = true;
|
||||
@@ -51,10 +54,29 @@ export async function init(flags, options) {
|
||||
pm = await npm();
|
||||
}
|
||||
|
||||
const config = {
|
||||
language: data.lang,
|
||||
paths: {
|
||||
base: data.main_dir,
|
||||
commands: data.cmds_dir,
|
||||
},
|
||||
};
|
||||
const file = JSON.stringify(config, null, 2);
|
||||
|
||||
if (Object.keys(data).length < 5) process.exit(1);
|
||||
|
||||
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) {
|
||||
await writeFile(pkg.replace('package.json', 'sern.config.json'), file);
|
||||
}
|
||||
|
||||
git_init ? await git(data) : console.log(`Skipping git init...\n`);
|
||||
|
||||
let choice = '';
|
||||
|
||||
@@ -38,7 +38,7 @@ export async function installDeps(choice, name) {
|
||||
}).catch(() => null);
|
||||
if (!result || result?.failed) {
|
||||
spin.fail(`${redBright('Failed')} to install dependencies!`);
|
||||
return process.exit(1);
|
||||
process.exit(1);
|
||||
} else spin.succeed(`Dependencies installed!`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user