Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zoumiaojiang committed Jun 20, 2017
1 parent 422df0c commit dba5d76
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import path from 'path';
import lavasScaffoldSchema from './src/schema';
import lavasScaffoldProject from './src/project';
import lavasScaffoldTemplate from './src/template';
import utils from './src/utils';


/**
Expand Down Expand Up @@ -45,6 +46,15 @@ export default {
* @return {Promise} resolve 工程所在路径/工程的 zip buffer
*/
exportProject: async function (fields, isStream) {


if (!utils.hasCommand('git')) {
return {
code: 'no command',
message: '当前环境不能使用 git 命令'
};
}

fields = await getFields(fields);
const {err, ret} = await lavasScaffoldProject.exports(fields, isStream);

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lavas-scaffold",
"version": "1.0.1",
"version": "1.0.2",
"description": "a pwa project scaffold solution",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -36,6 +36,7 @@
"glob": "^7.1.2",
"request": "^2.81.0",
"request-promise": "^4.2.1",
"shelljs": "^0.7.8",
"simple-git": "^1.73.0"
},
"devDependencies": {
Expand Down
8 changes: 7 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ export default {
*
* @type {String}
*/
GLOBAL_CONF_URL: 'https://bos.nj.bpc.baidu.com/mms-res/lavas-scaffold/config.json'
GLOBAL_CONF_URL: 'https://bos.nj.bpc.baidu.com/mms-res/lavas-scaffold/config.json',


COMMON_DATA: {
year: (new Date()).getFullYear(),
time: Date.now()
}
};
7 changes: 3 additions & 4 deletions src/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ function renderTemplate(fields, ltd, template, isStream) {
// 这里可以直接通过外界配置的规则,重新计算出一份数据,只要和 template 里面的字段对应上就好了。
const extDataTpls = template.extData || {};
const extData = {};
const commonData = conf.COMMON_DATA;

Object.keys(extDataTpls).forEach(key => {
extData[key] = etplCompile.compile('' + extDataTpls[key])(fields);
extData.year = (new Date()).getFullYear();
});
const renderData = Object.assign({}, fields, extData);
const renderData = Object.assign({}, fields, extData, commonData);

const afterCon = etplCompile.compile(fileCon)(renderData);
fs.writeFileSync(filePath, afterCon);
Expand Down Expand Up @@ -166,9 +166,8 @@ export default {
fwobj = framework;
}
}

for (let template of fwobj.subList.template) {
if (template.valye === fields.template || template.value === data.defaults.template) {
if (template.value === fields.template || template.value === data.defaults.template) {
tobj = template;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
* @author mj(zoumiaojiang@gmail.com)
*/

import shelljs from 'shelljs';

/* eslint-disable fecs-use-method-definition */
export default {

hasCommand: function (commandName) {
return shelljs.which(commandName);
}
};

0 comments on commit dba5d76

Please sign in to comment.