New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@kokkoro/cli

Package Overview
Dependencies
Maintainers
2
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kokkoro/cli - npm Package Compare versions

Comparing version
2.0.1
to
2.0.2
+15
-34
lib/index.js
#!/usr/bin/env node
import { cwd } from 'process';
import { join } from 'node:path';
import { readFile } from 'node:fs/promises';
import { program } from 'commander';
import { fileURLToPath } from 'node:url';
import { readFile } from 'node:fs/promises';
import { colorful } from '@kokkoro/utils';
import init from './init.js';
import start from './start.js';
import plugin from './plugin.js';
export const plugins_path = join(cwd(), `plugins`);
export const config_path = join(cwd(), 'kokkoro.json');
export const colors = {
red: colorful(31),
green: colorful(32),
yellow: colorful(33),
blue: colorful(34),
magenta: colorful(35),
cyan: colorful(36),
white: colorful(37),
};
export const TIP_INFO = colors.cyan('Info:');
export const TIP_ERROR = colors.red('Error:');
export const TIP_WARN = colors.yellow('Warn:');
export const TIP_SUCCESS = colors.green('Success:');
async function getVersion() {
const url = new URL('../package.json', import.meta.url);
const text = await readFile(url, 'utf-8');
const { version } = JSON.parse(text);
return version;
}
const root = process.cwd();
const version = await getVersion();
export const plugins_path = join(root, `plugins`);
export const config_path = join(root, 'kokkoro.json');
export const INFO = colorful('Cyan', 'Info');
export const ERROR = colorful('Red', 'Error');
export const WARN = colorful('Yellow', 'Warn');
export const SUCCESS = colorful('Green', 'Success');
init(program);

@@ -30,17 +27,1 @@ start(program);

program.name('kokkoro').version(version, '-v, --version').parse();
/**
* 控制台彩色打印
*
* @param {number} code - ANSI escape code
* @returns {Function}
*/
function colorful(code) {
return (msg) => `\u001b[${code}m${msg}\u001b[0m`;
}
async function getVersion() {
const url = join(import.meta.url, '../../package.json');
const path = fileURLToPath(url);
const text = await readFile(path, 'utf8');
const { version } = JSON.parse(text);
return version;
}

@@ -1,3 +0,1 @@

import ora from 'ora';
import prompts from 'prompts';
import { exit } from 'node:process';

@@ -8,3 +6,6 @@ import { existsSync } from 'node:fs';

import { writeFile, mkdir } from 'node:fs/promises';
import { colors, config_path, plugins_path, TIP_ERROR, TIP_INFO, TIP_SUCCESS, TIP_WARN } from './index.js';
import ora from 'ora';
import prompts from 'prompts';
import { colorful } from '@kokkoro/utils';
import { ERROR, INFO, SUCCESS, WARN, config_path, plugins_path } from './index.js';
const questions = [

@@ -27,2 +28,7 @@ {

{
type: 'confirm',
name: 'is_public',
message: 'Is it a public domain robot?',
},
{
type: 'number',

@@ -36,26 +42,2 @@ name: 'port',

{
type: 'multiselect',
name: 'plugins',
message: 'Select the plugins to install',
choices: [
{
title: 'pcr',
value: 'kokkoro-plugin-pcr',
description: '公主连结(我不想打公会战.jpg)',
},
{
title: 'hitokoto',
value: 'kokkoro-plugin-hitokoto',
description: '一言语句(才不是网抑云)',
},
{
title: 'aircon',
value: 'kokkoro-plugin-aircon',
description: '群空调,低碳环保无污染,就是没风',
disabled: true,
},
],
warn: '- 近期重构中,当前插件暂时不可用',
},
{
type: 'select',

@@ -71,6 +53,2 @@ name: 'manager',

];
const onCancel = () => {
console.log(`${TIP_INFO} config file generation has been aborted.\n`);
exit();
};
const app_template = `import { setup } from 'kokkoro';\n\nsetup();\n`;

@@ -84,7 +62,13 @@ export default function (program) {

if (!options.forced && existsSync(config_path)) {
console.warn(`${TIP_ERROR} config file already exists. If you want to overwrite the current file, use ${colors.cyan('kokkoro init -f')}.\n`);
console.warn(`${ERROR}: config file already exists. If you want to overwrite the current file, use ${colorful('Cyan', 'kokkoro init -f')}.\n`);
exit(1);
}
const response = await prompts(questions, { onCancel });
const { appid, token, secret, port, plugins, manager } = response;
const response = await prompts(questions, {
onCancel() {
console.log(`${INFO}: config file generation has been aborted.\n`);
exit();
},
});
const { appid, token, secret, is_public, port, manager } = response;
const events = is_public ? ['PUBLIC_GUILD_MESSAGES'] : ['PUBLIC_GUILD_MESSAGES', 'GUILD_MESSAGES'];
const kokkoroConfig = {

@@ -96,3 +80,4 @@ $schema: 'https://kokkoro.js.org/schema.json',

},
logLevel: 'INFO',
events,
log_level: 'INFO',
bots: [{ appid, token, secret }],

@@ -106,9 +91,9 @@ };

}
console.log(`${TIP_SUCCESS} created config file ${colors.cyan(config_path)}.\n`);
console.log(`${SUCCESS}: created config file ${colorful('Cyan', config_path)}.\n`);
const promiseExec = promisify(exec);
await promiseExec('npm init -y && npm pkg set type="module"');
const modules = ['kokkoro', ...plugins];
const modules = ['kokkoro'];
const modules_length = modules.length;
let install_success = true;
let install_message = `${TIP_SUCCESS} project is initialized successfully.\n`;
let install_message = `${SUCCESS}: project is initialized successfully.\n`;
for (let i = 0; i < modules_length; i++) {

@@ -126,3 +111,3 @@ const module = modules[i];

install_success = false;
install_message = `${TIP_WARN} npm package was not installed successfully.\n`;
install_message = `${WARN}: npm package was not installed successfully.\n`;
}

@@ -137,3 +122,3 @@ }

const message = error instanceof Error ? error.message : JSON.stringify(error);
console.warn(`\n${TIP_ERROR} ${message}.`);
console.warn(`\n${ERROR}: ${message}.`);
exit(1);

@@ -140,0 +125,0 @@ }

@@ -5,8 +5,9 @@ import ora from 'ora';

import { exit } from 'node:process';
import { cp } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { cp } from 'node:fs/promises';
import { promisify } from 'node:util';
import { fileURLToPath } from 'node:url';
import { exec } from 'node:child_process';
import { colors, config_path, plugins_path, TIP_ERROR, TIP_INFO } from './index.js';
import { colorful } from '@kokkoro/utils';
import { ERROR, INFO, config_path, plugins_path } from './index.js';
const promiseExec = promisify(exec);

@@ -25,6 +26,2 @@ const questions = [

];
const onCancel = () => {
console.log(`${TIP_INFO} plugin module creation has been aborted.\n`);
exit(0);
};
export default function (program) {

@@ -36,7 +33,12 @@ program

if (!existsSync(config_path)) {
console.error(`${TIP_ERROR} config file is not exists. If you want to create the file, use ${colors.cyan('kokkoro init')}.\n`);
console.error(`${ERROR}: config file is not exists. If you want to create the file, use ${colorful('Cyan', 'kokkoro init')}.\n`);
exit(1);
}
try {
const response = await prompts(questions, { onCancel });
const response = await prompts(questions, {
onCancel() {
console.log(`${INFO}: plugin module creation has been aborted.\n`);
exit(0);
},
});
const { style } = response;

@@ -46,3 +48,3 @@ const module_path = join(plugins_path, name);

if (existsSync(module_path)) {
console.warn(`${TIP_ERROR} plugin directory already exists.\n`);
console.warn(`${ERROR}: plugin directory already exists.\n`);
exit(1);

@@ -64,7 +66,7 @@ }

}
console.log(`${TIP_INFO} plugin module create successful.\n`);
console.log(`${INFO}: plugin module create successful.\n`);
}
catch (error) {
const message = error instanceof Error ? error.message : JSON.stringify(error);
console.warn(`\n${TIP_ERROR} ${message}.`);
console.warn(`\n${ERROR}: ${message}.`);
exit(1);

@@ -71,0 +73,0 @@ }

import { exit } from 'node:process';
import { existsSync } from 'node:fs';
import { spawn } from 'node:child_process';
import { colors, config_path, TIP_ERROR, TIP_INFO } from './index.js';
import { colorful } from '@kokkoro/utils';
import { ERROR, INFO, config_path } from './index.js';
export default function (program) {

@@ -12,3 +13,3 @@ program

if (!existsSync(config_path)) {
console.error(`${TIP_ERROR} config file is not exists. If you want to create the file, use ${colors.cyan('kokkoro init')}.\n`);
console.error(`${ERROR}: config file is not exists. If you want to create the file, use ${colorful('Cyan', 'kokkoro init')}.\n`);
exit(1);

@@ -25,4 +26,4 @@ }

node.stderr?.on('data', data => console.error(data.toString()));
node.on('close', code => console.log(`${TIP_INFO} child process exited with code ${code}.\n`));
node.on('close', code => console.log(`${INFO}: child process exited with code ${code}.\n`));
});
}
{
"name": "@kokkoro/cli",
"version": "2.0.1",
"version": "2.0.2",
"description": "Cli tool for kokkoro.",

@@ -8,2 +8,6 @@ "engines": {

},
"files": [
"lib",
"template"
],
"type": "module",

@@ -34,9 +38,6 @@ "bin": {

"devDependencies": {
"@kokkoro/core": "^3.0.8",
"@types/prompts": "^2.4.9"
"@types/prompts": "^2.4.9",
"@kokkoro/core": "^3.0.10",
"@kokkoro/utils": "^0.8.0"
},
"files": [
"lib",
"template"
],
"scripts": {

@@ -43,0 +44,0 @@ "build": "tsc && tsc-alias",

@@ -10,3 +10,3 @@ import { Command, CommandContext, Context, Event, Plugin } from '@kokkoro/core';

onReady(ctx: Context<'session.ready'>) {
ctx.logger.mark('Bot online.');
ctx.logger.mark('link start');
}

@@ -13,0 +13,0 @@

@@ -8,6 +8,6 @@ import { Metadata, useCommand, useEvent } from '@kokkoro/core';

export default function Example(): void {
export default function Example() {
useEvent(
ctx => {
ctx.logger.mark('Bot online.');
ctx.logger.mark('link start');
},

@@ -14,0 +14,0 @@ ['session.ready'],

@@ -14,3 +14,3 @@ import { useCommand, useEvent } from '@kokkoro/core';

ctx => {
ctx.logger.mark('Bot online.');
ctx.logger.mark('link start');
},

@@ -17,0 +17,0 @@ ['session.ready'],