mirror of
https://github.com/sern-handler/cli
synced 2026-06-06 09:26:52 +00:00
Compare commits
20 Commits
v0.5.0
...
plugin-ver
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
088c3eb6ac | ||
|
|
68c096e689 | ||
|
|
34bf4d004c | ||
|
|
309bf5224a | ||
|
|
4382ce6d5e | ||
|
|
58fa3253f6 | ||
|
|
1421136181 | ||
|
|
f29c7881fe | ||
|
|
0d37da5689 | ||
|
|
504d36729e | ||
|
|
e391fddf20 | ||
|
|
e5d6de4841 | ||
|
|
fc47847eeb | ||
|
|
731017f637 | ||
|
|
a3f5f1bf52 | ||
|
|
386b30aedd | ||
|
|
f2531a6f9b | ||
| 69287ab1bd | |||
|
|
aa398a871c | ||
|
|
0855abfea3 |
4
.github/workflows/auto-deprecate.yml
vendored
4
.github/workflows/auto-deprecate.yml
vendored
@@ -12,10 +12,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout Project
|
||||
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
|
||||
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
with:
|
||||
node-version: 17
|
||||
registry-url: 'https://registry.npmjs.org/'
|
||||
|
||||
2
.github/workflows/codeql-analysis.yml
vendored
2
.github/workflows/codeql-analysis.yml
vendored
@@ -38,7 +38,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
|
||||
4
.github/workflows/continuous-delivery.yml
vendored
4
.github/workflows/continuous-delivery.yml
vendored
@@ -15,10 +15,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Check out Git repository
|
||||
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
|
||||
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
with:
|
||||
node-version: 17
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
8
.github/workflows/continuous-integration.yml
vendored
8
.github/workflows/continuous-integration.yml
vendored
@@ -17,10 +17,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Check out Git repository
|
||||
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
|
||||
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
with:
|
||||
node-version: 17
|
||||
|
||||
@@ -37,10 +37,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Check out Git repository
|
||||
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
|
||||
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
with:
|
||||
node-version: 17
|
||||
|
||||
|
||||
6
.github/workflows/publish.yml
vendored
6
.github/workflows/publish.yml
vendored
@@ -14,16 +14,16 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Check out Git repository
|
||||
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
|
||||
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
with:
|
||||
node-version: 17
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
- name: Install Node.js dependencies
|
||||
run: npm i
|
||||
run: npm i && npm run build
|
||||
|
||||
- name: Link Project
|
||||
run: npm link
|
||||
|
||||
8
.github/workflows/release-please.yml
vendored
8
.github/workflows/release-please.yml
vendored
@@ -12,15 +12,15 @@ jobs:
|
||||
with:
|
||||
release-type: node
|
||||
bump-patch-for-minor-pre-major: true
|
||||
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
|
||||
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
if: ${{ steps.release.outputs.release_created }}
|
||||
- uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
|
||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
with:
|
||||
node-version: 17
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
if: ${{ steps.release.outputs.release_created }}
|
||||
- run: npm i
|
||||
- run: npm i && npm run build
|
||||
if: ${{ steps.release.outputs.release_created }}
|
||||
- run: npm link
|
||||
if: ${{ steps.release.outputs.release_created }}
|
||||
@@ -29,4 +29,4 @@ jobs:
|
||||
- run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
if: ${{ steps.release.outputs.release_created }}
|
||||
if: ${{ steps.release.outputs.release_created }}
|
||||
|
||||
@@ -16,7 +16,7 @@ npm install -g @sern/cli@latest
|
||||
```
|
||||
|
||||
```sh
|
||||
yarn add -g @sern/cli@latest
|
||||
yarn global add @sern/cli@latest
|
||||
```
|
||||
|
||||
```sh
|
||||
|
||||
2881
package-lock.json
generated
2881
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@@ -11,7 +11,7 @@
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"format": "prettier --check .",
|
||||
"fix": "prettier --write .",
|
||||
"build": "tsc",
|
||||
"build": "tsup",
|
||||
"watch": "tsc --watch"
|
||||
},
|
||||
"repository": {
|
||||
@@ -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",
|
||||
@@ -41,10 +41,12 @@
|
||||
"undici": "^5.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@favware/npm-deprecate": "1.0.5",
|
||||
"@types/prompts": "2.0.14",
|
||||
"prettier": "2.7.1",
|
||||
"typescript": "4.7.4"
|
||||
"@favware/npm-deprecate": "1.0.7",
|
||||
"@types/prompts": "2.4.3",
|
||||
"esbuild-plugin-version-injector": "^1.0.3",
|
||||
"prettier": "2.8.4",
|
||||
"tsup": "^6.6.3",
|
||||
"typescript": "4.9.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 16.10.x"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { cyanBright, green, magentaBright } from 'colorette';
|
||||
|
||||
export function help() {
|
||||
return `
|
||||
export const help = `
|
||||
___ ___ _ __ _ __
|
||||
/ __|/ _ \\ '__| '_ \\
|
||||
\\__ \\ __/ | | | | |
|
||||
@@ -13,6 +12,5 @@ export function help() {
|
||||
)} for an interactive setup to your new bot project!
|
||||
|
||||
${green(
|
||||
`If you have any ideas, suggestions, bug reports, kindly join our support server: https://discord.gg/xzK5fUKT4r`
|
||||
`If you have any ideas, suggestions, bug reports, kindly join our support server: https://sern.dev/discord`
|
||||
)}`;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { greenBright, redBright } from 'colorette';
|
||||
import { greenBright, redBright, underline } from 'colorette';
|
||||
import { execa } from 'execa';
|
||||
import { findUp } from 'find-up';
|
||||
import ora from 'ora';
|
||||
@@ -98,19 +98,19 @@ async function git(data: Data) {
|
||||
spinner: 'aesthetic',
|
||||
}).start();
|
||||
|
||||
const exe = await execa('git', ['init', data.name]);
|
||||
|
||||
await wait(300);
|
||||
|
||||
if (!exe || exe?.failed) {
|
||||
try {
|
||||
await execa('git', ['init', data.name]);
|
||||
await wait(300);
|
||||
spin.succeed('Git initialized!');
|
||||
} catch (error) {
|
||||
spin.fail(
|
||||
`${redBright('Failed')} to initialize git!` +
|
||||
'\nMaybe you should run git init?'
|
||||
`${redBright(
|
||||
'Failed'
|
||||
)} to initialize git!\nTry to install it at ${underline(
|
||||
'https://git-scm.com'
|
||||
)}\nSkipping for now.`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
spin.succeed('Git initialized!');
|
||||
}
|
||||
|
||||
/** Wait for a specified number of milliseconds, then return a promise that resolves to undefined. */
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
24
src/index.ts
24
src/index.ts
@@ -6,13 +6,14 @@ import { init } from './commands/init.js';
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { plugins } from './commands/plugins.js';
|
||||
import { version } from './utilities/version.js';
|
||||
export const program = new Command();
|
||||
|
||||
const version: string = '[VI]{{inject}}[/VI]';
|
||||
|
||||
program
|
||||
.name('sern')
|
||||
.description(help())
|
||||
.version(version())
|
||||
.description(help)
|
||||
.version(`sern CLI v${version}`)
|
||||
.exitOverride(() => process.exit(0));
|
||||
|
||||
program
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ export async function installDeps(choice: PackageManagerChoice, name: string) {
|
||||
const result = await execa(choice, ['install'], {
|
||||
cwd: process.cwd() + '/' + name,
|
||||
}).catch(() => null);
|
||||
|
||||
if (!result || result?.failed) {
|
||||
spin.fail(`${redBright('Failed')} to install dependencies!`);
|
||||
process.exit(1);
|
||||
@@ -48,12 +49,21 @@ export async function installDeps(choice: PackageManagerChoice, name: string) {
|
||||
* @param name - The name of the project
|
||||
*/
|
||||
export async function cloneRepo(lang: string, name: string) {
|
||||
await execa('git', [
|
||||
'clone',
|
||||
`https://github.com/sern-handler/templates.git`,
|
||||
]);
|
||||
copyRecursiveSync(`templates/templates/${lang}`, name);
|
||||
fs.rmSync(`templates/`, { recursive: true, force: true });
|
||||
try {
|
||||
await execa('git', [
|
||||
'clone',
|
||||
`https://github.com/sern-handler/templates.git`,
|
||||
]);
|
||||
copyRecursiveSync(`templates/templates/${lang}`, name);
|
||||
fs.rmSync(`templates/`, { recursive: true, force: true });
|
||||
} catch (error) {
|
||||
console.log(
|
||||
`${redBright(
|
||||
'✖ Failed'
|
||||
)} to clone github templates repo. Install git and try again!`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1 +1,10 @@
|
||||
export type PackageManagerChoice = 'skip' | 'npm' | 'yarn';
|
||||
|
||||
export interface Config {
|
||||
language: string;
|
||||
paths : {
|
||||
base: string;
|
||||
commands: string;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { createRequire } from 'module';
|
||||
const require = createRequire(import.meta.url);
|
||||
import { requiree } from "..";
|
||||
|
||||
export function version() {
|
||||
const { version: v } = require('../../package.json');
|
||||
return `SernHandler CLI v${v}`;
|
||||
const { version: v } = requiree('../../package.json');
|
||||
return `@sern/cli v${v}`;
|
||||
}
|
||||
|
||||
19
tsup.config.ts
Normal file
19
tsup.config.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { defineConfig } from 'tsup'
|
||||
import { esbuildPluginVersionInjector } from 'esbuild-plugin-version-injector';
|
||||
const shared = {
|
||||
entry: ['src/index.ts'],
|
||||
platform: 'node',
|
||||
clean: true,
|
||||
sourcemap: true,
|
||||
};
|
||||
export default defineConfig(
|
||||
{
|
||||
format: 'esm',
|
||||
target: 'node16',
|
||||
tsconfig: './tsconfig.json',
|
||||
outDir: './dist',
|
||||
treeshake: true,
|
||||
esbuildPlugins: [esbuildPluginVersionInjector()],
|
||||
...shared,
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user