mirror of
https://github.com/sern-handler/cli
synced 2026-06-06 01:16:53 +00:00
feat: add commander and start plugins installer (#36)
Co-authored-by: EvolutionX
This commit is contained in:
1263
package-lock.json
generated
1263
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -34,6 +34,7 @@
|
||||
"homepage": "https://github.com/sern-handler/cli#readme",
|
||||
"dependencies": {
|
||||
"colorette": "^2.0.16",
|
||||
"commander": "^9.3.0",
|
||||
"degit": "^2.8.4",
|
||||
"execa": "^6.1.0",
|
||||
"find-up": "6.3.0",
|
||||
@@ -41,7 +42,7 @@
|
||||
"prompts": "2.4.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"cz-conventional-changelog": "3.3.0",
|
||||
"cz-conventional-changelog": "^3.0.1",
|
||||
"eslint": "8.15.0",
|
||||
"prettier": "2.6.2",
|
||||
"standard-version": "9.5.0"
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import { version } from '../utilities/version.js';
|
||||
|
||||
export function help({ flags }) {
|
||||
if (flags?.includes('v') || flags?.includes('version')) return version();
|
||||
console.log('This is the Sern CLI help section.\n\n' + 'Fill me up later!');
|
||||
export function help() {
|
||||
return 'This is the Sern CLI help section.\n\n' + 'TODO';
|
||||
}
|
||||
|
||||
@@ -12,12 +12,13 @@ import {
|
||||
skip_install_dep,
|
||||
name,
|
||||
} from '../prompts/init.js';
|
||||
|
||||
import { npm } from '../utilities/npm.js';
|
||||
import { cloneRepo, installDeps } from '../utilities/install.js';
|
||||
import { editDirs, editMain } from '../utilities/edits.js';
|
||||
const { prompt } = prompts;
|
||||
|
||||
export async function init({ flags }) {
|
||||
export async function init(flags, options) {
|
||||
// * Check if node version is valid
|
||||
const node = await execa('node', ['--version']);
|
||||
if (/v1(([0-6]\.[2-9])|([0-5]\.[0-9]))/gm.test(node.stdout)) {
|
||||
@@ -33,8 +34,7 @@ export async function init({ flags }) {
|
||||
let data;
|
||||
let git_init;
|
||||
let pm;
|
||||
|
||||
if (flags?.includes('y')) {
|
||||
if (flags.y) {
|
||||
const projectName = await prompt([name]);
|
||||
git_init = true;
|
||||
pm = 'npm';
|
||||
@@ -69,7 +69,7 @@ export async function init({ flags }) {
|
||||
|
||||
await installDeps(choice, data.name);
|
||||
await editMain(data.name);
|
||||
await editDirs(data.main_dir, data.cmds_dir, data.name);
|
||||
await editDirs(data.main_dir, data.cmds_dir, data.name, data.lang);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
5
src/commands/plugins.js
Normal file
5
src/commands/plugins.js
Normal file
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Installs plugins to project
|
||||
* @param flags
|
||||
*/
|
||||
export function plugins(flags) {}
|
||||
39
src/index.js
39
src/index.js
@@ -2,29 +2,26 @@
|
||||
|
||||
import { init } from './commands/init.js';
|
||||
import { help } from './commands/help.js';
|
||||
import { extra } from './commands/extra.js';
|
||||
|
||||
const regex = /(?<=--|-)\w+/gm;
|
||||
const rawArgs = process.argv.slice(2);
|
||||
const flags = rawArgs.join(' ').match(regex);
|
||||
import { Command } from 'commander';
|
||||
import { version } from './utilities/version.js';
|
||||
import { plugins } from './commands/plugins.js';
|
||||
export const program = new Command();
|
||||
|
||||
const args = rawArgs
|
||||
.join(' ')
|
||||
.trim()
|
||||
.split(/ +/)
|
||||
.filter((e) => !/(--|-)\w+/gm.test(e));
|
||||
program.name('sern').description(help()).version(version());
|
||||
|
||||
const cmdName = args[0] || '';
|
||||
program
|
||||
.command(init.name)
|
||||
.description('Quickest way to scaffold a new project')
|
||||
.option('-y', 'Finishes setup as default')
|
||||
.action(init);
|
||||
|
||||
const commands = new Map([
|
||||
['help', help],
|
||||
['', help],
|
||||
['init', init],
|
||||
['extra', extra],
|
||||
]);
|
||||
program
|
||||
.command(plugins.name)
|
||||
.description(
|
||||
'Install plugins from https://github.com/sern-handler/awesome-plugins'
|
||||
)
|
||||
.option('-n --name', 'Name of plugin')
|
||||
.action(plugins);
|
||||
|
||||
const found = commands.get(cmdName);
|
||||
|
||||
if (found) {
|
||||
await found({ args, flags });
|
||||
} else console.log('Unknown Command');
|
||||
program.parse();
|
||||
|
||||
@@ -9,13 +9,11 @@ export const lang = {
|
||||
title: 'JavaScript',
|
||||
description: 'JS',
|
||||
value: 'javascript',
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
title: 'TypeScript',
|
||||
description: 'TS',
|
||||
description: 'TS - (Recommended)',
|
||||
value: 'typescript',
|
||||
selected: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -70,6 +70,6 @@ export async function editDirs(
|
||||
regex,
|
||||
`commands: '${newfold}/${cmds_dirName}'`
|
||||
);
|
||||
|
||||
// TODO(@jacoobes): edit prefix as well in index.ts/js
|
||||
return writeFile(index, edit);
|
||||
}
|
||||
|
||||
@@ -48,13 +48,15 @@ export async function installDeps(choice, name) {
|
||||
* Clone the repo, copy the files from the repo to the new project directory, and delete the repo
|
||||
* @param {string} lang - The language of the template
|
||||
* @param {string} name - The name of the project
|
||||
* @param {string} location - Location of repository
|
||||
* @param {string} subDirs - path of sub-directory of location, if any
|
||||
*/
|
||||
export async function cloneRepo(lang, name) {
|
||||
const isCached = fs.existsSync(
|
||||
const isCached = fs.existsSync( //! @deprecated will be removed in future versions
|
||||
path.join(os.homedir(), '.degit/github/sern-handler/templates')
|
||||
);
|
||||
const emitter = degit('sern-handler/templates/templates', {
|
||||
cache: isCached,
|
||||
cache: false,
|
||||
force: true,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { createRequire } from 'module';
|
||||
const require = createRequire(import.meta.url);
|
||||
const { version: v } = require('../../package.json');
|
||||
|
||||
export function version() {
|
||||
console.log(`SernHandler CLI v${v}`);
|
||||
const { version: v } = require('../../package.json');
|
||||
return `SernHandler CLI v${v}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user