GithubHelp home page GithubHelp logo

ts-code-analysis's Introduction

ts-code-analysis

A code dependency analysis tool for ts

npm version Downloads

ts-code-analysis

ts-code-analysis是一款前端代码分析工具,用于实现代码调用分析报告,支持 CLI/API 两种使用模式,代码评分,代码告警,“脏调用”拦截,API 趋势变化分析等应用场景。

Install

npm install ts-code-analysis --save-dev
// or
yarn add ts-code-analysis --dev

Config

新建 analysis.config.js 配置文件:

module.exports = {
  scanSource: [
    {
      // 必须,待扫描源码的配置信息
      name: "Market", // 必填,项目名称
      path: ["src"], // 必填,需要扫描的文件路径(基准路径为配置文件所在路径)
      packageFile: "package.json", // 可选,package.json 文件路径配置,用于收集依赖的版本信息
    },
  ],
  analysisTarget: "framework", // 必须,要分析的目标依赖名
  analysisPlugins: [], // 可选,自定义分析插件,默认为空数组,一般不需要配置
  blackList: ["app.localStorage.set"], // 可选,需要标记的黑名单api,默认为空数组
  reportDir: "report", // 可选,生成代码分析报告的目录,默认为'report',不支持多级目录配置
  reportTitle: "Market依赖调用分析报告", // 可选,分析报告标题,默认为'依赖调用分析报告'
  scorePlugin: true, // 可选,是否要运行默认评分插件,默认为false表示不评分
  alarmThreshold: 90, // 可选,开启代码告警的阈值分数(0-100),默认为null表示关闭告警逻辑 (CLI模式生效)
};

Mode

1. cli

// package.json 片段,添加bin command到npm script
...
"scripts": {
    "analysis": "ca analysis"
}
...

$ npm run analysis
// or
$ yarn analysis

2. api

const analysis = require("ts-code-analysis"); // 代码分析包

async function scan() {
  try {
    const { report, diagnosisInfos } = await analysis({
  scanSource: [
    {
      // 必须,待扫描源码的配置信息
      name: "Market", // 必填,项目名称
      path: ["src"], // 必填,需要扫描的文件路径(基准路径为配置文件所在路径)
      packageFile: "package.json", // 可选,package.json 文件路径配置,用于收集依赖的版本信息
    },
  ],
  analysisTarget: "framework", // 必须,要分析的目标依赖名
  analysisPlugins: [], // 可选,自定义分析插件,默认为空数组,一般不需要配置
  blackList: ["app.localStorage.set"], // 可选,需要标记的黑名单api,默认为空数组
  reportDir: "report", // 可选,生成代码分析报告的目录,默认为'report',不支持多级目录配置
  reportTitle: "Market依赖调用分析报告", // 可选,分析报告标题,默认为'依赖调用分析报告'
  scorePlugin: true, // 可选,是否要运行默认评分插件,默认为false表示不评分
  alarmThreshold: 90, // 可选,开启代码告警的阈值分数(0-100),默认为null表示关闭告警逻辑 (CLI模式生效)
};);
    // console.log(report);
    // console.log(diagnosisInfos);
  } catch (e) {
    console.log(e);
  }
}

scan();

ts-code-analysis's People

Contributors

yeatsczx avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.