7 Commits

Author SHA1 Message Date
jacoobes
088c3eb6ac fix: homepage 2023-03-31 13:08:35 -05:00
jacoobes
68c096e689 chore: use constant instead of function 2023-03-31 12:57:07 -05:00
jacoobes
34bf4d004c merge corectly 2023-03-31 12:40:46 -05:00
jacoobes
309bf5224a merge 2023-03-31 12:40:04 -05:00
jacoobes
4382ce6d5e Merge branch 'main' into plugin-version-management 2023-03-31 12:39:03 -05:00
jacoobes
731017f637 feat: add more methods 2023-02-16 12:07:16 -06:00
Jacob Nguyen
a3f5f1bf52 chore: update discord link (#89) 2023-02-16 11:46:11 -06:00
7 changed files with 77 additions and 27 deletions

View File

@@ -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",

View File

@@ -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`
)}`; )}`;
}

View File

@@ -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
}

View File

@@ -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,13 +23,14 @@ 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)

View File

@@ -41,3 +41,5 @@ interface Data {
name: string; name: string;
download_url: string; download_url: string;
} }

View File

@@ -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
View File

@@ -0,0 +1,6 @@
import { requiree } from "..";
export function version() {
const { version: v } = requiree('../../package.json');
return `@sern/cli v${v}`;
}