在npm中,如何运行两个或多个并行任务,但是等待第一个任务将创建的资源可供第二个任务使用,等等?
例子(概念):
npm run task1 & waitfor task1 then task2 & waitFor task3 then task4 ...
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
编辑
作为一个例子:让我们说我的第一个任务是启动一个网络服务器,而我的第二个任务是每次事件发生时都从该网络服务器中消耗数据.另一个例子:我的第一个任务可能是启动webdriver-manager,我的第二个任务,启动一个网络服务器,以及我的第三个任务,运行e2e测试我的文件被更改的时间.因此,我需要所有这些任务保持并发运行,但它们需要按特定的顺序和时间进行初始化.
在我的package.json文件中,我具有以下脚本:
"scripts": {
"start": "npm run watch:all",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server",
"sass": "node-sass -o sass/ css/",
"watch:sass": "onchange 'sass/*.scss' -- npm run sass",
"watch:all": "parallelshell 'npm run watch:sass' 'npm run lite'"
}
Run Code Online (Sandbox Code Playgroud)
每当我运行代码时,我都会收到以下错误消息:
crs@1.0.0 start /home/hazem/crs
> npm run watch:all
> crs@1.0.0 watch:all /home/hazem/crs
> parallelshell 'npm run watch:sass' 'npm run lite'
child_process.js:422
throw new ERR_INVALID_ARG_TYPE('options.cwd', 'string', options.cwd);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "options.cwd" property must be of type string. Received type function
at …Run Code Online (Sandbox Code Playgroud)