UNPKG

bit-bin

Version:

<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b

61 lines (50 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const fs = require('fs'); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const path = require('path'); const compiler = require('vue-template-compiler'); const DEFAULT_SCRIPT_LANG = 'js'; const DEFAULT_STYLE_LANG = 'scss'; const languageMap = { css: 'scss', stylus: 'styl' }; function _default(options) { const { dependency, filename, isScript } = options; // eslint-disable-next-line import/no-dynamic-require, global-require const cabinet = require('../../filing-cabinet').default; const fileContent = fs.readFileSync(filename); const { script, styles } = compiler.parseComponent(fileContent.toString(), { pad: 'line' }); if (isScript) { const scriptExt = script.lang ? languageMap[script.lang] || script.lang : DEFAULT_SCRIPT_LANG; return cabinet(Object.assign(options, { directory: path.dirname(filename), content: script.content, ast: null, ext: `.${scriptExt}` || path.extname(dependency) })); } const stylesResult = styles.map(style => { const styleExt = style.lang ? languageMap[style.lang] || style.lang : DEFAULT_STYLE_LANG; return cabinet(Object.assign(options, { filename: `${path.join(path.dirname(filename), path.parse(filename).name)}.${styleExt}`, directory: path.dirname(filename), content: style.content, ast: null, ext: `.${styleExt}` })); }); return stylesResult[0]; }