Comparing version 2.0.0-alpha.57 to 2.0.0-alpha.58
@@ -9,4 +9,4 @@ "use strict"; | ||
const path_1 = require("path"); | ||
const utils_1 = require("./utils"); | ||
const prompts_1 = __importDefault(require("prompts")); | ||
const kleur_2 = __importDefault(require("kleur")); | ||
async function createConfig(options) { | ||
@@ -64,2 +64,4 @@ let succeed = true; | ||
function default_1(cli) { | ||
const error = kleur_2.default.red('error'); | ||
const success = kleur_2.default.green('success'); | ||
cli.command('init [file]', 'initialize a koishi configuration file') | ||
@@ -71,3 +73,3 @@ .option('-f, --forced', 'overwrite config file if it exists') | ||
if (!options.forced && fs_1.existsSync(path)) { | ||
utils_1.logger.error(`${options.output} already exists. If you want to overwrite the current file, use ${kleur_1.yellow('koishi init -f')}`); | ||
console.warn(`${error} ${options.output} already exists. If you want to overwrite the current file, use ${kleur_1.yellow('koishi init -f')}`); | ||
process.exit(1); | ||
@@ -78,7 +80,7 @@ } | ||
if (!extension) { | ||
utils_1.logger.error(`configuration file should have an extension, received "${file}"`); | ||
console.warn(`${error} configuration file should have an extension, received "${file}"`); | ||
process.exit(1); | ||
} | ||
else if (!supportedTypes.includes(extension)) { | ||
utils_1.logger.error(`configuration file type "${extension}" is currently not supported`); | ||
console.warn(`${error} configuration file type "${extension}" is currently not supported`); | ||
process.exit(1); | ||
@@ -89,3 +91,3 @@ } | ||
if (!config) { | ||
utils_1.logger.error('initialization was canceled'); | ||
console.warn(`${error} initialization was canceled`); | ||
process.exit(0); | ||
@@ -109,3 +111,3 @@ } | ||
fs_1.writeFileSync(path, output); | ||
utils_1.logger.success(`created config file: ${path}`); | ||
console.warn(`${success} created config file: ${path}`); | ||
process.exit(0); | ||
@@ -112,0 +114,0 @@ }); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -7,3 +10,3 @@ const perf_hooks_1 = require("perf_hooks"); | ||
const path_1 = require("path"); | ||
const utils_1 = require("./utils"); | ||
const kleur_1 = __importDefault(require("kleur")); | ||
process.env.KOISHI_START_TIME = '' + perf_hooks_1.performance.now(); | ||
@@ -23,18 +26,12 @@ function createWorker(options) { | ||
.alias('start') | ||
.option('--log-level <level>', 'specify log level (default: 2)') | ||
.option('--silent', 'use log level 0 (print no message)') | ||
.option('--debug', 'use log level 3 (print all messages)') | ||
.option('--debug [names]', 'specify debug names') | ||
.option('--level [level]', 'specify log level (default: 2)') | ||
.action((file, options) => { | ||
let logLevel = options.logLevel; | ||
if (options.silent) | ||
logLevel = 0; | ||
if (options.debug) | ||
logLevel = 3; | ||
if (logLevel !== undefined) { | ||
if (!koishi_utils_1.isInteger(logLevel) || logLevel < 0) { | ||
utils_1.logger.error('log level should be a positive integer.'); | ||
process.exit(1); | ||
} | ||
process.env.KOISHI_LOG_LEVEL = '' + logLevel; | ||
const { level } = options; | ||
if (level !== undefined && (!koishi_utils_1.isInteger(level) || level < 0)) { | ||
console.warn(`${kleur_1.default.red('error')} log level should be a positive integer.`); | ||
process.exit(1); | ||
} | ||
process.env.KOISHI_LOG_LEVEL = level || ''; | ||
process.env.KOISHI_DEBUG = options.debug || ''; | ||
process.env.KOISHI_CONFIG_FILE = file || ''; | ||
@@ -41,0 +38,0 @@ createWorker(options); |
@@ -8,11 +8,13 @@ "use strict"; | ||
const kleur_1 = require("kleur"); | ||
const utils_1 = require("./utils"); | ||
const util_1 = require("util"); | ||
const logger = koishi_utils_1.Logger.create('app'); | ||
const { version } = require('../package'); | ||
let baseLogLevel = 3; | ||
if (process.env.KOISHI_LOG_LEVEL !== undefined) { | ||
baseLogLevel = +process.env.KOISHI_LOG_LEVEL; | ||
if (process.env.KOISHI_LOG_LEVEL) { | ||
koishi_utils_1.Logger.baseLevel = +process.env.KOISHI_LOG_LEVEL; | ||
} | ||
if (process.env.KOISHI_DEBUG) { | ||
koishi_utils_1.Logger.levels = Object.fromEntries(process.env.KOISHI_DEBUG.split(',').map(name => [name, 3])); | ||
} | ||
function handleException(error) { | ||
utils_1.logger.error(error, baseLogLevel); | ||
logger.error(error); | ||
process.exit(1); | ||
@@ -41,8 +43,5 @@ } | ||
function loadEcosystem(type, name) { | ||
const modules = [path_1.resolve(configDir, name)]; | ||
const modules = [path_1.resolve(configDir, name), name]; | ||
const prefix = `koishi-${type}-`; | ||
if (name.includes(prefix)) { | ||
modules.push(name); | ||
} | ||
else { | ||
if (!name.includes(prefix)) { | ||
const index = name.lastIndexOf('/'); | ||
@@ -52,2 +51,3 @@ modules.push(name.slice(0, index + 1) + prefix + name.slice(index + 1)); | ||
for (const name of modules) { | ||
logger.debug('resolving %c', name); | ||
try { | ||
@@ -79,10 +79,14 @@ return require(name); | ||
if (plugin.name) | ||
utils_1.logger.info(`apply plugin ${kleur_1.cyan(plugin.name)}`, baseLogLevel); | ||
logger.info('apply plugin %c', plugin.name); | ||
} | ||
} | ||
function prepareApp(config) { | ||
Object.assign(koishi_utils_1.Logger.levels, config.logFilter); | ||
if (config.logLevel && !process.env.KOISHI_LOG_LEVEL) { | ||
koishi_utils_1.Logger.baseLevel = config.logLevel; | ||
} | ||
for (const name in config.database || {}) { | ||
const resolved = loadEcosystem('database', name); | ||
if (resolved) | ||
utils_1.logger.info(`apply database ${kleur_1.cyan(name)}`, baseLogLevel); | ||
logger.info('apply database %c', name); | ||
} | ||
@@ -116,8 +120,8 @@ const app = new koishi_core_1.App(config); | ||
if (type === 'http') { | ||
httpPorts.add(`server listening at ${kleur_1.cyan(port)}`); | ||
httpPorts.add(logger.format('server listening at %c', port)); | ||
if (server) | ||
httpServers.add(`connected to ${kleur_1.cyan(server)}`); | ||
httpServers.add(logger.format('connected to %c', server)); | ||
} | ||
else { | ||
wsServers.add(`connected to ${kleur_1.cyan(server.replace(/^http/, 'ws'))}`); | ||
wsServers.add(logger.format('connected to %c', server.replace(/^http/, 'ws'))); | ||
} | ||
@@ -127,20 +131,13 @@ }); | ||
for (const text of textSet) { | ||
utils_1.logger.info(text, baseLogLevel); | ||
logger.info(text); | ||
} | ||
} | ||
const time = Math.max(0, perf_hooks_1.performance.now() - +process.env.KOISHI_START_TIME).toFixed(); | ||
utils_1.logger.success(`bot started successfully in ${time} ms.`, baseLogLevel); | ||
logger.success(`bot started successfully in ${time} ms.`); | ||
process.send({ type: 'start' }); | ||
}); | ||
process.on('unhandledRejection', (error) => { | ||
utils_1.logger.warn(util_1.format(error), baseLogLevel); | ||
logger.warn(util_1.format(error)); | ||
}); | ||
koishi_core_1.appList.forEach((app) => { | ||
const { logLevel = 2, logFilter = {} } = app.options; | ||
app.on('logger', (scope, message, type) => { | ||
var _a; | ||
utils_1.logger[type](message, Math.min((_a = logFilter[scope]) !== null && _a !== void 0 ? _a : logLevel, baseLogLevel), scope); | ||
}); | ||
}); | ||
koishi_core_1.startAll().catch(handleException); | ||
//# sourceMappingURL=worker.js.map |
{ | ||
"name": "koishi", | ||
"description": "A QQ bot framework based on CQHTTP", | ||
"version": "2.0.0-alpha.57", | ||
"version": "2.0.0-alpha.58", | ||
"main": "dist/index.js", | ||
@@ -39,13 +39,12 @@ "typings": "dist/index.d.ts", | ||
"cac": "^6.5.12", | ||
"js-yaml": "^3.14.0", | ||
"kleur": "^4.0.2", | ||
"koishi-core": "^2.0.0-alpha.33", | ||
"koishi-plugin-common": "^3.0.0-alpha.36", | ||
"koishi-plugin-recorder": "^2.0.0-alpha.33", | ||
"koishi-plugin-schedule": "^2.0.0-alpha.37", | ||
"koishi-plugin-status": "^2.0.0-alpha.35", | ||
"koishi-plugin-teach": "^1.0.0-alpha.52", | ||
"koishi-utils": "^2.1.0", | ||
"koishi-core": "^2.0.0-alpha.34", | ||
"koishi-plugin-common": "^3.0.0-alpha.37", | ||
"koishi-plugin-recorder": "^2.0.0-alpha.34", | ||
"koishi-plugin-schedule": "^2.0.0-alpha.38", | ||
"koishi-plugin-status": "^2.0.0-alpha.36", | ||
"koishi-plugin-teach": "^1.0.0-alpha.53", | ||
"koishi-utils": "^2.1.1", | ||
"prompts": "^2.3.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
36861
10
412
16
- Removedjs-yaml@^3.14.0
- Removedargparse@1.0.10(transitive)
- Removedesprima@4.0.1(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedsprintf-js@1.0.3(transitive)
Updatedkoishi-core@^2.0.0-alpha.34
Updatedkoishi-utils@^2.1.1