我有一个monorepo,我希望在其中创建用于在本地启动特定项目的脚本。
该项目完全基于Node.js
。
为了让我在本地设置该项目以进行开发,我需要按此顺序运行以下命令:
启动docker映像
cd docker/dockerForTests
docker-compose up -d
启动Web Auth服务器
cd src/project/webAuthentication
setenvs projectAuthentication && npm start
启动API
cd src/project/api
setenvs projectAPI && npm start
启动Web客户端
cd src/project/web
setenvs projectWeb && npm start
为了方便使用,我通常在VSCode中的新终端窗口中开始每个部分。
为了自动执行此过程,我了解了VSCode任务。
尽管它们似乎是为“构建”或“监视”任务而设计的,但我认为我可以修改行为以为我运行上述命令。
这是我的尝试:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"runner": "terminal",
"version": "2.0.0",
"tasks": [
{
"label": "Start Docker",
"dependsOrder": "sequence",
"type": "shell",
"command": "cd docker/dockerForTests && docker-compose up -d",
},
{
"label": "Start Web Auth",
"dependsOrder": "sequence",
"type": "process",
"command": "cd src/project/webAuthentication && setenvs projectAuthentiction && npm start"
},
{
"label": "Start Up Local Development Environment",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new",
"showReuseMessage": false,
"clear": true
},
"dependsOn": [
"Start Docker",
"Start Web Auth"
],
"problemMatcher": []
}
]
}
第一个命令可以正常工作,但是我希望它像集成终端一样,一旦命令运行完成,它就挂在这里以供输入。
第二,第二个任务不起作用,因为它不是Node命令。
我希望它像常规的bash输入一样工作。
如何实现上述工作流程自动化?可能吗?
至少对于第2、3和4点,concurrently正常,对于第1点也应正常。在根目录中package.json的scripts
部分中使用以下脚本,您应该仅用一个命令即可启动dev env。
"start-docker": "cd docker/dockerForTests && docker-compose up -d", "start-auth": "cd src/project/webAuthentication && setenvs projectAuthentication && npm start", "start-api": "cd src/project/api && setenvs projectAPI && npm start", "start-client": "cd src/project/web && setenvs projectWeb && npm start", "start-dev": "concurrently \"npm run start-docker\" \"npm run start-auth\" \"npm run start-api\" \"npm run start-client\""
这不使用VSCode任务,但是无论如何都会简化您的生活。