diff --git a/index.js b/index.js index c64eac1..9892998 100644 --- a/index.js +++ b/index.js @@ -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'; /** @@ -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); diff --git a/package.json b/package.json index 28e76ce..e9d1caa 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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": { diff --git a/src/config.js b/src/config.js index bfbc22c..7b6c4e3 100644 --- a/src/config.js +++ b/src/config.js @@ -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() + } }; diff --git a/src/template.js b/src/template.js index f72540e..117c702 100644 --- a/src/template.js +++ b/src/template.js @@ -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); @@ -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; } } diff --git a/src/utils.js b/src/utils.js index d68c4e3..7baf0a7 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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); + } };