Skip to content

Commit

Permalink
add --tasks-simple flag and update autocompletion scripts to use that,
Browse files Browse the repository at this point in the history
…closes gulpjs#474
  • Loading branch information
Contra committed May 25, 2014
1 parent cf9e3bf commit 6baf8bb
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 60 deletions.
50 changes: 36 additions & 14 deletions bin/gulp.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,30 @@ var semver = require('semver');
var archy = require('archy');
var Liftoff = require('liftoff');
var tildify = require('tildify');
var interpret = require('interpret');
var completion = require('../lib/completion');
var taskTree = require('../lib/taskTree');

var cli = new Liftoff({
name: 'gulp',
completions: require('../lib/completion'),
extensions: require('interpret').jsVariants
completions: completion,
extensions: interpret.jsVariants
});

// parse those args m8
var argv = cli.argv;
var cliPackage = require('../package');
var versionFlag = argv.v || argv.version;
var tasksFlag = argv.T || argv.tasks;
var tasks = argv._;
var toRun = tasks.length ? tasks : ['default'];
// this is a hold-over until we have a better logging system
// with log levels
var simpleTasksFlag = argv['tasks-simple'];
var shouldLog = !argv.silent && !simpleTasksFlag;

cli.on('require', function(name) {
if (!shouldLog) return;
gutil.log('Requiring external module', chalk.magenta(name));
});

Expand All @@ -27,14 +42,6 @@ cli.on('requireFail', function(name) {
cli.launch(handleArguments);

function handleArguments(env) {

var argv = env.argv;
var cliPackage = require('../package');
var versionFlag = argv.v || argv.version;
var tasksFlag = argv.T || argv.tasks;
var tasks = argv._;
var toRun = tasks.length ? tasks : ['default'];

if (versionFlag) {
gutil.log('CLI version', cliPackage.version);
if (env.modulePackage) {
Expand All @@ -55,7 +62,7 @@ function handleArguments(env) {
}

// check for semver difference between cli and local installation
if (semver.gt(cliPackage.version, env.modulePackage.version)) {
if (semver.gt(cliPackage.version, env.modulePackage.version) && shouldLog) {
gutil.log(chalk.red('Warning: gulp version mismatch:'));
gutil.log(chalk.red('Running gulp is', cliPackage.version));
gutil.log(chalk.red('Local gulp (installed in gulpfile dir) is', env.modulePackage.version));
Expand All @@ -65,16 +72,25 @@ function handleArguments(env) {
// we let them chdir as needed
if (process.cwd() !== env.cwd) {
process.chdir(env.cwd);
gutil.log('Working directory changed to', chalk.magenta(tildify(env.cwd)));
if (shouldLog) {
gutil.log('Working directory changed to', chalk.magenta(tildify(env.cwd)));
}
}

var gulpFile = require(env.configPath);
gutil.log('Using gulpfile', chalk.magenta(tildify(env.configPath)));
// this is what actually loads up the gulpfile
require(env.configPath);

if (shouldLog) {
gutil.log('Using gulpfile', chalk.magenta(tildify(env.configPath)));
}

var gulpInst = require(env.modulePath);
logEvents(gulpInst);

process.nextTick(function() {
if (simpleTasksFlag) {
return logTasksSimple(env, gulpInst);
}
if (tasksFlag) {
return logTasks(env, gulpInst);
}
Expand All @@ -91,6 +107,10 @@ function logTasks(env, localGulp) {
});
}

function logTasksSimple(env, localGulp) {
console.log(Object.keys(localGulp.tasks).join('\n').trim());
}

// format orchestrator errors
function formatError(e) {
if (!e.err) return e.message;
Expand All @@ -100,6 +120,8 @@ function formatError(e) {

// wire up logging events
function logEvents(gulpInst) {

// total hack due to fucked up error management in orchestrator
gulpInst.on('err', function(){});

gulpInst.on('task_start', function(e) {
Expand Down
4 changes: 1 addition & 3 deletions completion/bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ function _gulp_completions() {
# The currently-being-completed word.
local cur="${COMP_WORDS[COMP_CWORD]}"
#Grab tasks
local compls=$(node -e "try { var gulp = require('gulp'); require('./gulpfile'); console.log(Object.keys(gulp.tasks).join(' ')); } catch (e) {}")
# Trim whitespace.
compls=$(echo "$compls" | sed -e 's/^ *//g' -e 's/ *$//g')
local compls=$(gulp --tasks-simple)
# Tell complete what stuff to show.
COMPREPLY=($(compgen -W "$compls" -- "$cur"))
}
Expand Down
6 changes: 3 additions & 3 deletions completion/powershell
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ $gulp_completion_Process = {
if($cache.ContainsKey($sha1gulpFile)){
$tasks = $cache[$sha1gulpFile];
} else {
$tasks = (node -e "try { var gulp = require('gulp'); require('./gulpfile'); console.log(Object.keys(gulp.tasks).join(' ')); } catch (e) {}").split(' ');
$tasks = (gulp --tasks-simple).split('\n');
$cache[$sha1gulpFile] = $tasks;
}


$tasks |
$tasks |
where { $_.startswith($commandName) }
Sort-Object |
Sort-Object |
foreach { New-Object System.Management.Automation.CompletionResult $_, $_, 'ParameterValue', ('{0}' -f $_) }
}

Expand Down
6 changes: 2 additions & 4 deletions completion/zsh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

# Enable zsh autocompletion.
function _gulp_completion() {
# Grap tasks
compls=$(node -e "try { var gulp = require('gulp'); require('./gulpfile'); console.log(Object.keys(gulp.tasks).join(' ')); } catch (e) {}")
# Trim whitespace.
compls=$(echo "$compls" | sed -e 's/^ *//g' -e 's/ *$//g')
# Grab tasks
compls=$(gulp --tasks-simple)
completions=(${=compls})
compadd -- $completions
}
Expand Down
9 changes: 2 additions & 7 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gulp has very few flags to know about. All other flags are for tasks to use if n
- `--gulpfile <gulpfile path>` manually set path of gulpfile. Useful if you have multiple gulpfiles. This will set the CWD to the gulpfile directory as well.
- `--cwd <dir path>` manually set the CWD. The search for the gulpfile, as well as the relativity of all requires will be from here.
- `-T` or `--tasks` will display the task dependency tree for the loaded gulpfile
- `--tasks-simple` will display a plaintext list of tasks for the loaded gulpfile
- `--color` will force gulp and gulp plugins to display colors even when no color support is detected
- `--no-color` will force gulp and gulp plugins to not display colors even when color support is detected

Expand All @@ -18,10 +19,4 @@ Tasks can be executed by running `gulp <task> <othertask>`. Just running `gulp`

### Compilers

You can use any language you want for your gulpfile. You will have to specify the language module name so the CLI can load it (and its associated extensions) before attempting to find your gulpfile. Make sure you have this module installed accessible by the folder you are running the CLI in.

Example:

```
gulp dosomething --require coffee-script/register
```
You can find a list of supported languages at [interpret](https://github.com/tkellen/node-interpret#jsvariants). If you would like to add support for a new language send pull request/open issues there.
1 change: 0 additions & 1 deletion docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ gulp updates can be found on the following twitters:

- [@wearefractal](https://twitter.com/wearefractal)
- [@eschoff](https://twitter.com/eschoff)
- [@funkytek](https://twitter.com/funkytek)
- [@gulpjs](https://twitter.com/gulpjs)

## Does gulp have an IRC channel?
Expand Down
25 changes: 0 additions & 25 deletions docs/recipes/using-coffee-script-for-gulpfile.md

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gulp",
"description": "The streaming build system",
"version": "3.6.3",
"version": "3.7.0",
"homepage": "http://gulpjs.com",
"repository": "gulpjs/gulp",
"author": "Fractal <[email protected]> (http://wearefractal.com/)",
Expand All @@ -28,7 +28,7 @@
"chalk": "^0.4.0",
"deprecated": "^0.0.1",
"gulp-util": "^2.2.0",
"liftoff": "^0.10.0",
"liftoff": "https://github.com/contra/node-liftoff/archive/patch-2.tar.gz",
"orchestrator": "^0.3.0",
"pretty-hrtime": "^0.2.0",
"semver": "^2.2.1",
Expand All @@ -46,7 +46,7 @@
"q": "^1.0.0",
"jshint": "^2.5.0",
"graceful-fs": "^2.0.1",
"mkdirp": "^0.3.5"
"mkdirp": "^0.5.0"
},
"scripts": {
"test": "jshint && mocha --reporter spec",
Expand Down

0 comments on commit 6baf8bb

Please sign in to comment.