Skip to content

Commit d68a2ac

Browse files
author
nicolaslabbe
committed
build refactor request
1 parent c44d23e commit d68a2ac

File tree

15 files changed

+695
-745
lines changed

15 files changed

+695
-745
lines changed

dist/cli/handlebars/abe/listPage.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ function listPage(file, index, text) {
2929
file = _.Hooks.instance.trigger('beforeListPage', file, index, text);
3030

3131
res += '<tr>';
32-
res += '<td>' + (0, _math2.default)(index, '+', 1) + '</td>\n <td>\n <a href="/abe/' + file.template + '?filePath=' + file.fileUrl + '" class="file-path">\n ' + file.fileUrl + '\n </a>\n </td>';
32+
res += '<td>' + (0, _math2.default)(index, '+', 1) + '</td>\n <td>\n <a href="/abe/' + file.abe_meta.template + '?filePath=' + file.abe_meta.link + '" class="file-path">\n ' + file.abe_meta.link + '\n </a>\n </td>';
3333

34-
if (file.template) {
35-
res += '<td align="center">\n ' + file.template + '\n </td>';
34+
if (file.abe_meta.template) {
35+
res += '<td align="center">\n ' + file.abe_meta.template + '\n </td>';
3636
} else {
3737
res += '<td align="center"></td>';
3838
}
@@ -49,16 +49,16 @@ function listPage(file, index, text) {
4949

5050
workflow += '<td align="center" class="draft">';
5151
if (_typeof(file.published) !== undefined && file.published !== null && !file.published || file.published && file.draft && file.published.date < file.draft.date) {
52-
workflow += '<a href="/abe/' + file.template + '?filePath=' + file.fileUrl + '" class="label label-default label-draft">draft</a>';
52+
workflow += '<a href="/abe/' + file.abe_meta.template + '?filePath=' + file.abe_meta.link + '" class="label label-default label-draft">draft</a>';
5353
} else {
54-
workflow += '<a href="/abe/' + file.template + '?filePath=' + file.fileUrl + '" class="hidden label label-default label-draft"></a>';
54+
workflow += '<a href="/abe/' + file.abe_meta.template + '?filePath=' + file.abe_meta.link + '" class="hidden label label-default label-draft"></a>';
5555
}
5656

5757
workflow += '</td>';
5858
workflow += '<td align="center" class="publish">';
5959

6060
if (file.published) {
61-
workflow += '<a href="/abe/' + file.template + '?filePath=' + file.published.filePath + '" class="checkmark label-published">&#10004;</a>';
61+
workflow += '<a href="/abe/' + file.abe_meta.template + '?filePath=' + file.published.filePath + '" class="checkmark label-published">&#10004;</a>';
6262
}
6363
workflow += '</td>';
6464

@@ -68,10 +68,10 @@ function listPage(file, index, text) {
6868
res += '<td align="center">\n <div class="row icons-action">';
6969

7070
if (this.published) {
71-
res += '<a href="/unpublish/?filePath=' + file.fileUrl + '"\n title="' + text.unpublish + '"\n class="icon" data-unpublish="true" data-text="' + text.confirmUnpublish + ' ' + file.fileUrl + '">\n <span class="glyphicon glyphicon-eye-close"></span>\n </a>';
71+
res += '<a href="/unpublish/?filePath=' + file.abe_meta.link + '"\n title="' + text.unpublish + '"\n class="icon" data-unpublish="true" data-text="' + text.confirmUnpublish + ' ' + file.abe_meta.link + '">\n <span class="glyphicon glyphicon-eye-close"></span>\n </a>';
7272
}
7373

74-
res += '<a href="/delete/?filePath=' + this.path + '"\n title="' + text.delete + '"\n class="icon"\n data-delete="true"\n data-text="' + text.confirmDelete + ' ' + file.fileUrl + '">\n <span class="glyphicon glyphicon-trash"></span>\n </a>';
74+
res += '<a href="/delete/?filePath=' + this.path + '"\n title="' + text.delete + '"\n class="icon"\n data-delete="true"\n data-text="' + text.confirmDelete + ' ' + file.abe_meta.link + '">\n <span class="glyphicon glyphicon-trash"></span>\n </a>';
7575

7676
res += '\n </div>\n </td>\n </tr>';
7777

dist/cli/handlebars/abe/sourceAttr.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,36 @@ function sourceAttr(val, params) {
1717
if ((typeof hiddenVal === 'undefined' ? 'undefined' : _typeof(hiddenVal)) === 'object' && Object.prototype.toString.call(hiddenVal) === '[object Object]') {
1818
hiddenVal = JSON.stringify(hiddenVal).replace(/'/g, "&apos;");
1919

20-
var displayVal = _.Sql.deep_value_array(val, params.display);
21-
if (typeof params.display !== 'undefined' && params.display !== null && typeof displayVal !== 'undefined' && displayVal !== null) {
22-
val = displayVal;
23-
} else {
20+
try {
21+
var displayVal = eval('val.' + params.display);
22+
if (typeof params.display !== 'undefined' && params.display !== null && typeof displayVal !== 'undefined' && displayVal !== null) {
23+
val = displayVal;
24+
} else {
25+
val = val[Object.keys(val)[0]];
26+
}
27+
} catch (e) {
2428
val = val[Object.keys(val)[0]];
2529
}
2630
}
2731

2832
if (_typeof(params.value) === 'object' && Object.prototype.toString.call(params.value) === '[object Array]') {
2933
Array.prototype.forEach.call(params.value, function (v) {
3034
var item = v;
31-
var displayV = _.Sql.deep_value_array(item, params.display);
32-
if (typeof params.display !== 'undefined' && params.display !== null && typeof displayV !== 'undefined' && displayV !== null) {
33-
item = displayV;
34-
} else {
35-
if (typeof v === 'string') {
36-
item = v;
35+
try {
36+
var displayV = eval('item.' + params.display);
37+
if (typeof params.display !== 'undefined' && params.display !== null && typeof displayV !== 'undefined' && displayV !== null) {
38+
item = displayV;
3739
} else {
38-
item = v[Object.keys(v)[0]];
40+
if (typeof v === 'string') {
41+
item = v;
42+
} else {
43+
item = v[Object.keys(v)[0]];
44+
}
3945
}
46+
} catch (e) {
47+
item = v[Object.keys(v)[0]];
4048
}
49+
4150
if ((typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object' && Object.prototype.toString.call(val) === '[object Array]' && (typeof item === 'undefined' ? 'undefined' : _typeof(item)) === 'object' && Object.prototype.toString.call(item) === '[object Array]') {
4251

4352
Array.prototype.forEach.call(item, function (i) {

dist/cli/helpers/abe-get-select-template-keys.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,48 @@ var _cli = require('../../cli');
1818

1919
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2020

21+
var traverseFileSystem = function traverseFileSystem(currentPath, arr) {
22+
var res = [];
23+
var files = _fsExtra2.default.readdirSync(currentPath);
24+
for (var i in files) {
25+
var currentFile = currentPath + '/' + files[i];
26+
var stats = _fsExtra2.default.statSync(currentFile);
27+
if (stats.isFile()) {
28+
if (currentFile.indexOf(_cli.config.files.templates.extension) > -1) {
29+
res.push(currentFile);
30+
}
31+
} else if (stats.isDirectory()) {
32+
res = res.concat(traverseFileSystem(currentFile));
33+
}
34+
}
35+
return res;
36+
};
37+
2138
var findTemplates = function findTemplates(templatesPath) {
2239
var p = new Promise(function (resolve, reject) {
23-
(0, _child_process.execFile)('find', [templatesPath], function (err, stdout, stderr) {
24-
if (err) reject(err);
25-
26-
var file_list = stdout.split('\n');
27-
var file_list_with_extention = [];
28-
Array.prototype.forEach.call(file_list, function (file) {
29-
if (file.indexOf(_cli.config.files.templates.extension) > -1) {
30-
file_list_with_extention.push(file);
31-
}
32-
});
33-
34-
resolve(file_list_with_extention);
35-
});
40+
var templatesList = traverseFileSystem(templatesPath);
41+
resolve(templatesList);
3642
});
3743

3844
return p;
3945
};
4046

41-
var findRequestKeys = function findRequestKeys(file_list_with_extention) {
47+
/**
48+
* Get columns and where.left ids of a select statement
49+
*
50+
* select title, image from ../ where template=""
51+
*
52+
* return [title, image, template]
53+
*
54+
* @param {Array} templatesList ["article.html", "other.html"]
55+
* @return {Promise}
56+
*/
57+
var findRequestColumns = function findRequestColumns(templatesList) {
4258
var whereKeysCheck = {};
4359
var whereKeys = [];
4460
var p = new Promise(function (resolve, reject) {
4561
var util = new _cli.Util();
46-
Array.prototype.forEach.call(file_list_with_extention, function (file) {
62+
Array.prototype.forEach.call(templatesList, function (file) {
4763
var template = _fsExtra2.default.readFileSync(file, 'utf8');
4864
var matches = util.dataRequest(template);
4965

@@ -79,13 +95,13 @@ var findRequestKeys = function findRequestKeys(file_list_with_extention) {
7995

8096
var getSelectTemplateKeys = function getSelectTemplateKeys(templatesPath) {
8197
var p = new Promise(function (resolve, reject) {
82-
findTemplates(templatesPath).then(function (file_list_with_extention) {
98+
findTemplates(templatesPath).then(function (templatesList) {
8399

84-
findRequestKeys(file_list_with_extention).then(function (whereKeys) {
100+
findRequestColumns(templatesList).then(function (whereKeys) {
85101

86102
resolve(whereKeys);
87103
}, function () {
88-
console.log('findRequestKeys reject');
104+
console.log('findRequestColumns reject');
89105
reject();
90106
}).catch(function (e) {
91107
console.error('getSelectTemplateKeys', e);

dist/cli/helpers/abe-sql.js

Lines changed: 51 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,15 @@ var Sql = function () {
109109
var toReplace = matchFromExec[1];
110110
while (fromMatch = matchVariable.exec(toReplace)) {
111111
if (typeof fromMatch !== 'undefined' && fromMatch !== null && typeof fromMatch[1] !== 'undefined' && fromMatch[1] !== null) {
112-
var value = Sql.deep_value_array(jsonPage, fromMatch[1]);
113-
if (typeof value !== 'undefined' && value !== null) {
114-
toReplace = toReplace.replace('{{' + fromMatch[1] + '}}', value);
115-
} else {
116-
toReplace = toReplace.replace('{{' + fromMatch[1] + '}}', '');
117-
}
112+
113+
try {
114+
var value = eval('jsonPage.' + fromMatch[1]);
115+
if (typeof value !== 'undefined' && value !== null) {
116+
toReplace = toReplace.replace('{{' + fromMatch[1] + '}}', value);
117+
} else {
118+
toReplace = toReplace.replace('{{' + fromMatch[1] + '}}', '');
119+
}
120+
} catch (e) {}
118121
}
119122
}
120123

@@ -358,10 +361,12 @@ var Sql = function () {
358361

359362
var fromDirectory = Sql.getFromDirectory(from, pathFromClause);
360363

364+
var dateStart = new Date();
365+
361366
var list = _.Manager.instance.getList();
362-
var files_array = list[0].files.filter(function (element, index, arr) {
363-
if (typeof element.published !== 'undefined' && element.published !== null) {
364-
if (element.published.path.indexOf(fromDirectory) > -1) {
367+
var files_array = list.filter(function (element, index, arr) {
368+
if (element.published) {
369+
if (element.path.indexOf(fromDirectory) > -1) {
365370
return true;
366371
}
367372
}
@@ -429,59 +434,6 @@ var Sql = function () {
429434

430435
return 'other';
431436
}
432-
}, {
433-
key: 'deep_value',
434-
value: function deep_value(obj, pathDeep) {
435-
436-
if (pathDeep.indexOf('.') === -1) {
437-
return typeof obj[pathDeep] !== 'undefined' && obj[pathDeep] !== null ? obj[pathDeep] : null;
438-
}
439-
440-
var pathSplit = pathDeep.split('.');
441-
var res = JSON.parse(JSON.stringify(obj));
442-
for (var i = 0; i < pathSplit.length; i++) {
443-
if (typeof res[pathSplit[i]] !== 'undefined' && res[pathSplit[i]] !== null) {
444-
res = res[pathSplit[i]];
445-
} else {
446-
return null;
447-
}
448-
}
449-
450-
return res;
451-
}
452-
}, {
453-
key: 'deep_value_array',
454-
value: function deep_value_array(obj, pathDeep) {
455-
456-
if (pathDeep.indexOf('.') === -1) {
457-
return typeof obj[pathDeep] !== 'undefined' && obj[pathDeep] !== null ? obj[pathDeep] : null;
458-
}
459-
460-
var pathSplit = pathDeep.split('.');
461-
var res = JSON.parse(JSON.stringify(obj));
462-
463-
while (pathSplit.length > 0) {
464-
465-
if (typeof res[pathSplit[0]] !== 'undefined' && res[pathSplit[0]] !== null) {
466-
if (_typeof(res[pathSplit[0]]) === 'object' && Object.prototype.toString.call(res[pathSplit[0]]) === '[object Array]') {
467-
var resArray = [];
468-
469-
Array.prototype.forEach.call(res[pathSplit[0]], function (item) {
470-
resArray.push(Sql.deep_value_array(item, pathSplit.join('.').replace(pathSplit[0] + '.', '')));
471-
});
472-
res = resArray;
473-
pathSplit.shift();
474-
} else {
475-
res = res[pathSplit[0]];
476-
}
477-
} else {
478-
return null;
479-
}
480-
pathSplit.shift();
481-
}
482-
483-
return res;
484-
}
485437
}, {
486438
key: 'executeWhereClause',
487439
value: function executeWhereClause(files, wheres, maxLimit, columns, jsonPage) {
@@ -497,26 +449,28 @@ var Sql = function () {
497449
var file = _step.value;
498450

499451
if (limit < maxLimit || maxLimit === -1) {
500-
var doc = Sql.executeWhereClauseToFile(file.published, wheres, jsonPage);
452+
if (file.published === true) {
453+
var doc = Sql.executeWhereClauseOnDocument(file, wheres, jsonPage);
501454

502-
if (doc) {
503-
var json = JSON.parse(JSON.stringify(doc));
504-
var jsonValues = {};
455+
if (doc) {
456+
var json = JSON.parse(JSON.stringify(doc));
457+
var jsonValues = {};
505458

506-
if (typeof columns !== 'undefined' && columns !== null && columns.length > 0 && columns[0] !== '*') {
459+
if (typeof columns !== 'undefined' && columns !== null && columns.length > 0 && columns[0] !== '*') {
507460

508-
Array.prototype.forEach.call(columns, function (column) {
509-
if (typeof json[column] !== 'undefined' && json[column] !== null) {
510-
jsonValues[column] = json[column];
511-
}
512-
});
513-
jsonValues[_.config.meta.name] = json[_.config.meta.name];
514-
} else {
515-
jsonValues = json;
516-
}
461+
Array.prototype.forEach.call(columns, function (column) {
462+
if (typeof json[column] !== 'undefined' && json[column] !== null) {
463+
jsonValues[column] = json[column];
464+
}
465+
});
466+
jsonValues[_.config.meta.name] = json[_.config.meta.name];
467+
} else {
468+
jsonValues = json;
469+
}
517470

518-
res.push(jsonValues);
519-
limit++;
471+
res.push(jsonValues);
472+
limit++;
473+
}
520474
}
521475
} else {
522476
break;
@@ -683,37 +637,41 @@ var Sql = function () {
683637
return shouldAdd;
684638
}
685639
}, {
686-
key: 'executeWhereClauseToFile',
687-
value: function executeWhereClauseToFile(file, wheres, jsonPage) {
688-
var json = file;
689-
// if (fileUtils.isFile(file.path)) {
690-
// json = fse.readJsonSync(file.path)
691-
// }
692-
//
693-
var shouldAdd = json;
640+
key: 'executeWhereClauseOnDocument',
641+
value: function executeWhereClauseOnDocument(jsonDoc, wheres, jsonOriginalDoc) {
642+
var shouldAdd = jsonDoc;
694643

695644
if (typeof wheres !== 'undefined' && wheres !== null) {
696645
(function () {
697646
var meta = _.config.meta.name;
698-
if (typeof json[meta] !== 'undefined' && json[meta] !== null) {
647+
if (typeof jsonDoc[meta] !== 'undefined' && jsonDoc[meta] !== null) {
699648
Array.prototype.forEach.call(wheres, function (where) {
700649
var value;
701650
var compare;
702651

703652
if (where.left === 'template' || where.left === 'abe_meta.template') {
704-
value = _.FileParser.getTemplate(json[meta].template);
653+
value = _.FileParser.getTemplate(jsonDoc[meta].template);
705654
} else {
706-
value = Sql.deep_value_array(json, where.left);
655+
try {
656+
value = eval('jsonDoc.' + where.left);
657+
} catch (e) {
658+
// console.log('e', e)
659+
}
707660
}
708661
compare = where.right;
709662

710663
var matchVariable = /^{{(.*)}}$/.exec(compare);
711664
if (typeof matchVariable !== 'undefined' && matchVariable !== null && matchVariable.length > 0) {
712-
var shouldCompare = Sql.deep_value_array(jsonPage, matchVariable[1]);
713-
if (typeof shouldCompare !== 'undefined' && shouldCompare !== null) {
714-
compare = shouldCompare;
715-
} else {
665+
try {
666+
var shouldCompare = eval('jsonOriginalDoc.' + matchVariable[1]);
667+
if (typeof shouldCompare !== 'undefined' && shouldCompare !== null) {
668+
compare = shouldCompare;
669+
} else {
670+
shouldAdd = false;
671+
}
672+
} catch (e) {
716673
shouldAdd = false;
674+
// console.log('e', e)
717675
}
718676
}
719677

0 commit comments

Comments
 (0)