This commit is contained in:
jacoobes
2023-03-31 12:40:04 -05:00
parent 4382ce6d5e
commit 309bf5224a
5 changed files with 67 additions and 15 deletions

View File

@@ -1,27 +1,56 @@
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
*/
function dispatchSave() {
}
function dispatchInstall() {
}
export async function plugins(options: PluginOptions) {
console.log(options)
const e: string[] = (await prompt([await pluginsQ()])).list;
if (!e) process.exit(1);
if(options.save) {
dispatchSave()
}
//Download instead based on names given. Must be a full filename ie: (publish.ts)
if(options.name) {
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')
)}`
);
}
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, path: string) {
const format = (res: Response) => res.text()
const data = await fetch(url, { method: 'GET' })
.then(format)
.catch(() => {
throw Error('Download failed! Kindly contact developers')
})
const fullPath = fromCwd(path)
}
async function download(url: string) {
@@ -41,7 +70,7 @@ async function download(url: string) {
}
interface PluginOptions {
name?: string;
save: boolean
name?: string[];
save: boolean
}

View File

@@ -8,7 +8,13 @@ import { Command } from 'commander';
import { plugins } from './commands/plugins.js';
export const program = new Command();
<<<<<<< Updated upstream
const version: string = '[VI]{{inject}}[/VI]';
=======
import { createRequire } from 'module';
export const requiree = createRequire(import.meta.url);
>>>>>>> Stashed changes
program
.name('sern')
.description(help())
@@ -27,7 +33,7 @@ pluginCommand
.description(
'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')
.option('-S --save', 'Save and keep plugins updated')
.action(plugins);

View File

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

View File

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

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