import { isExtTs } from '../js' import { babelTsFile } from '../compile' import { ConeScaffoldProps } from '../type' export function processJs({ filepath, str, props, }: { filepath: string str: string props: ConeScaffoldProps }): string { const { routerMode, ts, mobile, lowcode, useArms } = props // 处理 PropTypes if (isExtTs(filepath)) { if (!ts) { // 非 ts 项目要编译成 js str = babelTsFile({ filepath, str, props }) } else { // ts 项目要移除 PropTypes 定义 str = str // 移除包裹在 PropTypesBegin/PropTypesEnd 之间的代码 .replace(/\/\/\s*PropTypesBegin[\s\S]*?\/\/\s*PropTypesEnd/gi, '') // 移除 import PropTypes from 'prop-types'; // https://stackoverflow.com/questions/10805125/how-to-remove-all-line-breaks-from-a-string .replace(/import\s*PropTypes\s*from\s*'prop-types';(\r\n|\n|\r)/gi, '') } } str = str .replace(/\/\/\s*PropTypesBegin(\r\n|\n|\r)/gi, '') .replace(/\/\/\s*PropTypesEnd(\r\n|\n|\r|$)/gi, '') // 处理 js 的 store if (!ts && filepath.indexOf('src/stores/models') !== -1) { str = str.replace(/\/\/ eslint-disable-line import\/no-cycle/gi, '') } // 处理监控相关的代码 if (!useArms) { str = str.replace(/\/\/\s*MonitorBegin[\s\S]*?\/\/\s*MonitorEnd/gi, '') } else { str = str .replace(/\/\/\s*MonitorBegin(\r\n|\n|\r)/gi, '') .replace(/\/\/\s*MonitorEnd(\r\n|\n|\r)/gi, '') } if (routerMode === 'hash' && filepath.indexOf('arms') !== -1) { str = str.replace('enableHistory', 'enableHash') } // 低代码 if (!lowcode) { str = str.replace(/\/\/\s*LowcodeBegin[\s\S]*?\/\/\s*LowcodeEnd/gi, '') } else { str = str .replace(/\/\/\s*LowcodeBegin(\r\n|\n|\r)/gi, '') .replace(/\/\/\s*LowcodeEnd(\r\n|\n|\r)/gi, '') } // 处理移动端 if (mobile) { str = str.replace("import '@alife/tc-fusion/lib/style.scss';", '') str = str.replace( /cn-next\/index\.scss/gm, 'cn-meet-react/dist/meet-react.css', ) str = str.replace(/cn-next/gm, 'cn-meet-react') str = str.replace(/tc-fusion/gm, 'tc-meet') } return str }