| Conditions | 3 |
| Paths | 2 |
| Total Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import path from 'path' |
||
| 18 | function publishNext(published, tt, cb, i = 0) { |
||
| 19 | var pub = published.shift() |
||
| 20 | if(typeof pub !== 'undefined' && pub !== null) { |
||
| 21 | |||
| 22 | var jsonObject = fse.readJsonSync(pub.path) |
||
| 23 | i++ |
||
| 24 | var p = new Promise((resolve) => { |
||
| 25 | if(typeof templatesTexts[jsonObject.abe_meta.template] === 'undefined' || templatesTexts[jsonObject.abe_meta.template] === null) { |
||
| 26 | templatesTexts[jsonObject.abe_meta.template] = cmsTemplates.template.getTemplate(jsonObject.abe_meta.template) |
||
| 27 | } |
||
| 28 | |||
| 29 | cmsData.source.getDataList(path.dirname(jsonObject.abe_meta.link), templatesTexts[jsonObject.abe_meta.template], jsonObject, true) |
||
| 30 | .then(() => { |
||
| 31 | jsonObject = abeExtend.hooks.instance.trigger('afterGetDataListOnSave', jsonObject) |
||
| 32 | |||
| 33 | var obj = { |
||
| 34 | publishAll:true, |
||
| 35 | type: jsonObject.abe_meta.status, |
||
| 36 | json: { |
||
| 37 | content: jsonObject |
||
| 38 | } |
||
| 39 | } |
||
| 40 | obj = abeExtend.hooks.instance.trigger('beforeSave', obj) |
||
| 41 | |||
| 42 | var page = new Page(obj.json.content.abe_meta.template, templatesTexts[jsonObject.abe_meta.template], obj.json.content, true) |
||
| 43 | |||
| 44 | cmsOperations.save.saveHtml( |
||
| 45 | path.join(config.root, processConfig.ABE_DESTINATION, jsonObject.abe_meta.link), |
||
| 46 | page.html |
||
| 47 | ) |
||
| 48 | |||
| 49 | obj = abeExtend.hooks.instance.trigger('afterSave', obj) |
||
| 50 | |||
| 51 | trace('('+ getTime() + ') ' + i + ' - ' + pub.path.replace(config.root, '').replace(config.data.url, '') + ' (tpl: ' + jsonObject.abe_meta.template + ')') |
||
| 52 | resolve() |
||
| 53 | }, |
||
| 54 | () => { |
||
| 55 | error('publish-all ERROR on ' + pub.path.replace(config.root, '').replace(config.data.url, '')) |
||
| 56 | resolve() |
||
| 57 | }) |
||
| 58 | }) |
||
| 59 | |||
| 60 | p.then(function () { |
||
| 61 | publishNext(published, tt, cb, i++) |
||
| 62 | }) |
||
| 63 | .catch(function (e) { |
||
| 64 | publishNext(published, tt, cb, i++) |
||
| 65 | error('error', e) |
||
| 66 | }) |
||
| 67 | }else { |
||
| 68 | cb(i) |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 95 | }) |