मैंने देखा है कि VSCode में किसी कार्य को परिभाषित करना संभव है। लेकिन मुझे यकीन नहीं है कि tasks.json
फ़ाइल में कई कार्यों को कैसे परिभाषित किया जाए ।
मैंने देखा है कि VSCode में किसी कार्य को परिभाषित करना संभव है। लेकिन मुझे यकीन नहीं है कि tasks.json
फ़ाइल में कई कार्यों को कैसे परिभाषित किया जाए ।
जवाबों:
बस मामले में यह किसी की मदद करता है ...। यदि आपके पास gulp / grunt / etc नहीं है ... या अपने कार्य कमांड को प्रॉक्सी करने के लिए एक अतिरिक्त शेल स्क्रिप्ट है, तो "npm रन" पहले से ही है।
यह वेबपैक और मोचा के लिए है जैसे "बिल्ड एंड टेस्ट", Shift+ Ctrl+ B, Shift+ Ctrl+ मेंT
.vscode / tasks.json:
{
"name": "npmTask",
//...
"suppressTaskName": true,
"command": "npm",
"isShellCommand": true,
"args": [
"run"
],
"tasks": [
{
//Build Task
"taskName": "webpack",
//Run On Shift+Ctrl+B
"isBuildCommand": true,
//Don't run when Shift+Ctrl+T
"isTestCommand": false,
// Show the output window if error any
"showOutput": "silent",
//Npm Task Name
"args": [
"webpack"
],
// use 2 regex:
// 1st the file, then the problem
"problemMatcher": {
"owner": "webpack",
"severity": "error",
"fileLocation": "relative",
"pattern": [
{
"regexp": "ERROR in (.*)",
"file": 1
},
{
"regexp": "\\((\\d+),(\\d+)\\):(.*)",
"line": 1,
"column": 2,
"message": 3
}
]
}
},
{
//Test Task
"taskName": "mocha",
// Don't run on Shift+Ctrl+B
"isBuildCommand": false,
// Run on Shift+Ctrl+T
"isTestCommand": true,
"showOutput": "always",
"args": [
"mocha"
]
}
]
}
package.json:
{
...
"scripts": {
"webpack": "webpack",
"mocha": "/usr/bin/mocha"
},
...
}
इस बात को बेहतर ढंग से समझने में मुझे जो मदद मिली, वह है कमांड के पास दिए गए तर्कों का क्रम। यह कुछ के लिए स्पष्ट हो सकता है लेकिन यह प्रलेखन में स्पष्ट नहीं है।
केवल भेजे जाने वाले कमांड पर ध्यान केंद्रित करने के लिए कुछ क्षेत्रों को छोड़ते हुए:
{ "command": "myCommand"
"args": ["myCommandArguments"],
"tasks" : [
{ "taskName": "myTask",
"args": ["myTaskArguments"],
"suppressTaskName": false,
}
]
}
उपरोक्त परिभाषा निम्नलिखित कमांड में परिणाम देगी:
myCommand myCommandArguments myTaskArguments myTask
कार्य का नाम myTask
हमेशा अंतिम होता है। संस्करण 0.4 के बाद से इसे छोड़ा जा सकता है "suppressTaskName": true
।
इसे इस्तेमाल करे
{
"version": "0.1.0",
"command": "cmd",
"isShellCommand": true,
"args": ["/C"],
"tasks": [
{
"taskName": "install",
"args": ["npm install"]
},
{
"taskName": "build",
"args": ["gulp build"],
"isBuildCommand": true,
"problemMatcher": "$gulp-tsc"
}
]
}
मैं कई टाइपस्क्रिप्ट बिल्ड परिदृश्यों को चलाने के लिए निम्न कार्य। Json फ़ाइल का उपयोग करता हूं। मैंने प्रत्येक फ़ोल्डर में एक tsconfig.json फ़ाइल डाली, जिससे मुझे व्यक्तिगत रूप से प्रत्येक फ़ोल्डर के आउटपुट को ट्यून करने की अनुमति मिलती है। बस सुनिश्चित करें कि आप कार्य नाम को दबा देते हैं, क्योंकि यह कमांड स्ट्रिंग में डालने की कोशिश करता है।
{
"version": "0.1.0",
"command": "tsc",
"showOutput": "always",
"isShellCommand": true,
"args": [],
"windows": {
"command": "tsc",
"showOutput": "always",
"isShellCommand": true
},
"tasks": [
{
"taskName": "Build the examples",
"suppressTaskName": true,
"isBuildCommand": false,
"args": ["-p", "./source/examples", "--outDir", "./script/examples"],
"problemMatcher": "$tsc"
},
{
"taskName": "Build the solution",
"suppressTaskName": true,
"isBuildCommand": false,
"args": ["-p", "./source/solution", "--outDir", "./script/solution"],
"problemMatcher": "$tsc"
}
]
}
यह वह फ़ोल्डर संरचना है जो दिखता है, जहां / स्क्रिप्ट आउटपुट रूट है और / स्रोत इनपुट रूट है। दोनों फ़ोल्डर / टाइपिंग फ़ोल्डर और / टाइपिंग फ़ोल्डर में संदर्भ प्रकार की घोषणाएं करते हैं। टाइपस्क्रिप्ट कुछ हद तक बाहरी संदर्भों में सापेक्ष पथों का उपयोग करने तक सीमित है, इसलिए यह चीजों को सरल बनाने में मदद करता है यदि ये फ़ोल्डर संरचनाएं समान हैं।
अरे हाँ, उन्हें चुनिंदा तरीके से लॉन्च करना आसान बनाता है यदि आप उन्हें गैर बिल्ड के रूप में चिह्नित करते हैं और किसी सूची से किसी विशिष्ट कार्य का चयन करने के लिए बिल्ड कुंजी को ओवरराइड करते हैं, जैसे कि ।।
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "ctrl+shift+b", "command": "workbench.action.tasks.runTask" }
]
अपडेट : आप हमेशा पूरी तरह से दुष्ट हो सकते हैं, यदि आप चाहें। आर्गों को संभालने के बेहतर तरीके हो सकते हैं, लेकिन यह मेरे लिए फिलहाल OSX के तहत काम करता है।
{
"version": "0.1.0",
"isShellCommand": true,
"linux": { "command": "sh", "args": ["-c"] },
"osx": { "command": "sh", "args": ["-c"] },
"windows": { "command": "powershell", "args": ["-Command"] },
"tasks": [
{
"taskName": "build-models",
"args": ["gulp build-models"],
"suppressTaskName": true,
"isBuildCommand": false,
"isTestCommand": false
},
{
"taskName": "run tests",
"args": ["mocha ${workspaceRoot}/test"],
"suppressTaskName": true,
"isBuildCommand": false,
"isTestCommand": false
}
]
}
मुझे इसका उचित उत्तर नहीं पता (और जानना भी चाहेंगे), लेकिन किसी को भी मदद करने के मामले में मेरा बदसूरत व्यवहार। मैं विंडोज पर हूं, मैंने खुद को एक साधारण बैच स्क्रिप्ट तैयार किया है जिसमें बस हो सकता है
"%1" "%2"
तब मेरा कार्य.जॉन कुछ ऐसा दिखता है
{
"version": "0.1.0",
"command": "c:\\...\\mytasks.bat"
"tasks" : [
{
"taskName": "myFirstTask",
"args": "c:\\...\\task1.exe", "${file}"],
},
{
"taskName": "mySecondTask",
"args": "c:\\...\\task2.exe", "${file}"],
},
]
}
आप कार्य संपत्ति में एक से अधिक कार्य सूचीबद्ध कर सकते हैं। कुछ इस तरह:
"tasks": [
{
"taskName": "build",
...
},
{
"taskName": "package",
...
}
]
tsc
और mocha
कार्यों का उदाहरण देखें ।
यह कार्यक्षमता विज़ुअल स्टूडियो कोड v1.9 (जनवरी 2017) में जोड़ी गई थी । उदाहरण और पाठ रिलीज नोट्स से आते हैं :
{
"version": "0.1.0",
"tasks": [
{
"taskName": "tsc",
"command": "tsc",
"args": ["-w"],
"isShellCommand": true,
"isBackground": true,
"problemMatcher": "$tsc-watch"
},
{
"taskName": "build",
"command": "gulp",
"args": ["build"],
"isShellCommand": true
}
]
}
अब आप प्रति कार्य ( # 981 ) विभिन्न आदेशों को परिभाषित कर सकते हैं । यह आपके स्वयं के शेल स्क्रिप्ट को लिखे बिना विभिन्न कार्यों के लिए अलग-अलग कमांड चलाने की अनुमति देता है। एtasks.json
कार्य के अनुसार आदेशों का उपयोग करने वाली फ़ाइल [ऊपर दी गई] जैसी दिखती है।
इसलिए मैंने इस उत्तर को @hurelu द्वारा पहले बताए गए काम का उदाहरण दिखाने के लिए जोड़ा है। मेरे कार्य। संदेश:
{
"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"
]
}
]
}
/// <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));
}
}
{
"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"
]
}
]
}
[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
[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
के रूप में फरवरी 2017 में रिलीज, आप निर्भरता कार्यों की स्थापना करके टर्मिनल धावक और लिखें कई कार्य कर सकते हैं। यह थोड़ा फंकी है कि यह प्रत्येक कार्य के लिए एक अलग एकीकृत टर्मिनल खोलेगा, जिसे आपको यह देखने के लिए देखना होगा कि क्या चीजें काम करती हैं और बंद करने के लिए याद रखती हैं (वे "स्टैक"), और आपको "किया हुआ" सूचना नहीं मिलती है , लेकिन यह काम हो जाता है। कार्यक्षमता प्रारंभिक है लेकिन यह आशाजनक है। यहां एक कॉर्डोवा ऐप के लिए tsc और jspm चलाने का एक उदाहरण है।
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [{
"taskName": "tsc",
"command": "tsc",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "always",
"problemMatcher": "$tsc"
}, {
"taskName": "jspm",
"command": "jspm",
"isShellCommand": true,
"args": ["bundle-sfx", "www/app/main.js", "www/dist/bundle.js", "--inline-source-maps", "--source-map-contents"],
"showOutput": "always"
},
{
"taskName": "build",
"isBuildCommand": true,
"dependsOn": ["tsc", "jspm"]
}]
}
निम्नलिखित ने मेरे लिए काम किया:
tasks.json:
{
"version": "0.1.0",
"command": "cmd",
"isShellCommand": true,
"args": [
"/c"
],
"tasks": [
{
"taskName": "bower",
"args" : ["gulp bower"],
"isBuildCommand": true,
"showOutput": "always"
},
{
"taskName": "unittest",
"suppressTaskName": true,
"args" : ["dnx -p ${cwd}\\test\\MyProject.UnitTests test"],
"isTestCommand": true,
"showOutput": "always"
}
]
}
MyProject.UnitTests \ project.json :
"commands": {
"test": "xunit.runner.dnx"
}
Run bower: Ctrl + Shift + B vscode से परीक्षण करें: Ctrl + Shift + T vscode से
यह मेरे लिए काम करता है ...
मुझे पता है कि यहां बहुत सारे अलग-अलग उत्तर हैं लेकिन मेरा दृष्टिकोण फिर से थोड़ा अलग था इसलिए मैंने सोचा कि मैं अपने 2 पेंस को जोड़ दूंगा।
मैं खिड़कियों पर हूं और अपनी कमांड चलाने के लिए एक बाहरी बैच फ़ाइल का उपयोग करता हूं। यह ऊपर जोनाथन के जवाब के समान है, लेकिन मैं इसे करने के लिए कोई भी कमांड पाइप नहीं करता हूं, जिसका अर्थ है कि मेरी "कार्य। Json" फ़ाइल अलग है।
मैं समय के साथ इस दृष्टिकोण को बदल सकता हूं (उदाहरण के लिए मुझे अभी तक गोल के साथ खेलने के लिए चारों ओर नहीं मिला है) लेकिन यह विधि इस समय मेरे लिए बिल्कुल ठीक काम कर रही है।
मैं html टेम्प्लेटिंग, बेबल के लिए हैंडलबार्स का उपयोग कर रहा हूं ताकि मैं त्रुटियों को लेने के लिए ES6 कोड और एक कोड लिंटर का उपयोग कर सकूं। अंत में, बैच फ़ाइल मेरे प्रारंभ पृष्ठ (index.html) के साथ एक ब्राउज़र लॉन्च करती है
यहाँ मेरा बैच फ़ाइल है जिसका नाम run_tasks.bat है:
@ECHO OFF
@ECHO Startz!
@ECHO Running Handlebars!
call handlebars html_templates -e html -f dist/html_templates.js
@ECHO Linting ES6 code
call eslint -c eslint.json src
@ECHO Running Babel ES6 to ES5
call babel src --out-dir dist --source-maps
@ECHO Now startzing page up in browser!
index.html
@ECHO Donezz it!
और यहाँ मेरे कार्य हैं। json फ़ाइल:
{
"version": "0.1.0",
"command": "${workspaceRoot}/run_tasks.bat",
"isShellCommand": true,
"isWatching": true,
"showOutput": "always",
"args": [],
"tasks": [
{
"taskName": "build",
"isBuildCommand": true,
"isWatching": true,
"showOutput": "always"
}
}
फिर, VSCode में मैं अपना बैच फ़ाइल चलाने के लिए "CTRL + SHIFT + B" दबाता हूं।
मेरे पास एक इलेक्ट्रॉन ऐप है जिसे प्रोग्राम बनाने और लॉन्च करने के लिए कम स्टाइलशीट संकलित करने की आवश्यकता है। मैंने @ महासागर के समाधान का उपयोग किया जो मेरे लिए काम करता था ... और कुछ भी काम नहीं किया।
मेरे दोनों कार्य। Json और build-functions.bat फ़ाइल प्रोजेक्ट के रूट में .vscode डायरेक्टरी में हैं।
निर्माण tasks.bat
@ECHO OFF
@ECHO Begin!
@ECHO Compiling Less
call lessc ./css/styles.less ./css/styles.css
@ECHO Build Electron App and Launch
call electron ./app.js
@ECHO Finished!
tasks.json
{
"version": "0.1.0",
"command": "${workspaceRoot}\\.vscode\\build-tasks.bat",
"isShellCommand": true,
"isWatching": true,
"showOutput": "always",
"args": [],
"tasks": [
{
"taskName": "build",
"isBuildCommand": true,
"isWatching": true,
"showOutput": "always"
}
]
}
इस धागे की बदौलत, अब मेरे पास ओ # ओक्स में काम करने वाले सी # / dnxcore50 बिल्ड और टेस्ट डिबग आदि हैं:
{
"version": "0.1.0",
"command": "bash",
"args": [
],
"tasks": [
{
"taskName": "xbuild",
"args": [
"./src/Service.Host/Service.Host.csproj"
],
"showOutput": "always",
"problemMatcher": "$msCompile",
"isBuildCommand": true
},
{
"taskName": "dnx",
"args" : ["-p", "./test/Service.Tests.Unit", "test"],
"isTestCommand": true,
"showOutput": "always"
}
]
}
मुझे यकीन है कि लिनक्स मूल रूप से समान होगा। केवल एक चीज जो मुझे परेशान कर रही है वह है .csproj फाइलों को डिबगिंग के लिए बनाए रखना। मैं dnx के साथ डिबग करने का एक तरीका ढूंढ रहा हूं, हालांकि मैंने अभी कुछ हफ़्ते की तलाश नहीं की है।