Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(init): fix hexo init error with a number target project name #200

Merged
merged 2 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always parses it as a string. Manually convert is unnecessary anymore.

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