Skip to content

Commit

Permalink
feat: vue3 ts类型 CSSProperties 导出
Browse files Browse the repository at this point in the history
  • Loading branch information
liweijie0812 committed Nov 7, 2023
1 parent 56e36b2 commit ffcdc59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/scripts/config/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const GLOBAL_TYPES = [
// FormEvent comes from onChange/onInput/onInvalid/onReset/onSubmit .etc.
const REACT_EVENTS = ['MouseEvent', 'KeyboardEvent', 'ClipboardEvent', 'FocusEvent', 'WheelEvent', 'FormEvent', 'TransitionEvent', 'ChangeEvent', 'DragEvent', 'CompositionEvent'];
const REACT_TYPES = ['CSSProperties'].concat(REACT_EVENTS);
const VUE_TYPES = ['CSSProperties'];

const [component, framework, allParams] = process.argv.slice(2);
// const { finalProject } = parseParams(allParams);
Expand All @@ -45,7 +46,7 @@ const finalProject = allParams && allParams.includes('finalProject');
module.exports = {
GLOBAL_TYPES,
REACT_EVENTS,
REACT_TYPES,
VUE_TYPES,
FILE_RIGHTS_DESC: [
'/**',
'该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC',
Expand Down
10 changes: 8 additions & 2 deletions packages/scripts/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path');
const chalk = require('chalk');
const upperFirst = require('lodash/upperFirst');
const camelcase = require('lodash/camelCase');
const { FILE_RIGHTS_DESC, GLOBAL_TYPES, REACT_EVENTS, REACT_TYPES } = require('../config/const');
const { FILE_RIGHTS_DESC, GLOBAL_TYPES, REACT_EVENTS, REACT_TYPES, VUE_TYPES } = require('../config/const');
const { FRAMEWORK_MAP, TYPES_COMBINE_MAP } = require('../config');
const generateGlobals = require('./global');
const formatTNode = require('./t-node');
Expand Down Expand Up @@ -270,6 +270,12 @@ function getGlobalsImports(str, framework) {
types: formatCommonTypeImports(str, REACT_TYPES),
};
}
if (framework === 'VueNext(PC)' || framework === 'Vue(Mobile)') {
map.vue = {
path: 'vue',
types: formatCommonTypeImports(str, VUE_TYPES),
};
}
const r = Object.keys(map).filter(key => map[key].types.length)
.map(key => `import { ${map[key].types.join(', ')} } from '${map[key].path}';`);
return r;
Expand All @@ -293,7 +299,7 @@ function replaceInputEvent(str, newApi) {
function handleApiByFramework(api, framework) {
const newApi = { ...api };
// 某些组件的 API 定义在 Vue 中没有那么细,需要忽略
if (framework.indexOf('Vue') !== -1 && newApi.custom_field_type) {
if (framework === 'Vue(PC)' && newApi.custom_field_type) {
// Vue 需要忽略的 TS 类型定义
const VUE_IGNORE_TYPES = ['CSSProperties'];
const filters = VUE_IGNORE_TYPES.filter(item => newApi.custom_field_type.indexOf(item) !== -1);
Expand Down

0 comments on commit ffcdc59

Please sign in to comment.