UNPKG

@viewdo/dxp-story-cli

Version:
41 lines (33 loc) 1.57 kB
const IndexJsWriter = require('../common/index.js.js'); const SettingsJsWriter = require('../common/_settings.js.js'); const camelCase = require('lodash/camelCase'); const kebabCase = require('lodash/kebabCase'); class MetadataFileCreator { constructor(_console = console) { Object.assign(this, { index_js_writer: new IndexJsWriter(_console), settings_js_writer: new SettingsJsWriter(__dirname, _console), complex_data_js_writer: new SettingsJsWriter(undefined, _console), camelCase, kebabCase }); } create(static_data = {}, static_data_path, basic_data, static_data_complex_paths = []) { const { index_js_writer, settings_js_writer, complex_data_js_writer, isEmpty, omit, camelCase } = this; const complex_static_data_variables = static_data_complex_paths.map(static_data_complex_path => { const { data: complex_data, path: complex_data_path, key } = static_data_complex_path; const variable = camelCase(key); const file_path = `./${kebabCase(key)}`; complex_data_js_writer.write(complex_data, complex_data_path); index_js_writer.write(complex_data_path); return { data: static_data_complex_path, file_path, variable } }); index_js_writer.write(static_data_path); settings_js_writer.write({basic_data, complex_static_data_variables}, static_data_path); } } module.exports = MetadataFileCreator;