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

taskk

v0.1.3

Published

多进程执行多项目+项目tasks顺序执行/Multi-process execution Multi-project + Project Tasks executes in sequence

Downloads

2

Readme

taskk

English | 中文

Multi-process execution Multi-project + Project Tasks executes in sequence

Code running diagram

graph LR
A[taskk] --require--> 
B(taskk-tool.js) --config/projects--> 
C[fork project-worker]
graph
A[project-worker] --> B1([config:cache_cwd+deps_install]) --N--> runTasks

B1 --Y--> checkPackage([checkPackage -> package changed]) --Y--> depsInstall

checkPackage --N--> B2([config:cache_cwd+node_modules]) --no cache--> depsInstall

depsInstall --> zip-node_modules & runTasks
B2 --has cache--> unzip(unzip node_modules cache) --> runTasks

depsInstall(deps install)
zip-node_modules(zip node_modules-worker)

runTasks[runTasks]

The simplest projects configuration is as follows:

const projects_build_prod = [
  { name: 'my-vue-app', tasks: ['npm run build:prod'] },
  { name: 'my-react-app', tasks: ['npm run build:prod'] },
];

Each item of projects is independent of each other multiple processes are executed in parallel, and tasks under each item is executed synchronously in sequence

Where

Using terminal/git bash

node >= 10

Install

  • Local installation
npm i -D taskk

Configure npm scripts execute taskk, see _example folder

  "scripts": {
    "build:prod": "cross-env BUILD_ENV=prod taskk"
  }
  • Global installation
npm i -g taskk

There is no need to configure taskk in npm scripts; taskk is available globally

Feature

  • Simple to use: provide a taskk-tool.js file, global installation can be executed in the terminal taskk
  • Dynamic configuration: taskk-tool.js -> get_config function returns config/projects
  • Multi-process execution: child_process.fork creates a child process; tasks under each item is executed synchronously in sequence
  • Dependency installation management: config.deps_install, detects package.json updates, redownloads dependencies (works when config.cache_cwd is in effect)
  • node_modules cache management: config.node_modules, handles the node_modules cache and backup, etc. (works when config.cache_cwd is in effect)
  • Any task fails to execute: config.errorToExit: true, which can be enabled only if all tasks succeed. It will kill all children of the main process and exit all tasks
  • Pure execution: config.spawnStdio: 'ignore', in which case the execution of item.tasks will not print, only a small amount of process-related content is printed
  • Execution time statistics: prints the time when subitems item.tasks of projects are executed
  • Unified output: it is convenient to copy the construction product item.output of all subprojects of projects to the external specified path config.projectsDist
  • The completed callback run_all_done: taskk-tool.js -> run_all_done function will be called after normal execution

Parameter

You can manually require('taskk/types/index-en.js'), and then JSDoc can be used for syntax annotation

  • TaskkConfig: config field type

| Field | Type | Required | Default | Description | | ---------------- | ----------------- | -------- | ----------- | --------------------------------------- | | cache_cwd | string | no | "" | Cache path, without name; used with deps_install/node_modules | | deps_install | string | no | "" | Dependency installation command, such as npm install/yarn/pnpm install; Detect package.json update and re download dependency; If it is not configured, you need to manually download the dependency, or add a dependency download command in tasks; works when config.cache_cwd is in effect | | node_modules | boolean | no | false | Process node_modules cache and backup, etc; works when config.cache_cwd is in effect | | spawnStdio | inherit | ignore | no | inherit | spawn output mode of executing tasks (option. stdio); ignore the output of tasks will not be printed. At this time, only a small number of process prompts will be printed | | errorToExit | boolean | no | false | When true, when any tasks fails to execute, it will kill all children of the main process and exit all tasks, run_all_done will not be executed | | projectsDir | string | no | "" | The path of projects relative to the top level; such as packages, sub-apps, etc. | | projectsDist | string | no | "" | After all the projects are executed, the output of each item will be copied here | | forceUpdateCache | boolean | no | false | Sometimes node_modules unzip from the cache directory without error, but when the project cannot run, you can temporarily set true; The cache will be deleted and updated after the dependency is re downloaded (remember to set false after success, otherwise the subsequent cache will not work!) |

  • ProjectItem: Type of each item in projects

| Field | Type | Required | Description | | ------- | ------- | --------- | ------------------------------------------------ | | name | string | yes | Keep consistent with the project folder name. When executing the shell command, you need to obtain the cwd | | tasks | string | yes | List of shell commands to be executed | | output | string | no | The directory name of the output of the execution build, used with config.projectsdist |

  • TaskResult: Result of execution

| Field | Type | Description | | --------- | ------- | --------------- | | type | string | Execution stage flag of the task | | name | string | {roject name | | succeed | boolean | Success or not |

Usage

Generally used for multi-project build management, it has the following directory structure:

.
├── my-react-app
├── my-vue-app
├── package.json
└── taskk-tool.js

Where my-react-app and my-vue-app are two independent projects, taskk-tool.js is a configuration file

Configuration file

Under the top-level folder of multiple projects, create a new file taskk-tool.js. You need to export several data:

  • get_config: () => {config, projects}
    • config TaskkConfig: see Parameter Description
    • projects ProjectItem[]: see Parameter Description
  • run_all_done: (task_results: TaskResult[]) => void
    • Execute after all are successful
    • When config.errorToExit: true, it will not be called

When config.spawnStdio: 'ignore', output:

xxx@xxxdeMacBook-Pro _example $ taskk
  _____  _    ____  _  ___  __
 |_   _|/ \  / ___|| |/ / |/ /
   | | / _ \ \___ \| ' /| ' / 
   | |/ ___ \ ___) | . \| . \ 
   |_/_/   \_\____/|_|\_\_|\_\
                               taskk | v0.1.0
[2022/8/16 16:31:42]
[/Users/xxx/Desktop/FE/taskk/_example]

config: 
 {
  spawnStdio: 'ignore',
  deps_install: 'npm install --registry=http://registry.npmmirror.com',
  cache_cwd: '/Users/xxx/Desktop/FE/taskk/_example/_example-cache',
  projectsDist: '/Users/xxx/Desktop/FE/taskk/_example/_example-dist'
}
projects: 
┌─────────┬────────────────┬──────────────────────────┬─────────┐
│ (index) │      name      │          tasks           │ output  │
├─────────┼────────────────┼──────────────────────────┼─────────┤
│    0    │  'my-vue-app'  │ [ 'npm run build:prod' ] │ 'dist'  │
│    1    │ 'my-react-app' │ [ 'npm run build:prod' ] │ 'build' │
└─────────┴────────────────┴──────────────────────────┴─────────┘
[my-react-app] => ["npm run build:prod"] => start
[my-vue-app] => ["npm run build:prod"] => start

[my-vue-app] => ["npm run build:prod"] => done, used:3.981s

[my-react-app] => ["npm run build:prod"] => done, used:6.421s

projectsDist => [/Users/xxx/Desktop/FE/taskk/_example/_example-dist] => start

/Users/xxx/Desktop/FE/taskk/_example/my-vue-app/dist
/Users/xxx/Desktop/FE/taskk/_example/_example-dist/my-vue-app

/Users/xxx/Desktop/FE/taskk/_example/my-react-app/build
/Users/xxx/Desktop/FE/taskk/_example/_example-dist/my-react-app

projectsDist => [/Users/xxx/Desktop/FE/taskk/_example/_example-dist] => done


开始时间: Tue Aug 16 2022 16:31:42 GMT+0800 (中国标准时间)
结束时间: Tue Aug 16 2022 16:31:49 GMT+0800 (中国标准时间)

====== build_done ======

The contents of taskk-tool.js file are as follows:

// _example\taskk-tool.js
const path = require('path');
const { exec } = require('child_process');
const { writeFile } = require('fs');
const colors = require('colors');
require('taskk/types/index.js');

const start = new Date();

/**
 * 配置信息
 * @type {TaskkConfig}
 */
const config = {
  spawnStdio: 'ignore',
  // node_modules: true,
  deps_install: 'npm install --registry=http://registry.npmmirror.com',
  cache_cwd: path.join(process.cwd(), '_example-cache'),
  projectsDir: '',
  projectsDist: path.resolve(process.cwd(), '_example-dist'),
  // forceUpdateCache: true,
  // errorToExit: true,
};

/**
 * @type {ProjectItem[]}
 */
const projects_build_dev = [
  { name: 'my-vue-app', tasks: ['npm run build:dev'], output: 'dist' },
  { name: 'my-react-app', tasks: ['npm run build:dev'], output: 'build' },
];
const projects_build_prod = [
  { name: 'my-vue-app', tasks: ['npm run build:prod'], output: 'dist' },
  { name: 'my-react-app', tasks: ['npm run build:prod'], output: 'build' },
];

/**
 * 获取配置的方法
 * @returns {{config: TaskkConfig, projects: ProjectItem[]}}
 */
exports.get_config = function get_config() {
  if (process.env.BUILD_ENV === 'dev') {
    return { config, projects: projects_build_dev };
  }
  return { config, projects: projects_build_prod };
};

/**
 * 构建结束后执行
 * @description errorToExit: true时不执行,此时某一个执行失败将会杀掉所有相关子进程
 * @param {TaskResult[]} task_results 执行结果
 */
exports.run_all_done = function run_all_done(task_results) {
  console.log(`\n开始时间: ${start}\n结束时间: ${new Date()}\n`);
  if (task_results.every((i) => i.succeed)) {
    console.log(colors.cyan('====== build_done ======\n'));
  } else {
    console.warn(colors.red('====== 构建失败 ======\n'));
  }
};

End

It ends here