Comparing version 2.0.0-alpha.8 to 2.0.0-alpha.9
@@ -10,3 +10,2 @@ "use strict"; | ||
const utils_1 = require("./utils"); | ||
const js_yaml_1 = require("js-yaml"); | ||
const prompts_1 = __importDefault(require("prompts")); | ||
@@ -63,3 +62,3 @@ async function createConfig(options) { | ||
} | ||
const supportedTypes = ['js', 'json', 'ts', 'yml', 'yaml']; | ||
const supportedTypes = ['js', 'ts', 'json']; | ||
function default_1(cli) { | ||
@@ -92,16 +91,11 @@ cli.command('init [file]', 'initialize a koishi configuration file') | ||
// generate output | ||
let output; | ||
switch (extension) { | ||
case 'yml': | ||
case 'yaml': | ||
output = js_yaml_1.safeDump(config); | ||
break; | ||
default: | ||
output = JSON.stringify(config, null, 2); | ||
if (extension === 'js') { | ||
output = 'module.exports = ' + output.replace(/^(\s+)"([\w$]+)":/mg, '$1$2:'); | ||
} | ||
else if (extension === 'ts') { | ||
output = 'export = ' + output.replace(/^(\s+)"([\w$]+)":/mg, '$1$2:'); | ||
} | ||
let output = JSON.stringify(config, null, 2); | ||
if (extension !== 'json') { | ||
output = output.replace(/^(\s+)"([\w$]+)":/mg, '$1$2:'); | ||
if (extension === 'js') { | ||
output = 'module.exports = ' + output; | ||
} | ||
else if (extension === 'ts') { | ||
output = 'export = ' + output; | ||
} | ||
} | ||
@@ -108,0 +102,0 @@ // write to file |
@@ -10,4 +10,2 @@ "use strict"; | ||
const util_1 = require("util"); | ||
const fs_1 = require("fs"); | ||
const js_yaml_1 = require("js-yaml"); | ||
const { version } = require('../package'); | ||
@@ -24,5 +22,3 @@ let baseLogLevel = 3; | ||
const configFile = path_1.resolve(process.cwd(), process.env.KOISHI_CONFIG_FILE || 'koishi.config'); | ||
const extension = path_1.extname(configFile); | ||
const configDir = path_1.dirname(configFile); | ||
let config; | ||
function tryCallback(callback) { | ||
@@ -38,13 +34,3 @@ try { | ||
} | ||
if (['.js', '.json', '.ts'].includes(extension)) { | ||
config = tryCallback(() => require(configFile)); | ||
} | ||
else if (['.yaml', '.yml'].includes(extension)) { | ||
config = tryCallback(() => js_yaml_1.safeLoad(fs_1.readFileSync(configFile, 'utf8'))); | ||
} | ||
else { | ||
config = tryCallback(() => require(configFile)) | ||
|| tryCallback(() => js_yaml_1.safeLoad(fs_1.readFileSync(configFile + '.yml', 'utf8'))) | ||
|| tryCallback(() => js_yaml_1.safeLoad(fs_1.readFileSync(configFile + '.yaml', 'utf8'))); | ||
} | ||
const config = tryCallback(() => require(configFile)); | ||
if (!config) { | ||
@@ -51,0 +37,0 @@ throw new Error(`config file not found. use ${kleur_1.yellow('koishi init')} command to initialize a config file.`); |
{ | ||
"name": "koishi", | ||
"description": "A QQ bot framework based on CQHTTP", | ||
"version": "2.0.0-alpha.8", | ||
"version": "2.0.0-alpha.9", | ||
"main": "dist/index.js", | ||
@@ -34,18 +34,18 @@ "typings": "dist/index.d.ts", | ||
"devDependencies": { | ||
"@types/js-yaml": "^3.12.2", | ||
"@types/js-yaml": "^3.12.3", | ||
"@types/prompts": "^2.0.5" | ||
}, | ||
"dependencies": { | ||
"cac": "^6.5.7", | ||
"cac": "^6.5.8", | ||
"js-yaml": "^3.13.1", | ||
"kleur": "^3.0.3", | ||
"koishi-core": "^2.0.0-alpha.7", | ||
"koishi-plugin-common": "^3.0.0-alpha.7", | ||
"koishi-plugin-recorder": "^2.0.0-alpha.7", | ||
"koishi-plugin-schedule": "^2.0.0-alpha.9", | ||
"koishi-plugin-status": "^2.0.0-alpha.8", | ||
"koishi-plugin-teach": "^1.0.0-alpha.8", | ||
"koishi-utils": "^1.0.5", | ||
"prompts": "^2.3.1" | ||
"koishi-core": "^2.0.0-alpha.8", | ||
"koishi-plugin-common": "^3.0.0-alpha.8", | ||
"koishi-plugin-recorder": "^2.0.0-alpha.8", | ||
"koishi-plugin-schedule": "^2.0.0-alpha.10", | ||
"koishi-plugin-status": "^2.0.0-alpha.9", | ||
"koishi-plugin-teach": "^1.0.0-alpha.9", | ||
"koishi-utils": "^1.0.6", | ||
"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
Sorry, the diff of this file is not supported yet
12
38062
401
Updatedcac@^6.5.8
Updatedkoishi-core@^2.0.0-alpha.8
Updatedkoishi-utils@^1.0.6
Updatedprompts@^2.3.2