Skip to content

Commit af92881

Browse files
authored
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
1 parent a6d44ce commit af92881

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

.gitignore

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ tmp/
44
*.log
55
.idea/
66
.nyc_output/
7+
.vscode/

lib/console/init.js

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function initConsole(args) {
1515
args = Object.assign({ install: true, clone: true }, args);
1616

1717
const baseDir = this.base_dir;
18-
const target = args._[0] ? resolve(baseDir, String(args._[0])) : baseDir;
18+
const target = args._[0] ? resolve(baseDir, args._[0]) : baseDir;
1919
const { log } = this;
2020

2121
if (existsSync(target) && readdirSync(target).length !== 0) {

lib/hexo.js

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const { camelCaseKeys } = require('hexo-util');
1313
class HexoNotFoundError extends Error {}
1414

1515
function entry(cwd = process.cwd(), args) {
16-
args = camelCaseKeys(args || minimist(process.argv.slice(2)));
16+
args = camelCaseKeys(args || minimist(process.argv.slice(2), { string: ['_'] }));
1717

1818
let hexo = new Context(cwd, args);
1919
let { log } = hexo;

test/scripts/init.js

100644100755
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ describe('init', () => {
7777
await check(join(baseDir, 'test'));
7878
}));
7979

80+
it('unconventional path', () => withoutSpawn(async () => {
81+
await init({_: ['0x400']});
82+
await check(join(baseDir, '0x400'));
83+
84+
await init({_: ['0b101']});
85+
await check(join(baseDir, '0b101'));
86+
87+
await init({_: ['0o71']});
88+
await check(join(baseDir, '0o71'));
89+
90+
await init({_: ['undefined']});
91+
await check(join(baseDir, 'undefined'));
92+
93+
await init({_: ['null']});
94+
await check(join(baseDir, 'null'));
95+
96+
await init({_: ['true']});
97+
await check(join(baseDir, 'true'));
98+
}));
99+
100+
it('path multi-charset', () => withoutSpawn(async () => {
101+
await init({_: ['中文']});
102+
await check(join(baseDir, '中文'));
103+
}));
104+
80105
it('absolute path', () => {
81106
const path = join(baseDir, 'test');
82107

0 commit comments

Comments
 (0)