UNPKG

@viewdo/dxp-story-cli

Version:
207 lines (185 loc) 6.5 kB
module.exports = class StoryAssetConfig { constructor(story_config, existing_asset_config) { // setup defaults Object.assign(this, this._getConfig(story_config), { story_config }) // override from config if(existing_asset_config) Object.assign(this, existing_asset_config) } _getConfig(story_config) { let episodes = {} story_config.episodes.forEach(e => { episodes[e.key] = { } Object.assign(episodes[e.key],{ name: e.name, json_file: `${story_config.root}/episodes/${e.key}/story.json`, css_file: `${story_config.root}/episodes/${e.key}/story.css`, js_file: `${story_config.root}/episodes/${e.key}/story.js` }) }) let file_types = this.getFileTypeDefinitions(story_config) let html_templates = {} story_config.htmlTemplates.forEach(e => { html_templates[e.key] = this._getHtmlTemplatePath(story_config.root,e.key) }) let email_templates = {} story_config.emailTemplates.forEach(e => { email_templates[e.key] = this._getEmailTemplatePath(story_config.root,e.key) }) let text_templates = {} story_config.textTemplates.forEach(e => { text_templates[e.key] = this._getTextTemplatePath(story_config.root,e.key, e.type) }) return { name: story_config.name, organization_key: story_config.organizationKey, sync_file: story_config.file.path, js_file: file_types.js_file.paths[0].local_path, json_file: file_types.json_file.paths[0].local_path, css_file: file_types.css_file.paths[0].local_path, intro_html_file: file_types.intro_html_file.paths[0].local_path, episodes, email_templates, html_templates, text_templates } } // Story File Type Definitions --------------------------------------- getFileTypeDefinitions(story_config = this.story_config) { let resolvePath = (file_type, child_key, sub_type) => { let path = this[file_type] if(path && path[child_key]){ if(path[child_key] && path[child_key][sub_type]) path = path[child_key][sub_type] else path = path[child_key] } return (typeof path == 'string') ? path : null } return { intro_html_file: { name: 'Intro Html File', description: '', paths: [{ remote_path: `/stories/${story_config.key}/intro-html-file`, local_path: resolvePath('intro_html_file') || `${story_config.root}/story-intro.html` }] }, json_file: { name: 'Story JSON File', description: '', paths: [{ remote_path: `/stories/${story_config.key}/json-file`, local_path: resolvePath('json_file') || `${story_config.root}/story.json` }] }, js_file: { name: 'Story JS File', description: '', paths: [{ remote_path: `/stories/${story_config.key}/js-file`, local_path: resolvePath('js_file') || `${story_config.root}/story.js`, skip_validation: true }] }, css_file: { name: 'Story CSS File', description: '', paths: [{ remote_path: `/stories/${story_config.key}/css-file`, local_path: resolvePath('css_file') || `${story_config.root}/story.css` }] }, email_templates: { name: 'Email Template Files', description: '', paths: story_config.emailTemplates.map(e => { return { remote_path: `/stories/${story_config.key}/email-templates/${e.key}/file`, local_path: resolvePath('email_templates', e.key) || this._getEmailTemplatePath(story_config.root,e.key) } }) }, html_templates: { name: 'Html Template Files', description: '', paths: story_config.htmlTemplates.map(e => { return { remote_path: `/stories/${story_config.key}/html-templates/${e.key}/file`, local_path: resolvePath('html_templates', e.key) || this._getHtmlTemplatePath(story_config.root, e.key) } }) }, text_templates: { name: 'Text Template Files', description: '', paths: story_config.textTemplates.map(t => { return { remote_path: `/stories/${story_config.key}/text-templates/${t.key}/file`, local_path: resolvePath('text_templates', t.key) || this._getTextTemplatePath(story_config.root,t.key, t.type), skip_validation: t.type == 'js' } }) }, episode_files: { name: 'Episode Files', description: '', paths: [ ...story_config.episodes.filter(e => e.isEnabled && e.jsonAttachmentKey).map(e => { return { remote_path: `/attachments/${e.jsonAttachmentKey}`, local_path: resolvePath('episodes', e.key, 'json_file') || `${story_config.root}/episodes/${e.key}/story.json` } }), ...story_config.episodes.filter(e => e.isEnabled && e.cssAttachmentKey).map(e => { return { remote_path: `/attachments/${e.cssAttachmentKey}`, local_path: resolvePath('episodes', e.key, 'css_file') || `${story_config.root}/episodes/${e.key}/story.css` } }), ...story_config.episodes.filter(e => e.isEnabled && e.jsAttachmentKey).map(e => { return { remote_path: `/attachments/${e.jsAttachmentKey}`, local_path: resolvePath('episodes', e.key, 'js_file') || `${story_config.root}/episodes/${e.key}/story.js`, skip_validation: true } }) ] } } } _getHtmlTemplatePath (root, file_key) { return `${root}/html-templates/${file_key}.html` } _getEmailTemplatePath (root, file_key) { return `${root}/email-templates/${file_key}.liquid` } _getTextTemplatePath (root, file_key, type) { return `${root}/text-templates/${file_key}.${this._coerceTextTypeExtension(type)}` } _coerceTextTypeExtension (type) { let ext = type.toLowerCase() return (ext == 'text') ? 'txt' : ext } }