npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lingxiteam/ebe-utils

v0.2.10

Published

## cli

Downloads

385

Readme

出码模块工具

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 '@lingxiteam/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,
      },
      // 为 true 时,会自动翻译页面名称作为路由 path
      needTranslatePagePathToEnglish: true,
      // 默认为 true,会自动发起浏览器下载 zip 文件
      autoDownloadOnBower: true,
      // 默认为 true,忽略静态文件生成,通过 ebe setup 命令下载静态文件
      useEbeSetup: true,
    });
  };
  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,
  },
};