将任务 属性 定义为可以根据平台更改的任务
Define a task property as one that can change per platform
我正在开发 provide tasks 的 VSCode 扩展,我如何指定 属性 可以根据平台更改,例如我们可以在 "shell" 任务上这个 tasks.json
:
"tasks": [
{
"type": "shell",
"windows": { "command": "wndCmd.exe" },
"linux": { "command": "lnxCmd" },
"osx": { "command": "osxCmd" }
}]
但对我来说这是不可能的。
根据文档示例,无法创建如下任务:
"tasks": [
{
"type": "rake",
"task": "some",
"windows": { "file": "winFile" },
"linux": { "file": "linuxFile" },
"osx": { "file": "osxFile" }
}]
我真的不明白为什么你需要为动态生成的任务这样做,这只对声明性/静态任务声明有意义。
只需生成适合当前 OS 的任务版本。您可以查看 process.platform
,另请参阅:
- How do I determine the current operating system with Node.js.
我可以手工完成:
"taskDefinitions": [
{
"type": "rake",
"required": [
"task"
],
"properties": {
"task": {
"type": "string",
"description": "The Rake task to customize"
},
"file": {
"type": "string",
"description": "The Rake file that provides the task. Can be omitted."
},
"windows: {
"type": "object",
"properties": {
"file": {
"type": "string",
"description": "..."
}
}
},
"linux: {
"type": "object",
"properties": {
"file": {
"type": "string",
"description": "..."
}
}
},
"osx: {
"type": "object",
"properties": {
"file": {
"type": "string",
"description": "..."
}
}
}
}
}
]
我正在开发 provide tasks 的 VSCode 扩展,我如何指定 属性 可以根据平台更改,例如我们可以在 "shell" 任务上这个 tasks.json
:
"tasks": [
{
"type": "shell",
"windows": { "command": "wndCmd.exe" },
"linux": { "command": "lnxCmd" },
"osx": { "command": "osxCmd" }
}]
但对我来说这是不可能的。
根据文档示例,无法创建如下任务:
"tasks": [
{
"type": "rake",
"task": "some",
"windows": { "file": "winFile" },
"linux": { "file": "linuxFile" },
"osx": { "file": "osxFile" }
}]
我真的不明白为什么你需要为动态生成的任务这样做,这只对声明性/静态任务声明有意义。
只需生成适合当前 OS 的任务版本。您可以查看 process.platform
,另请参阅:
- How do I determine the current operating system with Node.js.
我可以手工完成:
"taskDefinitions": [
{
"type": "rake",
"required": [
"task"
],
"properties": {
"task": {
"type": "string",
"description": "The Rake task to customize"
},
"file": {
"type": "string",
"description": "The Rake file that provides the task. Can be omitted."
},
"windows: {
"type": "object",
"properties": {
"file": {
"type": "string",
"description": "..."
}
}
},
"linux: {
"type": "object",
"properties": {
"file": {
"type": "string",
"description": "..."
}
}
},
"osx: {
"type": "object",
"properties": {
"file": {
"type": "string",
"description": "..."
}
}
}
}
}
]