Skip to content

Commit

Permalink
fix:
Browse files Browse the repository at this point in the history
- fix: error when template info empty
- del `dist` ignore when adding template
- webpack error
compatibility
- fix: error when debug local task-template
  • Loading branch information
neikvon committed Dec 6, 2017
1 parent bb6611b commit 9419ea4
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ node_js:
branches:
only:
- "v3.x"
before_install:
- export TZ='Asia/Beijing'
install:
- npm install
script:
Expand Down
2 changes: 1 addition & 1 deletion lib/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = class Conifg {
}
} else {
logger.warn(`Template \`${templateName}\` not found.`)
delete localOpts.template
// TODO delete localOpts.template
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/core/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = class Task {
}

ctx.nodeModulesPaths = [utils.path.cwd('node_modules')]
if (ctx.options.template) {
if (ctx.options.template && ctx.stores[ctx.options.template.name]) {
ctx.nodeModulesPaths.push(
path.join(ctx.stores[ctx.options.template.name].path, 'node_modules')
)
Expand Down
2 changes: 1 addition & 1 deletion lib/data/configs.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"yarn.lock",
"package-lock.json"
],
"TEMPLATE_ADD_IGNORE": [".DS_Store", ".svn", ".git", "dst", "dist"],
"TEMPLATE_ADD_IGNORE": [".DS_Store", ".svn", ".git", "dst"],
"VERSION_SEPARATOR": "@"
}
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Fbi extends EventEmitter {
if (this.options.template) {
const tmplInfo = this.stores[this.options.template.name]
this.logger.debug('tmplInfo:', tmplInfo)
if (tmplInfo.version) {
if (tmplInfo && tmplInfo.version) {
const target = {
path: tmplInfo.path,
version: this.options.template.version || tmplInfo.version.latest
Expand Down
12 changes: 8 additions & 4 deletions lib/utils/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ async function copy(
throw `\`${from}\` not exist.`
}

logger(`Copy from \`${from}\` to \`${to}\` `)
if (!quiet) {
logger(`Copy from \`${from}\` to \`${to}\` `)
}

const stats = await stat(from)

Expand Down Expand Up @@ -215,7 +217,9 @@ async function copy(
}

for (let i = 0, len = splitArr.length; i < len; i++) {
logger(`splitArr[${i}].length:`, splitArr[i].length)
if (!quiet) {
logger(`splitArr[${i}].length:`, splitArr[i].length)
}
await Promise.all(
splitArr[i].map(async item => {
try {
Expand Down Expand Up @@ -292,8 +296,8 @@ function _list(dir, ignore) {
)
}

async function move(from, to, logger, ignore = []) {
await copy({from, to, ignore, log: logger})
async function move(from, to, logger, ignore = [], quiet = true) {
await copy({from, to, ignore, log: logger, quiet})
await remove(from)
}

Expand Down
11 changes: 9 additions & 2 deletions lib/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,18 @@ class Logger {
at Object.require (internal/module.js:20:19)
*/
errorStackLeaner(err) {
const title = err.toString()
if (!err || !err.stack) {
return {
title: '',
stack: err
}
}

// Ref: https://github.com/v8/v8/wiki/Stack%20Trace%20API
const title = err.toString()
const stacks = err.stack.split('\n').slice(1)
const stackReg = /at\s+(.*)\s+\((.*):(\d*):(\d*)\)/i
const stackReg2 = /at\s+()(.*):(\d*):(\d*)/i
const stacks = err.stack.split('\n').slice(1)
let stack = ''
for (const s of stacks) {
const sp = stackReg.exec(s) || stackReg2.exec(s)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
],
"no-use-extend-native/no-use-extend-native": 0,
"no-extend-native": 0,
"max-depth": ["error", 6],
"complexity": [
"error",
{
Expand Down
14 changes: 7 additions & 7 deletions test/utils/date-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ import test from 'ava'
import {dateFormat} from '../../lib/utils'

test('-', t => {
const dt = 'Fri Dec 01 2017 13:44:42+08'
const dt = 'Fri Dec 01 2017 13:44:42 GMT+0800'
const formated = dateFormat(dt, 'YYYY-MM-DD hh:mm:ss')
t.is(formated, '2017-12-01 05:44:42')
t.is(formated, '2017-12-01 13:44:42')
})

test('/', t => {
const dt = 'Fri Dec 01 2017 13:44:42+08'
const dt = 'Fri Dec 01 2017 13:44:42 GMT+0800'
const formated = dateFormat(dt, 'YYYY/MM/DD hh:mm:ss')
t.is(formated, '2017/12/01 05:44:42')
t.is(formated, '2017/12/01 13:44:42')
})

test('年月日 时分秒', t => {
const dt = 'Fri Dec 01 2017 13:44:42+08'
const dt = 'Fri Dec 01 2017 13:44:42 GMT+0800'
const formated = dateFormat(dt, 'YYYY年MM月DD日 hh时mm分ss秒')
t.is(formated, '2017年12月01日 05时44分42秒')
t.is(formated, '2017年12月01日 13时44分42秒')
})

test('string', t => {
const dt = new Date('2017-12-01 13:44:42')
const dt = new Date('2017-12-01 13:44:42 GMT+0800')
const formated = dateFormat(dt, 'YYYY年MM月DD日 hh时mm分ss秒')
t.is(formated, '2017年12月01日 13时44分42秒')
})

0 comments on commit 9419ea4

Please sign in to comment.