Skip to content

Commit

Permalink
fix(init): init error with a number target project name (#200)
Browse files Browse the repository at this point in the history
* fix: fix init error target with a number project
* test: add more hexo init tests
  • Loading branch information
brelian authored Jun 12, 2020
1 parent a6d44ce commit af92881
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ tmp/
*.log
.idea/
.nyc_output/
.vscode/
2 changes: 1 addition & 1 deletion lib/console/init.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/hexo.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions test/scripts/init.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit af92881

Please sign in to comment.