From af92881556fdca7d6a8d04415888232447211389 Mon Sep 17 00:00:00 2001 From: "Syncher Pylon, Peng" Date: Fri, 12 Jun 2020 11:42:02 +0800 Subject: [PATCH] fix(init): init error with a number target project name (#200) * fix: fix init error target with a number project * test: add more hexo init tests --- .gitignore | 1 + lib/console/init.js | 2 +- lib/hexo.js | 2 +- test/scripts/init.js | 25 +++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 lib/console/init.js mode change 100644 => 100755 lib/hexo.js mode change 100644 => 100755 test/scripts/init.js diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 19e149cb..d99d1ad8 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ tmp/ *.log .idea/ .nyc_output/ +.vscode/ diff --git a/lib/console/init.js b/lib/console/init.js old mode 100644 new mode 100755 index 60a0b941..b9e24603 --- a/lib/console/init.js +++ b/lib/console/init.js @@ -15,7 +15,7 @@ function initConsole(args) { args = Object.assign({ install: true, clone: true }, args); const baseDir = this.base_dir; - const target = args._[0] ? resolve(baseDir, String(args._[0])) : baseDir; + const target = args._[0] ? resolve(baseDir, args._[0]) : baseDir; const { log } = this; if (existsSync(target) && readdirSync(target).length !== 0) { diff --git a/lib/hexo.js b/lib/hexo.js old mode 100644 new mode 100755 index 16a7b8f8..3702420f --- a/lib/hexo.js +++ b/lib/hexo.js @@ -13,7 +13,7 @@ const { camelCaseKeys } = require('hexo-util'); class HexoNotFoundError extends Error {} function entry(cwd = process.cwd(), args) { - args = camelCaseKeys(args || minimist(process.argv.slice(2))); + args = camelCaseKeys(args || minimist(process.argv.slice(2), { string: ['_'] })); let hexo = new Context(cwd, args); let { log } = hexo; diff --git a/test/scripts/init.js b/test/scripts/init.js old mode 100644 new mode 100755 index a8db1e38..574cfb6d --- a/test/scripts/init.js +++ b/test/scripts/init.js @@ -77,6 +77,31 @@ describe('init', () => { await check(join(baseDir, 'test')); })); + it('unconventional path', () => withoutSpawn(async () => { + await init({_: ['0x400']}); + await check(join(baseDir, '0x400')); + + await init({_: ['0b101']}); + await check(join(baseDir, '0b101')); + + await init({_: ['0o71']}); + await check(join(baseDir, '0o71')); + + await init({_: ['undefined']}); + await check(join(baseDir, 'undefined')); + + await init({_: ['null']}); + await check(join(baseDir, 'null')); + + await init({_: ['true']}); + await check(join(baseDir, 'true')); + })); + + it('path multi-charset', () => withoutSpawn(async () => { + await init({_: ['中文']}); + await check(join(baseDir, '中文')); + })); + it('absolute path', () => { const path = join(baseDir, 'test');