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

parallel-wait-run

v0.2.2

Published

parallel-wait-run

Downloads

472

Readme

parallel-wait-run

支持同时运行多个npm scripts,并且可以通过自定义的异步函数控制每一个npm scripts的启动时机。

示例

文档

开始

  1. 安装
# npm
npm install -D parallel-wait-run

# pnpm
pnpm add -D parallel-wait-run

# yarn
yarn add -D parallel-wait-run
  1. 在项目根目录添加配置文件 parallel.config.ts(也支持其他JSTS扩展名)
import { defineConfig } from "parallel-wait-run";

export default defineConfig({
  scripts: [
    {
      name: "dev",
      command: `dev command`,
      wait: async () => {
        sleep(1000);
        return true;
      },
    },
    {
      name: `unit-test`,
      command: `unit-test command`,
      wait: async () => {
        sleep(2000);
        return true;
      },
    },
  ],
});

也支持使用函数生成配置

import { defineConfig } from "parallel-wait-run";

export default defineConfig(({ mode, root }) => {
  return {
    scripts: [
      {
        name: "dev",
        command: `pnpm  dev`,
      },
      {
        name: `unit-test`,
        command: `pnpm test-watch`,
      },
    ],
  };
});

异步函数也是支持的

import { defineConfig } from "parallel-wait-run";

export default defineConfig(async ({ mode, root }) => {
  return {
    scripts: [
      {
        name: "dev",
        command: `pnpm  dev`,
      },
      {
        name: `unit-test`,
        command: `pnpm test-watch`,
      },
    ],
  };
});
  1. 运行
# npm
npm run parallel

# pnpm
pnpm parallel

# yarn
yarn parallel

命令行选项

-r, --root

命令运行的根路径,默认process.cwd(), 必须为绝对路径

示例:

npm run parallel -r /a/b/c

-c, --config

指定配置文件,默认会在根路径下自动匹配parallel.config.[ts,js,cjs,mjs], 如果设置为相对路径,则会以 root为基础路径计算路径

示例:

npm run parallel -c ./parallel.custom-config.ts

-m, --mode

指定模式,一般在使用函数生成配置时使用,如

export default defineConfig(({ mode }) => {
  if (mode === "dev") {
    return {
      scripts: [],
    };
  } else {
    return {
      scripts: [],
    };
  }
});

-g, --group

指定运行某一组脚本

-h, --help

显示帮助信息

-v, --version

显示版本号

配置选项

root

  • 类型: string
  • 是否必填: 否
  • 默认值: process.cwd()
  • 根路径,如果使用命令行指定了root,则此配置会被覆盖

beforeRun

  • 类型: () => MaybePromise<boolean>
  • 是否必填: 否
  • 在运行所有脚本命令前运行的函数,如果返回false, 则会退出运行

scripts

  • 类型: array
  • 是否必填: 是
  • 默认运行的脚本列表

script的参数如下:

script.name

  • 类型: string
  • 是否必填: 是
  • 脚本名称

script.command

  • 类型: string
  • 是否必填: 是
  • 脚本的具体命令,例如npm run dev

script.wait

  • 类型: () => MaybePromise<boolean>
  • 是否必填: 否
  • 当此函数执行完成后,运行脚本中的命令,如果返回false,则会退出整个进程的运行

script.cwd

  • 类型: string
  • 是否必填: 否
  • 执行脚本命令的cwd,如果未指定,则会使用root的值

script.env

  • 类型: object
  • 是否必填: 否
  • 为当前脚本命令注入一些环境参数,类型为
type Env = {
  [name: string]: string;
}

script.prefix.text

  • 类型: string
  • 是否必填: 否
  • 脚本命令日志输出的前缀,如果没有指定,则会使用script.name

script.prefix.color

  • 类型: string
  • 是否必填: 否
  • 脚本命令日志前缀的颜色,如果没有指定,则会随机指定生成一种颜色,支持的颜色格式#FF8800,会使用chalk.hex来进行添加颜色

groups

  • 类型: object
  • 是否必填: 否
  • 定义多组脚本,类型为
type Group = {
  [name: string]: ParallelScripts;
}

ParallelScripts的相关参数参照上面的scripts选项

例子

致谢