0.1.18 • Published 1 year ago

ebe-utils v0.1.18

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

出码模块工具

cli

setup

eve setup

出码模块的后置处理,如拷贝静态文件等

move

通过指定的入口文件,将该文件所有关联文件一起拷贝到指定产物目录下。用于将项目中的组件抽离出来成为一个独立的组件。减少人工抽离时,过多转移文件的问题。

eve move ./a/index.ts --o ./dist

以上表示,将 ./a/index.ts 文件所有关联文件一起拷贝到 ./dist 目录下。

工具类

codeCreate

一键出码

import {
  findBusiCompById,
  findPageInstByVersionId,
  getThemeCss,
  qryAttrSpecPage,
  qryPageCompAssetList,
  qryPageInstListByAppId,
  queryFrontendDatasourcePage,
  queryFrontendHookList,
  findApplication,
} from '@/services/api';
import { useEffect } from 'react';
import { codeCreate, init } from 'ebe-utils';

const Page = () => {
  useEffect(() => {
    init();
  }, []);

  const onFinish = async (values: any) => {
    await codeCreate({
      appId: values.appId,
      platform: values.platform ? 'APP' : 'PC',
      baseUrl:
        process.env.BASE_URL === 'http://10.10.179.140:8047/HJF/'
          ? 'http://10.10.179.140:8048/HJF/'
          : process.env.BASE_URL!,
      services: {
        findBusiCompById,
        findPageInstByVersionId,
        getThemeCss,
        qryAttrSpecPage,
        qryPageCompAssetList,
        qryPageInstListByAppId,
        queryFrontendDatasourcePage,
        queryFrontendHookList,
        findApplication,
      },
    });
  };
  return <></>;
};

export default Page;

clearLXPagesDSL

使用内定规则清理 dsl,注意传入数据是一个页面 dsl 数组,如果仅有一个页面,可以传入 page

const clearPages = clearLXPagesDSL(pages);

for 开发

在 constants.ts 中修改规则

一个 key 对应一个规则,一般规则中需要存在 rule 函数,如果对象是数组,则必须存在 loopRule 和 loop

export interface IRule {
  // 是否删除的判断规则,会根据
  rule?: (props: IRulePrams) => any;
  // 如果存在 loopRule 表示循环对象是一个数组,就根据 loop 中定义的规则清理 item,loop 中的 key 为 loopRule 返回值的判断依据
  loopRule?: (item: any) => string;
  loop?: IRulesType;
}

rule 函数

export interface IRulePrams {
  // 根据当前循环的数据 key,比如 data.a.c ,paths 为 ['data','a','c']
  paths: string[];
  // 此时循环中的值
  value: any;
  // 此时循环中的key
  key: string;
  // 提供的工具类,此时的值和data比较,如果是字符串相等则返回 true,如果对象和 data key-value 都相同的值会被删除,并返回清楚后的新对象
  diffraction?: (data: any) => any;
}
({ paths, value, key, diffraction }) => any;
rule

rule 函数可以返回 true 或者对象,如果返回 true 表示删除当前的对象,如果返回对象,则表示用新对象替换旧对象

属性 diffraction 为提供的工具方法

const in = {
    size: 'm',
    title: 'hellp',
    number: 123
}

const diff = {
    size:'m',
}
const out = diffraction(diff);

此时 out 为

const in = {
    title: 'hellp',
    number: 123
}

以上逻辑表示当 in 中的值和 diff 中的值相等时,删除

一般用法为

const ruleObj = {
  rule: ({ diffraction }) => {
    // 当对象中的某个字为xxx的时候 delete value.xxx
    const diff = {};
    return diffraction(diff);
  },
};
loop & loopRule

loopRule 传入数组 item 返回一个 key,比如常用到的 components 中要找到某个 组件类型。

export const lingxiDslRules: IRulesType = {
  components: {
    loopRule: (item) => item.compName,
    loop: componentsRule,
  },
};

返回 compName 作为 loop 的 key

const components = [
  { compName: 'A', title: 'A' },
  { compName: 'C', title: 'C' },
];

const loop = {
  A: {
    rule: () => any,
  },
  C: {
    rule: () => any,
  },
};

以上逻辑表示循环 components 当 item 的 compName 等于 A 时,执行 loop.A 的规则

高级技巧

由于 rule 返回对象时,会覆盖旧的值,因此可以在 rule 中调用 removeObjectByRules 等方法来进一步实现内层的数据清理。

比如 View 组件的 components 也需要清理,就可以如下使用

import { removeObjectByRules } from './index';
import { IRulesType } from './types';
const isTrue = {
  rule: () => true,
};
const componentsRule: IRulesType = {
  View: {
    rule: ({ value, diffraction }) => {
      if (value?.components) {
        return removeObjectByRules(value, lingxiDslRules);
      }
    },
  },
};

export const lingxiDslRules: IRulesType = {
  components: {
    loopRule: (item) => item.compName,
    loop: componentsRule,
  },
};
0.1.18

1 year ago

0.1.17

1 year ago

0.1.16

1 year ago

0.0.10

1 year ago

0.1.12

1 year ago

0.0.11

1 year ago

0.1.13

1 year ago

0.0.12

1 year ago

0.1.14

1 year ago

0.0.13

1 year ago

0.1.15

1 year ago

0.0.14

1 year ago

0.1.0

1 year ago

0.1.1

1 year ago

0.0.15

1 year ago

0.0.9

1 year ago

0.0.16

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago