mirror of
https://github.com/sern-handler/cli
synced 2026-06-09 17:32:26 +00:00
Compare commits
7 Commits
main
...
plugin-ver
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
088c3eb6ac | ||
|
|
68c096e689 | ||
|
|
34bf4d004c | ||
|
|
309bf5224a | ||
|
|
4382ce6d5e | ||
|
|
731017f637 | ||
|
|
a3f5f1bf52 |
@@ -30,7 +30,7 @@
|
|||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/sern-handler/cli/issues"
|
"url": "https://github.com/sern-handler/cli/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://sern-handler.js.org",
|
"homepage": "https://sern.dev",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"colorette": "^2.0.16",
|
"colorette": "^2.0.16",
|
||||||
"commander": "^9.3.0",
|
"commander": "^9.3.0",
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { cyanBright, green, magentaBright } from 'colorette';
|
import { cyanBright, green, magentaBright } from 'colorette';
|
||||||
|
|
||||||
export function help() {
|
export const help = `
|
||||||
return `
|
|
||||||
___ ___ _ __ _ __
|
___ ___ _ __ _ __
|
||||||
/ __|/ _ \\ '__| '_ \\
|
/ __|/ _ \\ '__| '_ \\
|
||||||
\\__ \\ __/ | | | | |
|
\\__ \\ __/ | | | | |
|
||||||
@@ -15,4 +14,3 @@ export function help() {
|
|||||||
${green(
|
${green(
|
||||||
`If you have any ideas, suggestions, bug reports, kindly join our support server: https://sern.dev/discord`
|
`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 { greenBright } from 'colorette';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import prompt from 'prompts';
|
import prompt from 'prompts';
|
||||||
import { fetch } from 'undici';
|
import { fetch, type Response } from 'undici';
|
||||||
import { pluginsQ } from '../prompts/plugin.js';
|
import { pluginsQ } from '../prompts/plugin.js';
|
||||||
import { fromCwd } from '../utilities/fromCwd.js';
|
import { fromCwd } from '../utilities/fromCwd.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installs plugins to project
|
* 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) {
|
function dispatchSave() {
|
||||||
await download(url);
|
|
||||||
}
|
}
|
||||||
const pluginNames = e.map((e) => e.split('/').pop());
|
|
||||||
console.log(
|
function dispatchInstall() {
|
||||||
`Successfully downloaded plugin(s):\n${greenBright(
|
|
||||||
pluginNames.join('\n')
|
}
|
||||||
)}`
|
|
||||||
);
|
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) {
|
async function download(url: string) {
|
||||||
@@ -30,7 +57,7 @@ async function download(url: string) {
|
|||||||
|
|
||||||
if (!data) throw new Error('Download failed! Kindly contact developers');
|
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()}`;
|
const filedir = `${process.cwd()}/src/plugins/${url.split('/').pop()}`;
|
||||||
|
|
||||||
if (!fs.existsSync(dir)) {
|
if (!fs.existsSync(dir)) {
|
||||||
@@ -38,3 +65,9 @@ async function download(url: string) {
|
|||||||
}
|
}
|
||||||
fs.writeFileSync(filedir, data);
|
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();
|
export const program = new Command();
|
||||||
|
|
||||||
const version: string = '[VI]{{inject}}[/VI]';
|
const version: string = '[VI]{{inject}}[/VI]';
|
||||||
|
|
||||||
program
|
program
|
||||||
.name('sern')
|
.name('sern')
|
||||||
.description(help())
|
.description(help)
|
||||||
.version(`sern CLI v${version}`)
|
.version(`sern CLI v${version}`)
|
||||||
.exitOverride(() => process.exit(0));
|
.exitOverride(() => process.exit(0));
|
||||||
|
|
||||||
@@ -22,14 +23,15 @@ program
|
|||||||
.option('-s, --sync', 'Syncs the project and generates sern.config.json')
|
.option('-s, --sync', 'Syncs the project and generates sern.config.json')
|
||||||
.action(init);
|
.action(init);
|
||||||
|
|
||||||
program
|
const pluginCommand = program.command(plugins.name)
|
||||||
.command(plugins.name)
|
pluginCommand
|
||||||
.description(
|
.description(
|
||||||
'Install plugins from https://github.com/sern-handler/awesome-plugins'
|
'Get plugins from https://github.com/sern-handler/awesome-plugins'
|
||||||
)
|
)
|
||||||
.option('-n --name', 'Name of plugin')
|
.option('-n --name <string...>', 'Name(s) of plugin to install')
|
||||||
.action(plugins);
|
.option('-S --save', 'Save and keep plugins updated')
|
||||||
|
.action(plugins);
|
||||||
|
|
||||||
program
|
program
|
||||||
.command(extra.name)
|
.command(extra.name)
|
||||||
.description('Easy way to add extra things in your sern project')
|
.description('Easy way to add extra things in your sern project')
|
||||||
|
|||||||
@@ -41,3 +41,5 @@ interface Data {
|
|||||||
name: string;
|
name: string;
|
||||||
download_url: string;
|
download_url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,10 @@
|
|||||||
export type PackageManagerChoice = 'skip' | 'npm' | 'yarn';
|
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