'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var fs_fs = require('../fs/fs.js');
require('../nodejs/crypto.js');
require('../nodejs/fs.js');
require('../nodejs/os.js');

var getComponentNameStr = function getComponentNameStr(componentName) {
  return "export default {\n  name: '".concat(componentName, "',");
};
/**
 * 为 Vue 组件添加、修正 name 属性
 * @param {string} filePath 组件地址
 * @param {string} componentName 组件名称
 * @returns {string} 新的组件内容
 *
 * @example
 * ```ts
 * addNameForComponent('xxx.vue', 'PressUploader');
 * ```
 */
function addNameForComponent(filePath, componentName) {
  var content = fs_fs.readFileSync(filePath);
  var result = content.replace(/export default {(?!\s+name)/, getComponentNameStr(componentName)).replace(/export default {\s+name: '(\w+)',/, function (a, origin) {
    console.log('[origin] ', origin);
    return getComponentNameStr(componentName);
  });
  fs_fs.writeFileSync(filePath, result);
  return result;
}

exports.addNameForComponent = addNameForComponent;
