mirror of
https://github.com/sern-handler/cli
synced 2026-06-06 01:16:53 +00:00
Compare commits
7 Commits
v1.4.0
...
plugin-ver
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
088c3eb6ac | ||
|
|
68c096e689 | ||
|
|
34bf4d004c | ||
|
|
309bf5224a | ||
|
|
4382ce6d5e | ||
|
|
731017f637 | ||
|
|
a3f5f1bf52 |
@@ -30,7 +30,7 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/sern-handler/cli/issues"
|
||||
},
|
||||
"homepage": "https://sern-handler.js.org",
|
||||
"homepage": "https://sern.dev",
|
||||
"dependencies": {
|
||||
"colorette": "^2.0.16",
|
||||
"commander": "^9.3.0",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { cyanBright, green, magentaBright } from 'colorette';
|
||||
|
||||
export function help() {
|
||||
return `
|
||||
export const help = `
|
||||
___ ___ _ __ _ __
|
||||
/ __|/ _ \\ '__| '_ \\
|
||||
\\__ \\ __/ | | | | |
|
||||
@@ -15,4 +14,3 @@ export function help() {
|
||||
${green(
|
||||
`If you have any ideas, suggestions, bug reports, kindly join our support server: https://sern.dev/discord`
|
||||
)}`;
|
||||
}
|
||||
|
||||
@@ -1,26 +1,53 @@
|
||||
import { greenBright } from 'colorette';
|
||||
import fs from 'fs';
|
||||
import prompt from 'prompts';
|
||||
import { fetch } from 'undici';
|
||||
import { fetch, type Response } from 'undici';
|
||||
import { pluginsQ } from '../prompts/plugin.js';
|
||||
import { fromCwd } from '../utilities/fromCwd.js';
|
||||
|
||||
/**
|
||||
* Installs plugins to project
|
||||
*/
|
||||
export async function plugins() {
|
||||
const e: string[] = (await prompt([await pluginsQ()])).list;
|
||||
if (!e) process.exit(1);
|
||||
|
||||
for await (const url of e) {
|
||||
await download(url);
|
||||
}
|
||||
const pluginNames = e.map((e) => e.split('/').pop());
|
||||
console.log(
|
||||
`Successfully downloaded plugin(s):\n${greenBright(
|
||||
pluginNames.join('\n')
|
||||
)}`
|
||||
);
|
||||
function dispatchSave() {
|
||||
|
||||
}
|
||||
|
||||
function dispatchInstall() {
|
||||
|
||||
}
|
||||
|
||||
export async function plugins(options: PluginOptions) {
|
||||
if(options.save) {
|
||||
dispatchSave()
|
||||
}
|
||||
//Download instead based on names given. Must be a full filename ie: (publish)
|
||||
if(options.name) {
|
||||
|
||||
const pluginSource = await downloa();
|
||||
|
||||
}
|
||||
const e: string[] = (await prompt([await pluginsQ()])).list;
|
||||
if (!e) process.exit(1);
|
||||
|
||||
for await (const url of e) {
|
||||
await download(url);
|
||||
}
|
||||
const pluginNames = e.map((e) => e.split('/').pop());
|
||||
console.log(
|
||||
`Successfully downloaded plugin(s):\n${greenBright(
|
||||
pluginNames.join('\n')
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
async function downloa(url: string | URL) {
|
||||
const formatText = (res: Response) => res.text()
|
||||
return fetch(url, { method: 'GET' })
|
||||
.then(formatText)
|
||||
.catch(() => {
|
||||
throw Error('Download failed! Kindly contact developers')
|
||||
})
|
||||
}
|
||||
|
||||
async function download(url: string) {
|
||||
@@ -30,7 +57,7 @@ async function download(url: string) {
|
||||
|
||||
if (!data) throw new Error('Download failed! Kindly contact developers');
|
||||
|
||||
const dir = `${fromCwd('/src/plugins')}`;
|
||||
const dir = fromCwd('/src/plugins');
|
||||
const filedir = `${process.cwd()}/src/plugins/${url.split('/').pop()}`;
|
||||
|
||||
if (!fs.existsSync(dir)) {
|
||||
@@ -38,3 +65,9 @@ async function download(url: string) {
|
||||
}
|
||||
fs.writeFileSync(filedir, data);
|
||||
}
|
||||
|
||||
interface PluginOptions {
|
||||
name?: string[];
|
||||
save: boolean
|
||||
|
||||
}
|
||||
|
||||
20
src/index.ts
20
src/index.ts
@@ -9,9 +9,10 @@ import { plugins } from './commands/plugins.js';
|
||||
export const program = new Command();
|
||||
|
||||
const version: string = '[VI]{{inject}}[/VI]';
|
||||
|
||||
program
|
||||
.name('sern')
|
||||
.description(help())
|
||||
.description(help)
|
||||
.version(`sern CLI v${version}`)
|
||||
.exitOverride(() => process.exit(0));
|
||||
|
||||
@@ -22,14 +23,15 @@ program
|
||||
.option('-s, --sync', 'Syncs the project and generates sern.config.json')
|
||||
.action(init);
|
||||
|
||||
program
|
||||
.command(plugins.name)
|
||||
.description(
|
||||
'Install plugins from https://github.com/sern-handler/awesome-plugins'
|
||||
)
|
||||
.option('-n --name', 'Name of plugin')
|
||||
.action(plugins);
|
||||
|
||||
const pluginCommand = program.command(plugins.name)
|
||||
pluginCommand
|
||||
.description(
|
||||
'Get plugins from https://github.com/sern-handler/awesome-plugins'
|
||||
)
|
||||
.option('-n --name <string...>', 'Name(s) of plugin to install')
|
||||
.option('-S --save', 'Save and keep plugins updated')
|
||||
.action(plugins);
|
||||
|
||||
program
|
||||
.command(extra.name)
|
||||
.description('Easy way to add extra things in your sern project')
|
||||
|
||||
@@ -41,3 +41,5 @@ interface Data {
|
||||
name: string;
|
||||
download_url: string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1 +1,10 @@
|
||||
export type PackageManagerChoice = 'skip' | 'npm' | 'yarn';
|
||||
|
||||
export interface Config {
|
||||
language: string;
|
||||
paths : {
|
||||
base: string;
|
||||
commands: string;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
6
src/utilities/version.ts
Normal file
6
src/utilities/version.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { requiree } from "..";
|
||||
|
||||
export function version() {
|
||||
const { version: v } = requiree('../../package.json');
|
||||
return `@sern/cli v${v}`;
|
||||
}
|
||||
Reference in New Issue
Block a user