@viewdo/dxp-story-cli
Version:
README.md
93 lines (81 loc) • 1.9 kB
JavaScript
const JSONFile = require('./json-file')
module.exports = class StoryConfig {
constructor(story_key, output = '.', file_service) {
let root = [output, 'stories', story_key].join('/')
Object.assign(this, {
root,
file: new JSONFile(`${root}/story-config.json`, file_service)
})
let config = this.file.read()
if(config)
Object.assign(this, config)
}
save(story) {
// mapping from the domain-model
let {
key,
name,
description,
thumbnailUrl,
organizationKey,
milestones,
emailTemplates,
htmlTemplates,
textTemplates,
inputs,
inputMaps: inputMaps
} = story
let config = {
kind: 'Story',
apiVersion: 'api.view.do/v1',
key,
name,
description,
thumbnailUrl,
organizationKey,
milestones,
inputs,
events: story.events.map(e => {
let { key, name } = e
return { key, name }
}),
externalEvents: story.externalEvents.map(e => {
let { slug: key, name, url } = e
return { key, name, url }
}),
episodes: story.episodes.map(e => {
let {
key,
name,
description,
isEnabled,
jsonAttachmentKey,
cssAttachmentKey,
jsAttachmentKey
} = e
return {
key,
name,
description,
isEnabled,
jsonAttachmentKey,
cssAttachmentKey,
jsAttachmentKey
}
}),
actions: story.workflow,
customLinks: story.customLinks,
customKpis: story.customKpis.map(e => {
let { key, name } = e
return { key, name }
}),
emailTemplates,
htmlTemplates,
textTemplates,
inputMaps
}
Object.assign(this, config)
this.file.write(config)
return this
}
}