🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@didid1/d1-core

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@didid1/d1-core

provide core functions for d1 kits and plugins

latest
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

D1 Core

D1 工程套件或插件核心功能封装。

功能模块状态介绍
auth【待开发】实现对 SSO 登录的封装
camel【待开发】提供对 camel 的对接支持
ESLint【待开发】提供 ESLint 接入、检查、格式化 支持
logger部分👌提供 D1 统一的日志封装
notifier【待开发】提供 D1 统一的对外通知
userConfig👌提供统一的 D1 用户配置的读写功能
d1ProjectConfig👌提供统一的 D1 工程配置的读写功能
gitUtil部分👌提供 git 操作封装
formatUtil👌格式化工具
cliPromptUtil👌CLI 交互封装
yamlUtil👌yaml 类型文件读写封装
packageJsonUtil👌package.json 读写封装

功能列表

登录 【待开发】

该模块实现对 SSO 登录的封装,使用方式如下

  const { auth } = require('@didid1/d1-core');
  auth.login().then((result) => {
    // result: {
    // }
    //
  }).catch(err => {
    // ...
  });;
  auth.getUserInfo().then((result) => {
    // result: {
    // }
  }).catch(err => {
    // ...
  });

ESlint 【待开发】

实现 ESLint 接入、检查、格式化 等相关的功能

  const { eslint } = reuqire('@didid1/d1-core');
  eslint.init({
    type: 'react',
    silent: false,
    supportTypeScript: false,
    autoInstallDeps: false,
  });
  // eslintUtil.check(); 待开发
  // eslintUtil.fix(); 待开发

logger 👌

该模块提供 D1 统一的日志封装。

notifier 【待开发】

该模块提供 D1 统一的对外通知。

  const notify = require('@didid1/d1-core');

  notify(information, DChartID);

publish【待开发】

该模块提供统一的 发布 功能封装。

用户配置读写 👌

该模块提供统一的 D1 用户配置的读写功能。

  const { userConfig } = require('@didid1/d1-core');
  userConfig.get('key');
  userConfig.set('key', 'value');

工程配置读写 👌

工程目录目前采用 d1.jsond1.js 双配置方案,其中 json 文件中提供工程基础配置,js 文件提供更灵活的自定义和逻辑处理能力。

此外,d1.js 的优先级更好,会覆盖 d1.json 中的同名配置。

同时,自动化写入的配置,都会写入到 d1.json 中。

  const { projectConfig } = require('@didid1/d1-core');
  projectConfig.getProjectConfig();
  projectConfig.getProjectConfigItem('key');
  projectConfig.setProjectConfig('key', 'value');

分析【待开发】

该模块提供 D1 统一分析工具,用于提供统一的监控分析方案。

工具列表

git 操作【部分完成】

该模块提供对本地 Git 仓库及 remote 仓库的操作。

  const { gitUtil } = require('@didid1/d1-core');
  // 获取当前工程的 git origin 地址
  const gitOrigin = await gitUtil.getGit();
  // 非 git 工程或未设置 origin,return '' 
  console.log(gitOrigin);

Date 日期格式化

  const { formatUtil } = require('@didid1/d1-core');
  // format { Stirng } 时间格式
  // date { Date } 时间对象
  formatUtil('format', new Date());

prompt CLI 交互封装

  const { cliPromptUtil } = require('@didid1/d1-core');
  // true or false 型询问
  const { answer } = await cliPromptUtil.askIfORNot('question', true);
  // 文本输入型询问
  const { answer } = await cliPromptUtil.askForAnswer('question');
  // 密码输入型询问
  const { answer } = await cliPromptUtil.askForPassword('question');
  // 基于正则校验的循环询问
  const { answer } = await cliPromptUtil.askForAnswerValidated('question', /^test$/g, '输入不合法,请重试');

yaml 类型文件读写封装

  const { yamlUtil } = require('@didid1/d1-core');
  // 解析 yaml 文件
  yamlUtil.parseYaml('path-to-file');
  // 覆写 yaml 文件
  yamlUtil.safeDump(obj, 'path-to-file');

packageJson 读写

  const { packageJsonUtil } = require('@didid1/d1-core');
  // 首先执行初始化,再获取相关内容
  console.log(packageJsonUtil.init().getJSON());
  console.log(packageJsonUtil.init().getItem('name'));

发送统计日志

初始化

    // 需要提前传一些参数
  const tracker = new Tracker({
    // 应用名称
    appName: '',
    // 登陆用户
    ID: '',
    // 当前版本
    version: '1.0,0',
  });

统计命令次数

  
  //
  /**
   * 统计命令次数
   * @param {String} cmdName 命令名称
   * @param {Object} args 扩展参数,原样传递到 data 字段中
   */
  async cmdTimes(cmdName, args = {})

统计安装信息

  /**
   * 统计安装信息
   * @param {Object} params 安装信息
   * {
   *  // 当前 Node.js 版本
   *  nodeVersion: ''
   *  // 命令参数
   *  argv: ''
   *  // 是否全局安装,默认: false
   *  isGlobal: true / false
   *  // 其他自定义参数
   *  ...
   * }
   */
  async installInfo(obj = {})

统计错误信息

  /**
   * 统计日志信息(含错误)
   * @param {Object} err 经过 D1 包装过后的对象
   * 格式
   * { name: 'd1',
      msg: 'this is warin',
      time: 2018-12-17T08:19:12.318Z,
      levelName: 'WARN ' }
    */
  async log(errObj)

Keywords

d1

FAQs

Package last updated on 24 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts