"use strict";var y=Object.create;var p=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var E=(o,e)=>{for(var s in e)p(o,s,{get:e[s],enumerable:!0})},P=(o,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of _(e))!G.call(o,t)&&t!==s&&p(o,t,{get:()=>e[t],enumerable:!(i=D(e,t))||i.enumerable});return o};var l=(o,e,s)=>(s=o!=null?y(j(o)):{},P(e||!o||!o.__esModule?p(s,"default",{value:o,enumerable:!0}):s,o)),A=o=>P(p({},"__esModule",{value:!0}),o);var q={};E(q,{activate:()=>B,deactivate:()=>$});module.exports=A(q);var a=l(require("path")),w=l(require("fs")),C=l(require("child_process")),r=l(require("vscode"));async function f(o){try{if((await w.promises.stat(o)).isFile())return!0}catch{return!1}return!1}function O(o,e){return new Promise((s,i)=>{C.exec(o,e,(t,n,c)=>{t&&i({error:t,stdout:n,stderr:c}),s({stdout:n.toString(),stderr:c.toString()})})})}var L=["build","compile","watch"];function z(o){for(let e of L)if(o.indexOf(e)!==-1)return!0;return!1}var N=["test"];function M(o){for(let e of N)if(o.indexOf(e)!==-1)return!0;return!1}var h;function b(){return h||(h=r.window.createOutputChannel("Gulp Auto Detection")),h}function F(){r.window.showWarningMessage(r.l10n.t("Problem finding gulp tasks. See the output for more information."),r.l10n.t("Go to output")).then(o=>{o!==void 0&&h.show(!0)})}async function x(o){let e=process.platform;if(e==="win32"&&await f(a.join(o,"node_modules",".bin","gulp.cmd"))){let s=a.join(process.env.APPDATA?process.env.APPDATA:"","npm","gulp.cmd");return await f(s)?`"${s}"`:a.join(".","node_modules",".bin","gulp.cmd")}return(e==="linux"||e==="darwin")&&await f(a.join(o,"node_modules",".bin","gulp"))?a.join(".","node_modules",".bin","gulp"):"gulp"}var v=class{constructor(e,s){this._workspaceFolder=e;this._gulpCommand=s}_workspaceFolder;_gulpCommand;fileWatcher;promise;get workspaceFolder(){return this._workspaceFolder}isEnabled(){return r.workspace.getConfiguration("gulp",this._workspaceFolder.uri).get("autoDetect")==="on"}start(){let e=a.join(this._workspaceFolder.uri.fsPath,"{node_modules,gulpfile{.babel.js,.esm.js,.js,.mjs,.cjs,.ts}}");this.fileWatcher=r.workspace.createFileSystemWatcher(e),this.fileWatcher.onDidChange(()=>this.promise=void 0),this.fileWatcher.onDidCreate(()=>this.promise=void 0),this.fileWatcher.onDidDelete(()=>this.promise=void 0)}async getTasks(){return this.isEnabled()?(this.promise||(this.promise=this.computeTasks()),this.promise):[]}async getTask(e){let s=e.definition.task;if(s){let i=e.definition,t={cwd:this.workspaceFolder.uri.fsPath};return new r.Task(i,this.workspaceFolder,s,"gulp",new r.ShellExecution(await this._gulpCommand,[s],t))}}async hasGulpfile(e){for(let s of await w.promises.readdir(e)){let i=a.extname(s);if(i!==".js"&&i!==".mjs"&&i!==".cjs"&&i!==".ts"||!f(s))continue;let t=a.basename(s,i).toLowerCase();if(t==="gulpfile"||t==="gulpfile.esm"||t==="gulpfile.babel")return!0}return!1}async computeTasks(){let e=this._workspaceFolder.uri.scheme==="file"?this._workspaceFolder.uri.fsPath:void 0,s=[];if(!e||!await this.hasGulpfile(e))return s;let i=`${await this._gulpCommand} --tasks-simple --no-color`;try{let{stdout:t,stderr:n}=await O(i,{cwd:e});if(n&&n.length>0){let u=n.split(`
`);u.pop(),u.every(d=>d.indexOf("No license field")>=0)||(b().appendLine(n),F())}let c=[];if(t){let u=t.split(/\r{0,1}\n/);for(let d of u){if(d.length===0)continue;let S={type:"gulp",task:d},W={cwd:this.workspaceFolder.uri.fsPath},k=new r.Task(S,this.workspaceFolder,d,"gulp",new r.ShellExecution(await this._gulpCommand,[d],W));c.push(k);let T=d.toLowerCase();z(T)?k.group=r.TaskGroup.Build:M(T)&&(k.group=r.TaskGroup.Test)}}return c}catch(t){let n=b();return t.stderr&&n.appendLine(t.stderr),t.stdout&&n.appendLine(t.stdout),n.appendLine(r.l10n.t("Auto detecting gulp for folder {0} failed with error: {1}', this.workspaceFolder.name, err.error ? err.error.toString() : 'unknown")),F(),s}}dispose(){this.promise=void 0,this.fileWatcher&&this.fileWatcher.dispose()}},m=class{taskProvider;detectors=new Map;constructor(){}start(){let e=r.workspace.workspaceFolders;e&&this.updateWorkspaceFolders(e,[]),r.workspace.onDidChangeWorkspaceFolders(s=>this.updateWorkspaceFolders(s.added,s.removed)),r.workspace.onDidChangeConfiguration(this.updateConfiguration,this)}dispose(){this.taskProvider&&(this.taskProvider.dispose(),this.taskProvider=void 0),this.detectors.clear()}updateWorkspaceFolders(e,s){for(let i of s){let t=this.detectors.get(i.uri.toString());t&&(t.dispose(),this.detectors.delete(i.uri.toString()))}for(let i of e){let t=new v(i,x(i.uri.fsPath));this.detectors.set(i.uri.toString(),t),t.isEnabled()&&t.start()}this.updateProvider()}updateConfiguration(){for(let s of this.detectors.values())s.dispose(),this.detectors.delete(s.workspaceFolder.uri.toString());let e=r.workspace.workspaceFolders;if(e){for(let s of e)if(!this.detectors.has(s.uri.toString())){let i=new v(s,x(s.uri.fsPath));this.detectors.set(s.uri.toString(),i),i.isEnabled()&&i.start()}}this.updateProvider()}updateProvider(){if(!this.taskProvider&&this.detectors.size>0){let e=this;this.taskProvider=r.tasks.registerTaskProvider("gulp",{provideTasks(){return e.getTasks()},resolveTask(s){return e.getTask(s)}})}else this.taskProvider&&this.detectors.size===0&&(this.taskProvider.dispose(),this.taskProvider=void 0)}getTasks(){return this.computeTasks()}computeTasks(){if(this.detectors.size===0)return Promise.resolve([]);if(this.detectors.size===1)return this.detectors.values().next().value.getTasks();{let e=[];for(let s of this.detectors.values())e.push(s.getTasks().then(i=>i,()=>[]));return Promise.all(e).then(s=>{let i=[];for(let t of s)t&&t.length>0&&i.push(...t);return i})}}async getTask(e){if(this.detectors.size!==0){if(this.detectors.size===1)return this.detectors.values().next().value.getTask(e);if(e.scope===r.TaskScope.Workspace||e.scope===r.TaskScope.Global)return;if(e.scope){let s=this.detectors.get(e.scope.uri.toString());if(s)return s.getTask(e)}return}}},g;function B(o){g=new m,g.start()}function $(){g.dispose()}0&&(module.exports={activate,deactivate});
//# sourceMappingURL=main.js.map
