diff --git a/src/commands/plugins.ts b/src/commands/plugins.ts index 70ad271..05b9716 100644 --- a/src/commands/plugins.ts +++ b/src/commands/plugins.ts @@ -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 } diff --git a/src/index.ts b/src/index.ts index 858f639..8f3a56a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 ', 'Name(s) of plugin to install') .option('-S --save', 'Save and keep plugins updated') .action(plugins); diff --git a/src/prompts/plugin.ts b/src/prompts/plugin.ts index 8592884..195b865 100644 --- a/src/prompts/plugin.ts +++ b/src/prompts/plugin.ts @@ -41,3 +41,5 @@ interface Data { name: string; download_url: string; } + + diff --git a/src/utilities/types.ts b/src/utilities/types.ts index cf7dad6..80003c2 100644 --- a/src/utilities/types.ts +++ b/src/utilities/types.ts @@ -1 +1,10 @@ export type PackageManagerChoice = 'skip' | 'npm' | 'yarn'; + +export interface Config { + language: string; + paths : { + base: string; + commands: string; + } + +} diff --git a/src/utilities/version.ts b/src/utilities/version.ts new file mode 100644 index 0000000..25fa957 --- /dev/null +++ b/src/utilities/version.ts @@ -0,0 +1,6 @@ +import { requiree } from ".."; + +export function version() { + const { version: v } = requiree('../../package.json'); + return `@sern/cli v${v}`; +}