Skip to content

Commit

Permalink
fix:linting
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Nov 5, 2016
1 parent 82a8673 commit 542b367
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
48 changes: 22 additions & 26 deletions src/cli/cms/operations/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,40 @@ import {
Manager
} from '../../'

var create = function(template, pathCreate, name, req, forceJson = {}, duplicate = false) {
var p = new Promise((resolve, reject) => {
abeExtend.hooks.instance.trigger('beforeCreate', template, pathCreate, name, req, forceJson)
const create = function(templateId, pathCreate, name, req, forceJson = {}, duplicate = false) {
const p = new Promise((resolve, reject) => {
abeExtend.hooks.instance.trigger('beforeCreate', templateId, pathCreate, name, req, forceJson)

var templatePath = path.join(config.root, config.templates.url, `${template}.${config.files.templates.extension}`)
var filePath = path.join(pathCreate, name)
filePath = coreUtils.slug.clean(filePath)
filePath = path.join(config.root, config.draft.url, filePath.replace(config.root,''))
if(templatePath !== null && filePath !== null) {
var tplUrl = cmsData.file.fromUrl(filePath)

if(!coreUtils.file.exist(tplUrl.json.path)) {
var json = (forceJson) ? forceJson : {}
var tpl = templatePath
var text = cmsTemplates.template.getTemplate(tpl)
const templatePath = path.join(config.root, config.templates.url, `${templateId}.${config.files.templates.extension}`)
let postDataPath = path.join(pathCreate, name)
postDataPath = coreUtils.slug.clean(postDataPath)
postDataPath = path.join(config.root, config.data.url, postDataPath)

if(templatePath !== null && postDataPath !== null) {
if(!coreUtils.file.exist(postDataPath)) {
let postData = (forceJson) ? forceJson : {}
let template = cmsTemplates.template.getTemplate(templatePath)
if (duplicate) {
json = cmsData.values.removeDuplicate(text, json)
postData = cmsData.values.removeDuplicate(template, postData)
}
text = cmsData.source.removeDataList(text)
var resHook = abeExtend.hooks.instance.trigger('beforeFirstSave', filePath, req.query, json, text)
filePath = resHook.filePath
json = resHook.json
text = resHook.text
template = cmsData.source.removeDataList(template)
var resHook = abeExtend.hooks.instance.trigger('beforeFirstSave', postDataPath, req.query, postData, template)
postDataPath = resHook.filePath
postData = resHook.json
template = resHook.text

abeExtend.hooks.instance.trigger('afterCreate', json, text, pathCreate, name, req, forceJson)
cmsOperations.save.save(filePath, template, json, text, 'draft', null, 'draft')
abeExtend.hooks.instance.trigger('afterCreate', postData, template, pathCreate, name, req, forceJson)
cmsOperations.save.save(postDataPath, templateId, postData, template, 'draft', null, 'draft')
.then((resSave) => {
Manager.instance.updatePostInList(resSave.jsonPath)
filePath = resSave.htmlPath
tplUrl = cmsData.file.fromUrl(filePath)
resolve(resSave.json)
}).catch(function(e) {
reject()
console.error(e)
})
}else {
json = cmsData.file.get(tplUrl.json.path)
resolve(json, tplUrl.json.path)
postData = cmsData.file.get(postDataPath)
resolve(postData, postDataPath)
}
}else {
reject()
Expand Down
3 changes: 1 addition & 2 deletions src/cli/cms/operations/duplicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ const duplicate = function(oldPostUrl, template, newPath, name, req, isUpdate =
if(oldPostUrl != null) {
const files = Manager.instance.getList()
const oldPostDataPath = path.join(config.root, config.data.url, oldPostUrl.replace('.' + config.files.templates.extension, '.json'))
console.log(oldPostDataPath)
let posts = []
posts = coreUtils.array.filter(files, 'path', oldPostDataPath)
console.log(posts)

if(posts.length > 0 && posts[0].revisions != null) {
revisions = posts[0].revisions
if(revisions != null && revisions[0] != null) {
Expand Down

0 comments on commit 542b367

Please sign in to comment.