我定义了一个gulpfile任务,它使用javascript文件运行节点:
var exec = require('child_process').exec;
gulp.task('node-run', function (cb) {
exec('node dest/index.js', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
})

但是,我想将文件名(dest / index.js)作为task.json中任务的参数传递,该任务代表VS Code中的选定文件。例如:
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"args": [
"--no-color"
],
"tasks": [
{
"taskName": "node-run",
"showOutput": "always",
"args": ["${file}"]
}
]
}

但是,当我尝试执行任务时,收到以下错误:
Using gulpfile gulpfile.js
Task '/Users/Tony/Source/HelloVsCode/.vscode/tasks.json' is not in your gulpfile
Please check the documentation for proper gulpfile formatting

所以我想知道是否可以传递" $ {file}" gulpfile任务的参数?
答案 0 :(得分:0)
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"args": [
"--no-color"
],
"tasks": [
{
"taskName": "${file}",
"showOutput": "always",
"args": ["node-run"]
}
]
}
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"args": [
"--no-color"
],
"tasks": [
{
"taskName": "--verbose",
"isBuildCommand": true,
"showOutput": "always",
"args": [
"vet"
],
"problemMatcher": [
"$jshint",
"$jshint-stylish"
]
},
{
"taskName": "vet",
"isTestCommand": true,
"showOutput": "always",
"args": [],
"problemMatcher": [
"$jshint",
"$jshint-stylish"
]
}
]
}
注意相同的两个任务vet
但在一个实例中传递了一个arg --verbose
,它需要反转才能由于某种原因正确执行。我仍然使用这个hack用于VSCode。我在v3.9.0,Node v0.12.7和Ubuntu GNU / Linux 12.04上运行VSCode v0.9.1,Gulp CLI和Local。* LTS。
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"args": [
"--no-color"
],
"tasks": [
{
"taskName": "--verbose",
"isBuildCommand": true,
"isTestCommand": false,
"showOutput": "always",
"echoCommand": true,
"args": [
"serve-dev"
]
},
{
"taskName": "serve-dev",
"isBuildCommand": false,
"isTestCommand": true,
"showOutput": "always",
"echoCommand": true,
"args": []
}
]
}
running command$ gulp --no-color serve-dev --verbose
[07:29:35] Using gulpfile ~/Workspaces/FCC/Ziplines/Personal- Portfolio-Webpage/gulpfile.js
[07:29:35] Starting 'vet'...
[07:29:36] ***Analyzing js with jshint and jscs..
[gulp] app.js
[gulp] script.js
[07:29:40] Finished 'vet' after 4.61 s
[07:29:40] Starting 'clean-dev'...
[07:29:40] ***Cleaning ./styles.css
[07:29:40] Finished 'clean-dev' after 28 ms
[07:29:40] Starting 'css-prep'...
[07:29:40] ***Compiling less to css...
[07:29:44] Finished 'css-prep' after 3.86 s
[07:29:44] Starting 'serve-dev'...
[07:29:44] ***Start pre processes and node server...
[07:29:44] Finished 'serve-dev' after 611 ms
[07:29:44] [nodemon] v1.4.1
[07:29:44] [nodemon] to restart at any time, enter `rs`
[07:29:44] [nodemon] watching: *.*
[07:29:44] [nodemon] starting `node ./app.js`
[07:29:44] *** nodemon started
[07:29:44] ***Starting browserSync on port 7203
[BS] [debug] -> Starting Step: Finding an empty port
[BS] [debug] Found a free port: 3099
[BS] [debug] Setting Option: port - 3099
[BS] [debug] + Step Complete: Finding an empty port
[BS] [debug] -> Starting Step: Getting an extra port for Proxy
[BS] [debug] + Step Complete: Getting an extra port for Proxy
[BS] [debug] -> Starting Step: Checking online status
[BS] [debug] Resolved www.google.com, setting online: true
[BS] [debug] Setting Option: online - true
[BS] [debug] + Step Complete: Checking online status
[BS] [debug] -> Starting Step: Resolve user plugins from options
[BS] [debug] + Step Complete: Resolve user plugins from options
[BS] [debug] -> Starting Step: Set Urls and other options that rely on port/online status
[BS] [debug] Setting multiple Options
[BS] [debug] + Step Complete: Set Urls and other options that rely on port/online status
[BS] [debug] -> Starting Step: Setting Internal Events
[BS] [debug] + Step Complete: Setting Internal Events
[BS] [debug] -> Starting Step: Setting file watchers
[BS] [debug] + Step Complete: Setting file watchers
[BS] [debug] -> Starting Step: Merging middlewares from core + plugins
[BS] [debug] Setting Option: middleware - List []
[BS] [debug] + Step Complete: Merging middlewares from core + plugins
[BS] [debug] -> Starting Step: Setting the rewrite rules given in initial options
[BS] [debug] + Step Complete: Setting the rewrite rules given in initial options
[BS] [debug] -> Starting Step: Setting the rewrite rules middleware for snippet
[BS] [debug] + Step Complete: Setting the rewrite rules middleware for snippet
[BS] [debug] -> Starting Step: Starting the Server
[BS] [debug] Proxy running, proxing: http://10.0.0.57:7203
[BS] [debug] Running mode: PROXY
[BS] [debug] + Step Complete: Starting the Server
[BS] [debug] -> Starting Step: Adding serve static middlewares
[BS] [debug] + Step Complete: Adding serve static middlewares
[BS] [debug] -> Starting Step: Starting the HTTPS Tunnel
[BS] [debug] + Step Complete: Starting the HTTPS Tunnel
[BS] [debug] -> Starting Step: Starting the web-socket server
[BS] [debug] Setting Option: clientEvents - List [ "scroll", "scroll:element", "input:text", "input:toggles", "form:submit", "form:reset", "click" ]
[BS] [debug] + Step Complete: Starting the web-socket server
[BS] [debug] -> Starting Step: Adding the HTTP protocol
[BS] [debug] + Step Complete: Adding the HTTP protocol
[BS] [debug] -> Starting Step: Starting the UI
[BS] [debug] Setting Option: session - 1446035388137
[BS] [UI] Starting Step: Setting default plugins
[BS] [UI] Step Complete: Setting default plugins
[BS] [UI] Starting Step: Finding a free port
[*** browserSync] [warn] Proxy address not reachable - is your server running?
[BS] [UI] Step Complete: Finding a free port
[BS] [UI] Starting Step: Setting options also relevant to UI from BS
[BS] [UI] Step Complete: Setting options also relevant to UI from BS
[BS] [UI] Starting Step: Setting available URLS for UI
[BS] [debug] Getting option via path: urls
[BS] [UI] Step Complete: Setting available URLS for UI
[BS] [UI] Starting Step: Starting the Control Panel Server
[BS] [UI] Using port 3001
[BS] [UI] Step Complete: Starting the Control Panel Server
[BS] [UI] Starting Step: Add element events
[BS] [UI] Step Complete: Add element events
[BS] [UI] Starting Step: Registering default plugins
[BS] [debug] Getting option via path: urls,external
[BS] [UI] Step Complete: Registering default plugins
[BS] [UI] Starting Step: Add options setting event
[BS] [UI] Step Complete: Add options setting event
[BS] [debug] + Step Complete: Starting the UI
[BS] [debug] -> Starting Step: Merge UI settings
[BS] [debug] Setting Option: urls - Map { "local": "http://localhost:3099", "external": "http://10.0.0.57:3099", "ui": "http://localhost:3001", "ui-external": "http://10.0.0.57:3001" }
[BS] [debug] + Step Complete: Merge UI settings
[BS] [debug] -> Starting Step: Init user plugins
[BS] [debug] Setting Option: userPlugins -
[BS] [debug] + Step Complete: Init user plugins
[*** browserSync] Proxying: http://10.0.0.57:7203
[*** browserSync] Access URLs:
----------------------------------
Local: http://localhost:3099
External: http://10.0.0.57:3099
----------------------------------
UI: http://localhost:3001
UI External: http://10.0.0.57:3001
----------------------------------
[*** browserSync] Watching files...
About to crank up node
PORT=7203
NODE_ENV=dev
** DEV **
Express server listening on port 7203
env = dev
__dirname = /home/gjsmith3rd/Workspaces/FCC/Ziplines/Personal-Portfolio-Webpage
process.cwd = /home/gjsmith3rd/Workspaces/FCC/Ziplines/Personal-Portfolio-Webpage