diff --git a/package-lock.json b/package-lock.json index 74bca51..1be21fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "filewatcher", - "version": "1.0.2", + "version": "1.0.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -25,15 +25,15 @@ } }, "@types/node": { - "version": "12.12.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.6.tgz", - "integrity": "sha512-FjsYUPzEJdGXjwKqSpE0/9QEh6kzhTAeObA54rn6j3rR4C/mzpI9L0KNfoeASSPMMdxIsoJuCLDWcM/rVjIsSA==", + "version": "12.12.42", + "resolved": "https://registry.npm.taobao.org/@types/node/download/@types/node-12.12.42.tgz?cache=0&sync_timestamp=1590092201933&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fnode%2Fdownload%2F%40types%2Fnode-12.12.42.tgz", + "integrity": "sha1-0NEUkza9B1QN0epXZpKCnVdd7DQ=", "dev": true }, "@types/vscode": { - "version": "1.39.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.39.0.tgz", - "integrity": "sha512-rlg0okXDt7NjAyHXbZ2nO1I/VY/8y9w67ltLRrOxXQ46ayvrYZavD4A6zpYrGbs2+ZOEQzcUs+QZOqcVGQIxXQ==", + "version": "1.45.1", + "resolved": "https://registry.npm.taobao.org/@types/vscode/download/@types/vscode-1.45.1.tgz?cache=0&sync_timestamp=1589551101067&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fvscode%2Fdownload%2F%40types%2Fvscode-1.45.1.tgz", + "integrity": "sha1-Zy+4wswzzxTNTTvaoZuylP4rJwY=", "dev": true }, "ansi-styles": { diff --git a/package.json b/package.json index 723cc07..acec642 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,11 @@ "description": "Regex for matching files *not* to run commands on.", "default": ".*" }, + "channelName": { + "type": "string", + "description": "channel name for this task ", + "default": "" + }, "cmd": { "type": "string", "description": "Command to execute on save.", diff --git a/src/extension.ts b/src/extension.ts index 98833c9..22342e3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -34,10 +34,12 @@ export function activate(context: vscode.ExtensionContext): void { } type EventType = "onFileChange" | "onFolderChange"; +const baseChannelName = "File Watcher"; interface ICommand { match?: string; notMatch?: string; + channelName?: string; cmd: string; isAsync: boolean; event: EventType; @@ -59,14 +61,27 @@ class FileWatcherExtension { private _context: vscode.ExtensionContext; private _config!: IConfig; private _statusBar: StatusBar; + private _channelMap: Map; constructor(context: vscode.ExtensionContext) { this._context = context; - this._outputChannel = vscode.window.createOutputChannel("File Watcher"); + // this._outputChannel = vscode.window.createOutputChannel(baseChannelName); + this._channelMap = new Map(); + this._outputChannel = this.GetOrCreateChannel(baseChannelName); this.loadConfig(); this._statusBar = new StatusBar(); } + public GetOrCreateChannel(channelName: string): vscode.OutputChannel { + let channel: vscode.OutputChannel | undefined = this._channelMap.get(channelName); + if (channel == undefined) { + channel = vscode.window.createOutputChannel(channelName); + this._channelMap.set(channelName, channel); + } + + return channel; + } + public loadConfig(): void { const configName: string[] = ["filewatcher", "appulateinc.filewatcher"].filter(name => { const commands: ICommand[] | undefined = vscode.workspace.getConfiguration(name).get("commands"); @@ -82,8 +97,15 @@ class FileWatcherExtension { /** * Show message in output channel */ - public showOutputMessage(message: string): void { - this._outputChannel.appendLine(message); + public showOutputMessage(message: string, channelList: Array | null = null): void { + if (channelList == null) { + this._outputChannel.appendLine(message); + return; + } + for (let i = 0; i < channelList?.length; i++) { + channelList[i].appendLine(message); + } + } /** @@ -136,7 +158,7 @@ class FileWatcherExtension { let cmdStr: string = cfg.cmd; const extName: string = path.extname(documentUri.fsPath); - const workspaceFolders: vscode.WorkspaceFolder[] | undefined = vscode.workspace.workspaceFolders; + const workspaceFolders: readonly vscode.WorkspaceFolder[] | undefined = vscode.workspace.workspaceFolders; const rootPath: string = workspaceFolders?.[0]?.uri.fsPath ?? ""; const currentWorkspace: string = vscode.workspace.getWorkspaceFolder(documentUri)?.uri.fsPath ?? ""; @@ -152,7 +174,8 @@ class FileWatcherExtension { cmd: cmdStr, isAsync: !!cfg.isAsync, event, - match: cfg.match + match: cfg.match, + channelName: cfg.channelName }); } @@ -162,20 +185,32 @@ class FileWatcherExtension { private _runCommands(commands: ICommand[]): void { if (commands.length) { const cfg: ICommand = commands.shift()!; + + + let channelList: Array = [this._outputChannel]; + if (cfg.channelName && cfg.channelName.trim().length>0) { + let newChannel = this.GetOrCreateChannel(baseChannelName + "-" + cfg.channelName.trim()); + channelList.push(newChannel); + } this.showStatusMessage(cfg.event); - this.showOutputMessage(`[${cfg.event}] for pattern "${cfg.match}" started`); - this.showOutputMessage(`[cmd] ${cfg.cmd}`); + this.showOutputMessage(`[${cfg.event}] for pattern "${cfg.match}" started`, channelList); + this.showOutputMessage(`[cmd] ${cfg.cmd}`, channelList); const child: ChildProcess = exec(cfg.cmd, this._execOption); - child.stdout?.on("data", data => this._outputChannel.append(data)); + child.stdout?.on("data", data => { + for(let i=0;i { - this.showOutputMessage(`[error] ${data}`); + this.showOutputMessage(`[error] ${data}`, channelList); this._statusBar.showError(); }); child.on("exit", () => { - this.showOutputMessage(`[${cfg.event}]: for pattern "${cfg.match}" finished`); + + this.showOutputMessage(`[${cfg.event}]: for pattern "${cfg.match}" finished`, channelList); if (!cfg.isAsync) { this._runCommands(commands); }