Skip to content

Commit

Permalink
bump to 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zoumiaojiang committed Jun 19, 2017
1 parent aed30f7 commit 422df0c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lavas-scaffold",
"version": "1.0.0",
"version": "1.0.1",
"description": "a pwa project scaffold solution",
"main": "dist/index.js",
"scripts": {
Expand Down
18 changes: 9 additions & 9 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ export default {
getSchema: async function () {

let data = await gData();
let schemas = data.schemas;
let properties = {};

Object.keys(schemas).forEach(key => {
if (!schemas[key].disable) {
properties[key] = schemas[key];
}
});
let properties = data.schemas;

const keys = Object.keys(properties);

for (let key of keys) {
const item = properties[key];

if (item.type === 'list') {

if (item.link && !item.dependence) {
properties[key].list = data[item.link];
}
else if (item.dependence) {
const depList = properties[item.dependence].list;
depList.forEach(depItem => {
if (depItem.value === data.defaults[item.dependence]) {
properties[key].list = depItem.subList ? (depItem.subList[key] || []) : [];
}
});
}
}
}

Expand Down
29 changes: 21 additions & 8 deletions src/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ function renderTemplate(fields, ltd, template, isStream) {

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

Expand Down Expand Up @@ -156,18 +157,30 @@ export default {

let data = await gData();
let fwobj;
let tobj;

// 这里说明一下, 没办法做到完全解耦, 必须传入 fields.framework 字段,也就是必须得指定一个 framework
// 在 GLOBAL_CONF_URL 对应的必须得有 framework 这个 property,否则 run 不起来
for (let framework of data.templates) {
if (framework.value === data.defaultFramework || framework.value === fields.framework) {
for (let framework of data.frameworks) {
if (framework.value === fields.framework || framework.value === data.defaults.framework) {
fwobj = framework;
}
}

const gitRepo = fwobj.git;
for (let template of fwobj.subList.template) {
if (template.valye === fields.template || template.value === data.defaults.template) {
tobj = template;
}
}

const gitRepo = tobj.git;
const ltd = path.resolve(conf.LOCAL_TEMPLATES_DIR, `${Date.now()}`);
const tltd = path.resolve(conf.LOCAL_TEMPLATES_DIR, fields.framework || data.defaultFramework, 'templates');
const tltd = path.resolve(
conf.LOCAL_TEMPLATES_DIR,
fields.framework || data.defaults.framework,
fields.template || data.defaults.template,
'templates'
);

try {
if (fs.existsSync(ltd)) {
Expand All @@ -179,7 +192,7 @@ export default {
fs.copySync(tltd, ltd);

// 把指定的文件和文件夹都删掉
(fwobj.exportsIgnores || [
(tobj.exportsIgnores || [
'.git',
'docs'
]).forEach(fileOrDir => {
Expand All @@ -189,10 +202,10 @@ export default {
}
});

fields.framework = fields.framework || data.defaultFramework;
fields.appShell = fields.appShell || data.defaultAppShell;

const renderResult = await renderTemplate(fields, ltd, fwobj, isStream);
fields = Object.assign({}, fields, data.defaults);

const renderResult = await renderTemplate(fields, ltd, tobj, isStream);
fs.removeSync(ltd);

return renderResult;
Expand Down

0 comments on commit 422df0c

Please sign in to comment.