Skip to content

Commit

Permalink
simplify id & remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcaufy committed Apr 1, 2017
1 parent e3583f0 commit 93eb497
Showing 1 changed file with 9 additions and 27 deletions.
36 changes: 9 additions & 27 deletions packages/wepy-cli/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ colors.setTheme({
'写入': 'green'
});


let ID_CACHE = {};
const utils = {

seqPromise(promises) {
Expand Down Expand Up @@ -472,32 +472,14 @@ const utils = {
}
this.log(flag + ': ' + path.relative(this.currentDir, file), type);
},
mergeWpy (rst) {
const attrs = ['style', 'template', 'script'];
attrs.forEach((attr) => {
const typeRst = rst[attr];
if (typeRst) {
typeRst.blocks.forEach((block) => {
typeRst.code += block.code || '';
typeRst.src = typeRst.src || block.src || '';
typeRst.type = typeRst.type || block.type || '';
if (attr === 'style') {
typeRst.scoped = typeRst.scoped || block.scoped || '';
}
});
}
});
return rst;
},
genId
genId (filepath) {
if (!ID_CACHE[filepath]) {
ID_CACHE[filepath] = '_' + hash(filepath).slice(1, 8);
}
return ID_CACHE[filepath];
}
}

export default utils

const ID_CACHE = {};
function genId (filepath) {
if (!ID_CACHE[filepath]) {
ID_CACHE[filepath] = 'wpy-' + hash(filepath).slice(1, 6);
}
return ID_CACHE[filepath];
}


0 comments on commit 93eb497

Please sign in to comment.