|
11 | 11 | $gulp_completion_Process = {
|
12 | 12 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
|
13 | 13 |
|
14 |
| - (node -e "try { var gulp = require('gulp'); require('./gulpfile'); console.log(Object.keys(gulp.tasks).join(' ')); } catch (e) {}").split(' ') | |
| 14 | + |
| 15 | + # Load up an assembly to read the gulpfile's sha1 |
| 16 | + if(-not $global:GulpSHA1Managed) { |
| 17 | + [Reflection.Assembly]::LoadWithPartialName("System.Security") | out-null |
| 18 | + $global:GulpSHA1Managed = new-Object System.Security.Cryptography.SHA1Managed |
| 19 | + } |
| 20 | + |
| 21 | + # setup a global (in-memory) cache |
| 22 | + if(-not $global:GulpfileShaCache) { |
| 23 | + $global:GulpfileShaCache = @{}; |
| 24 | + } |
| 25 | + |
| 26 | + $cache = $global:GulpfileShaCache; |
| 27 | + |
| 28 | + # Get the gulpfile's sha1 |
| 29 | + $sha1gulpFile = (resolve-path gulpfile.js -ErrorAction Ignore | %{ |
| 30 | + $file = [System.IO.File]::Open($_.Path, "open", "read") |
| 31 | + [string]::join('', ($global:GulpSHA1Managed.ComputeHash($file) | %{ $_.ToString("x2") })) |
| 32 | + $file.Dispose() |
| 33 | + }) |
| 34 | + |
| 35 | + # lookup the sha1 for previously cached task lists. |
| 36 | + if($cache.ContainsKey($sha1gulpFile)){ |
| 37 | + $tasks = $cache[$sha1gulpFile]; |
| 38 | + } else { |
| 39 | + $tasks = (node -e "try { var gulp = require('gulp'); require('./gulpfile'); console.log(Object.keys(gulp.tasks).join(' ')); } catch (e) {}").split(' '); |
| 40 | + $cache[$sha1gulpFile] = $tasks; |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | + $tasks | |
15 | 45 | where { $_.startswith($commandName) }
|
16 | 46 | Sort-Object |
|
17 | 47 | foreach { New-Object System.Management.Automation.CompletionResult $_, $_, 'ParameterValue', ('{0}' -f $_) }
|
|
0 commit comments