Merge commit 'be3e8236086165e5e45a5a10783823874b3f3ebd' as 'lib/vscode'
This commit is contained in:
5
lib/vscode/extensions/gulp/.vscodeignore
Normal file
5
lib/vscode/extensions/gulp/.vscodeignore
Normal file
@ -0,0 +1,5 @@
|
||||
src/**
|
||||
tsconfig.json
|
||||
out/**
|
||||
extension.webpack.config.js
|
||||
yarn.lock
|
13
lib/vscode/extensions/gulp/README.md
Normal file
13
lib/vscode/extensions/gulp/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Gulp - Automate and enhance your workflow
|
||||
|
||||
**Notice:** This extension is bundled with Visual Studio Code. It can be disabled but not uninstalled.
|
||||
|
||||
## Features
|
||||
|
||||
This extension supports running [Gulp](https://gulpjs.com/) tasks defined in a `gulpfile.{js,ts}` file as [VS Code tasks](https://code.visualstudio.com/docs/editor/tasks). Gulp tasks with the name 'build', 'compile', or 'watch' are treated as build tasks.
|
||||
|
||||
To run Gulp tasks, use the **Tasks** menu.
|
||||
|
||||
## Settings
|
||||
|
||||
- `gulp.autoDetect` - Enable detecting tasks from `gulpfile.{js,ts}` files, the default is `on`.
|
20
lib/vscode/extensions/gulp/extension.webpack.config.js
Normal file
20
lib/vscode/extensions/gulp/extension.webpack.config.js
Normal file
@ -0,0 +1,20 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
//@ts-check
|
||||
|
||||
'use strict';
|
||||
|
||||
const withDefaults = require('../shared.webpack.config');
|
||||
|
||||
module.exports = withDefaults({
|
||||
context: __dirname,
|
||||
entry: {
|
||||
main: './src/main.ts',
|
||||
},
|
||||
resolve: {
|
||||
mainFields: ['module', 'main']
|
||||
}
|
||||
});
|
BIN
lib/vscode/extensions/gulp/images/gulp.png
Normal file
BIN
lib/vscode/extensions/gulp/images/gulp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
66
lib/vscode/extensions/gulp/package.json
Normal file
66
lib/vscode/extensions/gulp/package.json
Normal file
@ -0,0 +1,66 @@
|
||||
{
|
||||
"name": "gulp",
|
||||
"publisher": "vscode",
|
||||
"description": "%description%",
|
||||
"displayName": "%displayName%",
|
||||
"version": "1.0.0",
|
||||
"icon": "images/gulp.png",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"vscode": "*"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"scripts": {
|
||||
"compile": "gulp compile-extension:gulp",
|
||||
"watch": "gulp watch-extension:gulp"
|
||||
},
|
||||
"dependencies": {
|
||||
"vscode-nls": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^12.11.7"
|
||||
},
|
||||
"main": "./out/main",
|
||||
"activationEvents": [
|
||||
"onCommand:workbench.action.tasks.runTask"
|
||||
],
|
||||
"contributes": {
|
||||
"configuration": {
|
||||
"id": "gulp",
|
||||
"type": "object",
|
||||
"title": "Gulp",
|
||||
"properties": {
|
||||
"gulp.autoDetect": {
|
||||
"scope": "resource",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"off",
|
||||
"on"
|
||||
],
|
||||
"default": "on",
|
||||
"description": "%config.gulp.autoDetect%"
|
||||
}
|
||||
}
|
||||
},
|
||||
"taskDefinitions": [
|
||||
{
|
||||
"type": "gulp",
|
||||
"required": [
|
||||
"task"
|
||||
],
|
||||
"properties": {
|
||||
"task": {
|
||||
"type": "string",
|
||||
"description": "%gulp.taskDefinition.type.description%"
|
||||
},
|
||||
"file": {
|
||||
"type": "string",
|
||||
"description": "%gulp.taskDefinition.file.description%"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
7
lib/vscode/extensions/gulp/package.nls.json
Normal file
7
lib/vscode/extensions/gulp/package.nls.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"description": "Extension to add Gulp capabilities to VSCode.",
|
||||
"displayName": "Gulp support for VSCode",
|
||||
"config.gulp.autoDetect": "Controls whether auto detection of Gulp tasks is on or off. Default is on.",
|
||||
"gulp.taskDefinition.type.description": "The Gulp task to customize.",
|
||||
"gulp.taskDefinition.file.description": "The Gulp file that provides the task. Can be omitted."
|
||||
}
|
352
lib/vscode/extensions/gulp/src/main.ts
Normal file
352
lib/vscode/extensions/gulp/src/main.ts
Normal file
@ -0,0 +1,352 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as cp from 'child_process';
|
||||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
type AutoDetect = 'on' | 'off';
|
||||
|
||||
function exists(file: string): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, _reject) => {
|
||||
fs.exists(file, (value) => {
|
||||
resolve(value);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function exec(command: string, options: cp.ExecOptions): Promise<{ stdout: string; stderr: string }> {
|
||||
return new Promise<{ stdout: string; stderr: string }>((resolve, reject) => {
|
||||
cp.exec(command, options, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject({ error, stdout, stderr });
|
||||
}
|
||||
resolve({ stdout, stderr });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const buildNames: string[] = ['build', 'compile', 'watch'];
|
||||
function isBuildTask(name: string): boolean {
|
||||
for (let buildName of buildNames) {
|
||||
if (name.indexOf(buildName) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const testNames: string[] = ['test'];
|
||||
function isTestTask(name: string): boolean {
|
||||
for (let testName of testNames) {
|
||||
if (name.indexOf(testName) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
let _channel: vscode.OutputChannel;
|
||||
function getOutputChannel(): vscode.OutputChannel {
|
||||
if (!_channel) {
|
||||
_channel = vscode.window.createOutputChannel('Gulp Auto Detection');
|
||||
}
|
||||
return _channel;
|
||||
}
|
||||
|
||||
function showError() {
|
||||
vscode.window.showWarningMessage(localize('gulpTaskDetectError', 'Problem finding gulp tasks. See the output for more information.'),
|
||||
localize('gulpShowOutput', 'Go to output')).then((choice) => {
|
||||
if (choice !== undefined) {
|
||||
_channel.show(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function findGulpCommand(rootPath: string): Promise<string> {
|
||||
let gulpCommand: string;
|
||||
let platform = process.platform;
|
||||
if (platform === 'win32' && await exists(path.join(rootPath, 'node_modules', '.bin', 'gulp.cmd'))) {
|
||||
const globalGulp = path.join(process.env.APPDATA ? process.env.APPDATA : '', 'npm', 'gulp.cmd');
|
||||
if (await exists(globalGulp)) {
|
||||
gulpCommand = '"' + globalGulp + '"';
|
||||
} else {
|
||||
gulpCommand = path.join('.', 'node_modules', '.bin', 'gulp.cmd');
|
||||
}
|
||||
} else if ((platform === 'linux' || platform === 'darwin') && await exists(path.join(rootPath, 'node_modules', '.bin', 'gulp'))) {
|
||||
gulpCommand = path.join('.', 'node_modules', '.bin', 'gulp');
|
||||
} else {
|
||||
gulpCommand = 'gulp';
|
||||
}
|
||||
return gulpCommand;
|
||||
}
|
||||
|
||||
interface GulpTaskDefinition extends vscode.TaskDefinition {
|
||||
task: string;
|
||||
file?: string;
|
||||
}
|
||||
|
||||
class FolderDetector {
|
||||
|
||||
private fileWatcher: vscode.FileSystemWatcher | undefined;
|
||||
private promise: Thenable<vscode.Task[]> | undefined;
|
||||
|
||||
constructor(
|
||||
private _workspaceFolder: vscode.WorkspaceFolder,
|
||||
private _gulpCommand: Promise<string>) {
|
||||
}
|
||||
|
||||
public get workspaceFolder(): vscode.WorkspaceFolder {
|
||||
return this._workspaceFolder;
|
||||
}
|
||||
|
||||
public isEnabled(): boolean {
|
||||
return vscode.workspace.getConfiguration('gulp', this._workspaceFolder.uri).get<AutoDetect>('autoDetect') === 'on';
|
||||
}
|
||||
|
||||
public start(): void {
|
||||
let pattern = path.join(this._workspaceFolder.uri.fsPath, '{node_modules,gulpfile{.babel.js,.js,.ts}}');
|
||||
this.fileWatcher = vscode.workspace.createFileSystemWatcher(pattern);
|
||||
this.fileWatcher.onDidChange(() => this.promise = undefined);
|
||||
this.fileWatcher.onDidCreate(() => this.promise = undefined);
|
||||
this.fileWatcher.onDidDelete(() => this.promise = undefined);
|
||||
}
|
||||
|
||||
public async getTasks(): Promise<vscode.Task[]> {
|
||||
if (this.isEnabled()) {
|
||||
if (!this.promise) {
|
||||
this.promise = this.computeTasks();
|
||||
}
|
||||
return this.promise;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async getTask(_task: vscode.Task): Promise<vscode.Task | undefined> {
|
||||
const gulpTask = (<any>_task.definition).task;
|
||||
if (gulpTask) {
|
||||
let kind: GulpTaskDefinition = (<any>_task.definition);
|
||||
let options: vscode.ShellExecutionOptions = { cwd: this.workspaceFolder.uri.fsPath };
|
||||
let task = new vscode.Task(kind, this.workspaceFolder, gulpTask, 'gulp', new vscode.ShellExecution(await this._gulpCommand, [gulpTask], options));
|
||||
return task;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private async computeTasks(): Promise<vscode.Task[]> {
|
||||
let rootPath = this._workspaceFolder.uri.scheme === 'file' ? this._workspaceFolder.uri.fsPath : undefined;
|
||||
let emptyTasks: vscode.Task[] = [];
|
||||
if (!rootPath) {
|
||||
return emptyTasks;
|
||||
}
|
||||
let gulpfile = path.join(rootPath, 'gulpfile.js');
|
||||
if (!await exists(gulpfile)) {
|
||||
gulpfile = path.join(rootPath, 'Gulpfile.js');
|
||||
if (!await exists(gulpfile)) {
|
||||
gulpfile = path.join(rootPath, 'gulpfile.babel.js');
|
||||
if (!await exists(gulpfile)) {
|
||||
return emptyTasks;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let commandLine = `${await this._gulpCommand} --tasks-simple --no-color`;
|
||||
try {
|
||||
let { stdout, stderr } = await exec(commandLine, { cwd: rootPath });
|
||||
if (stderr && stderr.length > 0) {
|
||||
// Filter out "No license field"
|
||||
const errors = stderr.split('\n');
|
||||
errors.pop(); // The last line is empty.
|
||||
if (!errors.every(value => value.indexOf('No license field') >= 0)) {
|
||||
getOutputChannel().appendLine(stderr);
|
||||
showError();
|
||||
}
|
||||
}
|
||||
let result: vscode.Task[] = [];
|
||||
if (stdout) {
|
||||
let lines = stdout.split(/\r{0,1}\n/);
|
||||
for (let line of lines) {
|
||||
if (line.length === 0) {
|
||||
continue;
|
||||
}
|
||||
let kind: GulpTaskDefinition = {
|
||||
type: 'gulp',
|
||||
task: line
|
||||
};
|
||||
let options: vscode.ShellExecutionOptions = { cwd: this.workspaceFolder.uri.fsPath };
|
||||
let task = new vscode.Task(kind, this.workspaceFolder, line, 'gulp', new vscode.ShellExecution(await this._gulpCommand, [line], options));
|
||||
result.push(task);
|
||||
let lowerCaseLine = line.toLowerCase();
|
||||
if (isBuildTask(lowerCaseLine)) {
|
||||
task.group = vscode.TaskGroup.Build;
|
||||
} else if (isTestTask(lowerCaseLine)) {
|
||||
task.group = vscode.TaskGroup.Test;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (err) {
|
||||
let channel = getOutputChannel();
|
||||
if (err.stderr) {
|
||||
channel.appendLine(err.stderr);
|
||||
}
|
||||
if (err.stdout) {
|
||||
channel.appendLine(err.stdout);
|
||||
}
|
||||
channel.appendLine(localize('execFailed', 'Auto detecting gulp for folder {0} failed with error: {1}', this.workspaceFolder.name, err.error ? err.error.toString() : 'unknown'));
|
||||
showError();
|
||||
return emptyTasks;
|
||||
}
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
this.promise = undefined;
|
||||
if (this.fileWatcher) {
|
||||
this.fileWatcher.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TaskDetector {
|
||||
|
||||
private taskProvider: vscode.Disposable | undefined;
|
||||
private detectors: Map<string, FolderDetector> = new Map();
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
public start(): void {
|
||||
let folders = vscode.workspace.workspaceFolders;
|
||||
if (folders) {
|
||||
this.updateWorkspaceFolders(folders, []);
|
||||
}
|
||||
vscode.workspace.onDidChangeWorkspaceFolders((event) => this.updateWorkspaceFolders(event.added, event.removed));
|
||||
vscode.workspace.onDidChangeConfiguration(this.updateConfiguration, this);
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
if (this.taskProvider) {
|
||||
this.taskProvider.dispose();
|
||||
this.taskProvider = undefined;
|
||||
}
|
||||
this.detectors.clear();
|
||||
}
|
||||
|
||||
private updateWorkspaceFolders(added: readonly vscode.WorkspaceFolder[], removed: readonly vscode.WorkspaceFolder[]): void {
|
||||
for (let remove of removed) {
|
||||
let detector = this.detectors.get(remove.uri.toString());
|
||||
if (detector) {
|
||||
detector.dispose();
|
||||
this.detectors.delete(remove.uri.toString());
|
||||
}
|
||||
}
|
||||
for (let add of added) {
|
||||
let detector = new FolderDetector(add, findGulpCommand(add.uri.fsPath));
|
||||
this.detectors.set(add.uri.toString(), detector);
|
||||
if (detector.isEnabled()) {
|
||||
detector.start();
|
||||
}
|
||||
}
|
||||
this.updateProvider();
|
||||
}
|
||||
|
||||
private updateConfiguration(): void {
|
||||
for (let detector of this.detectors.values()) {
|
||||
detector.dispose();
|
||||
this.detectors.delete(detector.workspaceFolder.uri.toString());
|
||||
}
|
||||
let folders = vscode.workspace.workspaceFolders;
|
||||
if (folders) {
|
||||
for (let folder of folders) {
|
||||
if (!this.detectors.has(folder.uri.toString())) {
|
||||
let detector = new FolderDetector(folder, findGulpCommand(folder.uri.fsPath));
|
||||
this.detectors.set(folder.uri.toString(), detector);
|
||||
if (detector.isEnabled()) {
|
||||
detector.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.updateProvider();
|
||||
}
|
||||
|
||||
private updateProvider(): void {
|
||||
if (!this.taskProvider && this.detectors.size > 0) {
|
||||
const thisCapture = this;
|
||||
this.taskProvider = vscode.tasks.registerTaskProvider('gulp', {
|
||||
provideTasks(): Promise<vscode.Task[]> {
|
||||
return thisCapture.getTasks();
|
||||
},
|
||||
resolveTask(_task: vscode.Task): Promise<vscode.Task | undefined> {
|
||||
return thisCapture.getTask(_task);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (this.taskProvider && this.detectors.size === 0) {
|
||||
this.taskProvider.dispose();
|
||||
this.taskProvider = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
public getTasks(): Promise<vscode.Task[]> {
|
||||
return this.computeTasks();
|
||||
}
|
||||
|
||||
private computeTasks(): Promise<vscode.Task[]> {
|
||||
if (this.detectors.size === 0) {
|
||||
return Promise.resolve([]);
|
||||
} else if (this.detectors.size === 1) {
|
||||
return this.detectors.values().next().value.getTasks();
|
||||
} else {
|
||||
let promises: Promise<vscode.Task[]>[] = [];
|
||||
for (let detector of this.detectors.values()) {
|
||||
promises.push(detector.getTasks().then((value) => value, () => []));
|
||||
}
|
||||
return Promise.all(promises).then((values) => {
|
||||
let result: vscode.Task[] = [];
|
||||
for (let tasks of values) {
|
||||
if (tasks && tasks.length > 0) {
|
||||
result.push(...tasks);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async getTask(task: vscode.Task): Promise<vscode.Task | undefined> {
|
||||
if (this.detectors.size === 0) {
|
||||
return undefined;
|
||||
} else if (this.detectors.size === 1) {
|
||||
return this.detectors.values().next().value.getTask(task);
|
||||
} else {
|
||||
if ((task.scope === vscode.TaskScope.Workspace) || (task.scope === vscode.TaskScope.Global)) {
|
||||
// Not supported, we don't have enough info to create the task.
|
||||
return undefined;
|
||||
} else if (task.scope) {
|
||||
const detector = this.detectors.get(task.scope.uri.toString());
|
||||
if (detector) {
|
||||
return detector.getTask(task);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let detector: TaskDetector;
|
||||
export function activate(_context: vscode.ExtensionContext): void {
|
||||
detector = new TaskDetector();
|
||||
detector.start();
|
||||
}
|
||||
|
||||
export function deactivate(): void {
|
||||
detector.dispose();
|
||||
}
|
7
lib/vscode/extensions/gulp/src/typings/refs.d.ts
vendored
Normal file
7
lib/vscode/extensions/gulp/src/typings/refs.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/// <reference path='../../../../src/vs/vscode.d.ts'/>
|
||||
/// <reference types='@types/node'/>
|
9
lib/vscode/extensions/gulp/tsconfig.json
Normal file
9
lib/vscode/extensions/gulp/tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../shared.tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
]
|
||||
}
|
13
lib/vscode/extensions/gulp/yarn.lock
Normal file
13
lib/vscode/extensions/gulp/yarn.lock
Normal file
@ -0,0 +1,13 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/node@^12.11.7":
|
||||
version "12.11.7"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.11.7.tgz#57682a9771a3f7b09c2497f28129a0462966524a"
|
||||
integrity sha512-JNbGaHFCLwgHn/iCckiGSOZ1XYHsKFwREtzPwSGCVld1SGhOlmZw2D4ZI94HQCrBHbADzW9m4LER/8olJTRGHA==
|
||||
|
||||
vscode-nls@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-4.0.0.tgz#4001c8a6caba5cedb23a9c5ce1090395c0e44002"
|
||||
integrity sha512-qCfdzcH+0LgQnBpZA53bA32kzp9rpq/f66Som577ObeuDlFIrtbEJ+A/+CCxjIh4G8dpJYNCKIsxpRAHIfsbNw==
|
Reference in New Issue
Block a user