Define multiple tasks in VSCode

后端 未结 13 1977
旧时难觅i
旧时难觅i 2020-11-28 05:40

I have seen that it is possible to define a task in the VSCode. But I am not sure how to define multiple tasks in the tasks.json file.

相关标签:
13条回答
  • 2020-11-28 06:15

    This Seems To Be A VSCode Bug As Of v0.5.0

    so I've added this answer to show a working example of what was previously explained by @hurelu. My tasks.json:

    {
        "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"
                ]
            }
        ]
    }
    

    My gulp.js:

    /// <reference path="typings/tsd.d.ts" />
    
    var gulp = require('gulp');
    var jshint = require('gulp-jshint');
    var jscs = require('gulp-jscs');
    var util = require('gulp-util');
    var gulpprint = require('gulp-print');
    var gulpif = require('gulp-if');
    var args = require('yargs').argv;
    
    gulp.task('vet', function () {
        log('Analyzing source with JSHint and JSCS');
    
        return gulp
            .src
            ([
                './src/**/*.js',
                './*.js'
            ])
            .pipe(gulpif(args.verbose, gulpprint()))
            .pipe(jscs())
            .pipe(jshint())
            .pipe(jshint.reporter('jshint-stylish', { verbose: true }))
            .pipe(jshint.reporter('fail'));
    });
    
    gulp.task('hello-world', function () {
        console.log('This is our first Gulp task!');
    });
    
    ////////////
    function log(msg) {
        if (typeof (msg) === 'object') {
            for (var item in msg) {
                if (msg.hasOwnProperty(item)) {
                    util.log(util.colors.blue(msg[item]));
                }
            }
        } else {
            util.log(util.colors.blue(msg));
        }
    
    }
    

    Notice the first task uses isBuildCommand so CTRL+SHFT+B launches and the next task is isTestCommand so CTRL+SHFT+T launches. However, in order to get the the first task to accept args the task name and args had to be reversed.

    As of VSCode 0.5.0 the above works but the following does not:

    {
        "version": "0.1.0",
        "command": "gulp",
        "isShellCommand": true,
        "args": [
            "--no-color"
        ],
        "tasks": [
            {
                "taskName": "vet",
                "isBuildCommand": true,
                "showOutput": "always",
                "args": [
                    "--verbose"
                ],
                "problemMatcher": [
                    "$jshint",
                    "$jshint-stylish"
                ]
            },
            {
                "taskName": "vet",
                "isTestCommand": true,
                "showOutput": "always",
                "args": [],
                "problemMatcher": [
                    "$jshint",
                    "$jshint-stylish"
                ]
            }
        ]
    }
    

    Here's output from task.json with correct task and args order:

    [10:59:29] Using gulpfile ~/Workspaces/Examples/Gulp/pluralsight-gulp/gulpfile.js
    [10:59:29] Task 'default' is not in your gulpfile
    [10:59:29] Please check the documentation for proper gulpfile formatting
    

    Here's the correct output from the tasks.json with the taskname and arg reversed when using args:

    [11:02:44] Using gulpfile ~/Workspaces/Examples/Gulp/pluralsight-gulp/gulpfile.js
    [11:02:44] Starting 'vet'...
    [11:02:44] Analyzing source with JSHint and JSCS
    [gulp] src/server/app.js
    [gulp] src/client/app/app.module.js
    [gulp] src/client/test-helpers/bind-polyfill.js
    [gulp] src/client/test-helpers/mock-data.js
    [gulp] src/server/routes/index.js
    [gulp] src/client/app/core/config.js
    [gulp] src/client/app/core/constants.js
    [gulp] src/client/app/core/core.module.js
    [gulp] src/client/app/core/dataservice.js
    [gulp] src/client/app/core/dataservice.spec.js
    [gulp] src/client/app/customers/customer-detail.controller.js
    [gulp] src/client/app/customers/customer-detail.controller.spec.js
    [gulp] src/client/app/customers/customers.controller.js
    [gulp] src/client/app/customers/customers.controller.spec.js
    [gulp] src/client/app/customers/customers.module.js
    [gulp] src/client/app/customers/customers.route.js
    [gulp] src/client/app/customers/customers.route.spec.js
    [gulp] src/client/app/dashboard/dashboard.controller.js
    [gulp] src/client/app/dashboard/dashboard.controller.spec.js
    [gulp] src/client/app/dashboard/dashboard.module.js
    [gulp] src/client/app/dashboard/dashboard.route.js
    [gulp] src/client/app/dashboard/dashboard.route.spec.js
    [gulp] src/client/app/layout/ht-sidebar.directive.js
    [gulp] src/client/app/layout/ht-sidebar.directive.spec.js
    [gulp] src/client/app/layout/ht-top-nav.directive.js
    [gulp] src/client/app/layout/layout.module.js
    [gulp] src/client/app/layout/shell.controller.js
    [gulp] src/client/app/layout/shell.controller.spec.js
    [gulp] src/client/app/layout/sidebar.controller.js
    [gulp] src/client/app/layout/sidebar.controller.spec.js
    [gulp] src/client/app/widgets/ht-img-person.directive.js
    [gulp] src/client/app/widgets/ht-widget-header.directive.js
    [gulp] src/client/app/widgets/widgets.module.js
    [gulp] src/client/tests/server-integration/dataservice.spec.js
    [gulp] src/server/routes/utils/errorHandler.js
    [gulp] src/server/routes/utils/jsonfileservice.js
    [gulp] src/client/app/blocks/exception/exception-handler.provider.js
    [gulp] src/client/app/blocks/exception/exception-handler.provider.spec.js
    [gulp] src/client/app/blocks/exception/exception.js
    [gulp] src/client/app/blocks/exception/exception.module.js
    [gulp] src/client/app/blocks/logger/logger.js
    [gulp] src/client/app/blocks/logger/logger.module.js
    [gulp] src/client/app/blocks/router/router-helper.provider.js
    [gulp] src/client/app/blocks/router/router.module.js
    [gulp] gulpfile.js
    [gulp] karma.conf.js
    [11:02:48] Finished 'vet' after 4.37 s
    
    0 讨论(0)
提交回复
热议问题