From da8241ecbacd59158deaa5471ff8a7f43901a94b Mon Sep 17 00:00:00 2001 From: SeekingMeaning Date: Mon, 13 Jul 2020 12:49:48 -0700 Subject: [PATCH 01/19] Docs: Add install section to README (#216) --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index a9986378..6c4249e9 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,12 @@ Command Line Utility for Gulp +## Install + +```bash +npm install --global gulp-cli +``` + ## Usage ```bash From f0c673022187301fb962815fdb1eb13b461f08d9 Mon Sep 17 00:00:00 2001 From: Marco Colombo <4977000+marcomow@users.noreply.github.com> Date: Wed, 22 Feb 2023 15:19:32 -0800 Subject: [PATCH 02/19] chore(docs): Updated interpret link to point to gulpjs location (#241) --- docs/CLI.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CLI.md b/docs/CLI.md index 2d3db6f1..fd40368f 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -16,7 +16,7 @@ Just running `gulp` will execute the task `default`. If there is no ### Compilers -You can find a list of supported languages at https://github.com/js-cli/js-interpret. If you would like to add support for a new language, send pull requests/open issues on that project. +You can find a list of supported languages at [https://github.com/gulpjs/interpret](https://github.com/gulpjs/interpret). If you would like to add support for a new language, send pull requests/open issues on that project. ### Environment From 3544dc65138c6409758c28e083ea1d93640246d8 Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Mon, 8 Jan 2024 05:36:58 +0900 Subject: [PATCH 03/19] chore!: Normalize repository, dropping node <10.13 support (#239) chore: Remove gulp-test-tool dependency chore: Replace ansi-colors and color-support with chalk chore: Remove array-sort dependency chore: Remove isobject dependency chore: Upgrade yargs dependency chore: Upgrade liftoff dependency chore!: Replace `--require` flag with `--preload` chore: Upgrade expect devDependency chore: Upgrade marked-man devDependency chore: Remove dependency on concat-stream chore: Remove archy dependency chore: Remove pretty-hrtime dependency chore: Remove matchdep --- .editorconfig | 13 +- .eslintrc | 2 +- .github/support.yml | 2 - .github/workflows/dev.yml | 86 ++++++ .github/workflows/release.yml | 16 + .prettierignore | 3 + .travis.yml | 21 -- LICENSE | 2 +- README.md | 37 ++- appveyor.yml | 29 -- index.js | 123 ++++---- lib/shared/ansi.js | 41 --- lib/shared/blacklist/get-remote-json.js | 39 +++ lib/shared/blacklist/index.js | 11 + lib/shared/config/cli-flags.js | 9 +- lib/shared/config/env-flags.js | 24 +- lib/shared/config/load-files.js | 30 -- lib/shared/config/merge-configs.js | 28 ++ lib/shared/get-blacklist.js | 62 ---- lib/shared/is-object.js | 7 + lib/shared/log/blacklist-error.js | 4 +- lib/shared/log/format-hrtime.js | 48 +++ lib/shared/log/tasks.js | 268 ++++++++--------- lib/shared/log/verify.js | 8 +- .../{cli-options.js => options/parser.js} | 57 ++-- lib/shared/require-or-import.js | 17 +- lib/shared/verify-dependencies.js | 17 +- lib/versioned/^3.7.0/index.js | 18 +- lib/versioned/^3.7.0/log/events.js | 22 +- lib/versioned/^4.0.0-alpha.1/index.js | 19 +- lib/versioned/^4.0.0-alpha.2/index.js | 19 +- lib/versioned/^4.0.0/index.js | 19 +- lib/versioned/^4.0.0/log/events.js | 20 +- lib/versioned/^4.0.0/log/get-task.js | 2 +- lib/versioned/^4.0.0/log/sync-task.js | 8 +- package.json | 69 ++--- test/.eslintrc | 6 - test/completion.js | 25 +- test/config-description.js | 71 ++--- ...Tasks.js => config-flags-compact-tasks.js} | 63 ++-- test/config-flags-continue.js | 69 ++--- test/config-flags-gulpfile.js | 157 +++++----- test/config-flags-log-level.js | 280 +++++++++--------- test/config-flags-node-flags.js | 87 ++---- test/config-flags-preload.js | 90 ++++++ test/config-flags-require.js | 109 ------- test/config-flags-series.js | 107 +++---- test/config-flags-silent.js | 54 ++-- ...ortTasks.js => config-flags-sort-tasks.js} | 65 ++-- test/config-flags-tasks-depth.js | 41 +++ test/config-flags-tasksDepth.js | 53 ---- test/esm.js | 44 ++- test/execution-errors.js | 127 ++++---- test/expected/config/output2.txt | 2 + test/expected/flags-help.txt | 72 ++--- test/expected/with-desc-and-flags.txt | 2 +- test/exports-as-tasks.js | 23 +- test/fixtures/.babelrc | 3 - .../fixtures/config/flags/gulpfile/.gulp.json | 5 - .../flags/gulpfile/autoload-fail/.gulp.json | 5 + .../autoload-fail/other_dir/gulpfile.coffee | 1 + .../config/flags/gulpfile/cwd/.gulp.json | 5 + .../config/flags/gulpfile/cwd/findup/.gitkeep | 0 .../config/flags/gulpfile/cwd/gulpfile.js | 8 - .../{mygulpfile.js => gulpfile-by-cwd-cfg.js} | 0 .../gulpfile/is/here/gulpfile-by-prj-cfg.js | 9 + .../config/flags/gulpfile/is/here/gulpfile.js | 9 + .../config/flags/gulpfile/prj/.gulp.json | 5 + .../config/flags/gulpfile/prj/findup/.gitkeep | 0 .../{require => preload}/array/.gulp.json | 2 +- .../{require => preload}/array/gulpfile.js | 0 .../{require => preload}/array/preload_one.js | 0 .../{require => preload}/array/preload_two.js | 0 .../join-flags/.gulp.json | 2 +- .../join-flags/gulpfile.js | 0 .../join-flags/preload_one.js | 0 .../join-flags/preload_two.js | 0 .../flags/{require => preload}/preload.js | 0 .../config/flags/preload/string/.gulp.json | 5 + .../{require => preload}/string/gulpfile.js | 0 .../{require => preload}/string/preload.js | 0 .../with-absolute/.gulp.js | 2 +- .../with-absolute/gulpfile.js | 0 .../config/flags/preload/with-cwd/.gulp.json | 5 + .../{require => preload}/with-cwd/gulpfile.js | 0 .../config/flags/require/string/.gulp.json | 5 - .../config/flags/require/with-cwd/.gulp.json | 5 - test/fixtures/config/foo/bar/baz/.gitkeep | 0 .../foo/bar/{baz => quux}/.gulp.babel.js | 4 +- .../fixtures/gulpfiles/with-desc-and-flags.js | 2 +- test/fixtures/logging.js | 5 +- test/flags-continue.js | 45 ++- test/flags-gulpfile.js | 33 +-- test/flags-help.js | 42 +-- test/flags-preload.js | 157 ++++++++++ test/flags-require.js | 158 ---------- test/flags-series.js | 40 +-- test/flags-silent.js | 17 +- test/flags-tasks-json.js | 53 ++-- test/flags-tasks-simple.js | 25 +- test/flags-tasks.js | 132 +++++---- test/flags-v8flags.js | 40 +-- test/flags-verify.js | 58 ++-- test/flags-version.js | 33 ++- test/lib/config-cli-flags.js | 11 +- test/lib/config-env-flags.js | 38 ++- test/lib/config-load-files.js | 58 ---- test/lib/format-hrtime.js | 238 +++++++++++++++ test/lib/get-remote-json.js | 34 +++ test/lib/log-copy-tree.js | 30 +- test/lib/merge-configs.js | 119 ++++++++ test/lib/task-tree.js | 2 +- test/logging.js | 22 +- test/non-completing-tasks.js | 63 ---- test/sync-task.js | 72 +++++ test/tool/erase-lapse.js | 7 + test/tool/erase-time.js | 5 + test/tool/gulp-cmd.js | 16 + test/tool/slice-lines.js | 11 + 119 files changed, 2425 insertions(+), 1968 deletions(-) delete mode 100644 .github/support.yml create mode 100644 .github/workflows/dev.yml create mode 100644 .github/workflows/release.yml create mode 100644 .prettierignore delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100644 lib/shared/ansi.js create mode 100644 lib/shared/blacklist/get-remote-json.js create mode 100644 lib/shared/blacklist/index.js delete mode 100644 lib/shared/config/load-files.js create mode 100644 lib/shared/config/merge-configs.js delete mode 100644 lib/shared/get-blacklist.js create mode 100644 lib/shared/is-object.js create mode 100644 lib/shared/log/format-hrtime.js rename lib/shared/{cli-options.js => options/parser.js} (79%) delete mode 100644 test/.eslintrc rename test/{config-flags-compactTasks.js => config-flags-compact-tasks.js} (59%) create mode 100644 test/config-flags-preload.js delete mode 100644 test/config-flags-require.js rename test/{config-flags-sortTasks.js => config-flags-sort-tasks.js} (51%) create mode 100644 test/config-flags-tasks-depth.js delete mode 100644 test/config-flags-tasksDepth.js create mode 100644 test/expected/config/output2.txt delete mode 100644 test/fixtures/.babelrc delete mode 100644 test/fixtures/config/flags/gulpfile/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/autoload-fail/other_dir/gulpfile.coffee create mode 100644 test/fixtures/config/flags/gulpfile/cwd/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/cwd/findup/.gitkeep delete mode 100644 test/fixtures/config/flags/gulpfile/cwd/gulpfile.js rename test/fixtures/config/flags/gulpfile/is/here/{mygulpfile.js => gulpfile-by-cwd-cfg.js} (100%) create mode 100644 test/fixtures/config/flags/gulpfile/is/here/gulpfile-by-prj-cfg.js create mode 100644 test/fixtures/config/flags/gulpfile/is/here/gulpfile.js create mode 100644 test/fixtures/config/flags/gulpfile/prj/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/prj/findup/.gitkeep rename test/fixtures/config/flags/{require => preload}/array/.gulp.json (80%) rename test/fixtures/config/flags/{require => preload}/array/gulpfile.js (100%) rename test/fixtures/config/flags/{require => preload}/array/preload_one.js (100%) rename test/fixtures/config/flags/{require => preload}/array/preload_two.js (100%) rename test/fixtures/config/flags/{require => preload}/join-flags/.gulp.json (74%) rename test/fixtures/config/flags/{require => preload}/join-flags/gulpfile.js (100%) rename test/fixtures/config/flags/{require => preload}/join-flags/preload_one.js (100%) rename test/fixtures/config/flags/{require => preload}/join-flags/preload_two.js (100%) rename test/fixtures/config/flags/{require => preload}/preload.js (100%) create mode 100644 test/fixtures/config/flags/preload/string/.gulp.json rename test/fixtures/config/flags/{require => preload}/string/gulpfile.js (100%) rename test/fixtures/config/flags/{require => preload}/string/preload.js (100%) rename test/fixtures/config/flags/{require => preload}/with-absolute/.gulp.js (57%) rename test/fixtures/config/flags/{require => preload}/with-absolute/gulpfile.js (100%) create mode 100644 test/fixtures/config/flags/preload/with-cwd/.gulp.json rename test/fixtures/config/flags/{require => preload}/with-cwd/gulpfile.js (100%) delete mode 100644 test/fixtures/config/flags/require/string/.gulp.json delete mode 100644 test/fixtures/config/flags/require/with-cwd/.gulp.json create mode 100644 test/fixtures/config/foo/bar/baz/.gitkeep rename test/fixtures/config/foo/bar/{baz => quux}/.gulp.babel.js (66%) create mode 100644 test/flags-preload.js delete mode 100644 test/flags-require.js delete mode 100644 test/lib/config-load-files.js create mode 100644 test/lib/format-hrtime.js create mode 100644 test/lib/get-remote-json.js create mode 100644 test/lib/merge-configs.js delete mode 100644 test/non-completing-tasks.js create mode 100644 test/sync-task.js create mode 100644 test/tool/erase-lapse.js create mode 100644 test/tool/erase-time.js create mode 100644 test/tool/gulp-cmd.js create mode 100644 test/tool/slice-lines.js diff --git a/.editorconfig b/.editorconfig index aaa39996..e7b73a7a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,18 +1,13 @@ -# EditorConfig is Awesome: http://editorconfig.org - -# Top-most EditorConfig file. +# https://editorconfig.org root = true -# Unix-style newlines with a newline ending every file. [*] -end_of_line = lf -insert_final_newline = true -charset = utf-8 indent_style = space indent_size = 2 +charset = utf-8 trim_trailing_whitespace = true +insert_final_newline = true +end_of_line = lf -# Don't trim whitespace in Markdown in order to be able -# to do two spaces for line breaks. [*.md] trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc index ea9ec781..331ecbe0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,7 @@ { "extends": "gulp", "rules": { - "max-len": [1, 90], + "max-len": [1, 130], "max-statements": [1, 40], "no-console": "off" } diff --git a/.github/support.yml b/.github/support.yml deleted file mode 100644 index 3ee3d22c..00000000 --- a/.github/support.yml +++ /dev/null @@ -1,2 +0,0 @@ -# Configuration for support-requests - https://github.com/dessant/support-requests -_extends: gulp diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 00000000..90a12261 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,86 @@ +name: dev +on: + pull_request: + push: + branches: + - master + - main +env: + CI: true + +jobs: + prettier: + name: Format code + runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' }} + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Prettier + uses: gulpjs/prettier_action@v3.0 + with: + commit_message: 'chore: Run prettier' + prettier_options: '--write .' + + test: + name: Tests for Node ${{ matrix.node }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + node: [10, 12, 14, 16, 18] + os: [ubuntu-latest, windows-latest, macos-latest] + + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Set Node.js version + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + + - run: node --version + - run: npm --version + + - name: Install npm dependencies + run: npm install + + - name: Run lint + run: npm run lint + + - name: Run tests + # Run test without coverage because a behavior about esm is different with nyc or not + run: npm test + + coveralls: + needs: test + name: Finish up + + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Set Node.js version + uses: actions/setup-node@v2 + with: + # Coverage with LTS version + node-version: 18 + + - run: node --version + - run: npm --version + + - name: Install npm dependencies + run: npm install + + - name: Run coverage + run: npm run cover + + - name: Coveralls + uses: coverallsapp/github-action@v1.1.2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..87cd13c0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,16 @@ +name: release +on: + push: + branches: + - master + - main + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: GoogleCloudPlatform/release-please-action@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + release-type: node + package-name: release-please-action diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..c96ebe0c --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +coverage/ +.nyc_output/ +CHANGELOG.md diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 25fc79b7..00000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -sudo: false -language: node_js -node_js: - - "14" - - "12" - - "10" - - "8" - - "6" - - "4" - - "0.12" - - "0.10" -after_script: - - if [ $(echo "${TRAVIS_NODE_VERSION}" | cut -d'.' -f1) -ge 6 ]; then - npm run coveralls; - fi - -git: - depth: 10 -os: - - linux - - osx diff --git a/LICENSE b/LICENSE index 9aedc0d7..6443cad0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Blaine Bublitz, Eric Schoffstall and other contributors +Copyright (c) 2015, 2017-2020, 2022-2023 Blaine Bublitz and Eric Schoffstall Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 6c4249e9..71f4d7a7 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@

- +

# gulp-cli -[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] +[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url] Command Line Utility for Gulp @@ -91,15 +91,15 @@ Add `gulp --completion=fish | source` to `~/.config/fish/config.fish`. ## Compilers -You can find a list of supported languages at https://github.com/js-cli/js-interpret. If you would like to add support for a new language, send pull requests/open issues on that project. +You can find a list of supported languages at https://github.com/gulpjs/interpret. If you would like to add support for a new language, send pull requests/open issues on that project. ## Environment -The CLI adds process.env.INIT_CWD which is the original cwd it was launched from. +The CLI adds `process.env.INIT_CWD` which is the original cwd it was launched from. ## Configuration -Configuration is supported through the use of a `.gulp.*` file (e.g. `.gulp.json`, `.gulp.yml`). You can find a list of supported languages at https://github.com/js-cli/js-interpret. +Configuration is supported through the use of a `.gulp.*` file (e.g. `.gulp.json`, `.gulp.yml`). You can find a list of supported languages at https://github.com/gulpjs/interpret. Configuration from the home directory (`~`) and current working directory (`cwd`) are merged with `cwd` taking precedence. @@ -114,7 +114,7 @@ Supported configurations properties: | flags.gulpfile | Set a default gulpfile | | flags.silent | Silence logging by default | | flags.series | Run tasks given on the CLI in series (the default is parallel) | -| flags.require | An array of modules to require before running the gulpfile. Any relative paths will be resolved against the `--cwd` directory (if you don't want that behavior, use absolute paths) | +| flags.preload | An array of modules to preload before running the gulpfile. Any relative paths will be resolved against the `--cwd` directory (if you don't want that behavior, use absolute paths) | | flags.nodeFlags | An array of flags used to forcibly respawn the process upon startup. For example, if you always want your gulpfiles to run in node's harmony mode, you can set `--harmony` here | ## Flags @@ -143,9 +143,9 @@ __Some flags only work with gulp 4 and will be ignored when invoked against gulp Print the global and local gulp versions. - --require [path] + --preload [path] - Will require a module before running the gulpfile. This is useful for transpilers but also has other applications. + Will preload a module before running the gulpfile. This is useful for transpilers but also has other applications. --gulpfile [path] @@ -155,7 +155,7 @@ __Some flags only work with gulp 4 and will be ignored when invoked against gulp --cwd [path] - Manually set the CWD. The search for the gulpfile, as well as the relativity of all requires (including the `--require` flag) will be from here. + Manually set the CWD. The search for the gulpfile, as well as the relativity of all preloads (with the `--preload` flag) will be from here. --verify [path (optional)] @@ -229,18 +229,15 @@ __Some flags only work with gulp 4 and will be ignored when invoked against gulp MIT -[downloads-image]: http://img.shields.io/npm/dm/gulp-cli.svg -[npm-url]: https://www.npmjs.com/package/gulp-cli -[npm-image]: http://img.shields.io/npm/v/gulp-cli.svg -[travis-url]: https://travis-ci.org/gulpjs/gulp-cli -[travis-image]: http://img.shields.io/travis/gulpjs/gulp-cli.svg?label=travis-ci + +[downloads-image]: https://img.shields.io/npm/dm/gulp-cli.svg?style=flat-square +[npm-url]: https://www.npmjs.com/package/gulp-cli +[npm-image]: https://img.shields.io/npm/v/gulp-cli.svg?style=flat-square -[appveyor-url]: https://ci.appveyor.com/project/gulpjs/gulp-cli -[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/gulp-cli.svg?label=appveyor +[ci-url]: https://github.com/gulpjs/gulp-cli/actions?query=workflow:dev +[ci-image]: https://img.shields.io/github/actions/workflow/status/gulpjs/gulp-cli/dev.yml?branch=master&style=flat-square [coveralls-url]: https://coveralls.io/r/gulpjs/gulp-cli -[coveralls-image]: http://img.shields.io/coveralls/gulpjs/gulp-cli/master.svg - -[gitter-url]: https://gitter.im/gulpjs/gulp -[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg +[coveralls-image]: https://img.shields.io/coveralls/gulpjs/gulp-cli.svg?style=flat-square + diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 32e31abb..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,29 +0,0 @@ -# http://www.appveyor.com/docs/appveyor-yml -# http://www.appveyor.com/docs/lang/nodejs-iojs - -environment: - matrix: - # node.js - - nodejs_version: "0.10" - - nodejs_version: "0.12" - - nodejs_version: "4" - - nodejs_version: "6" - - nodejs_version: "8" - - nodejs_version: "10" - - nodejs_version: "12" - - nodejs_version: "14" - -install: - - npm install -g npm@^3 - - ps: Install-Product node $env:nodejs_version - - npm install - -test_script: - - node --version - - npm --version - - cmd: npm test - -build: off - -# build version format -version: "{build}" diff --git a/index.js b/index.js index 258c86ac..9e5f43b6 100644 --- a/index.js +++ b/index.js @@ -3,25 +3,24 @@ var fs = require('fs'); var path = require('path'); var log = require('gulplog'); -var yargs = require('yargs'); + var Liftoff = require('liftoff'); var interpret = require('interpret'); var v8flags = require('v8flags'); var findRange = require('semver-greatest-satisfied-range'); -var ansi = require('./lib/shared/ansi'); +var chalk = require('chalk'); var exit = require('./lib/shared/exit'); var tildify = require('./lib/shared/tildify'); var makeTitle = require('./lib/shared/make-title'); -var cliOptions = require('./lib/shared/cli-options'); +var parser = require('./lib/shared/options/parser'); var completion = require('./lib/shared/completion'); var verifyDeps = require('./lib/shared/verify-dependencies'); var cliVersion = require('./package.json').version; -var getBlacklist = require('./lib/shared/get-blacklist'); +var getBlacklist = require('./lib/shared/blacklist'); var toConsole = require('./lib/shared/log/to-console'); -var loadConfigFiles = require('./lib/shared/config/load-files'); -var mergeConfigToCliFlags = require('./lib/shared/config/cli-flags'); -var mergeConfigToEnvFlags = require('./lib/shared/config/env-flags'); +var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); +var overrideEnvFlagsByConfigAndCliOpts = require('./lib/shared/config/env-flags'); // Logging functions var logVerify = require('./lib/shared/log/verify'); @@ -41,49 +40,69 @@ var cli = new Liftoff({ extensions: interpret.jsVariants, v8flags: v8flags, configFiles: { - '.gulp': { - home: { - path: '~', + project: [ + { + name: '.gulp', + path: '.', extensions: interpret.extensions, + findUp: true, }, - cwd: { - path: '.', + ], + userHome: [ + { + name: '.gulp', + path: '~', extensions: interpret.extensions, }, - }, + ], }, }); -var usage = - '\n' + ansi.bold('Usage:') + - ' gulp ' + ansi.blue('[options]') + ' tasks'; - -var parser = yargs.usage(usage, cliOptions); var opts = parser.argv; -cli.on('require', function(name) { +cli.on('preload:before', function(name) { + log.info('Preloading external module:', chalk.magenta(name)); +}); + +cli.on('preload:success', function(name) { + log.info('Preloaded external module:', chalk.magenta(name)); +}); + +cli.on('preload:failure', function(name, error) { + log.warn( + chalk.yellow('Failed to preload external module:'), + chalk.magenta(name) + ); + /* istanbul ignore else */ + if (error) { + log.warn(chalk.yellow(error.toString())); + } +}); + +cli.on('loader:success', function(name) { // This is needed because interpret needs to stub the .mjs extension // Without the .mjs require hook, rechoir blows up // However, we don't want to show the mjs-stub loader in the logs + /* istanbul ignore else */ if (path.basename(name, '.js') !== 'mjs-stub') { - log.info('Requiring external module', ansi.magenta(name)); + log.info('Loaded external module:', chalk.magenta(name)); } }); -cli.on('requireFail', function(name, error) { +cli.on('loader:failure', function(name, error) { log.warn( - ansi.yellow('Failed to load external module'), - ansi.magenta(name) + chalk.yellow('Failed to load external module:'), + chalk.magenta(name) ); /* istanbul ignore else */ if (error) { - log.warn(ansi.yellow(error.toString())); + log.warn(chalk.yellow(error.toString())); } }); cli.on('respawn', function(flags, child) { - var nodeFlags = ansi.magenta(flags.join(', ')); - var pid = ansi.magenta(child.pid); + var nodeFlags = chalk.magenta(flags.join(', ')); + var pid = chalk.magenta(child.pid); log.info('Node flags detected:', nodeFlags); log.info('Respawned to PID:', pid); }); @@ -92,49 +111,47 @@ function run() { cli.prepare({ cwd: opts.cwd, configPath: opts.gulpfile, - require: opts.require, + preload: opts.preload, completion: opts.completion, - }, function(env) { - var cfgLoadOrder = ['home', 'cwd']; - var cfg = loadConfigFiles(env.configFiles['.gulp'], cfgLoadOrder); - opts = mergeConfigToCliFlags(opts, cfg); - env = mergeConfigToEnvFlags(env, cfg, opts); - env.configProps = cfg; - - // Set up event listeners for logging again after configuring. - toConsole(log, opts); - - cli.execute(env, env.nodeFlags, handleArguments); - }); + }, onPrepare); } module.exports = run; -// The actual logic -function handleArguments(env) { +function onPrepare(env) { + var cfg = mergeProjectAndUserHomeConfigs(env); + env = overrideEnvFlagsByConfigAndCliOpts(env, cfg, opts); + + // Set up event listeners for logging again after configuring. + toConsole(log, env.config.flags); + cli.execute(env, env.nodeFlags, onExecute); +} + +// The actual logic +function onExecute(env) { // This translates the --continue flag in gulp // To the settle env variable for undertaker // We use the process.env so the user's gulpfile // Can know about the flag - if (opts.continue) { + if (env.config.flags.continue) { process.env.UNDERTAKER_SETTLE = 'true'; } - if (opts.help) { + if (env.config.flags.help) { parser.showHelp(console.log); exit(0); } // Anything that needs to print outside of the logging mechanism should use console.log - if (opts.version) { + if (env.config.flags.version) { console.log('CLI version:', cliVersion); console.log('Local version:', env.modulePackage.version || 'Unknown'); exit(0); } - if (opts.verify) { - var pkgPath = opts.verify !== true ? opts.verify : 'package.json'; + if (env.config.flags.verify) { + var pkgPath = env.config.flags.verify !== true ? env.config.flags.verify : 'package.json'; /* istanbul ignore else */ if (path.resolve(pkgPath) !== path.normalize(pkgPath)) { pkgPath = path.join(env.cwd, pkgPath); @@ -164,8 +181,8 @@ function handleArguments(env) { ? 'Local modules not found in' : 'Local gulp not found in'; log.error( - ansi.red(missingGulpMessage), - ansi.magenta(tildify(env.cwd)) + chalk.red(missingGulpMessage), + chalk.magenta(tildify(env.cwd)) ); var hasYarn = fs.existsSync(path.join(env.cwd, 'yarn.lock')); /* istanbul ignore next */ @@ -177,12 +194,12 @@ function handleArguments(env) { : hasYarn ? 'yarn add gulp' : 'npm install gulp'; - log.error(ansi.red('Try running: ' + installCommand)); + log.error(chalk.red('Try running: ' + installCommand)); exit(1); } if (!env.configPath) { - log.error(ansi.red('No gulpfile found')); + log.error(chalk.red('No gulpfile found')); exit(1); } @@ -192,7 +209,7 @@ function handleArguments(env) { process.chdir(env.cwd); log.info( 'Working directory changed to', - ansi.magenta(tildify(env.cwd)) + chalk.magenta(tildify(env.cwd)) ); } @@ -201,12 +218,12 @@ function handleArguments(env) { if (!range) { log.error( - ansi.red('Unsupported gulp version', env.modulePackage.version) + chalk.red('Unsupported gulp version', env.modulePackage.version) ); exit(1); } // Load and execute the CLI version var versionedDir = path.join(__dirname, '/lib/versioned/', range, '/'); - require(versionedDir)(opts, env, env.configProps); + require(versionedDir)(env); } diff --git a/lib/shared/ansi.js b/lib/shared/ansi.js deleted file mode 100644 index d5030fa0..00000000 --- a/lib/shared/ansi.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -var colors = require('ansi-colors'); -var supportsColor = require('color-support'); - -var hasColors = colorize(); - -/* istanbul ignore next */ -module.exports = { - red: hasColors ? colors.red : noColor, - green: hasColors ? colors.green : noColor, - blue: hasColors ? colors.blue : noColor, - magenta: hasColors ? colors.magenta : noColor, - cyan: hasColors ? colors.cyan : noColor, - white: hasColors ? colors.white : noColor, - gray: hasColors ? colors.gray : noColor, - bgred: hasColors ? colors.bgred : noColor, - bold: hasColors ? colors.bold : noColor, - yellow: hasColors ? colors.yellow : noColor, -}; - -function noColor(message) { - return message; -} - -function hasFlag(flag) { - return (process.argv.indexOf('--' + flag) !== -1); -} - -function colorize() { - if (hasFlag('no-color')) { - return false; - } - - /* istanbul ignore if */ - if (hasFlag('color')) { - return true; - } - - return supportsColor(); -} diff --git a/lib/shared/blacklist/get-remote-json.js b/lib/shared/blacklist/get-remote-json.js new file mode 100644 index 00000000..f5a21b68 --- /dev/null +++ b/lib/shared/blacklist/get-remote-json.js @@ -0,0 +1,39 @@ +'use strict'; + +var https = require('https'); + +function getRemoteJson(url, cb) { + var chunks = []; + + https.get(url, onRequest).on('error', onError);; + + function onRequest(res) { + if (res.statusCode !== 200) { + res.resume(); // Consume response data to free up memory + return cb(new Error('Request failed. Status Code: ' + res.statusCode)); + } + + res.on('error', onError); + res.on('data', onDrain); + res.on('end', onEnd); + } + + /* istanbul ignore next */ + function onError(e) { + cb(e, null); + } + + function onDrain(d) { + chunks.push(d); + } + + function onEnd() { + try { + cb(null, JSON.parse(Buffer.concat(chunks).toString('utf8'))); + } catch (err) { + cb(new Error('Invalid Blacklist JSON.')); + } + } +} + +module.exports = getRemoteJson; diff --git a/lib/shared/blacklist/index.js b/lib/shared/blacklist/index.js new file mode 100644 index 00000000..edf66fa1 --- /dev/null +++ b/lib/shared/blacklist/index.js @@ -0,0 +1,11 @@ +'use strict'; + +var getRemoteJson = require('./get-remote-json'); + +var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/blackList.json'; + +function getBlacklist(cb) { + getRemoteJson(url, cb); +} + +module.exports = getBlacklist; diff --git a/lib/shared/config/cli-flags.js b/lib/shared/config/cli-flags.js index 1baf38d0..996aaa6b 100644 --- a/lib/shared/config/cli-flags.js +++ b/lib/shared/config/cli-flags.js @@ -2,7 +2,7 @@ var copyProps = require('copy-props'); -var fromTo = { +var fromConfigToCliOpts = { 'flags.silent': 'silent', 'flags.continue': 'continue', 'flags.series': 'series', @@ -12,8 +12,9 @@ var fromTo = { 'flags.sortTasks': 'sortTasks', }; -function mergeConfigToCliFlags(opt, config) { - return copyProps(config, opt, fromTo, defaults); +function mergeCliOpts(opts, config) { + opts = copyProps(opts, {}); + return copyProps(config, opts, fromConfigToCliOpts, defaults); } function defaults(cfgInfo, optInfo) { @@ -22,4 +23,4 @@ function defaults(cfgInfo, optInfo) { } } -module.exports = mergeConfigToCliFlags; +module.exports = mergeCliOpts; diff --git a/lib/shared/config/env-flags.js b/lib/shared/config/env-flags.js index a5a4abd7..59b4d4be 100644 --- a/lib/shared/config/env-flags.js +++ b/lib/shared/config/env-flags.js @@ -3,17 +3,29 @@ var path = require('path'); var copyProps = require('copy-props'); -var toFrom = { +var mergeCliOpts = require('./cli-flags'); + +var toEnvFromConfig = { configPath: 'flags.gulpfile', configBase: 'flags.gulpfile', - require: 'flags.require', + preload: 'flags.preload', nodeFlags: 'flags.nodeFlags', }; -function mergeConfigToEnvFlags(env, config, cliOpts) { +function overrideEnvFlags(env, config, cliOpts) { + cliOpts = mergeCliOpts(cliOpts, config); + // This must reverse because `flags.gulpfile` determines 2 different properties var reverse = true; - return copyProps(env, config, toFrom, convert, reverse); + env = copyProps(env, config, toEnvFromConfig, convert, reverse); + + env.config = { + flags: cliOpts, + }; + if (config.description) { + env.config.description = config.description; + } + return env function convert(configInfo, envInfo) { if (envInfo.keyChain === 'configBase') { @@ -30,7 +42,7 @@ function mergeConfigToEnvFlags(env, config, cliOpts) { return; } - if (envInfo.keyChain === 'require') { + if (envInfo.keyChain === 'preload') { return [].concat(envInfo.value, configInfo.value); } @@ -41,4 +53,4 @@ function mergeConfigToEnvFlags(env, config, cliOpts) { } } -module.exports = mergeConfigToEnvFlags; +module.exports = overrideEnvFlags; diff --git a/lib/shared/config/load-files.js b/lib/shared/config/load-files.js deleted file mode 100644 index 4ebb29cb..00000000 --- a/lib/shared/config/load-files.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -var copyProps = require('copy-props'); -var path = require('path'); - -function loadConfigFiles(configFiles, configFileOrder) { - var config = {}; - - configFileOrder.forEach(loadFile); - - function loadFile(key) { - var filePath = configFiles[key]; - if (!filePath) { - return; - } - - copyProps(require(filePath), config, convert); - - function convert(loadedInfo) { - if (loadedInfo.keyChain === 'flags.gulpfile') { - return path.resolve(path.dirname(filePath), loadedInfo.value); - } - return loadedInfo.value; - } - } - - return config; -} - -module.exports = loadConfigFiles; diff --git a/lib/shared/config/merge-configs.js b/lib/shared/config/merge-configs.js new file mode 100644 index 00000000..8202f182 --- /dev/null +++ b/lib/shared/config/merge-configs.js @@ -0,0 +1,28 @@ +'use strict'; + +var copyProps = require('copy-props'); +var path = require('path'); + +function mergeConfigs(env) { + var cfg = {}; + if (env.configFiles.userHome) { + copyConfig(env.config.userHome, cfg, env.configFiles.userHome); + } + if (env.configFiles.project) { + copyConfig(env.config.project, cfg, env.configFiles.project); + } + return cfg; +} + +function copyConfig(src, dest, filePath) { + return copyProps(src, dest, convert); + + function convert(loadedInfo) { + if (loadedInfo.keyChain === 'flags.gulpfile') { + return path.resolve(path.dirname(filePath), loadedInfo.value); + } + return loadedInfo.value; + } +} + +module.exports = mergeConfigs; diff --git a/lib/shared/get-blacklist.js b/lib/shared/get-blacklist.js deleted file mode 100644 index 4cc16d45..00000000 --- a/lib/shared/get-blacklist.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - -var https = require('https'); - -var concat = require('concat-stream'); - -var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/blackList.json'; - -function collect(stream, cb) { - stream.on('error', cb); - stream.pipe(concat(onSuccess)); - - function onSuccess(result) { - cb(null, result); - } -} - -function parse(str, cb) { - try { - cb(null, JSON.parse(str)); - } catch (err) { - /* istanbul ignore next */ - cb(new Error('Invalid Blacklist JSON.')); - } -} - -// TODO: Test this impl -function getBlacklist(cb) { - https.get(url, onRequest); - - function onRequest(res) { - /* istanbul ignore if */ - if (res.statusCode !== 200) { - // TODO: Test different status codes - return cb(new Error('Request failed. Status Code: ' + res.statusCode)); - } - - res.setEncoding('utf8'); - - collect(res, onCollect); - } - - function onCollect(err, result) { - /* istanbul ignore if */ - if (err) { - return cb(err); - } - - parse(result, onParse); - } - - function onParse(err, blacklist) { - /* istanbul ignore if */ - if (err) { - return cb(err); - } - - cb(null, blacklist); - } -} - -module.exports = getBlacklist; diff --git a/lib/shared/is-object.js b/lib/shared/is-object.js new file mode 100644 index 00000000..6375b561 --- /dev/null +++ b/lib/shared/is-object.js @@ -0,0 +1,7 @@ +'use strict'; + +function isObject(v) { + return (v != null && typeof v === 'object' && !Array.isArray(v)); +} + +module.exports = isObject; diff --git a/lib/shared/log/blacklist-error.js b/lib/shared/log/blacklist-error.js index b0355b2d..f3361b72 100644 --- a/lib/shared/log/blacklist-error.js +++ b/lib/shared/log/blacklist-error.js @@ -1,13 +1,13 @@ 'use strict'; var log = require('gulplog'); +var chalk = require('chalk'); -var ansi = require('../ansi'); var exit = require('../exit'); /* istanbul ignore next */ function logBlacklistError(err) { - log.error(ansi.red('Error: failed to retrieve plugins black-list')); + log.error(chalk.red('Error: failed to retrieve plugins black-list')); log.error(err.message); // Avoid duplicating for each version exit(1); } diff --git a/lib/shared/log/format-hrtime.js b/lib/shared/log/format-hrtime.js new file mode 100644 index 00000000..0547bd1e --- /dev/null +++ b/lib/shared/log/format-hrtime.js @@ -0,0 +1,48 @@ +'use strict'; + +var units = [ + [ 'h', 3600e9 ], + [ 'min', 60e9 ], + [ 's', 1e9 ], + [ 'ms', 1e6 ], + [ 'μs', 1e3 ], +]; + +function formatHrTime(hrtime) { + if (!Array.isArray(hrtime) || hrtime.length !== 2) { + return ''; + } + if (typeof hrtime[0] !== 'number' || typeof hrtime[1] !== 'number') { + return ''; + } + + var nano = hrtime[0] * 1e9 + hrtime[1]; + + for (var i = 0; i < units.length; i++) { + if (nano < units[i][1]) { + continue; + } + + if (nano >= units[i][1] * 10) { + return Math.round(nano / units[i][1]) + ' ' + units[i][0]; + } + + var s = String(Math.round(nano * 1e2 / units[i][1])); + if (s.slice(-2) === '00') { + s = s.slice(0, -2); + } else if (s.slice(-1) === '0') { + s = s.slice(0, -2) + '.' + s.slice(-2, -1); + } else { + s = s.slice(0, -2) + '.' + s.slice(-2); + } + return s + ' ' + units[i][0]; + } + + if (nano > 0) { + return nano + ' ns'; + } + + return ''; +} + +module.exports = formatHrTime; diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 0b76b088..2d59fe35 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -1,165 +1,155 @@ 'use strict'; -var archy = require('archy'); var log = require('gulplog'); - -var sortBy = require('array-sort'); -var isObject = require('isobject'); - -var ansi = require('../ansi'); -var copyTree = require('./copy-tree'); +var chalk = require('chalk'); +var isObject = require('../is-object'); function logTasks(tree, opts, getTask) { if (opts.sortTasks) { - tree.nodes = sortBy(tree.nodes, 'label'); + tree.nodes = tree.nodes.sort(compareByLabel); } - var lineInfos = []; - var entryObserver = getLineInfoCollector(lineInfos); - var nodeFactory = getNodeFactory(getTask, entryObserver); - - tree = copyTree(tree, opts, nodeFactory); - var spacer = getSpacerForLineIndents(tree, lineInfos); - var lines = getLinesContainingOnlyBranches(tree); + var maxDepth = opts.tasksDepth; + if (typeof maxDepth !== 'number') { + maxDepth = 50; + } else if (maxDepth < 1) { + maxDepth = 1; + } - log.info(tree.label); - printTreeList(lines, spacer, lineInfos); -} + var compactedTasks = opts.compactTasks ? tree.nodes : []; -function getLineInfoCollector(lineInfos) { - return { - topTask: function(node) { - lineInfos.push({ - name: node.label, - desc: node.desc, - type: 'top', - }); - }, - option: function(opt) { - lineInfos.push({ - name: opt.label, - desc: opt.desc, - type: 'option', - }); - }, - childTask: function(node) { - lineInfos.push({ - name: node.label, - type: 'child', - }); - }, + var treeOpts = { + maxDepth: maxDepth, + compactedTasks: compactedTasks, + getTask: getTask, }; -} -function getNodeFactory(getTask, entryObserver) { - return { - topNode: function(node) { - return { - label: node.label, - }; - }, - - taskNode: function(node) { - /* istanbul ignore next */ - var task = getTask(node.label) || {}; - - var newNode = { - label: node.label, - desc: typeof task.description === 'string' ? task.description : '', - opts: [], - }; - entryObserver.topTask(newNode); - - if (isObject(task.flags)) { - Object.keys(task.flags).sort().forEach(function(flag) { - if (flag.length === 0) { - return; - } - /* istanbul ignore next */ - var opt = { - label: flag, - desc: typeof task.flags[flag] === 'string' ? task.flags[flag] : '', - }; - entryObserver.option(opt); - newNode.opts.push(opt); - newNode.label += '\n' + opt.label; // The way of archy for options. - }); - } - - return newNode; - }, - - childNode: function(node) { - var newChild = { - label: node.label, - }; - entryObserver.childTask(newChild); - newChild.label = ''; // Because don't use child tasks to calc indents. - - return newChild; - }, - }; + printTaskTree(tree, treeOpts); } -function getSpacerForLineIndents(tree, lineInfos) { - var maxSize = 0; - var sizes = []; - - archy(tree) - .split('\n') - .slice(1, -1) - .forEach(function(line, index) { - var info = lineInfos[index]; - if (info.type === 'top' || info.type === 'option') { - maxSize = Math.max(maxSize, line.length); - sizes.push(line.length); - } else { - sizes.push(0); - } - }); +function printTaskTree(tree, opts) { + var lines = []; + lines.push({ label: tree.label }); + var maxLabelWidth = 0; - maxSize += 3; + tree.nodes.forEach(function(node, idx, arr) { + var isLast = idx === arr.length - 1; + var w = createTreeLines(node, lines, opts, 1, '', isLast); + maxLabelWidth = Math.max(maxLabelWidth, w || 0); + }); - return function(index) { - return Array(maxSize - sizes[index]).join(' '); - }; + lines.forEach(function(line) { + var s = line.label; + if (line.desc) { + var spaces = ' '.repeat(maxLabelWidth - line.label.length) + ' '; + s += spaces + line.desc; + } + log.info(s); + }); } -function getLinesContainingOnlyBranches(tree) { - tree.nodes.forEach(function(node) { - node.label = ''; - node.opts.forEach(function() { - node.label += '\n'; +function createTreeLines(node, lines, opts, depth, bars, isLast) { + var task = { label: node.label, bars: bars, depth: depth }; + if (depth === 1) { + var t = opts.getTask(node.label); + task.desc = t.description; + task.flags = t.flags; + } + + var isLeaf = isLeafNode(node, depth, opts); + + var maxLabelWidth = addTaskToLines(task, lines, isLast, isLeaf); + + if (!isLeaf) { + bars += (isLast ? ' ' : '│ '); + node.nodes.forEach(function(node, idx, arr) { + var isLast = idx === arr.length - 1; + createTreeLines(node, lines, opts, depth + 1, bars, isLast); }); - }); + } - return archy(tree) - .split('\n') - .slice(1, -1); + return maxLabelWidth; } -function printTreeList(lines, spacer, lineInfos) { - lines.forEach(function(branch, index) { - var info = lineInfos[index]; - - var line = ansi.white(branch); - - if (info.type === 'top') { - line += ansi.cyan(info.name); - if (info.desc.length > 0) { - line += spacer(index) + ansi.white(info.desc); - } - } else if (info.type === 'option') { - line += ansi.magenta(info.name); - if (info.desc.length > 0) { - line += spacer(index) + ansi.white('…' + info.desc); - } - } else { // If (info.type === 'child') { - line += ansi.white(info.name); - } +function addTaskToLines(task, lines, isLast, isLeaf) { + var taskBars = task.bars + (isLast ? '└' : '├') + '─'; + if (isLeaf) { + taskBars += '─ '; + } else { + taskBars += '┬ '; + } - log.info(line); - }); + var line = {}; + if (task.depth === 1) { + line.label = chalk.white(taskBars) + chalk.white(task.label); + } else { + line.label = chalk.white(taskBars) + chalk.cyan(task.label); + } + if (typeof task.desc === 'string' && task.desc) { + line.desc = chalk.white(task.desc); + } + lines.push(line); + + var maxLabelWidth = line.label.length + + if (!isObject(task.flags)) { + return maxLabelWidth; + } + + var flagBars = task.bars; + if (isLast) { + flagBars += ' '; + } else { + flagBars += '│ '; + } + + if (isLeaf) { + flagBars += ' '; + } else { + flagBars += '│ '; + } + + Object.entries(task.flags).sort(flagSorter).forEach(addFlagsToLines); + + function addFlagsToLines(ent) { + if (typeof ent[0] !== 'string' || !ent[0]) return; + var line = {}; + lines.push(line); + line.label = chalk.white(flagBars) + chalk.magenta(ent[0]); + + maxLabelWidth = Math.max(maxLabelWidth, line.label.length); + + if (typeof ent[1] !== 'string' || !ent[1]) return; + line.desc = chalk.white('…' + ent[1]); + } + + return maxLabelWidth; +} + +function isLeafNode(node, depth, opts) { + if (depth >= opts.maxDepth) { + return true; + } else if (depth > 1 && opts.compactedTasks.includes(node)) { + return true; + } else if (!Array.isArray(node.nodes) || node.nodes.length === 0) { + return true; + } + return false; +} + +function compareByLabel(a, b) { + /* istanbul ignore if */ + if (!b.label) { + return -1; + } else /* istanbul ignore if */ if (!a.label) { + return 1; + } else { + return (a.label <= b.label) ? -1 : 1; + } +} + +function flagSorter(a, b) { + return (a[0] <= b[0]) ? -1 : 1; } module.exports = logTasks; diff --git a/lib/shared/log/verify.js b/lib/shared/log/verify.js index 71046237..f635bd39 100644 --- a/lib/shared/log/verify.js +++ b/lib/shared/log/verify.js @@ -2,7 +2,7 @@ var log = require('gulplog'); -var ansi = require('../ansi'); +var chalk = require('chalk'); var exit = require('../exit'); function logVerify(blacklisted) { @@ -10,16 +10,16 @@ function logVerify(blacklisted) { if (!pluginNames.length) { log.info( - ansi.green('There are no blacklisted plugins in this project') + chalk.green('There are no blacklisted plugins in this project') ); exit(0); } - log.warn(ansi.red('Blacklisted plugins found in this project:')); + log.warn(chalk.red('Blacklisted plugins found in this project:')); pluginNames.map(function(pluginName) { var reason = blacklisted[pluginName]; - log.warn(ansi.bgred(pluginName) + ': ' + reason); + log.warn(chalk.bgRed(pluginName) + ': ' + reason); }); exit(1); diff --git a/lib/shared/cli-options.js b/lib/shared/options/parser.js similarity index 79% rename from lib/shared/cli-options.js rename to lib/shared/options/parser.js index 09d98e3d..94801742 100644 --- a/lib/shared/cli-options.js +++ b/lib/shared/options/parser.js @@ -1,60 +1,65 @@ 'use strict'; -var ansi = require('./ansi'); +var chalk = require('chalk'); +var yargs = require('yargs'); -module.exports = { +var usage = + '\n' + chalk.bold('Usage:') + + ' gulp ' + chalk.blue('[options]') + ' tasks'; + +var options = { help: { alias: 'h', type: 'boolean', - desc: ansi.gray( + desc: chalk.gray( 'Show this help.'), }, version: { alias: 'v', type: 'boolean', - desc: ansi.gray( + desc: chalk.gray( 'Print the global and local gulp versions.'), }, - require: { + preload: { type: 'string', requiresArg: true, - desc: ansi.gray( - 'Will require a module before running the gulpfile. ' + + desc: chalk.gray( + 'Will preload a module before running the gulpfile. ' + 'This is useful for transpilers but also has other applications.'), }, gulpfile: { alias: 'f', type: 'string', requiresArg: true, - desc: ansi.gray( + desc: chalk.gray( 'Manually set path of gulpfile. Useful if you have multiple gulpfiles. ' + 'This will set the CWD to the gulpfile directory as well.'), }, cwd: { type: 'string', requiresArg: true, - desc: ansi.gray( + desc: chalk.gray( 'Manually set the CWD. The search for the gulpfile, ' + 'as well as the relativity of all requires will be from here.'), }, verify: { - desc: ansi.gray( + desc: chalk.gray( 'Will verify plugins referenced in project\'s package.json against ' + 'the plugins blacklist.'), }, tasks: { alias: 'T', type: 'boolean', - desc: ansi.gray( + desc: chalk.gray( 'Print the task dependency tree for the loaded gulpfile.'), }, 'tasks-simple': { type: 'boolean', - desc: ansi.gray( + desc: chalk.gray( 'Print a plaintext list of tasks for the loaded gulpfile.'), }, 'tasks-json': { - desc: ansi.gray( + desc: chalk.gray( 'Print the task dependency tree, ' + 'in JSON format, for the loaded gulpfile.'), }, @@ -63,31 +68,31 @@ module.exports = { type: 'number', requiresArg: true, default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Specify the depth of the task dependency tree.'), }, 'compact-tasks': { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Reduce the output of task dependency tree by printing ' + 'only top tasks and their child tasks.'), }, 'sort-tasks': { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Will sort top tasks of task dependency tree.'), }, color: { type: 'boolean', - desc: ansi.gray( + desc: chalk.gray( 'Will force gulp and gulp plugins to display colors, ' + 'even when no color support is detected.'), }, 'no-color': { type: 'boolean', - desc: ansi.gray( + desc: chalk.gray( 'Will force gulp and gulp plugins to not display colors, ' + 'even when color support is detected.'), }, @@ -95,19 +100,19 @@ module.exports = { alias: 'S', type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Suppress all gulp logging.'), }, continue: { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Continue execution of tasks upon failure.'), }, series: { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Run tasks given on the CLI in series (the default is parallel).'), }, 'log-level': { @@ -115,8 +120,14 @@ module.exports = { // Type isn't needed because count acts as a boolean count: true, default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Set the loglevel. -L for least verbose and -LLLL for most verbose. ' + '-LLL is default.'), - }, + } }; + +var parser = yargs + .help(false).version(false).detectLocale(false) + .usage(usage).options(options); + +module.exports = parser; diff --git a/lib/shared/require-or-import.js b/lib/shared/require-or-import.js index 6970ae42..4cf5877e 100644 --- a/lib/shared/require-or-import.js +++ b/lib/shared/require-or-import.js @@ -9,6 +9,7 @@ try { // That way we can keep supporting all Node.js versions all the way back to 0.10. importESM = new Function('id', 'return import(id);'); } catch (e) { + /* istanbul ignore next */ importESM = null; } @@ -18,12 +19,18 @@ function requireOrImport(path, callback) { try { cjs = require(path); } catch (e) { - if (pathToFileURL && importESM && e.code === 'ERR_REQUIRE_ESM') { - // This is needed on Windows, because import() fails if providing a Windows file path. - var url = pathToFileURL(path); - importESM(url).then(function(esm) { callback(null, esm); }, callback); - return; + /* istanbul ignore else */ + if (pathToFileURL && importESM) { + // Because e.code is undefined on nyc process. + /* istanbul ignore else */ + if (e.code === 'ERR_REQUIRE_ESM' || process.env.NYC_CONFIG) { + // This is needed on Windows, because import() fails if providing a Windows file path. + var url = pathToFileURL(path); + importESM(url).then(function(esm) { callback(null, esm); }, callback); + return; + } } + /* istanbul ignore next */ err = e; } process.nextTick(function() { callback(err, cjs); }); diff --git a/lib/shared/verify-dependencies.js b/lib/shared/verify-dependencies.js index a0d4812c..2dbe9b7a 100644 --- a/lib/shared/verify-dependencies.js +++ b/lib/shared/verify-dependencies.js @@ -1,7 +1,5 @@ 'use strict'; -var matchdep = require('matchdep'); - /** * Given a collection of plugin names verifies this collection against * the blacklist. Returns an object with: @@ -12,14 +10,25 @@ var matchdep = require('matchdep'); * @param blacklist - contents of the blacklist in JSON format */ function verifyDependencies(pkg, blacklist) { - var blacklisted = matchdep - .filterAll(Object.keys(blacklist), pkg) + var pluginNames = [ + 'dependencies', + 'devDependencies', + 'peerDependencies', + ].reduce(function(res, prop) { + return res.concat(Object.keys(pkg[prop] || {})); + }, []); + + var blacklisted = pluginNames.filter(isContainedInBlacklist) .reduce(function(blacklisted, pluginName) { blacklisted[pluginName] = blacklist[pluginName]; return blacklisted; }, {}); return blacklisted; + + function isContainedInBlacklist(pluginName) { + return Boolean(blacklist[pluginName]); + } } module.exports = verifyDependencies; diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index b3a0da55..a5cc2a9f 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -4,20 +4,22 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); +var chalk = require('chalk'); var taskTree = require('./task-tree'); var copyTree = require('../../shared/log/copy-tree'); var tildify = require('../../shared/tildify'); var logTasks = require('../../shared/log/tasks'); -var ansi = require('../../shared/ansi'); var exit = require('../../shared/exit'); var logEvents = require('./log/events'); var logTasksSimple = require('./log/tasks-simple'); var registerExports = require('../../shared/register-exports'); var requireOrImport = require('../../shared/require-or-import'); -function execute(opts, env, config) { +function execute(env) { + var opts = env.config.flags; + var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -35,7 +37,7 @@ function execute(opts, env, config) { exit(1); } - log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); + log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); var gulpInst = require(env.modulePath); logEvents(gulpInst); @@ -51,10 +53,10 @@ function execute(opts, env, config) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { - tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; @@ -62,8 +64,8 @@ function execute(opts, env, config) { } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } diff --git a/lib/versioned/^3.7.0/log/events.js b/lib/versioned/^3.7.0/log/events.js index b7bd00a8..a20de7ce 100644 --- a/lib/versioned/^3.7.0/log/events.js +++ b/lib/versioned/^3.7.0/log/events.js @@ -1,9 +1,9 @@ 'use strict'; var log = require('gulplog'); -var prettyTime = require('pretty-hrtime'); +var formatTime = require('../../../shared/log/format-hrtime'); +var chalk = require('chalk'); -var ansi = require('../../../shared/ansi'); var exit = require('../../../shared/exit'); var formatError = require('../format-error'); @@ -26,31 +26,31 @@ function logEvents(gulpInst) { gulpInst.on('task_start', function(e) { // TODO: batch these // so when 5 tasks start at once it only logs one time with all 5 - log.info('Starting', '\'' + ansi.cyan(e.task) + '\'...'); + log.info('Starting', '\'' + chalk.cyan(e.task) + '\'...'); }); gulpInst.on('task_stop', function(e) { - var time = prettyTime(e.hrDuration); + var time = formatTime(e.hrDuration); log.info( - 'Finished', '\'' + ansi.cyan(e.task) + '\'', - 'after', ansi.magenta(time) + 'Finished', '\'' + chalk.cyan(e.task) + '\'', + 'after', chalk.magenta(time) ); }); gulpInst.on('task_err', function(e) { var msg = formatError(e); - var time = prettyTime(e.hrDuration); + var time = formatTime(e.hrDuration); log.error( - '\'' + ansi.cyan(e.task) + '\'', - ansi.red('errored after'), - ansi.magenta(time) + '\'' + chalk.cyan(e.task) + '\'', + chalk.red('errored after'), + chalk.magenta(time) ); log.error(msg); }); gulpInst.on('task_not_found', function(err) { log.error( - ansi.red('Task \'' + err.task + '\' is not in your gulpfile') + chalk.red('Task \'' + err.task + '\' is not in your gulpfile') ); log.error('Please check the documentation for proper gulpfile formatting'); exit(1); diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js index 116956a8..c9c5ffc3 100644 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ b/lib/versioned/^4.0.0-alpha.1/index.js @@ -4,8 +4,8 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); +var chalk = require('chalk'); -var ansi = require('../../shared/ansi'); var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -18,7 +18,8 @@ var registerExports = require('../../shared/register-exports'); var copyTree = require('../../shared/log/copy-tree'); var requireOrImport = require('../../shared/require-or-import'); -function execute(opts, env, config) { +function execute(env) { + var opts = env.config.flags; var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -52,10 +53,10 @@ function execute(opts, env, config) { } if (opts.tasks) { tree = {}; - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { - tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } tree.nodes = gulpInst.tree({ deep: true }); return logTasks(tree, opts, function(taskname) { @@ -64,8 +65,8 @@ function execute(opts, env, config) { } if (opts.tasksJson) { tree = {}; - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } @@ -78,7 +79,7 @@ function execute(opts, env, config) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); + log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -86,7 +87,7 @@ function execute(opts, env, config) { } }); } catch (err) { - log.error(ansi.red(err.message)); + log.error(chalk.red(err.message)); log.error('To list available tasks, try running: gulp --tasks'); exit(1); } diff --git a/lib/versioned/^4.0.0-alpha.2/index.js b/lib/versioned/^4.0.0-alpha.2/index.js index 1fca06fb..3d1763a6 100644 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ b/lib/versioned/^4.0.0-alpha.2/index.js @@ -4,8 +4,8 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); +var chalk = require('chalk'); -var ansi = require('../../shared/ansi'); var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -19,7 +19,8 @@ var copyTree = require('../../shared/log/copy-tree'); var getTask = require('../^4.0.0/log/get-task'); var requireOrImport = require('../../shared/require-or-import'); -function execute(opts, env, config) { +function execute(env) { + var opts = env.config.flags; var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -54,18 +55,18 @@ function execute(opts, env, config) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { - tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } @@ -78,7 +79,7 @@ function execute(opts, env, config) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); + log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -86,7 +87,7 @@ function execute(opts, env, config) { } }); } catch (err) { - log.error(ansi.red(err.message)); + log.error(chalk.red(err.message)); log.error('To list available tasks, try running: gulp --tasks'); exit(1); } diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index f0f0f45b..d6883587 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -5,7 +5,7 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); -var ansi = require('../../shared/ansi'); +var chalk = require('chalk'); var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -19,7 +19,8 @@ var copyTree = require('../../shared/log/copy-tree'); var getTask = require('./log/get-task'); var requireOrImport = require('../../shared/require-or-import'); -function execute(opts, env, config) { +function execute(env) { + var opts = env.config.flags; var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -54,18 +55,18 @@ function execute(opts, env, config) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { - tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } @@ -78,7 +79,7 @@ function execute(opts, env, config) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); + log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -86,7 +87,7 @@ function execute(opts, env, config) { } }); } catch (err) { - log.error(ansi.red(err.message)); + log.error(chalk.red(err.message)); log.error('To list available tasks, try running: gulp --tasks'); exit(1); } diff --git a/lib/versioned/^4.0.0/log/events.js b/lib/versioned/^4.0.0/log/events.js index 1f6e7b16..0fb82c5c 100644 --- a/lib/versioned/^4.0.0/log/events.js +++ b/lib/versioned/^4.0.0/log/events.js @@ -1,9 +1,9 @@ 'use strict'; var log = require('gulplog'); -var prettyTime = require('pretty-hrtime'); +var formatTime = require('../../../shared/log/format-hrtime'); -var ansi = require('../../../shared/ansi'); +var chalk = require('chalk'); var formatError = require('../format-error'); // Wire up logging events @@ -16,27 +16,27 @@ function logEvents(gulpInst) { // TODO: batch these // so when 5 tasks start at once it only logs one time with all 5 var level = evt.branch ? 'debug' : 'info'; - log[level]('Starting', '\'' + ansi.cyan(evt.name) + '\'...'); + log[level]('Starting', '\'' + chalk.cyan(evt.name) + '\'...'); }); gulpInst.on('stop', function(evt) { - var time = prettyTime(evt.duration); + var time = formatTime(evt.duration); /* istanbul ignore next */ var level = evt.branch ? 'debug' : 'info'; log[level]( - 'Finished', '\'' + ansi.cyan(evt.name) + '\'', - 'after', ansi.magenta(time) + 'Finished', '\'' + chalk.cyan(evt.name) + '\'', + 'after', chalk.magenta(time) ); }); gulpInst.on('error', function(evt) { var msg = formatError(evt); - var time = prettyTime(evt.duration); + var time = formatTime(evt.duration); var level = evt.branch ? 'debug' : 'error'; log[level]( - '\'' + ansi.cyan(evt.name) + '\'', - ansi.red('errored after'), - ansi.magenta(time) + '\'' + chalk.cyan(evt.name) + '\'', + chalk.red('errored after'), + chalk.magenta(time) ); // If we haven't logged this before, log it and add to list diff --git a/lib/versioned/^4.0.0/log/get-task.js b/lib/versioned/^4.0.0/log/get-task.js index 1b158714..144acb47 100644 --- a/lib/versioned/^4.0.0/log/get-task.js +++ b/lib/versioned/^4.0.0/log/get-task.js @@ -1,6 +1,6 @@ 'use strict'; -var isObject = require('isobject'); +var isObject = require('../../../shared/is-object'); function getTask(gulpInst) { return function(name) { diff --git a/lib/versioned/^4.0.0/log/sync-task.js b/lib/versioned/^4.0.0/log/sync-task.js index 39cb4536..ff380f10 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -1,7 +1,7 @@ 'use strict'; var log = require('gulplog'); -var ansi = require('../../../shared/ansi'); +var chalk = require('chalk'); var tasks = {}; @@ -19,11 +19,11 @@ function warn() { process.exitCode = 1; log.warn( - ansi.red('The following tasks did not complete:'), - ansi.cyan(taskNames) + chalk.red('The following tasks did not complete:'), + chalk.cyan(taskNames) ); log.warn( - ansi.red('Did you forget to signal async completion?') + chalk.red('Did you forget to signal async completion?') ); } diff --git a/package.json b/package.json index bed47c0f..47ff7595 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "license": "MIT", "man": "gulp.1", "engines": { - "node": ">= 0.10" + "node": ">=10.13.0" }, "main": "index.js", "bin": { @@ -27,43 +27,44 @@ "prepublish": "marked-man --name gulp docs/CLI.md > gulp.1", "pretest": "npm run lint", "test": "mocha --async-only --timeout 5000 test/lib test", - "cover": "nyc --reporter=lcov --reporter=text-summary npm test", - "coveralls": "nyc --reporter=text-lcov npm test | coveralls" + "cover": "nyc mocha --async-only --timeout 5000 test/lib test" }, "dependencies": { - "ansi-colors": "^1.0.1", - "archy": "^1.0.0", - "array-sort": "^1.0.0", - "concat-stream": "^1.6.0", - "color-support": "^1.1.3", - "copy-props": "^2.0.1", - "fancy-log": "^1.3.2", - "gulplog": "^1.0.0", - "interpret": "^1.4.0", - "isobject": "^3.0.1", - "liftoff": "^3.1.0", - "matchdep": "^2.0.0", - "mute-stdout": "^1.0.0", - "pretty-hrtime": "^1.0.0", - "replace-homedir": "^1.0.0", - "semver-greatest-satisfied-range": "^1.1.0", - "v8flags": "^3.2.0", - "yargs": "^7.1.0" + "chalk": "^4.1.2", + "copy-props": "^4.0.0", + "fancy-log": "^2.0.0", + "gulplog": "^2.0.1", + "interpret": "^3.1.1", + "liftoff": "^4.0.0", + "mute-stdout": "^2.0.0", + "replace-homedir": "^2.0.0", + "semver-greatest-satisfied-range": "^2.0.0", + "v8flags": "^4.0.0", + "yargs": "^16.2.0" }, "devDependencies": { - "babel-preset-es2015": "^6.5.0", - "babel-register": "^6.5.1", - "coveralls": "^3.0.3", - "eslint": "^2.13.1", - "eslint-config-gulp": "^3.0.1", - "expect": "^1.20.2", - "gulp": "^4.0.0", - "gulp-test-tools": "^0.6.1", - "marked-man": "^0.2.1", - "mocha": "^3.2.0", - "nyc": "^13.3.0", - "rimraf": "^2.6.1", - "semver": "^5.7.1" + "@babel/core": "^7.20.2", + "@babel/preset-env": "^7.20.2", + "@babel/register": "^7.18.9", + "eslint": "^7.32.0", + "eslint-config-gulp": "^5.0.1", + "expect": "^27.5.1", + "gulp": "^4.0.2", + "marked-man": "^0.7.0", + "marked": "^0.7.0", + "mocha": "^8.4.0", + "nyc": "^15.1.0", + "rimraf": "^3.0.2", + "semver": "^7.3.8" + }, + "nyc": { + "reporter": [ + "lcov", + "text-summary" + ] + }, + "prettier": { + "singleQuote": true }, "keywords": [ "build", diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index ce82a15a..00000000 --- a/test/.eslintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "gulp/test", - "rules": { - "no-console": "off" - } -} diff --git a/test/completion.js b/test/completion.js index 745422b5..3c30ad74 100644 --- a/test/completion.js +++ b/test/completion.js @@ -1,10 +1,12 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; +var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); +var gulp = require('./tool/gulp-cmd'); + describe('flag: --completion', function() { ['bash', 'fish', 'powershell', 'zsh'].forEach(function(type) { @@ -12,12 +14,10 @@ describe('flag: --completion', function() { var file = path.resolve(__dirname, '../completion', type); var expected = fs.readFileSync(file, 'utf8') + '\n'; - runner({ verbose: false }) - .gulp('--completion=' + type) - .run(cb); + exec(gulp('--completion=' + type), cb); function cb(err, stdout, stderr) { - expect(err).toNotExist(); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(expected); done(err); @@ -26,15 +26,12 @@ describe('flag: --completion', function() { }); it('shows error message for unknown completion type', function(done) { - var expected = - 'echo "gulp autocompletion rules for \'unknown\' not found"\n'; + var expected = 'echo "gulp autocompletion rules for \'unknown\' not found"\n'; - runner({ verbose: false }) - .gulp('--completion=unknown') - .run(cb); + exec(gulp('--completion=unknown'), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(expected); done(); @@ -42,12 +39,10 @@ describe('flag: --completion', function() { }); it('shows error message for missing completion type', function(done) { - runner({ verbose: false }) - .gulp('--completion') - .run(cb); + exec(gulp('--completion'), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stderr).toMatch('Missing completion type'); expect(stdout).toEqual(''); done(); diff --git a/test/config-description.js b/test/config-description.js index 41709909..ac85fd70 100644 --- a/test/config-description.js +++ b/test/config-description.js @@ -1,68 +1,71 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var runner = require('gulp-test-tools').gulpRunner; +var sliceLines = require('./tool/slice-lines'); +var eraseTime = require('./tool/erase-time'); +var gulp = require('./tool/gulp-cmd'); -var fixturesDir = path.join(__dirname, 'fixtures', 'config'); +var baseDir = path.join(__dirname, 'fixtures', 'config'); var expectedDir = path.join(__dirname, 'expected', 'config'); describe('config: description', function() { it('Should configure with a .gulp.* file in cwd', function(done) { - runner({ verbose: false }) - .basedir(fixturesDir) - .chdir('foo/bar') - .gulp('--tasks') - .run(cb); + var opts = { cwd: path.join(baseDir, 'foo/bar') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), - 'utf-8'); - stdout = eraseTime(stdout); - expect(stdout).toEqual(expected); + var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); + expect(eraseTime(stdout)).toEqual(expected); done(err); } }); it('Should configure with a .gulp.* file in cwd found up', function(done) { - runner({ verbose: false }) - .basedir(fixturesDir) - .chdir('foo/bar/baz') - .gulp('--tasks') - .run(cb); + var opts = { cwd: path.join(baseDir, 'foo/bar/baz') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), - 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); + expect(sliceLines(stdout, 1)).toEqual(expected); + done(err); + } + }); + + it('Should configure with a .gulp.* file in cwd even if it is not a project root', function(done) { + var opts = { cwd: path.join(baseDir, 'foo/bar/quux') }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + var expected = fs.readFileSync(path.join(expectedDir, 'output2.txt'), 'utf-8'); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); it('Should configure with a .gulp.* file in cwd by --cwd', function(done) { - runner({ verbose: false }) - .basedir(fixturesDir) - .chdir('qux') - .gulp('--tasks', '--gulpfile ../foo/bar/gulpfile.js', '--cwd .') - .run(cb); + var opts = { cwd: path.join(baseDir, 'qux') }; + exec(gulp( + '--tasks', + '--gulpfile ../foo/bar/gulpfile.js', + '--cwd .' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'), - 'utf-8'); - stdout = eraseTime(stdout); - expect(stdout).toEqual(expected); + var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'), 'utf-8'); + expect(eraseTime(stdout)).toEqual(expected); done(err); } }); diff --git a/test/config-flags-compactTasks.js b/test/config-flags-compact-tasks.js similarity index 59% rename from test/config-flags-compactTasks.js rename to test/config-flags-compact-tasks.js index 460af741..06945128 100644 --- a/test/config-flags-compactTasks.js +++ b/test/config-flags-compact-tasks.js @@ -1,51 +1,42 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var fixturesDir = path.join(__dirname, 'fixtures/config'); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/compactTasks'); var expectedDir = path.join(__dirname, 'expected'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); describe('config: flags.compactTasks', function() { - it('Should compact task lists when `flags.compactTasks` is true in .gulp.*', - function(done) { - runner - .chdir('flags/compactTasks/t') - .gulp('--tasks') - .run(cb); + it('Should compact task lists when `flags.compactTasks` is true in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - + expected = sliceLines(expected, 1); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); } }); - it('Should not compact task lists when `flags.compactTasks` is false in ' + - '.gulp.*', function(done) { - runner - .chdir('flags/compactTasks/f') - .gulp('--tasks') - .run(cb); + it('Should not compact task lists when `flags.compactTasks` is false in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - + expected = sliceLines(expected, 1); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); @@ -53,18 +44,14 @@ describe('config: flags.compactTasks', function() { }); it('Should overridden by cli flag: --compact-tasks', function(done) { - runner - .chdir('flags/compactTasks/f') - .gulp('--tasks --compact-tasks') - .run(cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--tasks', '--compact-tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - + expected = sliceLines(expected, 1); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); @@ -72,18 +59,14 @@ describe('config: flags.compactTasks', function() { }); it('Should overridden by cli flag: --no-compact-tasks', function(done) { - runner - .chdir('flags/compactTasks/t') - .gulp('--tasks --no-compact-tasks') - .run(cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--tasks', '--no-compact-tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - + expected = sliceLines(expected, 1); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); diff --git a/test/config-flags-continue.js b/test/config-flags-continue.js index 30edf19b..5764bfbb 100644 --- a/test/config-flags-continue.js +++ b/test/config-flags-continue.js @@ -1,28 +1,23 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); -var skipLines = require('gulp-test-tools').skipLines; -var headLines = require('gulp-test-tools').headLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var eraseLapse = require('gulp-test-tools').eraseLapse; -var fixturesDir = path.join(__dirname, 'fixtures/config'); -var runner = require('gulp-test-tools').gulpRunner({ verbose: false }).basedir(fixturesDir); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/continue'); describe('config: flags.continue', function() { - it('Should continue if `flags.continue` is true in .gulp.*', - function(done) { - runner - .chdir('flags/continue/t') - .gulp() - .run(cb); + it('Should continue if `flags.continue` is true in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + expect(err).not.toBeNull(); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + @@ -30,7 +25,7 @@ describe('config: flags.continue', function() { 'Finished \'next\' after ?\n' + '' ); - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); + stderr = sliceLines(stderr, 0, 2); expect(stderr).toEqual( '\'err\' errored after ?\n' + 'Error: Error!' @@ -39,23 +34,19 @@ describe('config: flags.continue', function() { } }); - it('Should not continue if `flags.continue` is false in .gulp.*', - function(done) { - runner - .chdir('flags/continue/f') - .gulp() - .run(cb); + it('Should not continue if `flags.continue` is false in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + expect(err).not.toBeNull(); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + '' ); - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); + stderr = sliceLines(stderr, 0, 2); expect(stderr).toEqual( '\'err\' errored after ?\n' + 'Error: Error!' @@ -65,15 +56,12 @@ describe('config: flags.continue', function() { }); it('Should overridden by cli flag: --continue', function(done) { - runner - .chdir('flags/continue/f') - .gulp('--continue') - .run(cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--continue'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + expect(err).not.toBeNull(); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + @@ -81,7 +69,7 @@ describe('config: flags.continue', function() { 'Finished \'next\' after ?\n' + '' ); - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); + stderr = sliceLines(stderr, 0, 2); expect(stderr).toEqual( '\'err\' errored after ?\n' + 'Error: Error!' @@ -91,21 +79,18 @@ describe('config: flags.continue', function() { }); it('Should overridden by cli flag: --no-continue', function(done) { - runner - .chdir('flags/continue/t') - .gulp('--no-continue') - .run(cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--no-continue'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + expect(err).not.toBeNull(); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + '' ); - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); + stderr = sliceLines(stderr, 0, 2); expect(stderr).toEqual( '\'err\' errored after ?\n' + 'Error: Error!' diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index 3ac37ac1..329043d4 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -1,105 +1,117 @@ 'use strict'; var expect = require('expect'); - +var exec = require('child_process').exec; var path = require('path'); -var fixturesDir = path.join(__dirname, 'fixtures/config'); -var headLines = require('gulp-test-tools').headLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/gulpfile'); +var prjDir = path.join(baseDir, 'prj'); describe('config: flags.gulpfile', function() { it('Should configure with a .gulp.* file', function(done) { - runner - .chdir('flags/gulpfile') - .gulp() - .run(cb); + var opts = { cwd: prjDir }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = headLines(stdout, 2, 2); - expect(stdout).toEqual( - 'This gulpfile : ' + - path.join(fixturesDir, 'flags/gulpfile/is/here/mygulpfile.js') + - '\n' + - 'The current directory : ' + path.join(fixturesDir, 'flags/gulpfile') + expect(sliceLines(stdout, 2, 4)).toEqual( + 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-prj-cfg.js') + '\n' + + 'The current directory : ' + prjDir ); done(err); } }); - it('Should configure with a .gulp.* file in the directory specified by ' + - '\n\t--cwd', function(done) { - runner - .gulp('--cwd ./flags/gulpfile') - .run(cb); + it('Should configure with a .gulp.* file in the directory specified by --cwd', function(done) { + var opts = { cwd: prjDir }; + exec(gulp('--cwd ../cwd'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = headLines(stdout, 2, 3); - expect(stdout).toEqual( - 'This gulpfile : ' + - path.join(fixturesDir, 'flags/gulpfile/is/here/mygulpfile.js') + - '\n' + - 'The current directory : ' + path.join(fixturesDir, 'flags/gulpfile') + expect(sliceLines(stdout, 3, 5)).toEqual( + 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-cwd-cfg.js') + '\n' + + 'The current directory : ' + path.join(baseDir, 'cwd') ); done(err); } }); - it('Should ignore a ./gulp.* file if another directory is specified by ' + - '\n\t--cwd', function(done) { - runner - .chdir('./flags/gulpfile') - .gulp('--cwd ./cwd') - .run(cb); + it('Should configure with a .gulp.* file found up', function(done) { + var opts = { cwd: path.join(prjDir, 'findup') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = headLines(stdout, 1, 3); - expect(stdout).toEqual( - 'Another gulpfile : ' + - path.join(fixturesDir, 'flags/gulpfile/cwd/gulpfile.js') + expect(sliceLines(stdout, 2, 4)).toEqual( + 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-prj-cfg.js') + '\n' + + 'The current directory : ' + path.join(prjDir, 'findup') ); done(err); } }); - it('Should ignore a ./.gulp.* file if another gulpfile is specified by ' + - '\n\t--gulpfile', function(done) { - runner - .chdir('./flags/gulpfile') - .gulp('--gulpfile ./cwd/gulpfile.js') - .run(cb); + it('Should configure with a .gulp.* file found up the directory specified by --cwd', function(done) { + var opts = { cwd: prjDir }; + exec(gulp('--cwd ../cwd/findup'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = headLines(stdout, 1, 3); - expect(stdout).toEqual( - 'Another gulpfile : ' + - path.join(fixturesDir, 'flags/gulpfile/cwd/gulpfile.js') + expect(sliceLines(stdout, 3, 5)).toEqual( + 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-cwd-cfg.js') + '\n' + + 'The current directory : ' + path.join(baseDir, 'cwd/findup') + ); + done(err); + } + }); + + it('Should ignore a ./gulp.* file if another directory is specified by --cwd', function(done) { + var opts = { cwd: prjDir }; + exec(gulp('--cwd ../is/here'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 3, 5)).toEqual( + 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile.js') + '\n' + + 'The current directory : ' + path.join(baseDir, 'is/here') + ); + done(err); + } + }); + + it('Should ignore a ./.gulp.* file if another gulpfile is specified by --gulpfile', function(done) { + var opts = { cwd: prjDir }; + exec(gulp('--gulpfile ../is/here/gulpfile.js'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 3, 5)).toEqual( + 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile.js') + '\n' + + 'The current directory : ' + path.join(baseDir, 'is/here') ); done(err); } }); it('Should overridden by cli flag: --gulpfile', function(done) { - runner - .chdir('./flags/gulpfile/override-by-cliflag') - .gulp('--gulpfile mygulpfile.js') - .run(cb); + var opts = { cwd: path.join(baseDir, 'override-by-cliflag') }; + exec(gulp('--gulpfile mygulpfile.js'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = headLines(stdout, 1, 2); - expect(stdout).toEqual('Gulpfile : ' + path.join(fixturesDir, 'flags/gulpfile/override-by-cliflag/mygulpfile.js')); + expect(sliceLines(stdout, 2, 3)).toEqual( + 'Gulpfile : ' + path.join(baseDir, 'override-by-cliflag/mygulpfile.js') + ); done(err); } }); @@ -107,25 +119,30 @@ describe('config: flags.gulpfile', function() { it('Should autoload a module for loading a specified gulpfile', function(done) { this.timeout(0); - runner - .chdir('flags/gulpfile/autoload') - .gulp('dist') - .run(cb); + var opts = { cwd: path.join(baseDir, 'autoload') }; + exec(gulp('dist'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Loaded external module: @babel/register'); + expect(sliceLines(stdout, 4, 5)).toEqual('clean!'); + expect(sliceLines(stdout, 7, 8)).toEqual('build!'); + done(err); + } + }); - var requiring = eraseTime(headLines(stdout, 1)); - expect(requiring).toEqual('Requiring external module babel-register'); - var clean = eraseTime(headLines(stdout, 1, 4)); - expect(clean).toEqual('clean!'); - var build = eraseTime(headLines(stdout, 1, 7)); - expect(build).toEqual('build!'); + it('Should output error logs of autoload if fail to load module for a specified gulpfile', function(done) { + var opts = { cwd: path.join(baseDir, 'autoload-fail') }; + exec(gulp('dist'), opts, cb); - done(err); + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).not.toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Failed to load external module: coffeescript/register'); + expect(sliceLines(stdout, 1, 2)).toMatch('Error: Cannot find module \'coffeescript/register\''); + done(); } }); }); - diff --git a/test/config-flags-log-level.js b/test/config-flags-log-level.js index c3c20918..8d187cf0 100644 --- a/test/config-flags-log-level.js +++ b/test/config-flags-log-level.js @@ -1,196 +1,206 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); -var eraseTime = require('gulp-test-tools').eraseTime; -var headLines = require('gulp-test-tools').headLines; -var runner = require('gulp-test-tools').gulpRunner; + +var sliceLines = require('./tool/slice-lines'); +var eraseTime = require('./tool/erase-time'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/logLevel'); describe('config: flag.logLevel', function() { describe('log level 3 by default', function() { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel')) - .gulp; it('Should output error log', function(done) { - gulp('--gulpfile x') - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); - done(); - }); + var opts = { cwd: baseDir }; + exec(gulp('--gulpfile x'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + } }); it('Should output warn log', function(done) { - gulp('--require', 'mymodule') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(headLines(eraseTime(stdout), 2)).toMatch( - 'Failed to load external module mymodule\n' + - 'Error: Cannot find module \'mymodule\' from \''); - done(); - }); + var opts = { cwd: baseDir }; + exec(gulp('--preload mymodule'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 1, 3)).toMatch( + 'Failed to preload external module: mymodule\n' + + 'Error: Cannot find module \'mymodule\' from \''); + done(); + } }); it('Should output info log', function(done) { - gulp('--harmony') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(headLines(eraseTime(stdout), 2)).toMatch( - 'Node flags detected: --harmony\n' + - 'Respawned to PID: '); - done(err); - }); + var opts = { cwd: baseDir }; + exec(gulp('--harmony'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 2)).toMatch( + 'Node flags detected: --harmony\n' + + 'Respawned to PID: '); + done(err); + } }); }); describe('log level 1 by config `flags.logLevel`', function() { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/L')) - .gulp; it('Should output error log', function(done) { - gulp('--gulpfile x') - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); - done(); - }); + var opts = { cwd: baseDir }; + exec(gulp('--gulpfile x'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + } }); it('Should output warn log', function(done) { - gulp('--require', 'mymodule') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(stderr).toEqual(''); - done(); - }); + var opts = { cwd: path.join(baseDir, 'L') }; + exec(gulp('--preload mymodule'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stderr).toEqual(''); + done(); + } }); it('Should output info log', function(done) { - gulp('--harmony') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(stdout).toEqual(''); - done(err); - }); + var opts = { cwd: path.join(baseDir, 'L') }; + exec(gulp('--harmony'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(''); + done(err); + } }); }); describe('log level 2 by config `flags.logLevel`', function() { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LL')) - .gulp; - it('Should output error log', function(done) { - gulp('--gulpfile x') - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); - done(); - }); + var opts = { cwd: path.join(baseDir, 'LL') }; + exec(gulp('--gulpfile x'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + } }); it('Should output warn log', function(done) { - gulp('--require', 'mymodule') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toMatch( - 'Failed to load external module mymodule\n' + - 'Error: Cannot find module \'mymodule\' from \''); - done(); - }); + var opts = { cwd: path.join(baseDir, 'LL') }; + exec(gulp('--preload mymodule'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toMatch( + 'Failed to preload external module: mymodule\n' + + 'Error: Cannot find module \'mymodule\' from \''); + done(); + } }); it('Should output info log', function(done) { - gulp('--harmony') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(stdout).toEqual(''); - done(err); - }); + var opts = { cwd: path.join(baseDir, 'LL') }; + exec(gulp('--harmony'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(''); + done(err); + } }); }); describe('log level 3 by config `flags.logLevel`', function() { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LLL')) - .gulp; - it('Should output error log', function(done) { - gulp('--gulpfile x') - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); - done(); - }); + var opts = { cwd: path.join(baseDir, 'LLL') }; + exec(gulp('--gulpfile x'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + } }); it('Should output warn log', function(done) { - gulp('--require', 'mymodule') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(headLines(eraseTime(stdout), 2)).toMatch( - 'Failed to load external module mymodule\n' + - 'Error: Cannot find module \'mymodule\' from \''); - done(); - }); + var opts = { cwd: path.join(baseDir, 'LLL') }; + exec(gulp('--preload mymodule'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toMatch( + 'Failed to preload external module: mymodule\n' + + 'Error: Cannot find module \'mymodule\' from \''); + done(); + } }); it('Should output info log', function(done) { - gulp('--harmony') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(headLines(eraseTime(stdout), 2)).toMatch( - 'Node flags detected: --harmony\n' + - 'Respawned to PID: '); - done(err); - }); + var opts = { cwd: path.join(baseDir, 'LLL') }; + exec(gulp('--harmony'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 2)).toMatch( + 'Node flags detected: --harmony\n' + + 'Respawned to PID: '); + done(err); + } }); }); describe('Overridden by cli flag: -L/-LL/-LLL', function() { it('Should not output info log by -L', function(done) { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LLL')) - .gulp; - - gulp('-L', '--require', 'mymodule') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stdout).toEqual(''); - expect(stderr).toEqual(''); - done(err); - }); + var opts = { cwd: path.join(baseDir, 'LLL') }; + exec(gulp('-L', '--preload mymodule'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(''); + done(err); + } }); it('Should output info log by -LLL', function(done) { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/L')) - .gulp; - - gulp('-LLL', '--harmony') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(headLines(eraseTime(stdout), 2)).toMatch( - 'Node flags detected: --harmony\n' + - 'Respawned to PID: '); - done(err); - }); + var opts = { cwd: path.join(baseDir, 'L') }; + exec(gulp('-LLL', '--harmony'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 2)).toMatch( + 'Node flags detected: --harmony\n' + + 'Respawned to PID: '); + done(err); + } }); }); }); diff --git a/test/config-flags-node-flags.js b/test/config-flags-node-flags.js index ac05dbb3..eb9c00cb 100644 --- a/test/config-flags-node-flags.js +++ b/test/config-flags-node-flags.js @@ -1,88 +1,64 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); -var fixturesDir = path.join(__dirname, 'fixtures/config'); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); -var headLines = require('gulp-test-tools').headLines; -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var eraseLapse = require('gulp-test-tools').eraseLapse; +var baseDir = path.join(__dirname, 'fixtures/config/flags/nodeFlags'); describe('config: nodeFlags', function() { it('Should respawn by a node flag: --lazy', function(done) { - runner - .chdir('flags/nodeFlags/string') - .gulp() - .run(cb); + var opts = { cwd: path.join(baseDir, 'string') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - var line = eraseTime(headLines(stdout, 1)); - expect(line).toEqual('Node flags detected: --lazy'); - - line = eraseTime(headLines(stdout, 2, 1)); - expect(line).toMatch('Respawned to PID: '); + expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --lazy'); + expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); done(err); } }); it('Should respawn by a node flag: --lazy --trace-deprecation', function(done) { - runner - .chdir('flags/nodeFlags/array') - .gulp() - .run(cb); + var opts = { cwd: path.join(baseDir, 'array') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - var line = eraseTime(headLines(stdout, 1)); - expect(line).toEqual('Node flags detected: --lazy, --trace-deprecation'); - - line = eraseTime(headLines(stdout, 2, 1)); - expect(line).toMatch('Respawned to PID: '); + expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --lazy, --trace-deprecation'); + expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); done(err); } }); it('Should respawn with flags in config file and command line', function(done) { - runner - .chdir('flags/nodeFlags/string') - .gulp('--harmony') - .run(cb); + var opts = { cwd: path.join(baseDir, 'string') }; + exec(gulp('--harmony'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - var line = eraseTime(headLines(stdout, 1)); - expect(line).toEqual('Node flags detected: --lazy, --harmony'); - - line = eraseTime(headLines(stdout, 2, 1)); - expect(line).toMatch('Respawned to PID: '); + expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --lazy, --harmony'); + expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); done(err); } }); it('Should not respawn when a node flag is specified to undefined', function(done) { - runner - .chdir('flags/nodeFlags/undefined') - .gulp() - .run(cb); + var opts = { cwd: path.join(baseDir, 'undefined') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - stdout = eraseLapse(eraseTime(stdout)); - expect(headLines(stdout, 1)).toMatch('Using gulpfile '); - expect(skipLines(stdout, 1)).toEqual( + expect(sliceLines(stdout, 0, 1)).toMatch('Using gulpfile '); + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'default\'...\n' + 'Default\n' + 'Finished \'default\' after ?\n' + @@ -92,18 +68,14 @@ describe('config: nodeFlags', function() { }); it('Should not respawn when a node flag is specified to null', function(done) { - runner - .chdir('flags/nodeFlags/null') - .gulp() - .run(cb); + var opts = { cwd: path.join(baseDir, 'null') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - stdout = eraseLapse(eraseTime(stdout)); - expect(headLines(stdout, 1)).toMatch('Using gulpfile '); - expect(skipLines(stdout, 1)).toEqual( + expect(sliceLines(stdout, 0, 1)).toMatch('Using gulpfile '); + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'default\'...\n' + 'Default\n' + 'Finished \'default\' after ?\n' + @@ -111,5 +83,4 @@ describe('config: nodeFlags', function() { done(err); } }); - }); diff --git a/test/config-flags-preload.js b/test/config-flags-preload.js new file mode 100644 index 00000000..47942363 --- /dev/null +++ b/test/config-flags-preload.js @@ -0,0 +1,90 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); + +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/preload'); + +describe('config: flags.preload', function() { + + it('Should configure with an array in a .gulp.* file', function(done) { + var opts = { cwd: path.join(baseDir, 'array') }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ./preload_one'); + expect(sliceLines(stdout, 1, 2)).toEqual('Preloaded external module: ./preload_one'); + expect(sliceLines(stdout, 2, 3)).toEqual('Preloading external module: ./preload_two'); + expect(sliceLines(stdout, 3, 4)).toEqual('Preloaded external module: ./preload_two'); + expect(sliceLines(stdout, 6, 7)).toEqual('preload one!'); + expect(sliceLines(stdout, 7, 8)).toEqual('preload two!'); + done(err); + } + }); + + it('Should configure with a string in a .gulp.* file', function(done) { + var opts = { cwd: path.join(baseDir, 'string') }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ./preload'); + expect(sliceLines(stdout, 1, 2)).toEqual('Preloaded external module: ./preload'); + expect(sliceLines(stdout, 4, 5)).toEqual('hello preload!'); + done(err); + } + }); + + it('Combines --preload flag with .gulp.* file flags.preload', function(done) { + var opts = { cwd: path.join(baseDir, 'join-flags') }; + exec(gulp('--preload ./preload_one'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ./preload_one'); + expect(sliceLines(stdout, 1, 2)).toEqual('Preloaded external module: ./preload_one'); + expect(sliceLines(stdout, 2, 3)).toEqual('Preloading external module: ./preload_two'); + expect(sliceLines(stdout, 3, 4)).toEqual('Preloaded external module: ./preload_two'); + expect(sliceLines(stdout, 6, 7)).toEqual('preload one!'); + expect(sliceLines(stdout, 7, 8)).toEqual('preload two!'); + done(err); + } + }); + + it('resolves relative requires against cwd', function(done) { + var opts = { cwd: path.join(__dirname, 'fixtures/config') }; + exec(gulp('--cwd flags/preload/with-cwd'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ../preload'); + expect(sliceLines(stdout, 1, 2)).toEqual('Preloaded external module: ../preload'); + expect(sliceLines(stdout, 5, 6)).toEqual('hello preload!'); + done(err); + } + }); + + it('works with absolute paths, ignoring cwd', function(done) { + var opts = { cwd: path.join(__dirname, 'fixtures/config') }; + exec(gulp('--cwd flags/preload/with-absolute'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + var absolute = path.join(__dirname, './fixtures/config/flags/preload/preload'); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ' + absolute); + expect(sliceLines(stdout, 1, 2)).toEqual('Preloaded external module: ' + absolute); + expect(sliceLines(stdout, 5, 6)).toEqual('hello preload!'); + done(err); + } + }); +}); diff --git a/test/config-flags-require.js b/test/config-flags-require.js deleted file mode 100644 index 6db4de52..00000000 --- a/test/config-flags-require.js +++ /dev/null @@ -1,109 +0,0 @@ -'use strict'; - -var expect = require('expect'); - -var path = require('path'); -var fixturesDir = path.join(__dirname, 'fixtures/config'); - -var headLines = require('gulp-test-tools').headLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); - -describe('config: flags.require', function() { - - it('Should configure with an array in a .gulp.* file', function(done) { - runner - .chdir('flags/require/array') - .gulp() - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - - var requiring1 = eraseTime(headLines(stdout, 1)); - expect(requiring1).toEqual('Requiring external module ./preload_one'); - var requiring2 = eraseTime(headLines(stdout, 1, 1)); - expect(requiring2).toEqual('Requiring external module ./preload_two'); - var preload1 = eraseTime(headLines(stdout, 1, 4)); - expect(preload1).toEqual('preload one!'); - var preload2 = eraseTime(headLines(stdout, 1, 5)); - expect(preload2).toEqual('preload two!'); - done(err); - } - }); - - it('Should configure with a string in a .gulp.* file', function(done) { - runner - .chdir('flags/require/string') - .gulp() - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - var requiring = eraseTime(headLines(stdout, 1)); - expect(requiring).toEqual('Requiring external module ./preload'); - var preload1 = eraseTime(headLines(stdout, 1, 3)); - expect(preload1).toEqual('hello preload!'); - done(err); - } - }); - - it('Combines --require flag with .gulp.* file flags.require', function(done) { - runner - .chdir('flags/require/join-flags') - .gulp('--require ./preload_one') - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - - var requiring1 = eraseTime(headLines(stdout, 1)); - expect(requiring1).toEqual('Requiring external module ./preload_one'); - var requiring2 = eraseTime(headLines(stdout, 1, 1)); - expect(requiring2).toEqual('Requiring external module ./preload_two'); - var preload1 = eraseTime(headLines(stdout, 1, 4)); - expect(preload1).toEqual('preload one!'); - var preload2 = eraseTime(headLines(stdout, 1, 5)); - expect(preload2).toEqual('preload two!'); - done(err); - } - }); - - it('resolves relative requires against cwd', function(done) { - runner - .gulp('--cwd flags/require/with-cwd') - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - var requiring = eraseTime(headLines(stdout, 1)); - expect(requiring).toEqual('Requiring external module ../preload'); - var preload1 = eraseTime(headLines(stdout, 1, 4)); - expect(preload1).toEqual('hello preload!'); - done(err); - } - }); - - it('works with absolute paths, ignoring cwd', function(done) { - runner - .gulp('--cwd flags/require/with-absolute') - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - - var absolute = path.join(__dirname, './fixtures/config/flags/require/preload'); - var requiring = eraseTime(headLines(stdout, 1)); - expect(requiring).toEqual('Requiring external module ' + absolute); - var preload1 = eraseTime(headLines(stdout, 1, 4)); - expect(preload1).toEqual('hello preload!'); - done(err); - } - }); -}); - diff --git a/test/config-flags-series.js b/test/config-flags-series.js index f6145712..b298322a 100644 --- a/test/config-flags-series.js +++ b/test/config-flags-series.js @@ -1,75 +1,60 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var eraseLapse = require('gulp-test-tools').eraseLapse; +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); -var fixturesDir = path.join(__dirname, 'fixtures/config'); -var runner = require('gulp-test-tools').gulpRunner({ verbose: false }).basedir(fixturesDir); +var baseDir = path.join(__dirname, 'fixtures/config/flags/series'); describe('config: flags.series', function() { - it('Should run in series if `flags.series` is true in .gulp.*', - function(done) { - runner - .chdir('flags/series/t') - .gulp('task1 task2') - .run(cb); + it('Should run in series if `flags.series` is true in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('task1', 'task2'), opts, cb); - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); - expect(stdout).toEqual( - 'Starting \'task1\'...\n' + - 'Finished \'task1\' after ?\n' + - 'Starting \'task2\'...\n' + - 'Finished \'task2\' after ?\n' + - '' - ); - done(); - } - }); - - it('Should run in parallel if `flags.series` is false in .gulp.*', - function(done) { - runner - .chdir('flags/series/f') - .gulp('task1 task2') - .run(cb); + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 1)).toEqual( + 'Starting \'task1\'...\n' + + 'Finished \'task1\' after ?\n' + + 'Starting \'task2\'...\n' + + 'Finished \'task2\' after ?\n' + + '' + ); + done(); + } + }); - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); + it('Should run in parallel if `flags.series` is false in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('task1', 'task2'), opts, cb); - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); - expect(stdout).toEqual( - 'Starting \'task1\'...\n' + - 'Starting \'task2\'...\n' + - 'Finished \'task2\' after ?\n' + - 'Finished \'task1\' after ?\n' + - '' - ); - done(); - } - }); + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 1)).toEqual( + 'Starting \'task1\'...\n' + + 'Starting \'task2\'...\n' + + 'Finished \'task2\' after ?\n' + + 'Finished \'task1\' after ?\n' + + '' + ); + done(); + } + }); it('Should overridden by cli flag: --series', function(done) { - runner - .chdir('flags/series/f') - .gulp('--series', 'task1 task2') - .run(cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--series', 'task1', 'task2'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); - expect(stdout).toEqual( + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'task1\'...\n' + 'Finished \'task1\' after ?\n' + 'Starting \'task2\'...\n' + @@ -81,17 +66,13 @@ describe('config: flags.series', function() { }); it('Should overridden by cli flag: --no-series', function(done) { - runner - .chdir('flags/series/t') - .gulp('--no-series', 'task1 task2') - .run(cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--no-series', 'task1', 'task2'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); - expect(stdout).toEqual( + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'task1\'...\n' + 'Starting \'task2\'...\n' + 'Finished \'task2\' after ?\n' + diff --git a/test/config-flags-silent.js b/test/config-flags-silent.js index 4be02492..527bbc8f 100644 --- a/test/config-flags-silent.js +++ b/test/config-flags-silent.js @@ -1,43 +1,36 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var eraseLapse = require('gulp-test-tools').eraseLapse; -var fixturesDir = path.join(__dirname, 'fixtures/config'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/silent'); describe('config: flags.silent', function() { - it('Should be silent if `flags.silent` is true in .gulp.*', - function(done) { - runner - .chdir('flags/silent/t') - .gulp() - .run(cb); + it('Should be silent if `flags.silent` is true in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(''); done(err); } }); - it('Should not be silent if `flags.silent` is false in .gulp.*', - function(done) { - runner - .chdir('flags/silent/f') - .gulp() - .run(cb); + it('Should not be silent if `flags.silent` is false in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); - expect(stdout).toEqual( + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'default\'...\n' + 'Finished \'default\' after ?\n' + '' @@ -47,13 +40,11 @@ describe('config: flags.silent', function() { }); it('Should overridden by cli flag: --silent', function(done) { - runner - .chdir('flags/silent/f') - .gulp('--silent') - .run(cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--silent'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(''); done(err); @@ -61,16 +52,13 @@ describe('config: flags.silent', function() { }); it('Should overridden by cli flag: --no-silent', function(done) { - runner - .chdir('flags/silent/t') - .gulp('--no-silent') - .run(cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--no-silent'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); - expect(stdout).toEqual( + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'default\'...\n' + 'Finished \'default\' after ?\n' + '' diff --git a/test/config-flags-sortTasks.js b/test/config-flags-sort-tasks.js similarity index 51% rename from test/config-flags-sortTasks.js rename to test/config-flags-sort-tasks.js index d087dacd..01eada8d 100644 --- a/test/config-flags-sortTasks.js +++ b/test/config-flags-sort-tasks.js @@ -1,90 +1,65 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var fixturesDir = path.join(__dirname, 'fixtures/config'); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/sortTasks'); var expectedDir = path.join(__dirname, 'expected'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); -describe ('config: flags.sortTasks', function() { +describe('config: flags.sortTasks', function() { - it('Should sort top tasks in task list when `flags.sortTasks` is true in ' + - '.gulp.*', function(done) { - runner - .chdir('flags/sortTasks/t') - .gulp('--tasks') - .run(cb); + it('Should sort top tasks in task list when `flags.sortTasks` is true in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); expect(stderr).toEqual(''); done(err); } }); - it('Should sort top tasks in task list when `flags.sortTasks` is false in ' + - '.gulp.*', function(done) { - runner - .chdir('flags/sortTasks/f') - .gulp('--tasks') - .run(cb); + it('Should sort top tasks in task list when `flags.sortTasks` is false in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); expect(stderr).toEqual(''); done(err); } }); it('Should overridden by cli flag: --sort-tasks', function(done) { - runner - .chdir('flags/sortTasks/f') - .gulp('--tasks --sort-tasks') - .run(cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--tasks', '--sort-tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); expect(stderr).toEqual(''); done(err); } }); it('Should overridden by cli flag: --no-sort-tasks', function(done) { - runner - .chdir('flags/sortTasks/t') - .gulp('--tasks --no-sort-tasks') - .run(cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--tasks', '--no-sort-tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); expect(stderr).toEqual(''); done(err); } diff --git a/test/config-flags-tasks-depth.js b/test/config-flags-tasks-depth.js new file mode 100644 index 00000000..944766c2 --- /dev/null +++ b/test/config-flags-tasks-depth.js @@ -0,0 +1,41 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); +var fs = require('fs'); + +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/tasksDepth'); +var expectedDir = path.join(__dirname, 'expected'); + +describe('config: flags.tasksDepth', function() { + + it('Should limit depth of task list when `flags.tasksDepth` is specified', function(done) { + var opts = { cwd: baseDir }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); + var expected = fs.readFileSync(filepath, 'utf-8'); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(stderr).toEqual(''); + done(err); + } + }); + + it('Should overridden by cli flag: --tasks-depth', function(done) { + var opts = { cwd: baseDir }; + exec(gulp('--tasks', '--tasks-depth', '2'), opts, cb); + + function cb(err, stdout, stderr) { + var filepath = path.join(expectedDir, 'flags-tasks-depth2.txt'); + var expected = fs.readFileSync(filepath, 'utf-8'); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(stderr).toEqual(''); + done(err); + } + }); +}); diff --git a/test/config-flags-tasksDepth.js b/test/config-flags-tasksDepth.js deleted file mode 100644 index 6c915ed1..00000000 --- a/test/config-flags-tasksDepth.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var path = require('path'); -var fs = require('fs'); -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; - -var fixturesDir = path.join(__dirname, 'fixtures/config'); -var expectedDir = path.join(__dirname, 'expected'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); - -describe ('config: flags.tasksDepth', function() { - - it('Should limit depth of task list when `flags.tasksDepth` is ' + - 'specified', function(done) { - runner - .chdir('flags/tasksDepth') - .gulp('--tasks') - .run(cb); - - function cb(err, stdout, stderr) { - var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); - var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - - expect(stdout).toEqual(expected); - expect(stderr).toEqual(''); - done(err); - } - }); - - it('Should overridden by cli flag: --tasks-depth', function(done) { - runner - .chdir('flags/tasksDepth') - .gulp('--tasks', '--tasks-depth 2') - .run(cb); - - function cb(err, stdout, stderr) { - var filepath = path.join(expectedDir, 'flags-tasks-depth2.txt'); - var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - - expect(stdout).toEqual(expected); - expect(stderr).toEqual(''); - done(err); - } - }); -}); diff --git a/test/esm.js b/test/esm.js index bd27094b..52affdab 100644 --- a/test/esm.js +++ b/test/esm.js @@ -1,39 +1,61 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var fs = require('fs'); var path = require('path'); var semver = require('semver'); -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var runner = require('gulp-test-tools').gulpRunner; +var os = require('os'); + +var baseDir = path.join(__dirname, '..'); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); var expectedDir = path.join(__dirname, 'expected'); +function shouldSkip() { + switch (os.platform()) { + case 'win32': { + return semver.satisfies(process.version, '^11.2.0') || + (process.env.CI && semver.satisfies(process.version, '10.x.x')); + } + case 'darwin': { + return semver.satisfies(process.version, '>=11.0.0 <11.11.0'); + } + case 'linux': { + return semver.satisfies(process.version, '>=11.2.0 <11.4.0'); + } + } + return semver.satisfies(process.version, '12.8.x || >=12.11.0 <12.18.0 || >=13.0.0 <13.8.0'); +} + describe('ESM', function() { it('prints the task list', function(done) { - if (semver.lt(process.version, '10.15.3')) { + if (shouldSkip()) { this.skip(); } - var options = '--tasks --sort-tasks ' + - '--gulpfile ./test/fixtures/gulpfiles/gulpfile.mjs'; + var options = '--tasks --sort-tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile.mjs'; var trailingLines = 1; if (!semver.satisfies(process.version, '^12.17.0 || >=13.2.0')) { options += ' --experimental-modules'; trailingLines += 2; } - runner({ verbose: false }).gulp(options).run(cb); + var opts = { cwd: baseDir }; + exec(gulp(options), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toMatch(/^(.*ExperimentalWarning: The ESM module loader is experimental\.\n)?$/); + expect(err).toBeNull(); + if (!semver.satisfies(process.version, '^12.20.0 || >=13.14.0')) { + expect(stderr).toMatch('ExperimentalWarning: The ESM module loader is experimental.\n'); + } else { + expect(stderr).toEqual(''); + } var filepath = path.join(expectedDir, 'esm.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, trailingLines)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, trailingLines)).toEqual(expected); done(err); } }); diff --git a/test/execution-errors.js b/test/execution-errors.js index cf4a50ad..35027883 100644 --- a/test/execution-errors.js +++ b/test/execution-errors.js @@ -1,83 +1,90 @@ 'use strict'; var expect = require('expect'); -var eraseTime = require('gulp-test-tools').eraseTime; -var eraseLapse = require('gulp-test-tools').eraseLapse; -var runner = require('gulp-test-tools').gulpRunner; +var exec = require('child_process').exec; var path = require('path'); var os = require('os'); + var tildify = require('../lib/shared/tildify'); +var eraseTime = require('./tool/erase-time'); +var eraseLapse = require('./tool/erase-lapse'); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + describe('execution error', function() { it('should output an error if a task is not defined', function(done) { - runner({ verbose: false }) - .chdir('test/fixtures/gulpfiles') - .gulp('a') - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(err.code).toEqual(1); - expect(eraseTime(stdout)).toMatch('Using gulpfile '); - expect(eraseTime(stderr)).toEqual( - 'Task never defined: a\n' + - 'To list available tasks, try running: gulp --tasks\n'); - done(); - }); + var opts = { cwd: path.join(__dirname, './fixtures/gulpfiles') }; + exec(gulp('a'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(eraseTime(stdout)).toMatch('Using gulpfile '); + expect(eraseTime(stderr)).toEqual( + 'Task never defined: a\n' + + 'To list available tasks, try running: gulp --tasks\n'); + done(); + } }); it('should output an error if gulp version is unsupported', function(done) { - runner({ verbose: false }) - .chdir('test/fixtures/errors/bad-gulp-version') - .gulp() - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(err.code).toEqual(1); - expect(eraseTime(stdout)).toEqual(''); - expect(eraseTime(stderr)).toEqual('Unsupported gulp version\n'); - done(); - }); + var opts = { cwd: path.join(__dirname, './fixtures/errors/bad-gulp-version') }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(eraseTime(stdout)).toEqual(''); + expect(eraseTime(stderr)).toEqual('Unsupported gulp version 1.2.3\n'); + done(); + } }); it('should output an error if gulp is not found', function(done) { - runner({ verbose: false }) - .chdir(os.tmpdir()) - .gulp() - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(err.code).toEqual(1); - expect(eraseTime(stdout)).toEqual(''); - stderr = eraseTime(stderr).split(/[\r\n]+/); - expect(stderr[0]).toMatch('Local gulp not found in '); - expect(stderr[1]).toEqual('Try running: npm install gulp'); - done(); - }); + var tmpdir = os.tmpdir(); + if (os.platform() === 'win32') { + var moveDrive = tmpdir.slice(0, 2); + exec(moveDrive + '& cd ' + tmpdir + ' & ' + gulp(), cb); + } else { + exec(gulp(), { cwd: tmpdir }, cb); + } + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(sliceLines(stderr, 0, 1)).toMatch('Local gulp not found in '); + expect(sliceLines(stderr, 1, 2)).toEqual('Try running: npm install gulp'); + done(); + } }); it('should log a same error once', function(done) { var dir = path.join(__dirname, 'fixtures/gulpfiles'); var gulpfileName = 'gulpfile-dedup-errorlog.js'; - runner({ verbose: false }) - .chdir(dir) - .gulp('--gulpfile', gulpfileName) - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(err.code).toEqual(1); - stdout = eraseLapse(eraseTime(stdout)); - expect(stdout).toEqual( - 'Using gulpfile ' + tildify(path.join(dir, gulpfileName)) + '\n' + - 'Starting \'default\'...\n' + - 'Starting \'b\'...\n' + - 'Starting \'a\'...\n' + - ''); - stderr = eraseLapse(eraseTime(stderr)).split(/[\r\n]+/); - var n = stderr.length; - expect(stderr[0]).toEqual('\'a\' errored after ?'); - expect(stderr[1]).toEqual('Error: Task \'a\' failed!'); - expect(stderr[n - 3]).toEqual('\'b\' errored after ?'); - expect(stderr[n - 2]).toEqual('\'default\' errored after ?'); - expect(stderr[n - 1]).toEqual(''); - done(); - }); + + exec(gulp( + '--gulpfile', gulpfileName + ), { cwd: dir }, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(sliceLines(stdout)).toEqual( + 'Using gulpfile ' + tildify(path.join(dir, gulpfileName)) + '\n' + + 'Starting \'default\'...\n' + + 'Starting \'b\'...\n' + + 'Starting \'a\'...\n' + + ''); + stderr = eraseLapse(eraseTime(stderr)).split(/[\r\n]+/); + var n = stderr.length; + expect(stderr[0]).toEqual('\'a\' errored after ?'); + expect(stderr[1]).toEqual('Error: Task \'a\' failed!'); + expect(stderr[n - 3]).toEqual('\'b\' errored after ?'); + expect(stderr[n - 2]).toEqual('\'default\' errored after ?'); + expect(stderr[n - 1]).toEqual(''); + done(); + } }); }); - diff --git a/test/expected/config/output2.txt b/test/expected/config/output2.txt new file mode 100644 index 00000000..a0d45083 --- /dev/null +++ b/test/expected/config/output2.txt @@ -0,0 +1,2 @@ +DESCRIPTION BY .gulp.babel.js in directory foo/bar/quux +└── default diff --git a/test/expected/flags-help.txt b/test/expected/flags-help.txt index eb275983..fed71d76 100644 --- a/test/expected/flags-help.txt +++ b/test/expected/flags-help.txt @@ -2,37 +2,41 @@ Usage: gulp [options] tasks Options: - --help, -h Show this help. [boolean] - --version, -v Print the global and local gulp versions. [boolean] - --require Will require a module before running the gulpfile. - This is useful for transpilers but also has other - applications. [string] - --gulpfile, -f Manually set path of gulpfile. Useful if you have - multiple gulpfiles. This will set the CWD to the - gulpfile directory as well. [string] - --cwd Manually set the CWD. The search for the gulpfile, as - well as the relativity of all requires will be from - here. [string] - --verify Will verify plugins referenced in project's - package.json against the plugins blacklist. - --tasks, -T Print the task dependency tree for the loaded - gulpfile. [boolean] - --tasks-simple Print a plaintext list of tasks for the loaded - gulpfile. [boolean] - --tasks-json Print the task dependency tree, in JSON format, for - the loaded gulpfile. - --tasks-depth, --depth Specify the depth of the task dependency tree.[number] - --compact-tasks Reduce the output of task dependency tree by printing - only top tasks and their child tasks. [boolean] - --sort-tasks Will sort top tasks of task dependency tree. [boolean] - --color Will force gulp and gulp plugins to display colors, - even when no color support is detected. [boolean] - --no-color Will force gulp and gulp plugins to not display - colors, even when color support is detected. [boolean] - --silent, -S Suppress all gulp logging. [boolean] - --continue Continue execution of tasks upon failure. [boolean] - --series Run tasks given on the CLI in series (the default is - parallel). [boolean] - --log-level, -L Set the loglevel. -L for least verbose and -LLLL for - most verbose. -LLL is default. [count] - + -h, --help Show this help. [boolean] + -v, --version Print the global and local gulp versions.[boolean] + --preload Will preload a module before running the gulpfile. + This is useful for transpilers but also has other + applications. [string] + -f, --gulpfile Manually set path of gulpfile. Useful if you have + multiple gulpfiles. This will set the CWD to the + gulpfile directory as well. [string] + --cwd Manually set the CWD. The search for the gulpfile, + as well as the relativity of all requires will be + from here. [string] + --verify Will verify plugins referenced in project's + package.json against the plugins blacklist. + -T, --tasks Print the task dependency tree for the loaded + gulpfile. [boolean] + --tasks-simple Print a plaintext list of tasks for the loaded + gulpfile. [boolean] + --tasks-json Print the task dependency tree, in JSON format, + for the loaded gulpfile. + --tasks-depth, --depth Specify the depth of the task dependency tree. + [number] + --compact-tasks Reduce the output of task dependency tree by + printing only top tasks and their child tasks. + [boolean] + --sort-tasks Will sort top tasks of task dependency tree. + [boolean] + --color Will force gulp and gulp plugins to display + colors, even when no color support is detected. + [boolean] + --no-color Will force gulp and gulp plugins to not display + colors, even when color support is detected. + [boolean] + -S, --silent Suppress all gulp logging. [boolean] + --continue Continue execution of tasks upon failure.[boolean] + --series Run tasks given on the CLI in series (the default + is parallel). [boolean] + -L, --log-level Set the loglevel. -L for least verbose and -LLLL + for most verbose. -LLL is default. [count] diff --git a/test/expected/with-desc-and-flags.txt b/test/expected/with-desc-and-flags.txt index 6d65313d..34e85d2c 100644 --- a/test/expected/with-desc-and-flags.txt +++ b/test/expected/with-desc-and-flags.txt @@ -1,6 +1,6 @@ gulp-cli/test/fixtures ├─┬ build Build all the things! -│ │ --dev …un-minified +│ │ --dev │ │ --production …compressed into single bundle │ └─┬ │ ├── clean diff --git a/test/exports-as-tasks.js b/test/exports-as-tasks.js index b94ff0e5..81bee75e 100644 --- a/test/exports-as-tasks.js +++ b/test/exports-as-tasks.js @@ -1,12 +1,14 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var fs = require('fs'); var path = require('path'); -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var runner = require('gulp-test-tools').gulpRunner; +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); var expectedDir = path.join(__dirname, 'expected'); // Long timeout is required because parse time is slow @@ -14,19 +16,20 @@ describe('exports as tasks', function() { this.timeout(0); it('prints the task list', function(done) { - runner({ verbose: false }) - .gulp('--tasks', '--sort-tasks', - '--gulpfile ./test/fixtures/gulpfiles/gulpfile-exports.babel.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--sort-tasks', + '--gulpfile', './test/fixtures/gulpfiles/gulpfile-exports.babel.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'tasks-as-exports.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); // Remove babel/register lines - stdout = eraseTime(skipLines(stdout, 2)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 2)).toEqual(expected); done(err); } }); diff --git a/test/fixtures/.babelrc b/test/fixtures/.babelrc deleted file mode 100644 index c13c5f62..00000000 --- a/test/fixtures/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["es2015"] -} diff --git a/test/fixtures/config/flags/gulpfile/.gulp.json b/test/fixtures/config/flags/gulpfile/.gulp.json deleted file mode 100644 index b2089dc7..00000000 --- a/test/fixtures/config/flags/gulpfile/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "gulpfile": "./is/here/mygulpfile.js" - } -} diff --git a/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json b/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json new file mode 100644 index 00000000..10707925 --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json @@ -0,0 +1,5 @@ +{ + "flags": { + "gulpfile": "./other_dir/gulpfile.coffee" + } +} diff --git a/test/fixtures/config/flags/gulpfile/autoload-fail/other_dir/gulpfile.coffee b/test/fixtures/config/flags/gulpfile/autoload-fail/other_dir/gulpfile.coffee new file mode 100644 index 00000000..1f8b8541 --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/autoload-fail/other_dir/gulpfile.coffee @@ -0,0 +1 @@ +console.log 'hello' diff --git a/test/fixtures/config/flags/gulpfile/cwd/.gulp.json b/test/fixtures/config/flags/gulpfile/cwd/.gulp.json new file mode 100644 index 00000000..231d1a67 --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/cwd/.gulp.json @@ -0,0 +1,5 @@ +{ + "flags": { + "gulpfile": "../is/here/gulpfile-by-cwd-cfg.js" + } +} diff --git a/test/fixtures/config/flags/gulpfile/cwd/findup/.gitkeep b/test/fixtures/config/flags/gulpfile/cwd/findup/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/config/flags/gulpfile/cwd/gulpfile.js b/test/fixtures/config/flags/gulpfile/cwd/gulpfile.js deleted file mode 100644 index 3b6476b6..00000000 --- a/test/fixtures/config/flags/gulpfile/cwd/gulpfile.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -var gulp = require('gulp'); - -gulp.task('default', function(done) { - console.log('Another gulpfile : ' + __filename); - done(); -}); diff --git a/test/fixtures/config/flags/gulpfile/is/here/mygulpfile.js b/test/fixtures/config/flags/gulpfile/is/here/gulpfile-by-cwd-cfg.js similarity index 100% rename from test/fixtures/config/flags/gulpfile/is/here/mygulpfile.js rename to test/fixtures/config/flags/gulpfile/is/here/gulpfile-by-cwd-cfg.js diff --git a/test/fixtures/config/flags/gulpfile/is/here/gulpfile-by-prj-cfg.js b/test/fixtures/config/flags/gulpfile/is/here/gulpfile-by-prj-cfg.js new file mode 100644 index 00000000..61b4199a --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/is/here/gulpfile-by-prj-cfg.js @@ -0,0 +1,9 @@ +'use strict'; + +var gulp = require('gulp'); + +gulp.task('default', function(done) { + console.log('This gulpfile : ' + __filename); + console.log('The current directory : ' + process.cwd()); + done(); +}); diff --git a/test/fixtures/config/flags/gulpfile/is/here/gulpfile.js b/test/fixtures/config/flags/gulpfile/is/here/gulpfile.js new file mode 100644 index 00000000..61b4199a --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/is/here/gulpfile.js @@ -0,0 +1,9 @@ +'use strict'; + +var gulp = require('gulp'); + +gulp.task('default', function(done) { + console.log('This gulpfile : ' + __filename); + console.log('The current directory : ' + process.cwd()); + done(); +}); diff --git a/test/fixtures/config/flags/gulpfile/prj/.gulp.json b/test/fixtures/config/flags/gulpfile/prj/.gulp.json new file mode 100644 index 00000000..64535ec4 --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/prj/.gulp.json @@ -0,0 +1,5 @@ +{ + "flags": { + "gulpfile": "../is/here/gulpfile-by-prj-cfg.js" + } +} diff --git a/test/fixtures/config/flags/gulpfile/prj/findup/.gitkeep b/test/fixtures/config/flags/gulpfile/prj/findup/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/config/flags/require/array/.gulp.json b/test/fixtures/config/flags/preload/array/.gulp.json similarity index 80% rename from test/fixtures/config/flags/require/array/.gulp.json rename to test/fixtures/config/flags/preload/array/.gulp.json index 42aaa0da..0031374c 100644 --- a/test/fixtures/config/flags/require/array/.gulp.json +++ b/test/fixtures/config/flags/preload/array/.gulp.json @@ -1,6 +1,6 @@ { "flags": { - "require": [ + "preload": [ "./preload_one", "./preload_two" ] diff --git a/test/fixtures/config/flags/require/array/gulpfile.js b/test/fixtures/config/flags/preload/array/gulpfile.js similarity index 100% rename from test/fixtures/config/flags/require/array/gulpfile.js rename to test/fixtures/config/flags/preload/array/gulpfile.js diff --git a/test/fixtures/config/flags/require/array/preload_one.js b/test/fixtures/config/flags/preload/array/preload_one.js similarity index 100% rename from test/fixtures/config/flags/require/array/preload_one.js rename to test/fixtures/config/flags/preload/array/preload_one.js diff --git a/test/fixtures/config/flags/require/array/preload_two.js b/test/fixtures/config/flags/preload/array/preload_two.js similarity index 100% rename from test/fixtures/config/flags/require/array/preload_two.js rename to test/fixtures/config/flags/preload/array/preload_two.js diff --git a/test/fixtures/config/flags/require/join-flags/.gulp.json b/test/fixtures/config/flags/preload/join-flags/.gulp.json similarity index 74% rename from test/fixtures/config/flags/require/join-flags/.gulp.json rename to test/fixtures/config/flags/preload/join-flags/.gulp.json index 61f4f87a..83d17ccf 100644 --- a/test/fixtures/config/flags/require/join-flags/.gulp.json +++ b/test/fixtures/config/flags/preload/join-flags/.gulp.json @@ -1,6 +1,6 @@ { "flags": { - "require": [ + "preload": [ "./preload_two" ] } diff --git a/test/fixtures/config/flags/require/join-flags/gulpfile.js b/test/fixtures/config/flags/preload/join-flags/gulpfile.js similarity index 100% rename from test/fixtures/config/flags/require/join-flags/gulpfile.js rename to test/fixtures/config/flags/preload/join-flags/gulpfile.js diff --git a/test/fixtures/config/flags/require/join-flags/preload_one.js b/test/fixtures/config/flags/preload/join-flags/preload_one.js similarity index 100% rename from test/fixtures/config/flags/require/join-flags/preload_one.js rename to test/fixtures/config/flags/preload/join-flags/preload_one.js diff --git a/test/fixtures/config/flags/require/join-flags/preload_two.js b/test/fixtures/config/flags/preload/join-flags/preload_two.js similarity index 100% rename from test/fixtures/config/flags/require/join-flags/preload_two.js rename to test/fixtures/config/flags/preload/join-flags/preload_two.js diff --git a/test/fixtures/config/flags/require/preload.js b/test/fixtures/config/flags/preload/preload.js similarity index 100% rename from test/fixtures/config/flags/require/preload.js rename to test/fixtures/config/flags/preload/preload.js diff --git a/test/fixtures/config/flags/preload/string/.gulp.json b/test/fixtures/config/flags/preload/string/.gulp.json new file mode 100644 index 00000000..9b061f1f --- /dev/null +++ b/test/fixtures/config/flags/preload/string/.gulp.json @@ -0,0 +1,5 @@ +{ + "flags": { + "preload": "./preload" + } +} diff --git a/test/fixtures/config/flags/require/string/gulpfile.js b/test/fixtures/config/flags/preload/string/gulpfile.js similarity index 100% rename from test/fixtures/config/flags/require/string/gulpfile.js rename to test/fixtures/config/flags/preload/string/gulpfile.js diff --git a/test/fixtures/config/flags/require/string/preload.js b/test/fixtures/config/flags/preload/string/preload.js similarity index 100% rename from test/fixtures/config/flags/require/string/preload.js rename to test/fixtures/config/flags/preload/string/preload.js diff --git a/test/fixtures/config/flags/require/with-absolute/.gulp.js b/test/fixtures/config/flags/preload/with-absolute/.gulp.js similarity index 57% rename from test/fixtures/config/flags/require/with-absolute/.gulp.js rename to test/fixtures/config/flags/preload/with-absolute/.gulp.js index 007b399b..c0e29e8a 100644 --- a/test/fixtures/config/flags/require/with-absolute/.gulp.js +++ b/test/fixtures/config/flags/preload/with-absolute/.gulp.js @@ -2,6 +2,6 @@ var path = require('path'); module.exports = { flags: { - require: path.join(__dirname, '../preload'), + preload: path.join(__dirname, '../preload'), }, }; diff --git a/test/fixtures/config/flags/require/with-absolute/gulpfile.js b/test/fixtures/config/flags/preload/with-absolute/gulpfile.js similarity index 100% rename from test/fixtures/config/flags/require/with-absolute/gulpfile.js rename to test/fixtures/config/flags/preload/with-absolute/gulpfile.js diff --git a/test/fixtures/config/flags/preload/with-cwd/.gulp.json b/test/fixtures/config/flags/preload/with-cwd/.gulp.json new file mode 100644 index 00000000..d43feab5 --- /dev/null +++ b/test/fixtures/config/flags/preload/with-cwd/.gulp.json @@ -0,0 +1,5 @@ +{ + "flags": { + "preload": "../preload" + } +} diff --git a/test/fixtures/config/flags/require/with-cwd/gulpfile.js b/test/fixtures/config/flags/preload/with-cwd/gulpfile.js similarity index 100% rename from test/fixtures/config/flags/require/with-cwd/gulpfile.js rename to test/fixtures/config/flags/preload/with-cwd/gulpfile.js diff --git a/test/fixtures/config/flags/require/string/.gulp.json b/test/fixtures/config/flags/require/string/.gulp.json deleted file mode 100644 index 3fbb4b37..00000000 --- a/test/fixtures/config/flags/require/string/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "require": "./preload" - } -} diff --git a/test/fixtures/config/flags/require/with-cwd/.gulp.json b/test/fixtures/config/flags/require/with-cwd/.gulp.json deleted file mode 100644 index 743fb112..00000000 --- a/test/fixtures/config/flags/require/with-cwd/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "require": "../preload" - } -} diff --git a/test/fixtures/config/foo/bar/baz/.gitkeep b/test/fixtures/config/foo/bar/baz/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/config/foo/bar/baz/.gulp.babel.js b/test/fixtures/config/foo/bar/quux/.gulp.babel.js similarity index 66% rename from test/fixtures/config/foo/bar/baz/.gulp.babel.js rename to test/fixtures/config/foo/bar/quux/.gulp.babel.js index 4e6e98c4..92986942 100644 --- a/test/fixtures/config/foo/bar/baz/.gulp.babel.js +++ b/test/fixtures/config/foo/bar/quux/.gulp.babel.js @@ -1,3 +1 @@ -// jscs:disable - -exports.description = 'DESCRIPTION BY .gulp.babel.js in directory foo/bar/baz' +exports.description = 'DESCRIPTION BY .gulp.babel.js in directory foo/bar/quux' diff --git a/test/fixtures/gulpfiles/with-desc-and-flags.js b/test/fixtures/gulpfiles/with-desc-and-flags.js index 5b2792c2..8a6937f4 100644 --- a/test/fixtures/gulpfiles/with-desc-and-flags.js +++ b/test/fixtures/gulpfiles/with-desc-and-flags.js @@ -17,7 +17,7 @@ gulp.task('styles').description = 'Compiles and bundles CSS'; var build = gulp.series('clean', 'scripts', 'styles'); build.description = 'Build all the things!'; build.flags = { - '--dev': 'un-minified', + '--dev': '', '--production': 'compressed into single bundle', '': 'dummy-empty-string', }; diff --git a/test/fixtures/logging.js b/test/fixtures/logging.js index 705b482a..aff166e0 100644 --- a/test/fixtures/logging.js +++ b/test/fixtures/logging.js @@ -1,10 +1,7 @@ var log = require('gulplog'); -var yargs = require('yargs'); var toConsole = require('../../lib/shared/log/to-console'); -var cliOptions = require('../../lib/shared/cli-options'); -var parser = yargs.usage('', cliOptions); -var opts = parser.argv; +var opts = require('../../lib/shared/options/parser').argv; toConsole(log, opts); diff --git a/test/flags-continue.js b/test/flags-continue.js index fbfe644a..cbf8a94f 100644 --- a/test/flags-continue.js +++ b/test/flags-continue.js @@ -1,32 +1,34 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; -var eraseTime = require('gulp-test-tools').eraseTime; -var eraseLapse = require('gulp-test-tools').eraseLapse; -var skipLines = require('gulp-test-tools').skipLines; -var headLines = require('gulp-test-tools').headLines; +var exec = require('child_process').exec; +var path = require('path'); + +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); describe('flag: --continue', function() { it('continues execution when flag is set', function(done) { - runner({ verbose: false }) - .gulp('test4', '--continue', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + 'test4', + '--continue', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); - expect(stdout).toEqual( + expect(err).not.toBeNull(); + expect(sliceLines(stdout, 2)).toEqual( 'Starting \'test4\'...\n' + 'Starting \'errorFunction\'...\n' + 'Starting \'anon\'...\n' + 'Finished \'anon\' after ?\n' + '' ); - - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); - expect(stderr).toEqual( + expect(sliceLines(stderr, 0, 2)).toEqual( '\'errorFunction\' errored after ?\n' + 'Error: Error!' ); @@ -35,22 +37,19 @@ describe('flag: --continue', function() { }); it('stops execution when flag is not set', function(done) { - runner({ verbose: false }) - .gulp('test4', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp('test4', '--cwd ./test/fixtures/gulpfiles'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toNotMatch('Starting \'anon\''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); + expect(err).not.toBeNull(); + expect(stdout).not.toMatch('Starting \'anon\''); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual( 'Starting \'test4\'...\n' + 'Starting \'errorFunction\'...\n' + '' ); - - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); - expect(stderr).toEqual( + expect(sliceLines(stderr, 0, 2)).toEqual( '\'errorFunction\' errored after ?\n' + 'Error: Error!' ); diff --git a/test/flags-gulpfile.js b/test/flags-gulpfile.js index 876f7f9c..7c9316b7 100644 --- a/test/flags-gulpfile.js +++ b/test/flags-gulpfile.js @@ -1,32 +1,32 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; -var skipLines = require('gulp-test-tools').skipLines; -var headLines = require('gulp-test-tools').headLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var eraseLapse = require('gulp-test-tools').eraseLapse; +var exec = require('child_process').exec; var path = require('path'); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); + describe('flag: --gulpfile', function() { it('Manually set path of gulpfile using --gulpfile', function(done) { var gulpfilePath = 'test/fixtures/gulpfiles/gulpfile-2.js'; - runner({ verbose: false }) - .gulp('--gulpfile', gulpfilePath) - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp('--gulpfile', gulpfilePath), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - var chgWorkdirLog = headLines(stdout, 1); + var chgWorkdirLog = sliceLines(stdout, 0, 1); var workdir = path.dirname(gulpfilePath).replace(/\//g, path.sep); expect(chgWorkdirLog).toMatch('Working directory changed to '); expect(chgWorkdirLog).toMatch(workdir); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'logGulpfilePath\'...\n' + @@ -42,20 +42,19 @@ describe('flag: --gulpfile', function() { it('Manually set path of gulpfile using -f', function(done) { var gulpfilePath = 'test/fixtures/gulpfiles/gulpfile-2.js'; - runner({ verbose: false }) - .gulp('-f', gulpfilePath) - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp('-f', gulpfilePath), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - var chgWorkdirLog = headLines(stdout, 1); + var chgWorkdirLog = sliceLines(stdout, 0, 1); var workdir = path.dirname(gulpfilePath).replace(/\//g, path.sep); expect(chgWorkdirLog).toMatch('Working directory changed to '); expect(chgWorkdirLog).toMatch(workdir); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'logGulpfilePath\'...\n' + diff --git a/test/flags-help.js b/test/flags-help.js index e781665b..b1947b41 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -1,58 +1,58 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; - +var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); -// Erases a first space inserted by `chalk`. -function eraseFirstSpace(s) { - return s.replace(/^(\r\n|\n|\r)\s?/g, '\n'); -} +var gulp = require('./tool/gulp-cmd'); +var baseDir = path.join(__dirname, '..'); var outputFile = path.join(__dirname, 'expected/flags-help.txt'); var outputText = fs.readFileSync(outputFile, 'utf8'); describe('flag: --help', function() { it('shows help using --help', function(done) { - runner({ verbose: false }) - .gulp('--help', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--help', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseFirstSpace(stdout); expect(stdout).toEqual(outputText); done(err); } }); it('shows help using short --h', function(done) { - runner({ verbose: false }) - .gulp('--h', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--h', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseFirstSpace(stdout); expect(stdout).toEqual(outputText); done(err); } }); it('avoids printing "Requiring external module *"', function(done) { - runner({ verbose: false }) - .gulp('--help --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--help', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseFirstSpace(stdout); expect(stdout).toEqual(outputText); done(err); } diff --git a/test/flags-preload.js b/test/flags-preload.js new file mode 100644 index 00000000..8a666ddc --- /dev/null +++ b/test/flags-preload.js @@ -0,0 +1,157 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); + +var sliceLines = require('./tool/slice-lines'); +var eraseTime = require('./tool/erase-time'); +var eraseLapse = require('./tool/erase-lapse'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); + +describe('flag: --preload', function() { + + it('preloads module before running gulpfile', function(done) { + var opts = { cwd: baseDir }; + exec(gulp( + '--preload ../test-module.js', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ../test-module.js'); + expect(sliceLines(stdout, 1, 2)).toEqual('inside test module'); + expect(sliceLines(stdout, 2, 3)).toEqual('Preloaded external module: ../test-module.js'); + + var chgWorkdirLog = sliceLines(stdout, 3, 4); + var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); + expect(chgWorkdirLog).toMatch('Working directory changed to '); + expect(chgWorkdirLog).toMatch(workdir); + + stdout = sliceLines(stdout, 5); + expect(stdout).toEqual( + 'Starting \'default\'...\n' + + 'Starting \'test1\'...\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'test1\' after ?\n' + + 'Starting \'test3\'...\n' + + 'Starting \'described\'...\n' + + 'Finished \'described\' after ?\n' + + 'Finished \'test3\' after ?\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'default\' after ?\n' + + '' + ); + done(err); + } + }); + + it('can preload multiple modules before running gulpfile', function(done) { + var opts = { cwd: baseDir }; + exec(gulp( + '--preload ../test-module.js', + '--preload ../test-module-2.js', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ../test-module.js'); + expect(sliceLines(stdout, 1, 2)).toEqual('inside test module'); + expect(sliceLines(stdout, 2, 3)).toEqual('Preloaded external module: ../test-module.js'); + expect(sliceLines(stdout, 3, 4)).toEqual('Preloading external module: ../test-module-2.js'); + expect(sliceLines(stdout, 4, 5)).toEqual('inside test module 2'); + expect(sliceLines(stdout, 5, 6)).toEqual('Preloaded external module: ../test-module-2.js'); + done(err); + } + }); + + it('warns if module doesn\'t exist', function(done) { + var opts = { cwd: baseDir }; + exec(gulp( + '--preload ./null-module.js', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 2)).toEqual( + 'Preloading external module: ./null-module.js\n' + + 'Failed to preload external module: ./null-module.js' + ); + expect(sliceLines(stdout, 2, 3)).toMatch('Error: Cannot find module \'./null-module.js\''); + + var chgWorkdirLog = sliceLines(stdout, 3, 4); + var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); + expect(chgWorkdirLog).toMatch('Working directory changed to '); + expect(chgWorkdirLog).toMatch(workdir); + + expect(sliceLines(stdout, 5)).toEqual( + 'Starting \'default\'...\n' + + 'Starting \'test1\'...\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'test1\' after ?\n' + + 'Starting \'test3\'...\n' + + 'Starting \'described\'...\n' + + 'Finished \'described\' after ?\n' + + 'Finished \'test3\' after ?\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'default\' after ?\n' + + '' + ); + + done(err); + } + }); + + it('warns if module throw some error', function(done) { + var opts = { cwd: baseDir }; + exec(gulp( + '--preload ../test-error-module.js', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); + + function cb(err, stdout, stderr) { + stdout = eraseLapse(eraseTime(stdout)); + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 1, 2)).toEqual('Failed to preload external module: ../test-error-module.js'); + expect(sliceLines(stdout, 2, 3)).toMatch('Error: from error module'); + expect(stdout).not.toMatch('inside error module'); + + var chgWorkdirLog = sliceLines(stdout, 3, 4); + var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); + expect(chgWorkdirLog).toMatch('Working directory changed to '); + expect(chgWorkdirLog).toMatch(workdir); + + expect(sliceLines(stdout, 5)).toEqual( + 'Starting \'default\'...\n' + + 'Starting \'test1\'...\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'test1\' after ?\n' + + 'Starting \'test3\'...\n' + + 'Starting \'described\'...\n' + + 'Finished \'described\' after ?\n' + + 'Finished \'test3\' after ?\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'default\' after ?\n' + + '' + ); + + done(err); + } + }); + +}); diff --git a/test/flags-require.js b/test/flags-require.js deleted file mode 100644 index 6cfa1d84..00000000 --- a/test/flags-require.js +++ /dev/null @@ -1,158 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; -var skipLines = require('gulp-test-tools').skipLines; -var headLines = require('gulp-test-tools').headLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var eraseLapse = require('gulp-test-tools').eraseLapse; -var path = require('path'); - -describe('flag: --require', function() { - - it('requires module before running gulpfile', function(done) { - runner({ verbose: false }) - .gulp('--require ../test-module.js', '--cwd ./test/fixtures/gulpfiles') - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - var insideLog = headLines(stdout, 1); - expect(insideLog).toEqual('inside test module'); - - var requireLog = eraseTime(headLines(stdout, 1, 1)); - expect(requireLog).toEqual( - 'Requiring external module ../test-module.js'); - - var chgWorkdirLog = headLines(stdout, 1, 2); - var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); - expect(chgWorkdirLog).toMatch('Working directory changed to '); - expect(chgWorkdirLog).toMatch(workdir); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 4))); - expect(stdout).toEqual( - 'Starting \'default\'...\n' + - 'Starting \'test1\'...\n' + - 'Starting \'noop\'...\n' + - 'Finished \'noop\' after ?\n' + - 'Finished \'test1\' after ?\n' + - 'Starting \'test3\'...\n' + - 'Starting \'described\'...\n' + - 'Finished \'described\' after ?\n' + - 'Finished \'test3\' after ?\n' + - 'Starting \'noop\'...\n' + - 'Finished \'noop\' after ?\n' + - 'Finished \'default\' after ?\n' + - '' - ); - done(err); - } - }); - - it('can require multiple modules before running gulpfile', function(done) { - runner({ verbose: false }) - .gulp('--require ../test-module.js', '--require ../test-module-2.js', '--cwd ./test/fixtures/gulpfiles') - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - var insideLog = headLines(stdout, 1); - expect(insideLog).toEqual('inside test module'); - - var requireLog = eraseTime(headLines(stdout, 1, 1)); - expect(requireLog).toEqual( - 'Requiring external module ../test-module.js'); - - var insideLog2 = headLines(stdout, 1, 2); - expect(insideLog2).toEqual('inside test module 2'); - - var requireLog2 = eraseTime(headLines(stdout, 1, 3)); - expect(requireLog2).toEqual( - 'Requiring external module ../test-module-2.js'); - - done(err); - } - }); - - it('warns if module doesn\'t exist', function(done) { - runner({ verbose: false }) - .gulp('--require ./null-module.js', '--cwd ./test/fixtures/gulpfiles') - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - stdout = eraseLapse(eraseTime(stdout)); - expect(stdout).toMatch('Failed to load external module ./null-module.js'); - expect(stdout).toMatch('Error: Cannot find module \'./null-module.js\''); - expect(stdout).toNotMatch('inside test module'); - expect(stdout).toNotMatch('Requiring external module ../test-module.js'); - - var chgWorkdirLog = headLines(stdout, 3); - var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); - expect(chgWorkdirLog).toMatch('Working directory changed to '); - expect(chgWorkdirLog).toMatch(workdir); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 4))); - expect(stdout).toEqual( - 'Starting \'default\'...\n' + - 'Starting \'test1\'...\n' + - 'Starting \'noop\'...\n' + - 'Finished \'noop\' after ?\n' + - 'Finished \'test1\' after ?\n' + - 'Starting \'test3\'...\n' + - 'Starting \'described\'...\n' + - 'Finished \'described\' after ?\n' + - 'Finished \'test3\' after ?\n' + - 'Starting \'noop\'...\n' + - 'Finished \'noop\' after ?\n' + - 'Finished \'default\' after ?\n' + - '' - ); - - done(err); - } - }); - - it('warns if module throw some error', function(done) { - runner({ verbose: false }) - .gulp('--require ../test-error-module.js', '--cwd ./test/fixtures/gulpfiles') - .run(cb); - - function cb(err, stdout, stderr) { - stdout = eraseLapse(eraseTime(stdout)); - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(stdout).toMatch('Failed to load external module ../test-error-module.js'); - expect(stdout).toMatch('Error: from error module'); - expect(stdout).toNotMatch('inside error module'); - - var chgWorkdirLog = headLines(stdout, 3); - var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); - expect(chgWorkdirLog).toMatch('Working directory changed to '); - expect(chgWorkdirLog).toMatch(workdir); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 4))); - expect(stdout).toEqual( - 'Starting \'default\'...\n' + - 'Starting \'test1\'...\n' + - 'Starting \'noop\'...\n' + - 'Finished \'noop\' after ?\n' + - 'Finished \'test1\' after ?\n' + - 'Starting \'test3\'...\n' + - 'Starting \'described\'...\n' + - 'Finished \'described\' after ?\n' + - 'Finished \'test3\' after ?\n' + - 'Starting \'noop\'...\n' + - 'Finished \'noop\' after ?\n' + - 'Finished \'default\' after ?\n' + - '' - ); - - done(err); - } - }); - -}); diff --git a/test/flags-series.js b/test/flags-series.js index 6ab5e694..b4ba6047 100644 --- a/test/flags-series.js +++ b/test/flags-series.js @@ -1,23 +1,28 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; -var eraseTime = require('gulp-test-tools').eraseTime; -var eraseLapse = require('gulp-test-tools').eraseLapse; -var skipLines = require('gulp-test-tools').skipLines; +var exec = require('child_process').exec; +var path = require('path'); + +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); describe('flag: --series', function() { it('runs tasks in series when flag is set', function(done) { - runner({ verbose: false }) - .gulp('test5 test6', '--series', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + 'test5 test6', + '--series', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); - expect(stdout).toEqual( + expect(sliceLines(stdout, 2)).toEqual( 'Starting \'test5\'...\n' + 'Finished \'test5\' after ?\n' + 'Starting \'test6\'...\n' + @@ -29,16 +34,17 @@ describe('flag: --series', function() { }); it('runs tasks in parallel when flag is not set', function(done) { - runner({ verbose: false }) - .gulp('test5 test6', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + 'test5 test6', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(stdout).toNotMatch('Starting \'anon\''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); - expect(stdout).toEqual( + expect(stdout).not.toMatch('Starting \'anon\''); + expect(sliceLines(stdout, 2)).toEqual( 'Starting \'test5\'...\n' + 'Starting \'test6\'...\n' + 'Finished \'test6\' after ?\n' + diff --git a/test/flags-silent.js b/test/flags-silent.js index 4396b508..c7bc12b0 100644 --- a/test/flags-silent.js +++ b/test/flags-silent.js @@ -1,17 +1,24 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; +var exec = require('child_process').exec; +var path = require('path'); + +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); describe('flag: --silent', function() { it('prints nothing when silent flag is set', function(done) { - runner({ verbose: false }) - .gulp('--silent', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--silent', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(''); done(err); diff --git a/test/flags-tasks-json.js b/test/flags-tasks-json.js index 27b043d7..5614ac33 100644 --- a/test/flags-tasks-json.js +++ b/test/flags-tasks-json.js @@ -1,23 +1,27 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var fs = require('fs'); var path = require('path'); var rimraf = require('rimraf'); -var skipLines = require('gulp-test-tools').skipLines; -var runner = require('gulp-test-tools').gulpRunner; +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); var expected = require(path.join(__dirname, 'expected/flags-tasks-json.json')); describe('flag: --tasks-json', function() { it('prints the task list with no args', function(done) { - runner({ verbose: false }) - .gulp('--tasks-json --gulpfile ./test/fixtures/gulpfiles/gulpfile.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks-json', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(JSON.parse(stdout)).toEqual(expected); done(err); @@ -27,14 +31,16 @@ describe('flag: --tasks-json', function() { it('prints the task list with the default description', function(done) { var cwdPath = __dirname; var gulpfilePath = path.join(__dirname, 'fixtures/gulpfiles/gulpfile.js'); - runner({ verbose: false }) - .gulp('--tasks-json', - '--cwd ', cwdPath, - '--gulpfile ', gulpfilePath) - .run(cb); + + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks-json', + '--cwd ', cwdPath, + '--gulpfile ', gulpfilePath + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var jsonObj = JSON.parse(stdout); expect(jsonObj.label).toMatch('Tasks for '); @@ -48,15 +54,16 @@ describe('flag: --tasks-json', function() { rimraf.sync(output); fs.mkdirSync(output); - runner({ verbose: false }) - .gulp('--tasks-json ../../output/tasks.json', - '--gulpfile ./test/fixtures/gulpfiles/gulpfile.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks-json ../../output/tasks.json', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = skipLines(stdout, 1); + stdout = stdout.split('\n').slice(1).join('\n'); expect(stdout).toEqual(''); var file = fs.readFileSync(path.join(output, '/tasks.json'), 'utf8'); var parsedJson = JSON.parse(file); @@ -70,12 +77,14 @@ describe('flag: --tasks-json', function() { // Disable the timeout for old node versions this.timeout(0); - runner({ verbose: false }) - .gulp('--tasks-json --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks-json', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(JSON.parse(stdout)).toEqual(expected); done(err); diff --git a/test/flags-tasks-simple.js b/test/flags-tasks-simple.js index a44bd91c..a2f54c22 100644 --- a/test/flags-tasks-simple.js +++ b/test/flags-tasks-simple.js @@ -1,22 +1,27 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; +var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); var outputFile = path.join(__dirname, 'expected/flags-tasks-simple.txt'); var outputText = fs.readFileSync(outputFile, 'utf8'); describe('flag: --tasks-simple', function() { it('prints the task list in simple format', function(done) { - runner({ verbose: false }) - .gulp('--tasks-simple', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks-simple', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(outputText); done(err); @@ -27,12 +32,14 @@ describe('flag: --tasks-simple', function() { // Disable the timeout for old node versions this.timeout(0); - runner({ verbose: false }) - .gulp('--tasks-simple --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks-simple', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(outputText); done(err); diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 10662cc1..4a1c689f 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -1,149 +1,159 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var fs = require('fs'); var path = require('path'); -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var runner = require('gulp-test-tools').gulpRunner; +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); var expectedDir = path.join(__dirname, 'expected'); describe('flag: --tasks', function() { it('prints the task list', function(done) { - runner({ verbose: false }) - .gulp('--tasks --sort-tasks --cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--sort-tasks', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); it('print the task list with description and flags', function(done) { - runner({ verbose: false }) - .gulp('--tasks', '--sort-tasks', - '--gulpfile ./test/fixtures/gulpfiles/with-desc-and-flags.js', - '--cwd ./test/fixtures') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--sort-tasks', + '--gulpfile ./test/fixtures/gulpfiles/with-desc-and-flags.js', + '--cwd ./test/fixtures' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'with-desc-and-flags.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); - it('print the task list by gulp.task(s).unwrap and gulp.task(s)', - function(done) { - runner({ verbose: false }) - .gulp('--tasks', '--sort-tasks', - '--gulpfile ./test/fixtures/gulpfiles/by-unwrap-and-not-by-unwrap.js', - '--cwd ./test/fixtures') - .run(cb); + it('print the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) { + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--sort-tasks', + '--gulpfile ./test/fixtures/gulpfiles/by-unwrap-and-not-by-unwrap.js', + '--cwd ./test/fixtures' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'by-unwrap-and-not-by-unwrap.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); it('prints the task list without --sort-tasks flag', function(done) { - runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); it('prints the task list with --sort-tasks flag', function(done) { - runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--sort-tasks') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--sort-tasks' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); it('prints the task list with --tasks-depth flag', function(done) { - runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--tasks-depth 4') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--tasks-depth 4' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); it('prints the task list with --depth flag', function(done) { - runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--depth 4') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--depth 4' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); it('prints the task list with --compact-tasks flag', function(done) { - runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--compact-tasks') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--compact-tasks' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); diff --git a/test/flags-v8flags.js b/test/flags-v8flags.js index 1a487980..30dec323 100644 --- a/test/flags-v8flags.js +++ b/test/flags-v8flags.js @@ -1,48 +1,38 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); -var runner = require('gulp-test-tools').gulpRunner; -var headLines = require('gulp-test-tools').headLines; -var eraseTime = require('gulp-test-tools').eraseTime; +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/gulpfiles'); describe('flags: v8flags', function() { it('Should respawn by a v8flag: --lazy', function(done) { - runner({ verbose: false }) - .chdir(path.join(__dirname, 'fixtures/gulpfiles')) - .gulp('--lazy') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp('--lazy'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - var line = eraseTime(headLines(stdout, 1)); - expect(line).toEqual('Node flags detected: --lazy'); - - line = eraseTime(headLines(stdout, 2, 1)); - expect(line).toMatch('Respawned to PID: '); + expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --lazy'); + expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); done(err); } }); it('Should respawn by v8flags: --lazy --harmony', function(done) { - runner({ verbose: false }) - .chdir(path.join(__dirname, 'fixtures/gulpfiles')) - .gulp('--lazy --harmony') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp('--lazy --harmony'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - var line = eraseTime(headLines(stdout, 1)); - expect(line).toEqual('Node flags detected: --harmony, --lazy'); - - line = eraseTime(headLines(stdout, 2, 1)); - expect(line).toMatch('Respawned to PID: '); + expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --harmony, --lazy'); + expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); done(err); } }); diff --git a/test/flags-verify.js b/test/flags-verify.js index bb1dcbc9..b3b6f53c 100644 --- a/test/flags-verify.js +++ b/test/flags-verify.js @@ -1,25 +1,28 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; -var eraseTime = require('gulp-test-tools').eraseTime; +var exec = require('child_process').exec; var path = require('path'); +var eraseTime = require('./tool/erase-time'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); + describe('flag: --verify', function() { it('dependencies with invalid dependency', function(done) { - runner({ verbose: false }) - .gulp('--verify invalid-package.json', '--cwd ./test/fixtures/verify/') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--verify invalid-package.json', + '--cwd ./test/fixtures/verify/' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stderr).toEqual(''); - stdout = eraseTime(stdout); - expect(stdout).toEqual( - 'Verifying plugins in ' + - path.resolve('./test/fixtures/verify/invalid-package.json') + - '\n' + + expect(eraseTime(stdout)).toEqual( + 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/invalid-package.json') + '\n' + 'Blacklisted plugins found in this project:\n' + 'gulp-blink: deprecated. use `blink` instead.\n' + '' @@ -29,18 +32,17 @@ describe('flag: --verify', function() { }); it('dependencies with valid dependency', function(done) { - runner({ verbose: false }) - .gulp('--verify valid-package.json', '--cwd ./test/fixtures/verify/') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--verify valid-package.json', + '--cwd ./test/fixtures/verify/' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseTime(stdout); - expect(stdout).toEqual( - 'Verifying plugins in ' + - path.resolve('./test/fixtures/verify/valid-package.json') + - '\n' + + expect(eraseTime(stdout)).toEqual( + 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/valid-package.json') + '\n' + 'There are no blacklisted plugins in this project\n' + '' ); @@ -49,17 +51,17 @@ describe('flag: --verify', function() { }); it('default args with invalid dependency', function(done) { - runner({ verbose: false }) - .gulp('--verify', '--cwd', path.resolve('./test/fixtures/verify/')) - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--verify', + '--cwd', path.resolve('./test/fixtures/verify/') + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stderr).toEqual(''); - stdout = eraseTime(stdout); - expect(stdout).toEqual( - 'Verifying plugins in ' + - path.resolve('./test/fixtures/verify/package.json') + '\n' + + expect(eraseTime(stdout)).toEqual( + 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/package.json') + '\n' + 'Blacklisted plugins found in this project:\n' + 'gulp-blink: deprecated. use `blink` instead.\n' + '' diff --git a/test/flags-version.js b/test/flags-version.js index 9ecfc9fc..75105570 100644 --- a/test/flags-version.js +++ b/test/flags-version.js @@ -1,21 +1,27 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; +var exec = require('child_process').exec; +var path = require('path'); var os = require('os'); +var gulp = require('./tool/gulp-cmd'); var cliVersion = require('../package.json').version; var gulpVersion = require('gulp/package.json').version; +var baseDir = path.join(__dirname, '..'); + describe('flag: --version', function() { it('prints the version of CLI and local gulp', function(done) { - runner({ verbose: false }) - .gulp('--version --cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--version', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual( 'CLI version: ' + cliVersion + '\n' + @@ -27,12 +33,14 @@ describe('flag: --version', function() { }); it('avoids printing "Requiring external module *"', function(done) { - runner({ verbose: false }) - .gulp('--version --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--version', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual( 'CLI version: ' + cliVersion + '\n' + @@ -44,12 +52,11 @@ describe('flag: --version', function() { }); it('should print only CLI version when gulp is not found', function(done) { - runner({ verbose: false }) - .gulp('--version', '--cwd', os.tmpdir()) - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp('--version', '--cwd', os.tmpdir()), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual( 'CLI version: ' + cliVersion + '\n' + diff --git a/test/lib/config-cli-flags.js b/test/lib/config-cli-flags.js index 97f5f236..e70a0d92 100644 --- a/test/lib/config-cli-flags.js +++ b/test/lib/config-cli-flags.js @@ -1,7 +1,7 @@ 'use strict'; var expect = require('expect'); -var mergeConfig = require('../../lib/shared/config/cli-flags'); +var mergeCliOpts = require('../../lib/shared/config/cli-flags'); describe('lib: config/cli-flags', function() { @@ -17,11 +17,12 @@ describe('lib: config/cli-flags', function() { }, }; - var result = mergeConfig(opts, config); + var result = mergeCliOpts(opts, config); expect(result).toEqual({ silent: true, continue: true, }); + expect(result).not.toBe(opts); done(); }); @@ -42,13 +43,14 @@ describe('lib: config/cli-flags', function() { }, }; - var result = mergeConfig(opts, config); + var result = mergeCliOpts(opts, config); expect(result).toEqual({ help: false, depth: 4, silent: true, tasks: false, }); + expect(result).not.toBe(opts); done(); }); @@ -62,13 +64,14 @@ describe('lib: config/cli-flags', function() { var config = {}; - var result = mergeConfig(opts, config); + var result = mergeCliOpts(opts, config); expect(result).toEqual({ help: false, depth: 4, silent: true, tasks: false, }); + expect(result).not.toBe(opts); done(); }); diff --git a/test/lib/config-env-flags.js b/test/lib/config-env-flags.js index 955b13c9..d8062c08 100644 --- a/test/lib/config-env-flags.js +++ b/test/lib/config-env-flags.js @@ -1,7 +1,7 @@ 'use strict'; var expect = require('expect'); -var mergeConfig = require('../../lib/shared/config/env-flags'); +var overrideEnvFlags = require('../../lib/shared/config/env-flags'); describe('lib: config/env-flags', function() { @@ -16,18 +16,25 @@ describe('lib: config/env-flags', function() { }, }; - var result = mergeConfig(env, config, {}); + var result = overrideEnvFlags(env, config, {}); expect(result).toEqual({ configPath: '/path/to/gulpfile', configBase: '/path/to', + config: { + description: 'DESCRIPTION.', + flags: { + silent: true, + }, + }, }); + expect(result).toBe(env); done(); }); it('Should take into account forced gulpfile opts from flags', function(done) { var env = { cwd: '/path/to/cwd', - require: 'preload', + preload: 'preload', configNameSearch: 'configNameSearch', configPath: '/path/of/config/path', configBase: '/path/of/config/base', @@ -41,7 +48,7 @@ describe('lib: config/env-flags', function() { flags: { silent: false, gulpfile: '/path/to/gulpfile', - require: ['a', 'b'], + preload: ['a', 'b'], }, }; @@ -49,24 +56,32 @@ describe('lib: config/env-flags', function() { gulpfile: env.configPath, }; - var result = mergeConfig(env, config, opts); + var result = overrideEnvFlags(env, config, opts); expect(result).toEqual({ cwd: '/path/to/cwd', - require: ['preload', 'a', 'b'], + preload: ['preload', 'a', 'b'], configNameSearch: 'configNameSearch', configPath: '/path/of/config/path', configBase: '/path/of/config/base', modulePath: '/path/of/module/path', modulePackage: { name: 'modulePackage' }, configFiles: { aaa: {} }, + config: { + description: "DESCRIPTION.", + flags: { + gulpfile: "/path/of/config/path", + silent: false, + }, + }, }); + expect(result).toBe(env); done(); }); it('Should not cause error if config is empty', function(done) { var env = { cwd: '/path/to/cwd', - require: 'preload', + preload: 'preload', configNameSearch: 'configNameSearch', configPath: '/path/of/config/path', configBase: '/path/of/config/base', @@ -77,18 +92,21 @@ describe('lib: config/env-flags', function() { var config = {}; - var result = mergeConfig(env, config, {}); + var result = overrideEnvFlags(env, config, {}); expect(result).toEqual({ cwd: '/path/to/cwd', - require: 'preload', + preload: 'preload', configNameSearch: 'configNameSearch', configPath: '/path/of/config/path', configBase: '/path/of/config/base', modulePath: '/path/of/module/path', modulePackage: { name: 'modulePackage' }, configFiles: { aaa: {} }, + config: { + flags: {}, + }, }); + expect(result).toBe(env); done(); }); - }); diff --git a/test/lib/config-load-files.js b/test/lib/config-load-files.js deleted file mode 100644 index 9d94b6fd..00000000 --- a/test/lib/config-load-files.js +++ /dev/null @@ -1,58 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var path = require('path'); -var loadConfigFiles = require('../../lib/shared/config/load-files'); - -var fixturesDir = path.join(__dirname, '../fixtures/config'); - -describe('lib: config/load-files', function() { - - it('Should load config from files', function(done) { - var configFiles = { - a: path.join(fixturesDir, 'foo/bar/.gulp.json'), - b: null, - c: path.join(fixturesDir, 'qux/.gulp.js'), - }; - - var config = loadConfigFiles(configFiles, ['a', 'b', 'c']); - - expect(config).toEqual({ - description: 'description by .gulp.js in directory qux', - }); - done(); - }); - - it('Should load config files in specified order', function(done) { - var configFiles = { - a: path.join(fixturesDir, 'foo/bar/.gulp.json'), - b: null, - c: path.join(fixturesDir, 'qux/.gulp.js'), - }; - - var config = loadConfigFiles(configFiles, ['b', 'c', 'a']); - - expect(config).toEqual({ - description: 'Description by .gulp.json in directory foo/bar', - }); - done(); - }); - - it('Should convert a value of `flags.gulpfile` to absolute path', - function(done) { - var configFiles = { - a: path.join(fixturesDir, 'flags/gulpfile/.gulp.json'), - }; - - var config = loadConfigFiles(configFiles, ['a']); - - expect(config).toEqual({ - flags: { - gulpfile: path.join(fixturesDir, - 'flags/gulpfile/is/here/mygulpfile.js'), - }, - }); - done(); - }); - -}); diff --git a/test/lib/format-hrtime.js b/test/lib/format-hrtime.js new file mode 100644 index 00000000..71eb9989 --- /dev/null +++ b/test/lib/format-hrtime.js @@ -0,0 +1,238 @@ +'use strict'; + +var expect = require('expect'); +var formatHrtime = require('../../lib/shared/log/format-hrtime'); + +describe('format-hrtime', function() { + describe('should convert hrtime to string: unit is "h"', function() { + it('should be no decimal part if integer part greater than 10', function(done) { + expect(formatHrtime([36000, 100])).toEqual('10 h'); + done(); + }); + + it('should round first decimal place if integer part greather than 10', function(done) { + expect(formatHrtime([36123, 100])).toEqual('10 h'); + expect(formatHrtime([37800, 0])).toEqual('11 h'); + done(); + }); + + it('should print until second decimal place if integer part less than 10', function(done) { + expect(formatHrtime([35100, 100])).toEqual('9.75 h'); + done(); + }); + + it('should round third decimal place if integer part less than 10', function(done) { + expect(formatHrtime([35117, 0])).toEqual('9.75 h'); + expect(formatHrtime([35119, 100])).toEqual('9.76 h'); + done(); + }); + + it('should trim last "0" in decimal part', function(done) { + expect(formatHrtime([32761, 100])).toEqual('9.1 h'); + expect(formatHrtime([32725, 100])).toEqual('9.09 h'); + expect(formatHrtime([32414, 100])).toEqual('9 h'); + done(); + }); + + it('should convert minimum hrtime of unit "h" normally', function(done) { + expect(formatHrtime([3600, 0])).toEqual('1 h'); + done(); + }); + + it('should be no larger unit than `h`', function(done) { + expect(formatHrtime([360123, 100])).toEqual('100 h'); + done(); + }); + }); + + describe('should convert hrtime to string: unit is "min"', function() { + it('should be no decimal part if integer part greater than 10', function(done) { + expect(formatHrtime([600, 100])).toEqual('10 min'); + done(); + }); + + it('should round first decimal place if integer part greather than 10', function(done) { + expect(formatHrtime([624, 100])).toEqual('10 min'); + expect(formatHrtime([630, 0])).toEqual('11 min'); + done(); + }); + + it('should print until second decimal place if integer part less than 10', function(done) { + expect(formatHrtime([599, 100])).toEqual('9.98 min'); + done(); + }); + + it('should round third decimal place if integer part less than 10', function(done) { + expect(formatHrtime([585, 29e7])).toEqual('9.75 min'); + expect(formatHrtime([585, 3e8])).toEqual('9.76 min'); + done(); + }); + + it('should trim last "0" in decimal part', function(done) { + expect(formatHrtime([594, 100])).toEqual('9.9 min'); + expect(formatHrtime([540, 100])).toEqual('9 min'); + done(); + }); + + it('should convert minimum hrtime of unit "min" normally', function(done) { + expect(formatHrtime([60, 0])).toEqual('1 min'); + done(); + }); + + it('should convert maximum hrtime of unit "min" normally', function(done) { + expect(formatHrtime([3599, 999999999])).toEqual('60 min'); + done(); + }); + }); + + describe('should convert hrtime to string: unit is "s"', function() { + it('should be no decimal part if integer part greater than 10', function(done) { + expect(formatHrtime([10, 12e7])).toEqual('10 s'); + done(); + }); + + it('should round first decimal place if integer part greather than 10', function(done) { + expect(formatHrtime([10, 4e8])).toEqual('10 s'); + expect(formatHrtime([10, 5e8])).toEqual('11 s'); + done(); + }); + + it('should print until second decimal place if integer part less than 10', function(done) { + expect(formatHrtime([9, 12e7])).toEqual('9.12 s'); + done(); + }); + + it('should round third decimal place if integer part less than 10', function(done) { + expect(formatHrtime([9, 124e6])).toEqual('9.12 s'); + expect(formatHrtime([9, 125e6])).toEqual('9.13 s'); + done(); + }); + + it('should trim last "0" in decimal part', function(done) { + expect(formatHrtime([9, 100e6])).toEqual('9.1 s'); + expect(formatHrtime([9, 0])).toEqual('9 s'); + done(); + }); + + it('should convert minimum hrtime of unit "s" normally', function(done) { + expect(formatHrtime([1, 0])).toEqual('1 s'); + done(); + }); + + it('should convert maximum hrtime of unit "s" normally', function(done) { + expect(formatHrtime([59, 999999999])).toEqual('60 s'); + done(); + }); + }); + + describe('should convert hrtime to string: unit is "ms"', function() { + it('should be no decimal part if integer part greater than 10', function(done) { + expect(formatHrtime([0, 10123456])).toEqual('10 ms'); + done(); + }); + + it('should round first decimal place if integer part greather than 10', function(done) { + expect(formatHrtime([0, 10423456])).toEqual('10 ms'); + expect(formatHrtime([0, 10500000])).toEqual('11 ms'); + done(); + }); + + it('should print until second decimal place if integer part less than 10', function(done) { + expect(formatHrtime([0, 9123456])).toEqual('9.12 ms'); + done(); + }); + + it('should round third decimal place if integer part less than 10', function(done) { + expect(formatHrtime([0, 9124999])).toEqual('9.12 ms'); + expect(formatHrtime([0, 9125000])).toEqual('9.13 ms'); + done(); + }); + + it('should trim last "0" in decimal part', function(done) { + expect(formatHrtime([0, 9100000])).toEqual('9.1 ms'); + expect(formatHrtime([0, 9000000])).toEqual('9 ms'); + done(); + }); + + it('should convert minimum hrtime of unit "ms" normally', function(done) { + expect(formatHrtime([0, 1000000])).toEqual('1 ms'); + done(); + }); + + it('should convert maximum hrtime of unit "ms" normally', function(done) { + expect(formatHrtime([0, 999999999])).toEqual('1000 ms'); + done(); + }); + }); + + describe('should convert hrtime to string: unit is "μs"', function() { + it('should be no decimal part if integer part greater than 10', function(done) { + expect(formatHrtime([0, 10123])).toEqual('10 μs'); + done(); + }); + + it('should round first decimal place if integer part greather than 10', function(done) { + expect(formatHrtime([0, 10423])).toEqual('10 μs'); + expect(formatHrtime([0, 10500])).toEqual('11 μs'); + done(); + }); + + it('should print until second decimal place if integer part less than 10', function(done) { + expect(formatHrtime([0, 9123])).toEqual('9.12 μs'); + done(); + }); + + it('should round third decimal place if integer part less than 10', function(done) { + expect(formatHrtime([0, 9124])).toEqual('9.12 μs'); + expect(formatHrtime([0, 9125])).toEqual('9.13 μs'); + done(); + }); + + it('should trim last "0" in decimal part', function(done) { + expect(formatHrtime([0, 9100])).toEqual('9.1 μs'); + expect(formatHrtime([0, 9000])).toEqual('9 μs'); + done(); + }); + + it('should convert minimum hrtime of unit "μs" normally', function(done) { + expect(formatHrtime([0, 1000])).toEqual('1 μs'); + done(); + }); + + it('should convert maximum hrtime of unit "μs" normally', function(done) { + expect(formatHrtime([0, 999999])).toEqual('1000 μs'); + done(); + }); + }); + + describe('should convert hrtime to string: unit is "ns"', function() { + it('should convert minimum hrtime of unit "μs" normally', function(done) { + expect(formatHrtime([0, 1])).toEqual('1 ns'); + done(); + }); + + it('should convert maximum hrtime of unit "μs" normally', function(done) { + expect(formatHrtime([0, 999])).toEqual('999 ns'); + done(); + }); + }); + + describe('should convert irregular hrtime to an empty string', function() { + it('should convert non hrtime to an empty string', function(done) { + expect(formatHrtime(1234567890)).toEqual(''); + expect(formatHrtime('1234567890')).toEqual(''); + done(); + }); + + it('should convert bad hrtime to an empty string', function(done) { + expect(formatHrtime(['123', 123])).toEqual(''); + expect(formatHrtime([123, '123'])).toEqual(''); + done(); + }); + + it('should covert zero hrtime to an empty string', function(done) { + expect(formatHrtime([0, 0])).toEqual(''); + done(); + }); + }); +}); diff --git a/test/lib/get-remote-json.js b/test/lib/get-remote-json.js new file mode 100644 index 00000000..f610f84a --- /dev/null +++ b/test/lib/get-remote-json.js @@ -0,0 +1,34 @@ +'use strict'; + +var expect = require('expect'); +var getRemoteJson = require('../../lib/shared/blacklist/get-remote-json'); + +describe('lib: blacklist/get-remote-json', function() { + + it('should get normal json', function(done) { + var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/blackList.json'; + getRemoteJson(url, function(err, json) { + expect(err).toBeNull(); + expect(json['gulp-blink']).toEqual('deprecated. use `blink` instead.'); + done(); + }); + }); + + it('should get error when 404', function(done) { + var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/xxx.json'; + getRemoteJson(url, function(err, json) { + expect(err.message).toEqual('Request failed. Status Code: 404'); + expect(json).toBeFalsy(); + done(); + }); + }); + + it('should get error when not json', function(done) { + var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/README.md'; + getRemoteJson(url, function(err, json) { + expect(err.message).toEqual('Invalid Blacklist JSON.'); + expect(json).toBeFalsy(); + done(); + }); + }); +}); diff --git a/test/lib/log-copy-tree.js b/test/lib/log-copy-tree.js index ab646443..4a679a6e 100644 --- a/test/lib/log-copy-tree.js +++ b/test/lib/log-copy-tree.js @@ -16,7 +16,7 @@ describe('lib: copy-tree', function() { var opts = {}; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual({ nodes: [] }); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -42,7 +42,7 @@ describe('lib: copy-tree', function() { }, ], }); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -51,7 +51,7 @@ describe('lib: copy-tree', function() { var opts = {}; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(srcTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -60,7 +60,7 @@ describe('lib: copy-tree', function() { var opts = {}; var newTree = copyTree(srcTree, opts); expect(newTree).toEqual(srcTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -68,7 +68,7 @@ describe('lib: copy-tree', function() { var srcTree = require('../fixtures/copy-tree'); var newTree = copyTree(srcTree); expect(newTree).toEqual(srcTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -81,7 +81,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: 0 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -92,7 +92,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: 1 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -103,7 +103,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: 2 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -114,7 +114,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: 3 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -125,7 +125,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: 4 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -136,7 +136,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: 5 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -147,7 +147,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: -1 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -158,12 +158,12 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: null }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); opts = { tasksDepth: 'A' }; newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -177,7 +177,7 @@ describe('lib: copy-tree', function() { var opts = { compactTasks: true }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); }); diff --git a/test/lib/merge-configs.js b/test/lib/merge-configs.js new file mode 100644 index 00000000..6d0a4bea --- /dev/null +++ b/test/lib/merge-configs.js @@ -0,0 +1,119 @@ +'use strict'; + +var expect = require('expect'); +var path = require('path'); +var mergeConfigs = require('../../lib/shared/config/merge-configs'); + +var fixturesDir = path.join(__dirname, '../fixtures/config'); + +describe('lib: config/merge-configs', function() { + + it('Should get merged config when there is only project config', function(done) { + var config = { + project: { + description: 'description by .gulp.js in directory project', + }, + userHome: {}, + }; + var configFiles = { + project: path.join(fixturesDir, 'project/.gulp.js'), + userHome: undefined, + }; + var env = { + config: config, + configFiles: configFiles, + }; + + var cfg = mergeConfigs(env); + + expect(cfg).toEqual({ + description: 'description by .gulp.js in directory project', + }); + done(); + }); + + it('Should get merged config when there is only user-home config', function(done) { + var config = { + project: {}, + userHome: { + description: 'description by .gulp.js in directory user home', + }, + }; + var configFiles = { + project: undefined, + userHome: path.join(fixturesDir, 'user/home/.gulp.js'), + }; + var env = { + config: config, + configFiles: configFiles, + }; + + var cfg = mergeConfigs(env); + + expect(cfg).toEqual({ + description: 'description by .gulp.js in directory user home', + }); + done(); + }); + + it('Should get merged config when there are both project and user-home config', function(done) { + var config = { + project: { + description: 'description by .gulp.js in directory project', + flags: { + series: true, + }, + }, + userHome: { + description: 'description by .gulp.js in directory user home', + flags: { + silent: true, + }, + }, + }; + var configFiles = { + project: path.join(fixturesDir, 'project/gulp.js'), + userHome: path.join(fixturesDir, 'user/home/.gulp.js'), + }; + var env = { + config: config, + configFiles: configFiles, + }; + + var cfg = mergeConfigs(env); + + expect(cfg).toEqual({ + description: 'description by .gulp.js in directory project', + flags: { + series: true, + silent: true, + }, + }); + done(); + }); + + it('Should convert a value of `flags.gulpfile` to absolute path', function(done) { + var config = { + project: { + flags: { gulpfile: './is/here/mygulpfile.js' }, + }, + }; + var configFiles = { + project: path.join(fixturesDir, 'flags/gulpfile/.gulp.json'), + }; + var env = { + config: config, + configFiles: configFiles, + }; + + var cfg = mergeConfigs(env); + + expect(cfg).toEqual({ + flags: { + gulpfile: path.join(fixturesDir, 'flags/gulpfile/is/here/mygulpfile.js'), + }, + }); + done(); + }); + +}); diff --git a/test/lib/task-tree.js b/test/lib/task-tree.js index 7dd46e89..ffe4dcad 100644 --- a/test/lib/task-tree.js +++ b/test/lib/task-tree.js @@ -7,7 +7,7 @@ var taskTree = require('../../lib/versioned/^3.7.0/task-tree'); describe('lib: taskTree', function() { it('forms a tree properly', function(done) { - expect(taskTree).toExist(); // Lol shutup jshint + expect(taskTree).not.toBeNull(); // Lol shutup jshint var tasks = { test: { diff --git a/test/logging.js b/test/logging.js index 9f7eac03..11d6bd5a 100644 --- a/test/logging.js +++ b/test/logging.js @@ -1,15 +1,15 @@ 'use strict'; var expect = require('expect'); -var child = require('child_process'); +var exec = require('child_process').exec; describe('logging', function() { it('log-level flag for debug: -LLLL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -LLLL', cb); + exec('node ' + __dirname + '/fixtures/logging.js -LLLL', cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toMatch('test error'); stdout = stdout.replace(/\\/g, '/').split('\n'); expect(stdout[0]).toMatch('test debug'); @@ -20,10 +20,10 @@ describe('logging', function() { }); it('no log-level flag: defaults to -LLL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js', cb); + exec('node ' + __dirname + '/fixtures/logging.js', cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toMatch('test error'); stdout = stdout.replace(/\\/g, '/').split('\n'); expect(stdout[0]).toMatch('test info'); @@ -33,10 +33,10 @@ describe('logging', function() { }); it('log-level flag for info: -LLL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -LLL', cb); + exec('node ' + __dirname + '/fixtures/logging.js -LLL', cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toMatch('test error'); stdout = stdout.replace(/\\/g, '/').split('\n'); expect(stdout[0]).toMatch('test info'); @@ -46,10 +46,10 @@ describe('logging', function() { }); it('log-level flag for warn: -LL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -LL', cb); + exec('node ' + __dirname + '/fixtures/logging.js -LL', cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toMatch('test error'); stdout = stdout.replace(/\\/g, '/').split('\n'); expect(stdout[0]).toMatch('test warn'); @@ -58,10 +58,10 @@ describe('logging', function() { }); it('log-level flag for error: -L', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -L', cb); + exec('node ' + __dirname + '/fixtures/logging.js -L', cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toMatch('test error'); expect(stdout).toEqual(''); done(err); diff --git a/test/non-completing-tasks.js b/test/non-completing-tasks.js deleted file mode 100644 index e7a521e3..00000000 --- a/test/non-completing-tasks.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var eraseTime = require('gulp-test-tools').eraseTime; -var runner = require('gulp-test-tools').gulpRunner; - - -describe('sync-task', function() { - it('should return error code 1 if any tasks did not complete', function(done) { - // The exit code is set to 1 by setting process.exitCode = 1 which is only supported from nodejs 0.11 on - if (process.version.slice(0, 5) === 'v0.10') { - this.skip(); - } - - runner({ verbose: false }) - .chdir('test/fixtures/gulpfiles') - .gulp('test6 test7 test8') - .run(function(err) { - expect(err).toNotEqual(null); - expect(err.code).toEqual(1); - done(); - }); - }); - - it('should log tasks which did not complete', function(done) { - runner({ verbose: false }) - .chdir('test/fixtures/gulpfiles') - .gulp('test6 test7 test8') - .run(function(err, stdout) { - var lines = stdout.split('\n'); - expect(lines.length).toEqual(8); - expect(eraseTime(lines[5])).toEqual('The following tasks did not complete: test7, test8'); - done(); - }); - }); - - it('should not log false positive in case of parallel failure', function(done) { - runner({ verbose: false }) - .gulp('--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js') - .run(function(err, stdout) { - expect(stdout).toExclude('The following tasks did not complete:'); - done(); - }); - }); - - it('should not log false positive in case of parallel failure in continue mode', function(done) { - runner({ verbose: false }) - .gulp('--continue --gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js') - .run(function(err, stdout) { - expect(stdout).toExclude('The following tasks did not complete:'); - done(); - }); - }); - - it('should log non-completing task alongside a failure in continue mode', function(done) { - runner({ verbose: false }) - .gulp('--continue --gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js broken') - .run(function(err, stdout) { - expect(stdout).toInclude('The following tasks did not complete: broken, notCompleting1\n'); - done(); - }); - }); -}); diff --git a/test/sync-task.js b/test/sync-task.js new file mode 100644 index 00000000..8f1bf677 --- /dev/null +++ b/test/sync-task.js @@ -0,0 +1,72 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); + +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +describe('sync-task', function() { + it('should return error code 1 if any tasks did not complete', function(done) { + var opts = { cwd: path.join(__dirname, 'fixtures/gulpfiles') }; + exec(gulp('test6 test7 test8'), opts, cb); + + function cb(err) { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + done(); + } + }); + + it('should log tasks which did not complete', function(done) { + var opts = { cwd: path.join(__dirname, 'fixtures/gulpfiles') }; + exec(gulp('test6 test7 test8'), opts, cb); + + function cb(err, stdout) { + expect(sliceLines(stdout, 5, 7)).toEqual( + 'The following tasks did not complete: test7, test8\n' + + 'Did you forget to signal async completion?' + ); + done(); + } + }); + + it('should not log false positive in case of parallel failure', function(done) { + var opts = { cwd: path.join(__dirname, '..') }; + exec(gulp( + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js' + ), opts, cb); + + function cb(err, stdout) { + expect(stdout).not.toMatch('The following tasks did not complete:'); + done(); + } + }); + + it('should not log false positive in case of parallel failure in continue mode', function(done) { + var opts = { cwd: path.join(__dirname, '..') }; + exec(gulp( + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js' + ), opts, cb); + + function cb(err, stdout) { + expect(stdout).not.toMatch('The following tasks did not complete:'); + done(); + } + }); + + it('should log non-completing task alongside a failure in continue mode', function(done) { + var opts = { cwd: path.join(__dirname, '..') }; + exec(gulp( + '--continue', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js', + 'broken' + ), opts, cb); + + function cb(err, stdout) { + expect(stdout).toMatch('The following tasks did not complete: broken, notCompleting1\n'); + done(); + } + }); +}); diff --git a/test/tool/erase-lapse.js b/test/tool/erase-lapse.js new file mode 100644 index 00000000..f1345e2d --- /dev/null +++ b/test/tool/erase-lapse.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = function(text) { + return (text + '\n') + .replace(/ after [0-9.]+ (s|ms|μs|min)(\r\n|\r|\n)/g, ' after ?\n') + .slice(0, -1); +}; diff --git a/test/tool/erase-time.js b/test/tool/erase-time.js new file mode 100644 index 00000000..444c4412 --- /dev/null +++ b/test/tool/erase-time.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = function(text) { + return ('\n' + text).replace(/(\r\n|\r|\n)\[[0-9:]{8}\] /g, '\n').slice(1); +}; diff --git a/test/tool/gulp-cmd.js b/test/tool/gulp-cmd.js new file mode 100644 index 00000000..87540be1 --- /dev/null +++ b/test/tool/gulp-cmd.js @@ -0,0 +1,16 @@ +'use strict'; + +var path = require('path'); + +function gulp(/* ... */) { + var arr = Array.prototype.slice.apply(arguments); + arr.unshift('node ' + path.join(__dirname, '../../bin/gulp.js')); + return arr.join(' '); +} +gulp.debug = function(/* ... */) { + var s = gulp.apply(null, arguments); + console.log(s); + return s; +} + +module.exports = gulp; diff --git a/test/tool/slice-lines.js b/test/tool/slice-lines.js new file mode 100644 index 00000000..4431d3c8 --- /dev/null +++ b/test/tool/slice-lines.js @@ -0,0 +1,11 @@ +'use strict'; + +var eraseLapse = require('./erase-lapse'); +var eraseTime = require('./erase-time'); + +function sliceLines(text, start, end) { + text = eraseLapse(eraseTime(text)); + return text.split('\n').slice(start, end).join('\n'); +} + +module.exports = sliceLines; From 89a67e5b04b1fd29e0a7b414f45a25e190f54526 Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Fri, 19 Jan 2024 00:08:38 +0900 Subject: [PATCH 04/19] chore(test): Add test for Windows extended-length paths (#225) --- test/window-extended-length-paths.js | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/window-extended-length-paths.js diff --git a/test/window-extended-length-paths.js b/test/window-extended-length-paths.js new file mode 100644 index 00000000..23b5dfe8 --- /dev/null +++ b/test/window-extended-length-paths.js @@ -0,0 +1,55 @@ +'use strict'; + +var expect = require('expect'); +var os = require('os'); +var path = require('path'); + +var childProcess = require('child_process'); +var exec = childProcess.exec; + +var eraseTime = require('./tool/erase-time'); +var eraseLapse = require('./tool/erase-lapse'); +var tildify = require('../lib/shared/tildify'); + +var gulpfileDir = path.resolve(__dirname, 'fixtures/gulpfiles'); +var gulpfilePath = path.resolve(gulpfileDir, 'gulpfile.js'); + +var gulpJsPath = '\\\\?\\' + path.resolve(__dirname, '../bin/gulp.js'); + +describe('windows extended length paths', function() { + it('Should run normaly even if using \'\\\\?\\\'prefix in paths', function(done) { + if (os.platform() !== 'win32') { + this.skip(); + return; + } + + var cmd = ['node', gulpJsPath, '--no-color', '--gulpfile', gulpfilePath].join(' '); + + exec(cmd, function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + + var workingDir = tildify(gulpfileDir); + var usingGulpfile = tildify(gulpfilePath); + + stdout = eraseLapse(eraseTime(stdout)); + expect(stdout).toEqual('' + + 'Working directory changed to ' + workingDir + '\n' + + 'Using gulpfile ' + usingGulpfile + '\n' + + 'Starting \'default\'...\n' + + 'Starting \'test1\'...\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'test1\' after ?\n' + + 'Starting \'test3\'...\n' + + 'Starting \'described\'...\n' + + 'Finished \'described\' after ?\n' + + 'Finished \'test3\' after ?\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'default\' after ?\n' + + ''); + done(); + }); + }); +}); From 7aeee5d82e09099696f44fae25d315ef31c14030 Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Sat, 20 Jan 2024 11:02:37 +0900 Subject: [PATCH 05/19] chore!: Remove `--verify` flag (#251) --- README.md | 5 -- docs/CLI.md | 3 - index.js | 25 --------- lib/shared/blacklist/get-remote-json.js | 39 ------------- lib/shared/blacklist/index.js | 11 ---- lib/shared/log/blacklist-error.js | 15 ----- lib/shared/log/verify.js | 28 ---------- lib/shared/options/parser.js | 5 -- lib/shared/verify-dependencies.js | 34 ------------ test/expected/flags-help.txt | 2 - test/flags-verify.js | 73 ------------------------- test/lib/get-remote-json.js | 34 ------------ 12 files changed, 274 deletions(-) delete mode 100644 lib/shared/blacklist/get-remote-json.js delete mode 100644 lib/shared/blacklist/index.js delete mode 100644 lib/shared/log/blacklist-error.js delete mode 100644 lib/shared/log/verify.js delete mode 100644 lib/shared/verify-dependencies.js delete mode 100644 test/flags-verify.js delete mode 100644 test/lib/get-remote-json.js diff --git a/README.md b/README.md index 71f4d7a7..bde183fd 100644 --- a/README.md +++ b/README.md @@ -157,11 +157,6 @@ __Some flags only work with gulp 4 and will be ignored when invoked against gulp Manually set the CWD. The search for the gulpfile, as well as the relativity of all preloads (with the `--preload` flag) will be from here. - - --verify [path (optional)] - - Will verify plugins referenced in project's package.json against the plugins blacklist. - --tasks -T diff --git a/docs/CLI.md b/docs/CLI.md index fd40368f..0b2bd592 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -43,9 +43,6 @@ gulp has very few flags to know about. All other flags are for tasks to use if n **--cwd** [path] Manually set the CWD. The search for the gulpfile, as well as the relativity of all requires will be from here. -**--verify** [path (optional)] - Will verify plugins referenced in project's package.json against the plugins blacklist. - **--tasks**, **-T** Print the task dependency tree for the loaded gulpfile. diff --git a/index.js b/index.js index 9e5f43b6..935f8928 100644 --- a/index.js +++ b/index.js @@ -14,18 +14,12 @@ var tildify = require('./lib/shared/tildify'); var makeTitle = require('./lib/shared/make-title'); var parser = require('./lib/shared/options/parser'); var completion = require('./lib/shared/completion'); -var verifyDeps = require('./lib/shared/verify-dependencies'); var cliVersion = require('./package.json').version; -var getBlacklist = require('./lib/shared/blacklist'); var toConsole = require('./lib/shared/log/to-console'); var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); var overrideEnvFlagsByConfigAndCliOpts = require('./lib/shared/config/env-flags'); -// Logging functions -var logVerify = require('./lib/shared/log/verify'); -var logBlacklistError = require('./lib/shared/log/blacklist-error'); - // Get supported ranges var ranges = fs.readdirSync(path.join(__dirname, '/lib/versioned/')); @@ -150,25 +144,6 @@ function onExecute(env) { exit(0); } - if (env.config.flags.verify) { - var pkgPath = env.config.flags.verify !== true ? env.config.flags.verify : 'package.json'; - /* istanbul ignore else */ - if (path.resolve(pkgPath) !== path.normalize(pkgPath)) { - pkgPath = path.join(env.cwd, pkgPath); - } - log.info('Verifying plugins in ' + pkgPath); - return getBlacklist(function(err, blacklist) { - /* istanbul ignore if */ - if (err) { - return logBlacklistError(err); - } - - var blacklisted = verifyDeps(require(pkgPath), blacklist); - - logVerify(blacklisted); - }); - } - if (!env.modulePath) { /* istanbul ignore next */ var missingNodeModules = diff --git a/lib/shared/blacklist/get-remote-json.js b/lib/shared/blacklist/get-remote-json.js deleted file mode 100644 index f5a21b68..00000000 --- a/lib/shared/blacklist/get-remote-json.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -var https = require('https'); - -function getRemoteJson(url, cb) { - var chunks = []; - - https.get(url, onRequest).on('error', onError);; - - function onRequest(res) { - if (res.statusCode !== 200) { - res.resume(); // Consume response data to free up memory - return cb(new Error('Request failed. Status Code: ' + res.statusCode)); - } - - res.on('error', onError); - res.on('data', onDrain); - res.on('end', onEnd); - } - - /* istanbul ignore next */ - function onError(e) { - cb(e, null); - } - - function onDrain(d) { - chunks.push(d); - } - - function onEnd() { - try { - cb(null, JSON.parse(Buffer.concat(chunks).toString('utf8'))); - } catch (err) { - cb(new Error('Invalid Blacklist JSON.')); - } - } -} - -module.exports = getRemoteJson; diff --git a/lib/shared/blacklist/index.js b/lib/shared/blacklist/index.js deleted file mode 100644 index edf66fa1..00000000 --- a/lib/shared/blacklist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -var getRemoteJson = require('./get-remote-json'); - -var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/blackList.json'; - -function getBlacklist(cb) { - getRemoteJson(url, cb); -} - -module.exports = getBlacklist; diff --git a/lib/shared/log/blacklist-error.js b/lib/shared/log/blacklist-error.js deleted file mode 100644 index f3361b72..00000000 --- a/lib/shared/log/blacklist-error.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -var log = require('gulplog'); -var chalk = require('chalk'); - -var exit = require('../exit'); - -/* istanbul ignore next */ -function logBlacklistError(err) { - log.error(chalk.red('Error: failed to retrieve plugins black-list')); - log.error(err.message); // Avoid duplicating for each version - exit(1); -} - -module.exports = logBlacklistError; diff --git a/lib/shared/log/verify.js b/lib/shared/log/verify.js deleted file mode 100644 index f635bd39..00000000 --- a/lib/shared/log/verify.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -var log = require('gulplog'); - -var chalk = require('chalk'); -var exit = require('../exit'); - -function logVerify(blacklisted) { - var pluginNames = Object.keys(blacklisted); - - if (!pluginNames.length) { - log.info( - chalk.green('There are no blacklisted plugins in this project') - ); - exit(0); - } - - log.warn(chalk.red('Blacklisted plugins found in this project:')); - - pluginNames.map(function(pluginName) { - var reason = blacklisted[pluginName]; - log.warn(chalk.bgRed(pluginName) + ': ' + reason); - }); - - exit(1); -} - -module.exports = logVerify; diff --git a/lib/shared/options/parser.js b/lib/shared/options/parser.js index 94801742..67594a05 100644 --- a/lib/shared/options/parser.js +++ b/lib/shared/options/parser.js @@ -42,11 +42,6 @@ var options = { 'Manually set the CWD. The search for the gulpfile, ' + 'as well as the relativity of all requires will be from here.'), }, - verify: { - desc: chalk.gray( - 'Will verify plugins referenced in project\'s package.json against ' + - 'the plugins blacklist.'), - }, tasks: { alias: 'T', type: 'boolean', diff --git a/lib/shared/verify-dependencies.js b/lib/shared/verify-dependencies.js deleted file mode 100644 index 2dbe9b7a..00000000 --- a/lib/shared/verify-dependencies.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -/** - * Given a collection of plugin names verifies this collection against - * the blacklist. Returns an object with: - * [plugin name]=>[blacklisting reason] - * or an empty object if none of the dependencies to check are blacklisted. - * - * @param pkg - package.json contents - * @param blacklist - contents of the blacklist in JSON format - */ -function verifyDependencies(pkg, blacklist) { - var pluginNames = [ - 'dependencies', - 'devDependencies', - 'peerDependencies', - ].reduce(function(res, prop) { - return res.concat(Object.keys(pkg[prop] || {})); - }, []); - - var blacklisted = pluginNames.filter(isContainedInBlacklist) - .reduce(function(blacklisted, pluginName) { - blacklisted[pluginName] = blacklist[pluginName]; - return blacklisted; - }, {}); - - return blacklisted; - - function isContainedInBlacklist(pluginName) { - return Boolean(blacklist[pluginName]); - } -} - -module.exports = verifyDependencies; diff --git a/test/expected/flags-help.txt b/test/expected/flags-help.txt index fed71d76..bdf95bbe 100644 --- a/test/expected/flags-help.txt +++ b/test/expected/flags-help.txt @@ -13,8 +13,6 @@ Options: --cwd Manually set the CWD. The search for the gulpfile, as well as the relativity of all requires will be from here. [string] - --verify Will verify plugins referenced in project's - package.json against the plugins blacklist. -T, --tasks Print the task dependency tree for the loaded gulpfile. [boolean] --tasks-simple Print a plaintext list of tasks for the loaded diff --git a/test/flags-verify.js b/test/flags-verify.js deleted file mode 100644 index b3b6f53c..00000000 --- a/test/flags-verify.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var exec = require('child_process').exec; -var path = require('path'); - -var eraseTime = require('./tool/erase-time'); -var gulp = require('./tool/gulp-cmd'); - -var baseDir = path.join(__dirname, '..'); - -describe('flag: --verify', function() { - - it('dependencies with invalid dependency', function(done) { - var opts = { cwd: baseDir }; - exec(gulp( - '--verify invalid-package.json', - '--cwd ./test/fixtures/verify/' - ), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/invalid-package.json') + '\n' + - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use `blink` instead.\n' + - '' - ); - done(); - } - }); - - it('dependencies with valid dependency', function(done) { - var opts = { cwd: baseDir }; - exec(gulp( - '--verify valid-package.json', - '--cwd ./test/fixtures/verify/' - ), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/valid-package.json') + '\n' + - 'There are no blacklisted plugins in this project\n' + - '' - ); - done(err); - } - }); - - it('default args with invalid dependency', function(done) { - var opts = { cwd: baseDir }; - exec(gulp( - '--verify', - '--cwd', path.resolve('./test/fixtures/verify/') - ), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/package.json') + '\n' + - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use `blink` instead.\n' + - '' - ); - done(); - } - }); - -}); diff --git a/test/lib/get-remote-json.js b/test/lib/get-remote-json.js deleted file mode 100644 index f610f84a..00000000 --- a/test/lib/get-remote-json.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var getRemoteJson = require('../../lib/shared/blacklist/get-remote-json'); - -describe('lib: blacklist/get-remote-json', function() { - - it('should get normal json', function(done) { - var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/blackList.json'; - getRemoteJson(url, function(err, json) { - expect(err).toBeNull(); - expect(json['gulp-blink']).toEqual('deprecated. use `blink` instead.'); - done(); - }); - }); - - it('should get error when 404', function(done) { - var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/xxx.json'; - getRemoteJson(url, function(err, json) { - expect(err.message).toEqual('Request failed. Status Code: 404'); - expect(json).toBeFalsy(); - done(); - }); - }); - - it('should get error when not json', function(done) { - var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/README.md'; - getRemoteJson(url, function(err, json) { - expect(err.message).toEqual('Invalid Blacklist JSON.'); - expect(json).toBeFalsy(); - done(); - }); - }); -}); From 0a35a9e396ba3e0d95cd4738c6707b6dd1bf2135 Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Thu, 25 Jan 2024 11:19:53 +0900 Subject: [PATCH 06/19] chore: Remove custom Windows tmpdir logic in test (#252) --- test/execution-errors.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/test/execution-errors.js b/test/execution-errors.js index 35027883..769832a9 100644 --- a/test/execution-errors.js +++ b/test/execution-errors.js @@ -43,13 +43,8 @@ describe('execution error', function() { }); it('should output an error if gulp is not found', function(done) { - var tmpdir = os.tmpdir(); - if (os.platform() === 'win32') { - var moveDrive = tmpdir.slice(0, 2); - exec(moveDrive + '& cd ' + tmpdir + ' & ' + gulp(), cb); - } else { - exec(gulp(), { cwd: tmpdir }, cb); - } + var opts = { cwd: os.tmpdir() }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); From f71effac571906a7fed98a3708ee0e4fd60e5070 Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Thu, 25 Jan 2024 11:20:44 +0900 Subject: [PATCH 07/19] chore: Add a test case for config file in current dir (#253) --- test/config-flags-gulpfile.js | 11 +++++++++++ .../gulpfile/use-current-cfg/current-dir/.gulp.js | 5 +++++ .../use-current-cfg/current-dir/gulpfile-2.js | 8 ++++++++ .../config/flags/gulpfile/use-current-cfg/gulpfile.js | 8 ++++++++ 4 files changed, 32 insertions(+) create mode 100644 test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js create mode 100644 test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/gulpfile-2.js create mode 100644 test/fixtures/config/flags/gulpfile/use-current-cfg/gulpfile.js diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index 329043d4..ae04b7f6 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -145,4 +145,15 @@ describe('config: flags.gulpfile', function() { } }); + it('Should not find up but use config file in current directory', function(done) { + var opts = { cwd: path.join(baseDir, 'use-current-cfg/current-dir') }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 3, 4)).toEqual(path.join(opts.cwd, 'gulpfile-2.js')); + done(err); + } + }); }); diff --git a/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js b/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js new file mode 100644 index 00000000..0cbce526 --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js @@ -0,0 +1,5 @@ +module.exports = { + flags: { + gulpfile: './gulpfile-2.js', + }, +}; diff --git a/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/gulpfile-2.js b/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/gulpfile-2.js new file mode 100644 index 00000000..a2e5369a --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/gulpfile-2.js @@ -0,0 +1,8 @@ +'use strict'; + +var gulp = require('gulp'); + +gulp.task('default', function(done) { + console.log(__filename); + done(); +}); diff --git a/test/fixtures/config/flags/gulpfile/use-current-cfg/gulpfile.js b/test/fixtures/config/flags/gulpfile/use-current-cfg/gulpfile.js new file mode 100644 index 00000000..a2e5369a --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/use-current-cfg/gulpfile.js @@ -0,0 +1,8 @@ +'use strict'; + +var gulp = require('gulp'); + +gulp.task('default', function(done) { + console.log(__filename); + done(); +}); From cb03b9a6698ead4537d77bd0478947366b7d29a6 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 15:20:09 -0700 Subject: [PATCH 08/19] chore!: Remove support for alpha versions of gulp 4 (#255) --- lib/versioned/^4.0.0-alpha.1/index.js | 97 --------------------------- lib/versioned/^4.0.0-alpha.2/index.js | 97 --------------------------- 2 files changed, 194 deletions(-) delete mode 100644 lib/versioned/^4.0.0-alpha.1/index.js delete mode 100644 lib/versioned/^4.0.0-alpha.2/index.js diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js deleted file mode 100644 index c9c5ffc3..00000000 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ /dev/null @@ -1,97 +0,0 @@ -'use strict'; - -var fs = require('fs'); - -var log = require('gulplog'); -var stdout = require('mute-stdout'); -var chalk = require('chalk'); - -var exit = require('../../shared/exit'); -var tildify = require('../../shared/tildify'); - -var logTasks = require('../../shared/log/tasks'); -var logEvents = require('../^4.0.0/log/events'); -var logSyncTask = require('../^4.0.0/log/sync-task'); -var logTasksSimple = require('../^4.0.0/log/tasks-simple'); -var registerExports = require('../../shared/register-exports'); - -var copyTree = require('../../shared/log/copy-tree'); -var requireOrImport = require('../../shared/require-or-import'); - -function execute(env) { - var opts = env.config.flags; - - var tasks = opts._; - var toRun = tasks.length ? tasks : ['default']; - - if (opts.tasksSimple || opts.tasks || opts.tasksJson) { - // Mute stdout if we are listing tasks - stdout.mute(); - } - - var gulpInst = require(env.modulePath); - logEvents(gulpInst); - logSyncTask(gulpInst, opts); - - // This is what actually loads up the gulpfile - requireOrImport(env.configPath, function(err, exported) { - // Before import(), if require() failed we got an unhandled exception on the module level. - // So console.error() & exit() were added here to mimic the old behavior as close as possible. - if (err) { - console.error(err); - exit(1); - } - - registerExports(gulpInst, exported); - - // Always unmute stdout after gulpfile is required - stdout.unmute(); - - var tree; - if (opts.tasksSimple) { - return logTasksSimple(gulpInst.tree()); - } - if (opts.tasks) { - tree = {}; - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; - } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); - } - tree.nodes = gulpInst.tree({ deep: true }); - return logTasks(tree, opts, function(taskname) { - return gulpInst.task(taskname); - }); - } - if (opts.tasksJson) { - tree = {}; - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; - } else { - tree.label = 'Tasks for ' + tildify(env.configPath); - } - tree.nodes = gulpInst.tree({ deep: true }); - - var output = JSON.stringify(copyTree(tree, opts)); - if (typeof opts.tasksJson === 'boolean' && opts.tasksJson) { - return console.log(output); - } - return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); - } - try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); - var runMethod = opts.series ? 'series' : 'parallel'; - gulpInst[runMethod](toRun)(function(err) { - if (err) { - exit(1); - } - }); - } catch (err) { - log.error(chalk.red(err.message)); - log.error('To list available tasks, try running: gulp --tasks'); - exit(1); - } - }); -} - -module.exports = execute; diff --git a/lib/versioned/^4.0.0-alpha.2/index.js b/lib/versioned/^4.0.0-alpha.2/index.js deleted file mode 100644 index 3d1763a6..00000000 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ /dev/null @@ -1,97 +0,0 @@ -'use strict'; - -var fs = require('fs'); - -var log = require('gulplog'); -var stdout = require('mute-stdout'); -var chalk = require('chalk'); - -var exit = require('../../shared/exit'); -var tildify = require('../../shared/tildify'); - -var logTasks = require('../../shared/log/tasks'); -var logEvents = require('../^4.0.0/log/events'); -var logSyncTask = require('../^4.0.0/log/sync-task'); -var logTasksSimple = require('../^4.0.0/log/tasks-simple'); -var registerExports = require('../../shared/register-exports'); - -var copyTree = require('../../shared/log/copy-tree'); -var getTask = require('../^4.0.0/log/get-task'); -var requireOrImport = require('../../shared/require-or-import'); - -function execute(env) { - var opts = env.config.flags; - - var tasks = opts._; - var toRun = tasks.length ? tasks : ['default']; - - if (opts.tasksSimple || opts.tasks || opts.tasksJson) { - // Mute stdout if we are listing tasks - stdout.mute(); - } - - var gulpInst = require(env.modulePath); - logEvents(gulpInst); - logSyncTask(gulpInst, opts); - - // This is what actually loads up the gulpfile - requireOrImport(env.configPath, function(err, exported) { - // Before import(), if require() failed we got an unhandled exception on the module level. - // So console.error() & exit() were added here to mimic the old behavior as close as possible. - if (err) { - console.error(err); - exit(1); - } - - registerExports(gulpInst, exported); - - // Always unmute stdout after gulpfile is required - stdout.unmute(); - - var tree; - if (opts.tasksSimple) { - tree = gulpInst.tree(); - return logTasksSimple(tree.nodes); - } - if (opts.tasks) { - tree = gulpInst.tree({ deep: true }); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; - } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); - } - - return logTasks(tree, opts, getTask(gulpInst)); - } - if (opts.tasksJson) { - tree = gulpInst.tree({ deep: true }); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; - } else { - tree.label = 'Tasks for ' + tildify(env.configPath); - } - - var output = JSON.stringify(copyTree(tree, opts)); - - if (typeof opts.tasksJson === 'boolean' && opts.tasksJson) { - return console.log(output); - } - return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); - } - try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); - var runMethod = opts.series ? 'series' : 'parallel'; - gulpInst[runMethod](toRun)(function(err) { - if (err) { - exit(1); - } - }); - } catch (err) { - log.error(chalk.red(err.message)); - log.error('To list available tasks, try running: gulp --tasks'); - exit(1); - } - }); -} - -module.exports = execute; From c70ce34366abbe7b03fadf33421c6ff2aff0f07a Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 15:33:44 -0700 Subject: [PATCH 09/19] chore: Move task list helper functions into the logTasks closure (#256) --- lib/shared/log/tasks.js | 160 ++++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 2d59fe35..4721774d 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -25,105 +25,105 @@ function logTasks(tree, opts, getTask) { }; printTaskTree(tree, treeOpts); -} - -function printTaskTree(tree, opts) { - var lines = []; - lines.push({ label: tree.label }); - var maxLabelWidth = 0; - - tree.nodes.forEach(function(node, idx, arr) { - var isLast = idx === arr.length - 1; - var w = createTreeLines(node, lines, opts, 1, '', isLast); - maxLabelWidth = Math.max(maxLabelWidth, w || 0); - }); - - lines.forEach(function(line) { - var s = line.label; - if (line.desc) { - var spaces = ' '.repeat(maxLabelWidth - line.label.length) + ' '; - s += spaces + line.desc; - } - log.info(s); - }); -} - -function createTreeLines(node, lines, opts, depth, bars, isLast) { - var task = { label: node.label, bars: bars, depth: depth }; - if (depth === 1) { - var t = opts.getTask(node.label); - task.desc = t.description; - task.flags = t.flags; - } - - var isLeaf = isLeafNode(node, depth, opts); - var maxLabelWidth = addTaskToLines(task, lines, isLast, isLeaf); + function printTaskTree(tree, opts) { + var lines = []; + lines.push({ label: tree.label }); + var maxLabelWidth = 0; - if (!isLeaf) { - bars += (isLast ? ' ' : '│ '); - node.nodes.forEach(function(node, idx, arr) { + tree.nodes.forEach(function(node, idx, arr) { var isLast = idx === arr.length - 1; - createTreeLines(node, lines, opts, depth + 1, bars, isLast); + var w = createTreeLines(node, lines, opts, 1, '', isLast); + maxLabelWidth = Math.max(maxLabelWidth, w || 0); }); - } - - return maxLabelWidth; -} -function addTaskToLines(task, lines, isLast, isLeaf) { - var taskBars = task.bars + (isLast ? '└' : '├') + '─'; - if (isLeaf) { - taskBars += '─ '; - } else { - taskBars += '┬ '; + lines.forEach(function(line) { + var s = line.label; + if (line.desc) { + var spaces = ' '.repeat(maxLabelWidth - line.label.length) + ' '; + s += spaces + line.desc; + } + log.info(s); + }); } - var line = {}; - if (task.depth === 1) { - line.label = chalk.white(taskBars) + chalk.white(task.label); - } else { - line.label = chalk.white(taskBars) + chalk.cyan(task.label); - } - if (typeof task.desc === 'string' && task.desc) { - line.desc = chalk.white(task.desc); - } - lines.push(line); + function createTreeLines(node, lines, opts, depth, bars, isLast) { + var task = { label: node.label, bars: bars, depth: depth }; + if (depth === 1) { + var t = opts.getTask(node.label); + task.desc = t.description; + task.flags = t.flags; + } - var maxLabelWidth = line.label.length + var isLeaf = isLeafNode(node, depth, opts); - if (!isObject(task.flags)) { - return maxLabelWidth; - } + var maxLabelWidth = addTaskToLines(task, lines, isLast, isLeaf); - var flagBars = task.bars; - if (isLast) { - flagBars += ' '; - } else { - flagBars += '│ '; - } + if (!isLeaf) { + bars += (isLast ? ' ' : '│ '); + node.nodes.forEach(function(node, idx, arr) { + var isLast = idx === arr.length - 1; + createTreeLines(node, lines, opts, depth + 1, bars, isLast); + }); + } - if (isLeaf) { - flagBars += ' '; - } else { - flagBars += '│ '; + return maxLabelWidth; } - Object.entries(task.flags).sort(flagSorter).forEach(addFlagsToLines); + function addTaskToLines(task, lines, isLast, isLeaf) { + var taskBars = task.bars + (isLast ? '└' : '├') + '─'; + if (isLeaf) { + taskBars += '─ '; + } else { + taskBars += '┬ '; + } - function addFlagsToLines(ent) { - if (typeof ent[0] !== 'string' || !ent[0]) return; var line = {}; + if (task.depth === 1) { + line.label = chalk.white(taskBars) + chalk.white(task.label); + } else { + line.label = chalk.white(taskBars) + chalk.cyan(task.label); + } + if (typeof task.desc === 'string' && task.desc) { + line.desc = chalk.white(task.desc); + } lines.push(line); - line.label = chalk.white(flagBars) + chalk.magenta(ent[0]); - maxLabelWidth = Math.max(maxLabelWidth, line.label.length); + var maxLabelWidth = line.label.length - if (typeof ent[1] !== 'string' || !ent[1]) return; - line.desc = chalk.white('…' + ent[1]); - } + if (!isObject(task.flags)) { + return maxLabelWidth; + } + + var flagBars = task.bars; + if (isLast) { + flagBars += ' '; + } else { + flagBars += '│ '; + } - return maxLabelWidth; + if (isLeaf) { + flagBars += ' '; + } else { + flagBars += '│ '; + } + + Object.entries(task.flags).sort(flagSorter).forEach(addFlagsToLines); + + function addFlagsToLines(ent) { + if (typeof ent[0] !== 'string' || !ent[0]) return; + var line = {}; + lines.push(line); + line.label = chalk.white(flagBars) + chalk.magenta(ent[0]); + + maxLabelWidth = Math.max(maxLabelWidth, line.label.length); + + if (typeof ent[1] !== 'string' || !ent[1]) return; + line.desc = chalk.white('…' + ent[1]); + } + + return maxLabelWidth; + } } function isLeafNode(node, depth, opts) { From 4fc66f6f5486fb8e4373a5cb3fc3386ff6ce0fea Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 16:06:08 -0700 Subject: [PATCH 10/19] chore: Revert options & yargs parser changes (#257) --- index.js | 18 +++++++++++++++--- .../options/{parser.js => cli-options.js} | 11 +---------- test/fixtures/logging.js | 4 +++- 3 files changed, 19 insertions(+), 14 deletions(-) rename lib/shared/options/{parser.js => cli-options.js} (92%) diff --git a/index.js b/index.js index 935f8928..318e1755 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,9 @@ var fs = require('fs'); var path = require('path'); -var log = require('gulplog'); +var log = require('gulplog'); +var yargs = require('yargs'); var Liftoff = require('liftoff'); var interpret = require('interpret'); var v8flags = require('v8flags'); @@ -12,7 +13,7 @@ var chalk = require('chalk'); var exit = require('./lib/shared/exit'); var tildify = require('./lib/shared/tildify'); var makeTitle = require('./lib/shared/make-title'); -var parser = require('./lib/shared/options/parser'); +var cliOptions = require('./lib/shared/options/cli-options'); var completion = require('./lib/shared/completion'); var cliVersion = require('./package.json').version; var toConsole = require('./lib/shared/log/to-console'); @@ -52,7 +53,18 @@ var cli = new Liftoff({ }, }); -var opts = parser.argv; +var usage = + '\n' + chalk.bold('Usage:') + + ' gulp ' + chalk.blue('[options]') + ' tasks'; + +var parser = yargs + .help(false) + .version(false) + .detectLocale(false) + .usage(usage) + .options(cliOptions); + +var opts = parser.parse(); cli.on('preload:before', function(name) { log.info('Preloading external module:', chalk.magenta(name)); diff --git a/lib/shared/options/parser.js b/lib/shared/options/cli-options.js similarity index 92% rename from lib/shared/options/parser.js rename to lib/shared/options/cli-options.js index 67594a05..8105d461 100644 --- a/lib/shared/options/parser.js +++ b/lib/shared/options/cli-options.js @@ -1,11 +1,6 @@ 'use strict'; var chalk = require('chalk'); -var yargs = require('yargs'); - -var usage = - '\n' + chalk.bold('Usage:') + - ' gulp ' + chalk.blue('[options]') + ' tasks'; var options = { help: { @@ -121,8 +116,4 @@ var options = { } }; -var parser = yargs - .help(false).version(false).detectLocale(false) - .usage(usage).options(options); - -module.exports = parser; +module.exports = options; diff --git a/test/fixtures/logging.js b/test/fixtures/logging.js index aff166e0..6f5c5566 100644 --- a/test/fixtures/logging.js +++ b/test/fixtures/logging.js @@ -1,7 +1,9 @@ var log = require('gulplog'); +var yargs = require('yargs'); var toConsole = require('../../lib/shared/log/to-console'); +var cliOptions = require('../../lib/shared/options/cli-options'); -var opts = require('../../lib/shared/options/parser').argv; +var opts = yargs.options(cliOptions).parse(); toConsole(log, opts); From 36f05d5a8bb5c56437204a37f12fc4b2e31c5430 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 17:48:09 -0700 Subject: [PATCH 11/19] fix: Ensure the logger is wired up before running liftoff (#258) --- index.js | 3 +++ test/config-description.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 318e1755..6ff75f34 100644 --- a/index.js +++ b/index.js @@ -66,6 +66,9 @@ var parser = yargs var opts = parser.parse(); +// Set up event listeners for logging temporarily. +toConsole(log, opts); + cli.on('preload:before', function(name) { log.info('Preloading external module:', chalk.magenta(name)); }); diff --git a/test/config-description.js b/test/config-description.js index ac85fd70..2a185459 100644 --- a/test/config-description.js +++ b/test/config-description.js @@ -48,7 +48,7 @@ describe('config: description', function() { expect(err).toBeNull(); expect(stderr).toEqual(''); var expected = fs.readFileSync(path.join(expectedDir, 'output2.txt'), 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 2)).toEqual(expected); done(err); } }); From ed86da75fddfe0965d9bcc0a299e74f961f50957 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 11:47:58 -0700 Subject: [PATCH 12/19] feat!: Upgrade to Liftoff v5 and avoid merging flags/config/env (#259) --- README.md | 8 +- index.js | 64 +++++----- lib/shared/array-find.js | 19 +++ lib/shared/config/env-flags.js | 56 --------- lib/shared/config/merge-configs.js | 28 ----- lib/versioned/^3.7.0/index.js | 12 +- lib/versioned/^4.0.0/index.js | 12 +- package.json | 2 +- test/config-flags-compact-tasks.js | 16 +-- test/config-flags-gulpfile.js | 16 +-- test/config-flags-preload.js | 2 +- test/config-flags-sort-tasks.js | 8 +- test/config-flags-tasks-depth.js | 4 +- test/expected/flags-tasks-compact.txt | 1 + test/expected/flags-tasks-depth2.txt | 1 + test/expected/flags-tasks-depth4.txt | 1 + test/expected/flags-tasks-sorted.txt | 1 + test/expected/flags-tasks-unsorted.txt | 1 + .../config/flags/compactTasks/f/.gulp.js | 2 +- .../config/flags/compactTasks/t/.gulp.js | 2 +- .../flags/gulpfile/autoload-fail/.gulp.json | 4 +- .../config/flags/gulpfile/autoload/.gulp.json | 4 +- .../config/flags/gulpfile/cwd/.gulp.json | 4 +- .../gulpfile/override-by-cliflag/.gulp.json | 4 +- .../config/flags/gulpfile/prj/.gulp.json | 4 +- .../use-current-cfg/current-dir/.gulp.js | 4 +- .../config/flags/nodeFlags/array/.gulp.json | 4 +- .../config/flags/nodeFlags/null/.gulp.js | 4 +- .../config/flags/nodeFlags/string/.gulp.js | 4 +- .../config/flags/nodeFlags/undefined/.gulp.js | 4 +- .../config/flags/preload/array/.gulp.json | 10 +- .../flags/preload/join-flags/.gulp.json | 8 +- .../config/flags/preload/string/.gulp.json | 4 +- .../flags/preload/with-absolute/.gulp.js | 4 +- .../config/flags/preload/with-cwd/.gulp.json | 4 +- .../config/flags/sortTasks/f/.gulp.json | 4 +- .../config/flags/sortTasks/t/.gulp.json | 4 +- .../config/flags/tasksDepth/.gulp.json | 4 +- test/flags-tasks.js | 10 +- test/lib/config-env-flags.js | 112 ----------------- test/lib/merge-configs.js | 119 ------------------ 41 files changed, 129 insertions(+), 450 deletions(-) create mode 100644 lib/shared/array-find.js delete mode 100644 lib/shared/config/env-flags.js delete mode 100644 lib/shared/config/merge-configs.js delete mode 100644 test/lib/config-env-flags.js delete mode 100644 test/lib/merge-configs.js diff --git a/README.md b/README.md index bde183fd..78ae7453 100644 --- a/README.md +++ b/README.md @@ -101,21 +101,21 @@ The CLI adds `process.env.INIT_CWD` which is the original cwd it was launched fr Configuration is supported through the use of a `.gulp.*` file (e.g. `.gulp.json`, `.gulp.yml`). You can find a list of supported languages at https://github.com/gulpjs/interpret. -Configuration from the home directory (`~`) and current working directory (`cwd`) are merged with `cwd` taking precedence. +A configuration file from the current working directory (`cwd`) or above are selected before a configuration file from the home directory (`~`). Supported configurations properties: | Property | Description | |--------------------|-------------| | description | Top-level description of the project/gulpfile (Replaces "Tasks for ~/path/of/gulpfile.js") | +| gulpfile | Set a default gulpfile | +| preload | An array of modules to preload before running the gulpfile. Any relative paths will be resolved against the `--cwd` directory (if you don't want that behavior, use absolute paths) | +| nodeFlags | An array of flags used to forcibly respawn the process upon startup. For example, if you always want your gulpfiles to run in node's harmony mode, you can set `--harmony` here | | flags.continue | Continue execution of tasks upon failure by default. | | flags.compactTasks | Reduce the output of task dependency tree by default. | | flags.tasksDepth | Set default depth of task dependency tree. | -| flags.gulpfile | Set a default gulpfile | | flags.silent | Silence logging by default | | flags.series | Run tasks given on the CLI in series (the default is parallel) | -| flags.preload | An array of modules to preload before running the gulpfile. Any relative paths will be resolved against the `--cwd` directory (if you don't want that behavior, use absolute paths) | -| flags.nodeFlags | An array of flags used to forcibly respawn the process upon startup. For example, if you always want your gulpfiles to run in node's harmony mode, you can set `--harmony` here | ## Flags diff --git a/index.js b/index.js index 6ff75f34..1ace11ea 100644 --- a/index.js +++ b/index.js @@ -10,16 +10,16 @@ var interpret = require('interpret'); var v8flags = require('v8flags'); var findRange = require('semver-greatest-satisfied-range'); var chalk = require('chalk'); + var exit = require('./lib/shared/exit'); var tildify = require('./lib/shared/tildify'); +var arrayFind = require('./lib/shared/array-find'); var makeTitle = require('./lib/shared/make-title'); var cliOptions = require('./lib/shared/options/cli-options'); var completion = require('./lib/shared/completion'); var cliVersion = require('./package.json').version; var toConsole = require('./lib/shared/log/to-console'); - -var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); -var overrideEnvFlagsByConfigAndCliOpts = require('./lib/shared/config/env-flags'); +var mergeCliOpts = require('./lib/shared/config/cli-flags'); // Get supported ranges var ranges = fs.readdirSync(path.join(__dirname, '/lib/versioned/')); @@ -34,23 +34,19 @@ var cli = new Liftoff({ completions: completion, extensions: interpret.jsVariants, v8flags: v8flags, - configFiles: { - project: [ - { - name: '.gulp', - path: '.', - extensions: interpret.extensions, - findUp: true, - }, - ], - userHome: [ - { - name: '.gulp', - path: '~', - extensions: interpret.extensions, - }, - ], - }, + configFiles: [ + { + name: '.gulp', + path: '.', + extensions: interpret.extensions, + findUp: true, + }, + { + name: '.gulp', + path: '~', + extensions: interpret.extensions, + }, + ], }); var usage = @@ -127,33 +123,41 @@ function run() { module.exports = run; +function isDefined(cfg) { + return cfg != null; +} + function onPrepare(env) { - var cfg = mergeProjectAndUserHomeConfigs(env); - env = overrideEnvFlagsByConfigAndCliOpts(env, cfg, opts); + // We only use the first config found, which is a departure from + // the previous implementation that merged with the home + var cfg = arrayFind(env.config, isDefined); + var flags = mergeCliOpts(opts, cfg); - // Set up event listeners for logging again after configuring. - toConsole(log, env.config.flags); + // Set up event listeners for logging after configuring. + toConsole(log, flags); - cli.execute(env, env.nodeFlags, onExecute); + cli.execute(env, cfg.nodeFlags, function (env) { + onExecute(env, cfg, flags); + }); } // The actual logic -function onExecute(env) { +function onExecute(env, cfg, flags) { // This translates the --continue flag in gulp // To the settle env variable for undertaker // We use the process.env so the user's gulpfile // Can know about the flag - if (env.config.flags.continue) { + if (flags.continue) { process.env.UNDERTAKER_SETTLE = 'true'; } - if (env.config.flags.help) { + if (flags.help) { parser.showHelp(console.log); exit(0); } // Anything that needs to print outside of the logging mechanism should use console.log - if (env.config.flags.version) { + if (flags.version) { console.log('CLI version:', cliVersion); console.log('Local version:', env.modulePackage.version || 'Unknown'); exit(0); @@ -215,5 +219,5 @@ function onExecute(env) { // Load and execute the CLI version var versionedDir = path.join(__dirname, '/lib/versioned/', range, '/'); - require(versionedDir)(env); + require(versionedDir)(env, cfg, flags); } diff --git a/lib/shared/array-find.js b/lib/shared/array-find.js new file mode 100644 index 00000000..0596268c --- /dev/null +++ b/lib/shared/array-find.js @@ -0,0 +1,19 @@ +'use strict'; + +function arrayFind(arr, fn) { + if (!Array.isArray(arr)) { + return; + } + + var idx = 0; + while (idx < arr.length) { + var result = fn(arr[idx]); + if (result) { + // TODO: This is wrong in Liftoff + return arr[idx]; + } + idx++; + } +} + +module.exports = arrayFind; diff --git a/lib/shared/config/env-flags.js b/lib/shared/config/env-flags.js deleted file mode 100644 index 59b4d4be..00000000 --- a/lib/shared/config/env-flags.js +++ /dev/null @@ -1,56 +0,0 @@ -'use strict'; - -var path = require('path'); -var copyProps = require('copy-props'); - -var mergeCliOpts = require('./cli-flags'); - -var toEnvFromConfig = { - configPath: 'flags.gulpfile', - configBase: 'flags.gulpfile', - preload: 'flags.preload', - nodeFlags: 'flags.nodeFlags', -}; - -function overrideEnvFlags(env, config, cliOpts) { - cliOpts = mergeCliOpts(cliOpts, config); - - // This must reverse because `flags.gulpfile` determines 2 different properties - var reverse = true; - env = copyProps(env, config, toEnvFromConfig, convert, reverse); - - env.config = { - flags: cliOpts, - }; - if (config.description) { - env.config.description = config.description; - } - return env - - function convert(configInfo, envInfo) { - if (envInfo.keyChain === 'configBase') { - if (cliOpts.gulpfile === undefined) { - return path.dirname(configInfo.value); - } - return; - } - - if (envInfo.keyChain === 'configPath') { - if (cliOpts.gulpfile === undefined) { - return configInfo.value; - } - return; - } - - if (envInfo.keyChain === 'preload') { - return [].concat(envInfo.value, configInfo.value); - } - - /* istanbul ignore else */ - if (envInfo.keyChain === 'nodeFlags') { - return [].concat(configInfo.value || []); - } - } -} - -module.exports = overrideEnvFlags; diff --git a/lib/shared/config/merge-configs.js b/lib/shared/config/merge-configs.js deleted file mode 100644 index 8202f182..00000000 --- a/lib/shared/config/merge-configs.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -var copyProps = require('copy-props'); -var path = require('path'); - -function mergeConfigs(env) { - var cfg = {}; - if (env.configFiles.userHome) { - copyConfig(env.config.userHome, cfg, env.configFiles.userHome); - } - if (env.configFiles.project) { - copyConfig(env.config.project, cfg, env.configFiles.project); - } - return cfg; -} - -function copyConfig(src, dest, filePath) { - return copyProps(src, dest, convert); - - function convert(loadedInfo) { - if (loadedInfo.keyChain === 'flags.gulpfile') { - return path.resolve(path.dirname(filePath), loadedInfo.value); - } - return loadedInfo.value; - } -} - -module.exports = mergeConfigs; diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index a5cc2a9f..397bd579 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -17,9 +17,7 @@ var logTasksSimple = require('./log/tasks-simple'); var registerExports = require('../../shared/register-exports'); var requireOrImport = require('../../shared/require-or-import'); -function execute(env) { - var opts = env.config.flags; - +function execute(env, cfg, opts) { var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -53,8 +51,8 @@ function execute(env) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; + if (cfg.description && typeof cfg.description === 'string') { + tree.label = cfg.description; } else { tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } @@ -64,8 +62,8 @@ function execute(env) { } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; + if (cfg.description && typeof cfg.description === 'string') { + tree.label = cfg.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index d6883587..137ad438 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -19,9 +19,7 @@ var copyTree = require('../../shared/log/copy-tree'); var getTask = require('./log/get-task'); var requireOrImport = require('../../shared/require-or-import'); -function execute(env) { - var opts = env.config.flags; - +function execute(env, cfg, opts) { var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -55,8 +53,8 @@ function execute(env) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; + if (cfg.description && typeof cfg.description === 'string') { + tree.label = cfg.description; } else { tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } @@ -65,8 +63,8 @@ function execute(env) { } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; + if (cfg.description && typeof cfg.description === 'string') { + tree.label = cfg.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } diff --git a/package.json b/package.json index 47ff7595..dace639b 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "fancy-log": "^2.0.0", "gulplog": "^2.0.1", "interpret": "^3.1.1", - "liftoff": "^4.0.0", + "liftoff": "^5.0.0", "mute-stdout": "^2.0.0", "replace-homedir": "^2.0.0", "semver-greatest-satisfied-range": "^2.0.0", diff --git a/test/config-flags-compact-tasks.js b/test/config-flags-compact-tasks.js index 06945128..57fd19a1 100644 --- a/test/config-flags-compact-tasks.js +++ b/test/config-flags-compact-tasks.js @@ -20,8 +20,8 @@ describe('config: flags.compactTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = sliceLines(expected, 1); - stdout = sliceLines(stdout, 1); + expected = sliceLines(expected, 2); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); @@ -35,8 +35,8 @@ describe('config: flags.compactTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = sliceLines(expected, 1); - stdout = sliceLines(stdout, 1); + expected = sliceLines(expected, 2); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); @@ -50,8 +50,8 @@ describe('config: flags.compactTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = sliceLines(expected, 1); - stdout = sliceLines(stdout, 1); + expected = sliceLines(expected, 2); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); @@ -65,8 +65,8 @@ describe('config: flags.compactTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = sliceLines(expected, 1); - stdout = sliceLines(stdout, 1); + expected = sliceLines(expected, 2); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index ae04b7f6..4d62031c 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -10,7 +10,7 @@ var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, 'fixtures/config/flags/gulpfile'); var prjDir = path.join(baseDir, 'prj'); -describe('config: flags.gulpfile', function() { +describe('config: gulpfile', function() { it('Should configure with a .gulp.* file', function(done) { var opts = { cwd: prjDir }; @@ -19,9 +19,9 @@ describe('config: flags.gulpfile', function() { function cb(err, stdout, stderr) { expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 2, 4)).toEqual( + expect(sliceLines(stdout, 3, 5)).toEqual( 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-prj-cfg.js') + '\n' + - 'The current directory : ' + prjDir + 'The current directory : ' + path.join(baseDir, 'is/here') ); done(err); } @@ -49,9 +49,9 @@ describe('config: flags.gulpfile', function() { function cb(err, stdout, stderr) { expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 2, 4)).toEqual( + expect(sliceLines(stdout, 3, 5)).toEqual( 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-prj-cfg.js') + '\n' + - 'The current directory : ' + path.join(prjDir, 'findup') + 'The current directory : ' + path.join(baseDir, 'is/here') ); done(err); } @@ -126,8 +126,8 @@ describe('config: flags.gulpfile', function() { expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 0, 1)).toEqual('Loaded external module: @babel/register'); - expect(sliceLines(stdout, 4, 5)).toEqual('clean!'); - expect(sliceLines(stdout, 7, 8)).toEqual('build!'); + expect(sliceLines(stdout, 5, 6)).toEqual('clean!'); + expect(sliceLines(stdout, 8, 9)).toEqual('build!'); done(err); } }); @@ -152,7 +152,7 @@ describe('config: flags.gulpfile', function() { function cb(err, stdout, stderr) { expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 3, 4)).toEqual(path.join(opts.cwd, 'gulpfile-2.js')); + expect(sliceLines(stdout, 2, 3)).toEqual(path.join(opts.cwd, 'gulpfile-2.js')); done(err); } }); diff --git a/test/config-flags-preload.js b/test/config-flags-preload.js index 47942363..e406da09 100644 --- a/test/config-flags-preload.js +++ b/test/config-flags-preload.js @@ -9,7 +9,7 @@ var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, 'fixtures/config/flags/preload'); -describe('config: flags.preload', function() { +describe('config: preload', function() { it('Should configure with an array in a .gulp.* file', function(done) { var opts = { cwd: path.join(baseDir, 'array') }; diff --git a/test/config-flags-sort-tasks.js b/test/config-flags-sort-tasks.js index 01eada8d..197f8d39 100644 --- a/test/config-flags-sort-tasks.js +++ b/test/config-flags-sort-tasks.js @@ -20,7 +20,7 @@ describe('config: flags.sortTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } @@ -33,7 +33,7 @@ describe('config: flags.sortTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } @@ -46,7 +46,7 @@ describe('config: flags.sortTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } @@ -59,7 +59,7 @@ describe('config: flags.sortTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } diff --git a/test/config-flags-tasks-depth.js b/test/config-flags-tasks-depth.js index 944766c2..68a09037 100644 --- a/test/config-flags-tasks-depth.js +++ b/test/config-flags-tasks-depth.js @@ -20,7 +20,7 @@ describe('config: flags.tasksDepth', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } @@ -33,7 +33,7 @@ describe('config: flags.tasksDepth', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-depth2.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } diff --git a/test/expected/flags-tasks-compact.txt b/test/expected/flags-tasks-compact.txt index 45bc48d3..d15def9b 100644 --- a/test/expected/flags-tasks-compact.txt +++ b/test/expected/flags-tasks-compact.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ taskC │ └─┬ diff --git a/test/expected/flags-tasks-depth2.txt b/test/expected/flags-tasks-depth2.txt index ffd130ef..3edbdf74 100644 --- a/test/expected/flags-tasks-depth2.txt +++ b/test/expected/flags-tasks-depth2.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ taskC │ └── diff --git a/test/expected/flags-tasks-depth4.txt b/test/expected/flags-tasks-depth4.txt index b1550ad5..6d79eb1e 100644 --- a/test/expected/flags-tasks-depth4.txt +++ b/test/expected/flags-tasks-depth4.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ taskC │ └─┬ diff --git a/test/expected/flags-tasks-sorted.txt b/test/expected/flags-tasks-sorted.txt index 65d61c0c..1bdc4cfd 100644 --- a/test/expected/flags-tasks-sorted.txt +++ b/test/expected/flags-tasks-sorted.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ default │ └─┬ diff --git a/test/expected/flags-tasks-unsorted.txt b/test/expected/flags-tasks-unsorted.txt index fe916931..edd85682 100644 --- a/test/expected/flags-tasks-unsorted.txt +++ b/test/expected/flags-tasks-unsorted.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ taskC │ └─┬ diff --git a/test/fixtures/config/flags/compactTasks/f/.gulp.js b/test/fixtures/config/flags/compactTasks/f/.gulp.js index 53447e50..9fef64e2 100644 --- a/test/fixtures/config/flags/compactTasks/f/.gulp.js +++ b/test/fixtures/config/flags/compactTasks/f/.gulp.js @@ -1,8 +1,8 @@ 'use strict'; module.exports = { + gulpfile: '../../../../gulpfiles/gulpfile-4.js', flags: { compactTasks: false, - gulpfile: '../../../../gulpfiles/gulpfile-4.js', }, }; diff --git a/test/fixtures/config/flags/compactTasks/t/.gulp.js b/test/fixtures/config/flags/compactTasks/t/.gulp.js index 70c8de7d..8ac27e43 100644 --- a/test/fixtures/config/flags/compactTasks/t/.gulp.js +++ b/test/fixtures/config/flags/compactTasks/t/.gulp.js @@ -1,8 +1,8 @@ 'use strict'; module.exports = { + gulpfile: '../../../../gulpfiles/gulpfile-4.js', flags: { compactTasks: true, - gulpfile: '../../../../gulpfiles/gulpfile-4.js', }, }; diff --git a/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json b/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json index 10707925..42846df5 100644 --- a/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "./other_dir/gulpfile.coffee" - } + "gulpfile": "./other_dir/gulpfile.coffee" } diff --git a/test/fixtures/config/flags/gulpfile/autoload/.gulp.json b/test/fixtures/config/flags/gulpfile/autoload/.gulp.json index 0d5c0009..10c5b586 100644 --- a/test/fixtures/config/flags/gulpfile/autoload/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/autoload/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "other_folder/gulpfile-exports.babel.js" - } + "gulpfile": "other_folder/gulpfile-exports.babel.js" } diff --git a/test/fixtures/config/flags/gulpfile/cwd/.gulp.json b/test/fixtures/config/flags/gulpfile/cwd/.gulp.json index 231d1a67..7f0181dd 100644 --- a/test/fixtures/config/flags/gulpfile/cwd/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/cwd/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "../is/here/gulpfile-by-cwd-cfg.js" - } + "gulpfile": "../is/here/gulpfile-by-cwd-cfg.js" } diff --git a/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json b/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json index f071d31d..fb737ede 100644 --- a/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "../cwd/gulpfile.js" - } + "gulpfile": "../cwd/gulpfile.js" } diff --git a/test/fixtures/config/flags/gulpfile/prj/.gulp.json b/test/fixtures/config/flags/gulpfile/prj/.gulp.json index 64535ec4..625bb7c1 100644 --- a/test/fixtures/config/flags/gulpfile/prj/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/prj/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "../is/here/gulpfile-by-prj-cfg.js" - } + "gulpfile": "../is/here/gulpfile-by-prj-cfg.js" } diff --git a/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js b/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js index 0cbce526..8e905bea 100644 --- a/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js +++ b/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js @@ -1,5 +1,3 @@ module.exports = { - flags: { - gulpfile: './gulpfile-2.js', - }, + gulpfile: './gulpfile-2.js', }; diff --git a/test/fixtures/config/flags/nodeFlags/array/.gulp.json b/test/fixtures/config/flags/nodeFlags/array/.gulp.json index f327928a..79cd530d 100644 --- a/test/fixtures/config/flags/nodeFlags/array/.gulp.json +++ b/test/fixtures/config/flags/nodeFlags/array/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "nodeFlags": ["--lazy", "--trace-deprecation"] - } + "nodeFlags": ["--lazy", "--trace-deprecation"] } diff --git a/test/fixtures/config/flags/nodeFlags/null/.gulp.js b/test/fixtures/config/flags/nodeFlags/null/.gulp.js index 1b0bdfb1..4f613ce0 100644 --- a/test/fixtures/config/flags/nodeFlags/null/.gulp.js +++ b/test/fixtures/config/flags/nodeFlags/null/.gulp.js @@ -1,7 +1,5 @@ 'use strict'; module.exports = { - flags: { - nodeFlags: null, - }, + nodeFlags: null, }; diff --git a/test/fixtures/config/flags/nodeFlags/string/.gulp.js b/test/fixtures/config/flags/nodeFlags/string/.gulp.js index 608862dd..f14523e4 100644 --- a/test/fixtures/config/flags/nodeFlags/string/.gulp.js +++ b/test/fixtures/config/flags/nodeFlags/string/.gulp.js @@ -1,7 +1,5 @@ 'use strict'; module.exports = { - flags: { - nodeFlags: '--lazy', - }, + nodeFlags: '--lazy', }; diff --git a/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js b/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js index 35082449..78532965 100644 --- a/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js +++ b/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js @@ -1,7 +1,5 @@ 'use strict'; module.exports = { - flags: { - nodeFlags: undefined, - }, + nodeFlags: undefined, }; diff --git a/test/fixtures/config/flags/preload/array/.gulp.json b/test/fixtures/config/flags/preload/array/.gulp.json index 0031374c..2f4855e1 100644 --- a/test/fixtures/config/flags/preload/array/.gulp.json +++ b/test/fixtures/config/flags/preload/array/.gulp.json @@ -1,8 +1,6 @@ { - "flags": { - "preload": [ - "./preload_one", - "./preload_two" - ] - } + "preload": [ + "./preload_one", + "./preload_two" + ] } diff --git a/test/fixtures/config/flags/preload/join-flags/.gulp.json b/test/fixtures/config/flags/preload/join-flags/.gulp.json index 83d17ccf..63405ae5 100644 --- a/test/fixtures/config/flags/preload/join-flags/.gulp.json +++ b/test/fixtures/config/flags/preload/join-flags/.gulp.json @@ -1,7 +1,5 @@ { - "flags": { - "preload": [ - "./preload_two" - ] - } + "preload": [ + "./preload_two" + ] } diff --git a/test/fixtures/config/flags/preload/string/.gulp.json b/test/fixtures/config/flags/preload/string/.gulp.json index 9b061f1f..22886303 100644 --- a/test/fixtures/config/flags/preload/string/.gulp.json +++ b/test/fixtures/config/flags/preload/string/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "preload": "./preload" - } + "preload": "./preload" } diff --git a/test/fixtures/config/flags/preload/with-absolute/.gulp.js b/test/fixtures/config/flags/preload/with-absolute/.gulp.js index c0e29e8a..1e7872b2 100644 --- a/test/fixtures/config/flags/preload/with-absolute/.gulp.js +++ b/test/fixtures/config/flags/preload/with-absolute/.gulp.js @@ -1,7 +1,5 @@ var path = require('path'); module.exports = { - flags: { - preload: path.join(__dirname, '../preload'), - }, + preload: path.join(__dirname, '../preload'), }; diff --git a/test/fixtures/config/flags/preload/with-cwd/.gulp.json b/test/fixtures/config/flags/preload/with-cwd/.gulp.json index d43feab5..c92f9743 100644 --- a/test/fixtures/config/flags/preload/with-cwd/.gulp.json +++ b/test/fixtures/config/flags/preload/with-cwd/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "preload": "../preload" - } + "preload": "../preload" } diff --git a/test/fixtures/config/flags/sortTasks/f/.gulp.json b/test/fixtures/config/flags/sortTasks/f/.gulp.json index ac703623..daa8a926 100644 --- a/test/fixtures/config/flags/sortTasks/f/.gulp.json +++ b/test/fixtures/config/flags/sortTasks/f/.gulp.json @@ -1,6 +1,6 @@ { + "gulpfile": "../../../../gulpfiles/gulpfile-4.js", "flags": { - "sortTasks": false, - "gulpfile": "../../../../gulpfiles/gulpfile-4.js" + "sortTasks": false } } diff --git a/test/fixtures/config/flags/sortTasks/t/.gulp.json b/test/fixtures/config/flags/sortTasks/t/.gulp.json index 7e801098..254cd26a 100644 --- a/test/fixtures/config/flags/sortTasks/t/.gulp.json +++ b/test/fixtures/config/flags/sortTasks/t/.gulp.json @@ -1,6 +1,6 @@ { + "gulpfile": "../../../../gulpfiles/gulpfile-4.js", "flags": { - "sortTasks": true, - "gulpfile": "../../../../gulpfiles/gulpfile-4.js" + "sortTasks": true } } diff --git a/test/fixtures/config/flags/tasksDepth/.gulp.json b/test/fixtures/config/flags/tasksDepth/.gulp.json index 5a9da057..bc309203 100644 --- a/test/fixtures/config/flags/tasksDepth/.gulp.json +++ b/test/fixtures/config/flags/tasksDepth/.gulp.json @@ -1,6 +1,6 @@ { + "gulpfile": "../../../gulpfiles/gulpfile-4.js", "flags": { - "tasksDepth": 4, - "gulpfile": "../../../gulpfiles/gulpfile-4.js" + "tasksDepth": 4 } } diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 4a1c689f..270b5ffc 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -81,7 +81,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); @@ -99,7 +99,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); @@ -117,7 +117,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); @@ -135,7 +135,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); @@ -153,7 +153,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); diff --git a/test/lib/config-env-flags.js b/test/lib/config-env-flags.js deleted file mode 100644 index d8062c08..00000000 --- a/test/lib/config-env-flags.js +++ /dev/null @@ -1,112 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var overrideEnvFlags = require('../../lib/shared/config/env-flags'); - -describe('lib: config/env-flags', function() { - - it('Should copy only config props specified to env flags', function(done) { - var env = {}; - - var config = { - description: 'DESCRIPTION.', - flags: { - silent: true, - gulpfile: '/path/to/gulpfile', - }, - }; - - var result = overrideEnvFlags(env, config, {}); - expect(result).toEqual({ - configPath: '/path/to/gulpfile', - configBase: '/path/to', - config: { - description: 'DESCRIPTION.', - flags: { - silent: true, - }, - }, - }); - expect(result).toBe(env); - done(); - }); - - it('Should take into account forced gulpfile opts from flags', function(done) { - var env = { - cwd: '/path/to/cwd', - preload: 'preload', - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - }; - - var config = { - description: 'DESCRIPTION.', - flags: { - silent: false, - gulpfile: '/path/to/gulpfile', - preload: ['a', 'b'], - }, - }; - - var opts = { - gulpfile: env.configPath, - }; - - var result = overrideEnvFlags(env, config, opts); - expect(result).toEqual({ - cwd: '/path/to/cwd', - preload: ['preload', 'a', 'b'], - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - config: { - description: "DESCRIPTION.", - flags: { - gulpfile: "/path/of/config/path", - silent: false, - }, - }, - }); - expect(result).toBe(env); - done(); - }); - - it('Should not cause error if config is empty', function(done) { - var env = { - cwd: '/path/to/cwd', - preload: 'preload', - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - }; - - var config = {}; - - var result = overrideEnvFlags(env, config, {}); - expect(result).toEqual({ - cwd: '/path/to/cwd', - preload: 'preload', - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - config: { - flags: {}, - }, - }); - expect(result).toBe(env); - done(); - }); -}); diff --git a/test/lib/merge-configs.js b/test/lib/merge-configs.js deleted file mode 100644 index 6d0a4bea..00000000 --- a/test/lib/merge-configs.js +++ /dev/null @@ -1,119 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var path = require('path'); -var mergeConfigs = require('../../lib/shared/config/merge-configs'); - -var fixturesDir = path.join(__dirname, '../fixtures/config'); - -describe('lib: config/merge-configs', function() { - - it('Should get merged config when there is only project config', function(done) { - var config = { - project: { - description: 'description by .gulp.js in directory project', - }, - userHome: {}, - }; - var configFiles = { - project: path.join(fixturesDir, 'project/.gulp.js'), - userHome: undefined, - }; - var env = { - config: config, - configFiles: configFiles, - }; - - var cfg = mergeConfigs(env); - - expect(cfg).toEqual({ - description: 'description by .gulp.js in directory project', - }); - done(); - }); - - it('Should get merged config when there is only user-home config', function(done) { - var config = { - project: {}, - userHome: { - description: 'description by .gulp.js in directory user home', - }, - }; - var configFiles = { - project: undefined, - userHome: path.join(fixturesDir, 'user/home/.gulp.js'), - }; - var env = { - config: config, - configFiles: configFiles, - }; - - var cfg = mergeConfigs(env); - - expect(cfg).toEqual({ - description: 'description by .gulp.js in directory user home', - }); - done(); - }); - - it('Should get merged config when there are both project and user-home config', function(done) { - var config = { - project: { - description: 'description by .gulp.js in directory project', - flags: { - series: true, - }, - }, - userHome: { - description: 'description by .gulp.js in directory user home', - flags: { - silent: true, - }, - }, - }; - var configFiles = { - project: path.join(fixturesDir, 'project/gulp.js'), - userHome: path.join(fixturesDir, 'user/home/.gulp.js'), - }; - var env = { - config: config, - configFiles: configFiles, - }; - - var cfg = mergeConfigs(env); - - expect(cfg).toEqual({ - description: 'description by .gulp.js in directory project', - flags: { - series: true, - silent: true, - }, - }); - done(); - }); - - it('Should convert a value of `flags.gulpfile` to absolute path', function(done) { - var config = { - project: { - flags: { gulpfile: './is/here/mygulpfile.js' }, - }, - }; - var configFiles = { - project: path.join(fixturesDir, 'flags/gulpfile/.gulp.json'), - }; - var env = { - config: config, - configFiles: configFiles, - }; - - var cfg = mergeConfigs(env); - - expect(cfg).toEqual({ - flags: { - gulpfile: path.join(fixturesDir, 'flags/gulpfile/is/here/mygulpfile.js'), - }, - }); - done(); - }); - -}); From e5c79839e87154aa5bc5d8888eeba29314b17fc6 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 15:48:09 -0700 Subject: [PATCH 13/19] chore!: Only allow js variants for `.gulp` config files (#261) --- README.md | 7 +++++-- index.js | 4 ++-- test/fixtures/.gulp.js | 3 +++ test/fixtures/.gulp.json | 3 --- test/fixtures/config/flags/continue/f/.gulp.js | 5 +++++ test/fixtures/config/flags/continue/f/.gulp.json | 5 ----- test/fixtures/config/flags/continue/t/.gulp.js | 5 +++++ test/fixtures/config/flags/continue/t/.gulp.json | 5 ----- test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.js | 3 +++ .../config/flags/gulpfile/autoload-fail/.gulp.json | 3 --- test/fixtures/config/flags/gulpfile/autoload/.gulp.js | 3 +++ test/fixtures/config/flags/gulpfile/autoload/.gulp.json | 3 --- test/fixtures/config/flags/gulpfile/cwd/.gulp.js | 3 +++ test/fixtures/config/flags/gulpfile/cwd/.gulp.json | 3 --- .../config/flags/gulpfile/override-by-cliflag/.gulp.js | 3 +++ .../config/flags/gulpfile/override-by-cliflag/.gulp.json | 3 --- test/fixtures/config/flags/gulpfile/prj/.gulp.js | 3 +++ test/fixtures/config/flags/gulpfile/prj/.gulp.json | 3 --- test/fixtures/config/flags/logLevel/L/.gulp.js | 5 +++++ test/fixtures/config/flags/logLevel/L/.gulp.json | 5 ----- test/fixtures/config/flags/logLevel/LL/.gulp.js | 5 +++++ test/fixtures/config/flags/logLevel/LL/.gulp.json | 5 ----- test/fixtures/config/flags/logLevel/LLL/.gulp.js | 5 +++++ test/fixtures/config/flags/logLevel/LLL/.gulp.json | 5 ----- test/fixtures/config/flags/nodeFlags/array/.gulp.js | 3 +++ test/fixtures/config/flags/nodeFlags/array/.gulp.json | 3 --- .../config/flags/preload/array/{.gulp.json => .gulp.js} | 6 +++--- test/fixtures/config/flags/preload/join-flags/.gulp.js | 5 +++++ test/fixtures/config/flags/preload/join-flags/.gulp.json | 5 ----- test/fixtures/config/flags/preload/string/.gulp.js | 3 +++ test/fixtures/config/flags/preload/string/.gulp.json | 3 --- test/fixtures/config/flags/preload/with-cwd/.gulp.js | 3 +++ test/fixtures/config/flags/preload/with-cwd/.gulp.json | 3 --- test/fixtures/config/flags/series/f/.gulp.js | 5 +++++ test/fixtures/config/flags/series/f/.gulp.json | 5 ----- test/fixtures/config/flags/series/t/.gulp.js | 5 +++++ test/fixtures/config/flags/series/t/.gulp.json | 5 ----- test/fixtures/config/flags/silent/f/.gulp.js | 5 +++++ test/fixtures/config/flags/silent/f/.gulp.json | 5 ----- test/fixtures/config/flags/silent/t/.gulp.js | 5 +++++ test/fixtures/config/flags/silent/t/.gulp.json | 5 ----- test/fixtures/config/flags/sortTasks/f/.gulp.js | 6 ++++++ test/fixtures/config/flags/sortTasks/f/.gulp.json | 6 ------ test/fixtures/config/flags/sortTasks/t/.gulp.js | 6 ++++++ test/fixtures/config/flags/sortTasks/t/.gulp.json | 6 ------ test/fixtures/config/flags/tasksDepth/.gulp.js | 6 ++++++ test/fixtures/config/flags/tasksDepth/.gulp.json | 6 ------ test/fixtures/config/foo/bar/.gulp.js | 3 +++ test/fixtures/config/foo/bar/.gulp.json | 3 --- test/fixtures/gulpfiles/.gulp.js | 3 +++ test/fixtures/gulpfiles/.gulp.json | 3 --- 51 files changed, 111 insertions(+), 108 deletions(-) create mode 100644 test/fixtures/.gulp.js delete mode 100644 test/fixtures/.gulp.json create mode 100644 test/fixtures/config/flags/continue/f/.gulp.js delete mode 100644 test/fixtures/config/flags/continue/f/.gulp.json create mode 100644 test/fixtures/config/flags/continue/t/.gulp.js delete mode 100644 test/fixtures/config/flags/continue/t/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.js delete mode 100644 test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/autoload/.gulp.js delete mode 100644 test/fixtures/config/flags/gulpfile/autoload/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/cwd/.gulp.js delete mode 100644 test/fixtures/config/flags/gulpfile/cwd/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.js delete mode 100644 test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/prj/.gulp.js delete mode 100644 test/fixtures/config/flags/gulpfile/prj/.gulp.json create mode 100644 test/fixtures/config/flags/logLevel/L/.gulp.js delete mode 100644 test/fixtures/config/flags/logLevel/L/.gulp.json create mode 100644 test/fixtures/config/flags/logLevel/LL/.gulp.js delete mode 100644 test/fixtures/config/flags/logLevel/LL/.gulp.json create mode 100644 test/fixtures/config/flags/logLevel/LLL/.gulp.js delete mode 100644 test/fixtures/config/flags/logLevel/LLL/.gulp.json create mode 100644 test/fixtures/config/flags/nodeFlags/array/.gulp.js delete mode 100644 test/fixtures/config/flags/nodeFlags/array/.gulp.json rename test/fixtures/config/flags/preload/array/{.gulp.json => .gulp.js} (56%) create mode 100644 test/fixtures/config/flags/preload/join-flags/.gulp.js delete mode 100644 test/fixtures/config/flags/preload/join-flags/.gulp.json create mode 100644 test/fixtures/config/flags/preload/string/.gulp.js delete mode 100644 test/fixtures/config/flags/preload/string/.gulp.json create mode 100644 test/fixtures/config/flags/preload/with-cwd/.gulp.js delete mode 100644 test/fixtures/config/flags/preload/with-cwd/.gulp.json create mode 100644 test/fixtures/config/flags/series/f/.gulp.js delete mode 100644 test/fixtures/config/flags/series/f/.gulp.json create mode 100644 test/fixtures/config/flags/series/t/.gulp.js delete mode 100644 test/fixtures/config/flags/series/t/.gulp.json create mode 100644 test/fixtures/config/flags/silent/f/.gulp.js delete mode 100644 test/fixtures/config/flags/silent/f/.gulp.json create mode 100644 test/fixtures/config/flags/silent/t/.gulp.js delete mode 100644 test/fixtures/config/flags/silent/t/.gulp.json create mode 100644 test/fixtures/config/flags/sortTasks/f/.gulp.js delete mode 100644 test/fixtures/config/flags/sortTasks/f/.gulp.json create mode 100644 test/fixtures/config/flags/sortTasks/t/.gulp.js delete mode 100644 test/fixtures/config/flags/sortTasks/t/.gulp.json create mode 100644 test/fixtures/config/flags/tasksDepth/.gulp.js delete mode 100644 test/fixtures/config/flags/tasksDepth/.gulp.json create mode 100644 test/fixtures/config/foo/bar/.gulp.js delete mode 100644 test/fixtures/config/foo/bar/.gulp.json create mode 100644 test/fixtures/gulpfiles/.gulp.js delete mode 100644 test/fixtures/gulpfiles/.gulp.json diff --git a/README.md b/README.md index 78ae7453..1e9089e0 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ Add `gulp --completion=fish | source` to `~/.config/fish/config.fish`. ## Compilers -You can find a list of supported languages at https://github.com/gulpjs/interpret. If you would like to add support for a new language, send pull requests/open issues on that project. +You can find a list of supported JavaScript variant languages in [Interpret][interpret-js-variants]. If you would like to add support for a new language, send pull requests/open issues on that project. ## Environment @@ -99,7 +99,7 @@ The CLI adds `process.env.INIT_CWD` which is the original cwd it was launched fr ## Configuration -Configuration is supported through the use of a `.gulp.*` file (e.g. `.gulp.json`, `.gulp.yml`). You can find a list of supported languages at https://github.com/gulpjs/interpret. +Configuration is supported through the use of a `.gulp.*` file (e.g. `.gulp.js`, `.gulp.ts`). You can find a list of supported JavaScript variant languages in [Interpret][interpret-js-variants]. A configuration file from the current working directory (`cwd`) or above are selected before a configuration file from the home directory (`~`). @@ -224,6 +224,9 @@ __Some flags only work with gulp 4 and will be ignored when invoked against gulp MIT + +[interpret-js-variants]: https://github.com/gulpjs/interpret#jsvariants + [downloads-image]: https://img.shields.io/npm/dm/gulp-cli.svg?style=flat-square diff --git a/index.js b/index.js index 1ace11ea..7b286c60 100644 --- a/index.js +++ b/index.js @@ -38,13 +38,13 @@ var cli = new Liftoff({ { name: '.gulp', path: '.', - extensions: interpret.extensions, + extensions: interpret.jsVariants, findUp: true, }, { name: '.gulp', path: '~', - extensions: interpret.extensions, + extensions: interpret.jsVariants, }, ], }); diff --git a/test/fixtures/.gulp.js b/test/fixtures/.gulp.js new file mode 100644 index 00000000..a1dacc5f --- /dev/null +++ b/test/fixtures/.gulp.js @@ -0,0 +1,3 @@ +module.exports = { + description: "gulp-cli/test/fixtures" +}; diff --git a/test/fixtures/.gulp.json b/test/fixtures/.gulp.json deleted file mode 100644 index 6aad6e7f..00000000 --- a/test/fixtures/.gulp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "description" : "gulp-cli/test/fixtures" -} diff --git a/test/fixtures/config/flags/continue/f/.gulp.js b/test/fixtures/config/flags/continue/f/.gulp.js new file mode 100644 index 00000000..6edb0159 --- /dev/null +++ b/test/fixtures/config/flags/continue/f/.gulp.js @@ -0,0 +1,5 @@ +module.exports = { + flags: { + continue: false + } +}; diff --git a/test/fixtures/config/flags/continue/f/.gulp.json b/test/fixtures/config/flags/continue/f/.gulp.json deleted file mode 100644 index e0a7cbf2..00000000 --- a/test/fixtures/config/flags/continue/f/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "continue": false - } -} diff --git a/test/fixtures/config/flags/continue/t/.gulp.js b/test/fixtures/config/flags/continue/t/.gulp.js new file mode 100644 index 00000000..ed371532 --- /dev/null +++ b/test/fixtures/config/flags/continue/t/.gulp.js @@ -0,0 +1,5 @@ +module.exports = { + flags: { + continue: true + } +}; diff --git a/test/fixtures/config/flags/continue/t/.gulp.json b/test/fixtures/config/flags/continue/t/.gulp.json deleted file mode 100644 index 7161f7a2..00000000 --- a/test/fixtures/config/flags/continue/t/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "continue": true - } -} diff --git a/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.js b/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.js new file mode 100644 index 00000000..ecfc61d3 --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.js @@ -0,0 +1,3 @@ +module.exports = { + gulpfile: "./other_dir/gulpfile.coffee" +}; diff --git a/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json b/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json deleted file mode 100644 index 42846df5..00000000 --- a/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "gulpfile": "./other_dir/gulpfile.coffee" -} diff --git a/test/fixtures/config/flags/gulpfile/autoload/.gulp.js b/test/fixtures/config/flags/gulpfile/autoload/.gulp.js new file mode 100644 index 00000000..b307baf1 --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/autoload/.gulp.js @@ -0,0 +1,3 @@ +module.exports = { + gulpfile: "other_folder/gulpfile-exports.babel.js" +}; diff --git a/test/fixtures/config/flags/gulpfile/autoload/.gulp.json b/test/fixtures/config/flags/gulpfile/autoload/.gulp.json deleted file mode 100644 index 10c5b586..00000000 --- a/test/fixtures/config/flags/gulpfile/autoload/.gulp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "gulpfile": "other_folder/gulpfile-exports.babel.js" -} diff --git a/test/fixtures/config/flags/gulpfile/cwd/.gulp.js b/test/fixtures/config/flags/gulpfile/cwd/.gulp.js new file mode 100644 index 00000000..3ff2eb25 --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/cwd/.gulp.js @@ -0,0 +1,3 @@ +module.exports = { + gulpfile: "../is/here/gulpfile-by-cwd-cfg.js" +}; diff --git a/test/fixtures/config/flags/gulpfile/cwd/.gulp.json b/test/fixtures/config/flags/gulpfile/cwd/.gulp.json deleted file mode 100644 index 7f0181dd..00000000 --- a/test/fixtures/config/flags/gulpfile/cwd/.gulp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "gulpfile": "../is/here/gulpfile-by-cwd-cfg.js" -} diff --git a/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.js b/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.js new file mode 100644 index 00000000..3aa3b2db --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.js @@ -0,0 +1,3 @@ +module.exports = { + gulpfile: "../cwd/gulpfile.js" +}; diff --git a/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json b/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json deleted file mode 100644 index fb737ede..00000000 --- a/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "gulpfile": "../cwd/gulpfile.js" -} diff --git a/test/fixtures/config/flags/gulpfile/prj/.gulp.js b/test/fixtures/config/flags/gulpfile/prj/.gulp.js new file mode 100644 index 00000000..321e3bdf --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/prj/.gulp.js @@ -0,0 +1,3 @@ +module.exports = { + gulpfile: "../is/here/gulpfile-by-prj-cfg.js" +}; diff --git a/test/fixtures/config/flags/gulpfile/prj/.gulp.json b/test/fixtures/config/flags/gulpfile/prj/.gulp.json deleted file mode 100644 index 625bb7c1..00000000 --- a/test/fixtures/config/flags/gulpfile/prj/.gulp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "gulpfile": "../is/here/gulpfile-by-prj-cfg.js" -} diff --git a/test/fixtures/config/flags/logLevel/L/.gulp.js b/test/fixtures/config/flags/logLevel/L/.gulp.js new file mode 100644 index 00000000..fca4e6b7 --- /dev/null +++ b/test/fixtures/config/flags/logLevel/L/.gulp.js @@ -0,0 +1,5 @@ +module.exports = { + flags: { + logLevel: 1 + } +} diff --git a/test/fixtures/config/flags/logLevel/L/.gulp.json b/test/fixtures/config/flags/logLevel/L/.gulp.json deleted file mode 100644 index 8b4448e9..00000000 --- a/test/fixtures/config/flags/logLevel/L/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "logLevel": 1 - } -} diff --git a/test/fixtures/config/flags/logLevel/LL/.gulp.js b/test/fixtures/config/flags/logLevel/LL/.gulp.js new file mode 100644 index 00000000..033e74d7 --- /dev/null +++ b/test/fixtures/config/flags/logLevel/LL/.gulp.js @@ -0,0 +1,5 @@ +module.exports = { + flags: { + logLevel: 2 + } +}; diff --git a/test/fixtures/config/flags/logLevel/LL/.gulp.json b/test/fixtures/config/flags/logLevel/LL/.gulp.json deleted file mode 100644 index cd498c8d..00000000 --- a/test/fixtures/config/flags/logLevel/LL/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "logLevel": 2 - } -} diff --git a/test/fixtures/config/flags/logLevel/LLL/.gulp.js b/test/fixtures/config/flags/logLevel/LLL/.gulp.js new file mode 100644 index 00000000..5120f6f1 --- /dev/null +++ b/test/fixtures/config/flags/logLevel/LLL/.gulp.js @@ -0,0 +1,5 @@ +module.exports = { + flags: { + logLevel: 3 + } +}; diff --git a/test/fixtures/config/flags/logLevel/LLL/.gulp.json b/test/fixtures/config/flags/logLevel/LLL/.gulp.json deleted file mode 100644 index 267a3cec..00000000 --- a/test/fixtures/config/flags/logLevel/LLL/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "logLevel": 3 - } -} diff --git a/test/fixtures/config/flags/nodeFlags/array/.gulp.js b/test/fixtures/config/flags/nodeFlags/array/.gulp.js new file mode 100644 index 00000000..29053b1a --- /dev/null +++ b/test/fixtures/config/flags/nodeFlags/array/.gulp.js @@ -0,0 +1,3 @@ +module.exports = { + nodeFlags: ["--lazy", "--trace-deprecation"] +} diff --git a/test/fixtures/config/flags/nodeFlags/array/.gulp.json b/test/fixtures/config/flags/nodeFlags/array/.gulp.json deleted file mode 100644 index 79cd530d..00000000 --- a/test/fixtures/config/flags/nodeFlags/array/.gulp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "nodeFlags": ["--lazy", "--trace-deprecation"] -} diff --git a/test/fixtures/config/flags/preload/array/.gulp.json b/test/fixtures/config/flags/preload/array/.gulp.js similarity index 56% rename from test/fixtures/config/flags/preload/array/.gulp.json rename to test/fixtures/config/flags/preload/array/.gulp.js index 2f4855e1..da5c398f 100644 --- a/test/fixtures/config/flags/preload/array/.gulp.json +++ b/test/fixtures/config/flags/preload/array/.gulp.js @@ -1,6 +1,6 @@ -{ - "preload": [ +module.exports = { + preload: [ "./preload_one", "./preload_two" ] -} +}; diff --git a/test/fixtures/config/flags/preload/join-flags/.gulp.js b/test/fixtures/config/flags/preload/join-flags/.gulp.js new file mode 100644 index 00000000..fe2a9b08 --- /dev/null +++ b/test/fixtures/config/flags/preload/join-flags/.gulp.js @@ -0,0 +1,5 @@ +module.exports = { + preload: [ + "./preload_two" + ] +}; diff --git a/test/fixtures/config/flags/preload/join-flags/.gulp.json b/test/fixtures/config/flags/preload/join-flags/.gulp.json deleted file mode 100644 index 63405ae5..00000000 --- a/test/fixtures/config/flags/preload/join-flags/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "preload": [ - "./preload_two" - ] -} diff --git a/test/fixtures/config/flags/preload/string/.gulp.js b/test/fixtures/config/flags/preload/string/.gulp.js new file mode 100644 index 00000000..cb913254 --- /dev/null +++ b/test/fixtures/config/flags/preload/string/.gulp.js @@ -0,0 +1,3 @@ +module.exports = { + preload: "./preload" +}; diff --git a/test/fixtures/config/flags/preload/string/.gulp.json b/test/fixtures/config/flags/preload/string/.gulp.json deleted file mode 100644 index 22886303..00000000 --- a/test/fixtures/config/flags/preload/string/.gulp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "preload": "./preload" -} diff --git a/test/fixtures/config/flags/preload/with-cwd/.gulp.js b/test/fixtures/config/flags/preload/with-cwd/.gulp.js new file mode 100644 index 00000000..e51966f4 --- /dev/null +++ b/test/fixtures/config/flags/preload/with-cwd/.gulp.js @@ -0,0 +1,3 @@ +module.exports = { + preload: "../preload" +}; diff --git a/test/fixtures/config/flags/preload/with-cwd/.gulp.json b/test/fixtures/config/flags/preload/with-cwd/.gulp.json deleted file mode 100644 index c92f9743..00000000 --- a/test/fixtures/config/flags/preload/with-cwd/.gulp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "preload": "../preload" -} diff --git a/test/fixtures/config/flags/series/f/.gulp.js b/test/fixtures/config/flags/series/f/.gulp.js new file mode 100644 index 00000000..6605aca5 --- /dev/null +++ b/test/fixtures/config/flags/series/f/.gulp.js @@ -0,0 +1,5 @@ +module.exports = { + flags: { + series: false + } +}; diff --git a/test/fixtures/config/flags/series/f/.gulp.json b/test/fixtures/config/flags/series/f/.gulp.json deleted file mode 100644 index 6da4dba0..00000000 --- a/test/fixtures/config/flags/series/f/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "series": false - } -} diff --git a/test/fixtures/config/flags/series/t/.gulp.js b/test/fixtures/config/flags/series/t/.gulp.js new file mode 100644 index 00000000..f21fe066 --- /dev/null +++ b/test/fixtures/config/flags/series/t/.gulp.js @@ -0,0 +1,5 @@ +module.exports = { + flags: { + series: true + } +}; diff --git a/test/fixtures/config/flags/series/t/.gulp.json b/test/fixtures/config/flags/series/t/.gulp.json deleted file mode 100644 index 7f1f5a44..00000000 --- a/test/fixtures/config/flags/series/t/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "series": true - } -} diff --git a/test/fixtures/config/flags/silent/f/.gulp.js b/test/fixtures/config/flags/silent/f/.gulp.js new file mode 100644 index 00000000..4630a77a --- /dev/null +++ b/test/fixtures/config/flags/silent/f/.gulp.js @@ -0,0 +1,5 @@ +module.exports = { + flags: { + silent: false + } +}; diff --git a/test/fixtures/config/flags/silent/f/.gulp.json b/test/fixtures/config/flags/silent/f/.gulp.json deleted file mode 100644 index 4f3822ab..00000000 --- a/test/fixtures/config/flags/silent/f/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "silent": false - } -} diff --git a/test/fixtures/config/flags/silent/t/.gulp.js b/test/fixtures/config/flags/silent/t/.gulp.js new file mode 100644 index 00000000..22486fd8 --- /dev/null +++ b/test/fixtures/config/flags/silent/t/.gulp.js @@ -0,0 +1,5 @@ +module.exports = { + flags: { + silent: true + } +}; diff --git a/test/fixtures/config/flags/silent/t/.gulp.json b/test/fixtures/config/flags/silent/t/.gulp.json deleted file mode 100644 index 9917bd8c..00000000 --- a/test/fixtures/config/flags/silent/t/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "silent": true - } -} diff --git a/test/fixtures/config/flags/sortTasks/f/.gulp.js b/test/fixtures/config/flags/sortTasks/f/.gulp.js new file mode 100644 index 00000000..e4640d82 --- /dev/null +++ b/test/fixtures/config/flags/sortTasks/f/.gulp.js @@ -0,0 +1,6 @@ +module.exports = { + gulpfile: "../../../../gulpfiles/gulpfile-4.js", + flags: { + sortTasks: false + } +}; diff --git a/test/fixtures/config/flags/sortTasks/f/.gulp.json b/test/fixtures/config/flags/sortTasks/f/.gulp.json deleted file mode 100644 index daa8a926..00000000 --- a/test/fixtures/config/flags/sortTasks/f/.gulp.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "gulpfile": "../../../../gulpfiles/gulpfile-4.js", - "flags": { - "sortTasks": false - } -} diff --git a/test/fixtures/config/flags/sortTasks/t/.gulp.js b/test/fixtures/config/flags/sortTasks/t/.gulp.js new file mode 100644 index 00000000..aae6877b --- /dev/null +++ b/test/fixtures/config/flags/sortTasks/t/.gulp.js @@ -0,0 +1,6 @@ +module.exports = { + gulpfile: "../../../../gulpfiles/gulpfile-4.js", + flags: { + sortTasks: true + } +}; diff --git a/test/fixtures/config/flags/sortTasks/t/.gulp.json b/test/fixtures/config/flags/sortTasks/t/.gulp.json deleted file mode 100644 index 254cd26a..00000000 --- a/test/fixtures/config/flags/sortTasks/t/.gulp.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "gulpfile": "../../../../gulpfiles/gulpfile-4.js", - "flags": { - "sortTasks": true - } -} diff --git a/test/fixtures/config/flags/tasksDepth/.gulp.js b/test/fixtures/config/flags/tasksDepth/.gulp.js new file mode 100644 index 00000000..6960b163 --- /dev/null +++ b/test/fixtures/config/flags/tasksDepth/.gulp.js @@ -0,0 +1,6 @@ +module.exports = { + gulpfile: "../../../gulpfiles/gulpfile-4.js", + flags: { + tasksDepth: 4 + } +}; diff --git a/test/fixtures/config/flags/tasksDepth/.gulp.json b/test/fixtures/config/flags/tasksDepth/.gulp.json deleted file mode 100644 index bc309203..00000000 --- a/test/fixtures/config/flags/tasksDepth/.gulp.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "gulpfile": "../../../gulpfiles/gulpfile-4.js", - "flags": { - "tasksDepth": 4 - } -} diff --git a/test/fixtures/config/foo/bar/.gulp.js b/test/fixtures/config/foo/bar/.gulp.js new file mode 100644 index 00000000..4c3e35e7 --- /dev/null +++ b/test/fixtures/config/foo/bar/.gulp.js @@ -0,0 +1,3 @@ +module.exports = { + description: "Description by .gulp.json in directory foo/bar" +}; diff --git a/test/fixtures/config/foo/bar/.gulp.json b/test/fixtures/config/foo/bar/.gulp.json deleted file mode 100644 index 186db419..00000000 --- a/test/fixtures/config/foo/bar/.gulp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "description": "Description by .gulp.json in directory foo/bar" -} diff --git a/test/fixtures/gulpfiles/.gulp.js b/test/fixtures/gulpfiles/.gulp.js new file mode 100644 index 00000000..7aa69cc2 --- /dev/null +++ b/test/fixtures/gulpfiles/.gulp.js @@ -0,0 +1,3 @@ +module.exports = { + description: "gulp-cli/test/fixtures/gulpfiles" +}; diff --git a/test/fixtures/gulpfiles/.gulp.json b/test/fixtures/gulpfiles/.gulp.json deleted file mode 100644 index 65158fad..00000000 --- a/test/fixtures/gulpfiles/.gulp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "description" : "gulp-cli/test/fixtures/gulpfiles" -} From 9a1d013095f24b851fd970f39464209e088a7b98 Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Fri, 22 Mar 2024 10:00:24 +0900 Subject: [PATCH 14/19] chore: Augment `task not found` error with helpful properties (#262) --- lib/versioned/^4.0.0/index.js | 10 ++++++-- lib/versioned/^4.0.0/normalize-error.js | 26 +++++++++++++++++++++ test/execution-errors.js | 15 ++++++++++++ test/lib/check-task-not-found.js | 31 +++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 lib/versioned/^4.0.0/normalize-error.js create mode 100644 test/lib/check-task-not-found.js diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index 137ad438..c1888bb3 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -12,6 +12,7 @@ var tildify = require('../../shared/tildify'); var logTasks = require('../../shared/log/tasks'); var logEvents = require('./log/events'); var logSyncTask = require('./log/sync-task'); +var normalizeError = require('./normalize-error'); var logTasksSimple = require('./log/tasks-simple'); var registerExports = require('../../shared/register-exports'); @@ -85,8 +86,13 @@ function execute(env, cfg, opts) { } }); } catch (err) { - log.error(chalk.red(err.message)); - log.error('To list available tasks, try running: gulp --tasks'); + normalizeError(err); + if (err.task) { + log.error(chalk.red(err.message)); + log.error(chalk.red('To list available tasks, try running: gulp --tasks')); + } else /* istanbul ignore next */ { + log.error(chalk.red(err.message)); + } exit(1); } }); diff --git a/lib/versioned/^4.0.0/normalize-error.js b/lib/versioned/^4.0.0/normalize-error.js new file mode 100644 index 00000000..0f58d0c4 --- /dev/null +++ b/lib/versioned/^4.0.0/normalize-error.js @@ -0,0 +1,26 @@ +'use strict'; + +// Normalize an undertaker v1 error like an undertaker v2 error +function normalizeError(err) { + /* istanbul ignore if */ + if (!err || !err.message) { + return; + } + + var fixed0 = 'Task never defined: '; + var fixed1 = ' - did you mean? '; + + if (err.message.startsWith(fixed0)) { + var task = err.message.slice(fixed0.length); + var index = task.indexOf(fixed1); + + if (index >= 0) { + err.similar = task.slice(index + fixed1.length).split(', '); + err.task = task.slice(0, index); + } else { + err.task = task + } + } +} + +module.exports = normalizeError; diff --git a/test/execution-errors.js b/test/execution-errors.js index 769832a9..bd607e43 100644 --- a/test/execution-errors.js +++ b/test/execution-errors.js @@ -29,6 +29,21 @@ describe('execution error', function() { } }); + it('should output an error if a task is not defined but a similar task is found', function(done) { + var opts = { cwd: path.join(__dirname, './fixtures/gulpfiles') }; + exec(gulp('test0'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(eraseTime(stdout)).toMatch('Using gulpfile '); + expect(eraseTime(stderr)).toEqual( + 'Task never defined: test0 - did you mean? test1, test2, test3, test4, test5, test6, test7, test8\n' + + 'To list available tasks, try running: gulp --tasks\n'); + done(); + } + }); + it('should output an error if gulp version is unsupported', function(done) { var opts = { cwd: path.join(__dirname, './fixtures/errors/bad-gulp-version') }; exec(gulp(), opts, cb); diff --git a/test/lib/check-task-not-found.js b/test/lib/check-task-not-found.js new file mode 100644 index 00000000..d06aef95 --- /dev/null +++ b/test/lib/check-task-not-found.js @@ -0,0 +1,31 @@ +'use strict'; + +var expect = require('expect'); +var normalizeError = require('../../lib/versioned/^4.0.0/normalize-error'); + +describe('lib: normalizeError', function() { + + it('Should return target task and similar tasks if both are included in error message', function(done) { + var err = new Error('Task never defined: task2 - did you mean? task0, task1'); + normalizeError(err); + expect(err).toHaveProperty('task', 'task2'); + expect(err).toHaveProperty('similar', ['task0', 'task1']); + done(); + }); + + it('Should return only target task if similar tasks is not included in error message', function(done) { + var err = new Error('Task never defined: task2'); + normalizeError(err) + expect(err).toHaveProperty('task', 'task2'); + expect(err).not.toHaveProperty('similar'); + done(); + }); + + it('Should return undefined if error is other', function(done) { + var err = new Error('xxx'); + normalizeError(err) + expect(err).not.toHaveProperty('task'); + expect(err).not.toHaveProperty('similar'); + done(); + }); +}); From e16d675606867a5a3a64c24e7fa48bb0a664723d Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 22 Mar 2024 21:04:29 -0700 Subject: [PATCH 15/19] feat: Support theming and translations via config files (#260) chore!: Remove `description` in config to rely on translations --------- Co-authored-by: sttk --- .eslintrc | 2 +- .gitignore | 1 + README.md | 2 + index.js | 134 ++--- lib/shared/completion.js | 12 +- lib/shared/log/tasks.js | 61 ++- lib/shared/log/to-console.js | 129 +++-- lib/shared/options/cli-options.js | 61 +-- lib/shared/options/make-help.js | 24 + lib/shared/translate.js | 302 +++++++++++ lib/versioned/^3.7.0/index.js | 21 +- lib/versioned/^3.7.0/log/events.js | 26 +- lib/versioned/^4.0.0/index.js | 28 +- lib/versioned/^4.0.0/log/events.js | 21 +- lib/versioned/^4.0.0/log/sync-task.js | 10 +- package.json | 5 +- test/config-description.js | 72 --- test/config-message-function.js | 475 ++++++++++++++++++ test/execution-errors.js | 76 ++- test/expected/config/theming/bad-flag.txt | 41 ++ test/expected/config/theming/flags.txt | 18 + test/expected/config/theming/usage.txt | 39 ++ test/expected/flags-tasks-depth1.txt | 4 + test/fixtures/.gulp.js | 8 +- .../config/theming/ARGV_ERROR/.gulp.js | 9 + .../config/theming/ARGV_ERROR/gulpfile.js | 3 + .../theming/COMPLETION_TYPE_MISSING/.gulp.js | 9 + .../COMPLETION_TYPE_MISSING/gulpfile.js | 3 + .../theming/COMPLETION_TYPE_UNKNOWN/.gulp.js | 9 + .../COMPLETION_TYPE_UNKNOWN/gulpfile.js | 3 + .../config/theming/CWD_CHANGED/.gulp.js | 12 + .../config/theming/CWD_CHANGED/gulpfile.js | 3 + .../config/theming/DESCRIPTION/.gulp.js | 9 + .../config/theming/DESCRIPTION/gulpfile.js | 3 + .../theming/DESCRIPTION/remove/.gulp.js | 9 + .../theming/DESCRIPTION/remove/gulpfile.js | 3 + .../config/theming/EXEC_ERROR/.gulp.js | 13 + .../config/theming/EXEC_ERROR/gulpfile.js | 3 + .../fixtures/config/theming/GULPFILE/.gulp.js | 13 + .../config/theming/GULPFILE/gulpfile.js | 3 + .../config/theming/LOADER_FAILURE/.gulp.js | 14 + .../theming/LOADER_FAILURE/gulpfile.coffee | 1 + .../config/theming/LOADER_SUCCESS/.gulp.js | 12 + .../theming/LOADER_SUCCESS/gulpfile.babel.js | 3 + .../config/theming/MISSING_GULP/.gulp.js | 16 + .../config/theming/MISSING_GULPFILE/.gulp.js | 9 + .../theming/MISSING_NODE_MODULES/.gulp.js | 14 + .../theming/MISSING_NODE_MODULES/package.json | 7 + .../config/theming/NODE_FLAGS/.gulp.js | 12 + .../config/theming/NODE_FLAGS/gulpfile.js | 3 + .../config/theming/PRELOAD_BEFORE/.gulp.js | 12 + .../config/theming/PRELOAD_BEFORE/gulpfile.js | 3 + .../config/theming/PRELOAD_BEFORE/preload.js | 1 + .../config/theming/PRELOAD_FAILURE/.gulp.js | 12 + .../theming/PRELOAD_FAILURE/gulpfile.js | 3 + .../config/theming/PRELOAD_SUCCESS/.gulp.js | 12 + .../theming/PRELOAD_SUCCESS/gulpfile.js | 3 + .../config/theming/PRELOAD_SUCCESS/preload.js | 1 + .../config/theming/RESPAWNED/.gulp.js | 12 + .../config/theming/RESPAWNED/gulpfile.js | 3 + .../config/theming/TASK_ERROR/.gulp.js | 16 + .../config/theming/TASK_ERROR/gulpfile.js | 3 + .../config/theming/TASK_FAILURE/.gulp.js | 16 + .../config/theming/TASK_FAILURE/gulpfile.js | 3 + .../config/theming/TASK_MISSING/.gulp.js | 13 + .../config/theming/TASK_MISSING/gulpfile.js | 3 + .../config/theming/TASK_START/.gulp.js | 12 + .../config/theming/TASK_START/gulpfile.js | 3 + .../config/theming/TASK_STOP/.gulp.js | 12 + .../config/theming/TASK_STOP/gulpfile.js | 3 + .../config/theming/TASK_SYNC/.gulp.js | 9 + .../config/theming/TASK_SYNC/gulpfile.js | 3 + .../theming/UNSUPPORTED_GULP_VERSION/.gulp.js | 9 + .../UNSUPPORTED_GULP_VERSION/gulpfile.js | 3 + .../node_modules/gulp/index.js | 0 .../node_modules/gulp/package.json | 5 + test/fixtures/config/theming/USAGE/.gulp.js | 9 + test/fixtures/config/theming/flags/.gulp.js | 76 +++ test/fixtures/errors/yarn/yarn.lock | 0 test/fixtures/gulpfiles/.gulp.js | 8 +- test/fixtures/logging.js | 5 +- test/flags-help.js | 11 + test/flags-tasks.js | 22 +- test/lib/config-cli-flags.js | 2 +- test/lib/format-hrtime.js | 2 +- ...k-task-not-found.js => normalize-error.js} | 0 86 files changed, 1744 insertions(+), 336 deletions(-) create mode 100644 lib/shared/options/make-help.js create mode 100644 lib/shared/translate.js delete mode 100644 test/config-description.js create mode 100644 test/config-message-function.js create mode 100644 test/expected/config/theming/bad-flag.txt create mode 100644 test/expected/config/theming/flags.txt create mode 100644 test/expected/config/theming/usage.txt create mode 100644 test/expected/flags-tasks-depth1.txt create mode 100644 test/fixtures/config/theming/ARGV_ERROR/.gulp.js create mode 100644 test/fixtures/config/theming/ARGV_ERROR/gulpfile.js create mode 100644 test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js create mode 100644 test/fixtures/config/theming/COMPLETION_TYPE_MISSING/gulpfile.js create mode 100644 test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js create mode 100644 test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/gulpfile.js create mode 100644 test/fixtures/config/theming/CWD_CHANGED/.gulp.js create mode 100644 test/fixtures/config/theming/CWD_CHANGED/gulpfile.js create mode 100644 test/fixtures/config/theming/DESCRIPTION/.gulp.js create mode 100644 test/fixtures/config/theming/DESCRIPTION/gulpfile.js create mode 100644 test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js create mode 100644 test/fixtures/config/theming/DESCRIPTION/remove/gulpfile.js create mode 100644 test/fixtures/config/theming/EXEC_ERROR/.gulp.js create mode 100644 test/fixtures/config/theming/EXEC_ERROR/gulpfile.js create mode 100644 test/fixtures/config/theming/GULPFILE/.gulp.js create mode 100644 test/fixtures/config/theming/GULPFILE/gulpfile.js create mode 100644 test/fixtures/config/theming/LOADER_FAILURE/.gulp.js create mode 100644 test/fixtures/config/theming/LOADER_FAILURE/gulpfile.coffee create mode 100644 test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js create mode 100644 test/fixtures/config/theming/LOADER_SUCCESS/gulpfile.babel.js create mode 100644 test/fixtures/config/theming/MISSING_GULP/.gulp.js create mode 100644 test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js create mode 100644 test/fixtures/config/theming/MISSING_NODE_MODULES/.gulp.js create mode 100644 test/fixtures/config/theming/MISSING_NODE_MODULES/package.json create mode 100644 test/fixtures/config/theming/NODE_FLAGS/.gulp.js create mode 100644 test/fixtures/config/theming/NODE_FLAGS/gulpfile.js create mode 100644 test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js create mode 100644 test/fixtures/config/theming/PRELOAD_BEFORE/gulpfile.js create mode 100644 test/fixtures/config/theming/PRELOAD_BEFORE/preload.js create mode 100644 test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js create mode 100644 test/fixtures/config/theming/PRELOAD_FAILURE/gulpfile.js create mode 100644 test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js create mode 100644 test/fixtures/config/theming/PRELOAD_SUCCESS/gulpfile.js create mode 100644 test/fixtures/config/theming/PRELOAD_SUCCESS/preload.js create mode 100644 test/fixtures/config/theming/RESPAWNED/.gulp.js create mode 100644 test/fixtures/config/theming/RESPAWNED/gulpfile.js create mode 100644 test/fixtures/config/theming/TASK_ERROR/.gulp.js create mode 100644 test/fixtures/config/theming/TASK_ERROR/gulpfile.js create mode 100644 test/fixtures/config/theming/TASK_FAILURE/.gulp.js create mode 100644 test/fixtures/config/theming/TASK_FAILURE/gulpfile.js create mode 100644 test/fixtures/config/theming/TASK_MISSING/.gulp.js create mode 100644 test/fixtures/config/theming/TASK_MISSING/gulpfile.js create mode 100644 test/fixtures/config/theming/TASK_START/.gulp.js create mode 100644 test/fixtures/config/theming/TASK_START/gulpfile.js create mode 100644 test/fixtures/config/theming/TASK_STOP/.gulp.js create mode 100644 test/fixtures/config/theming/TASK_STOP/gulpfile.js create mode 100644 test/fixtures/config/theming/TASK_SYNC/.gulp.js create mode 100644 test/fixtures/config/theming/TASK_SYNC/gulpfile.js create mode 100644 test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js create mode 100644 test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/gulpfile.js create mode 100644 test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/index.js create mode 100644 test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/package.json create mode 100644 test/fixtures/config/theming/USAGE/.gulp.js create mode 100644 test/fixtures/config/theming/flags/.gulp.js create mode 100644 test/fixtures/errors/yarn/yarn.lock rename test/lib/{check-task-not-found.js => normalize-error.js} (100%) diff --git a/.eslintrc b/.eslintrc index 331ecbe0..c35bface 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,7 +2,7 @@ "extends": "gulp", "rules": { "max-len": [1, 130], - "max-statements": [1, 40], + "max-statements": [1, 65], "no-console": "off" } } diff --git a/.gitignore b/.gitignore index 3b569a93..c626059e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.log node_modules !test/fixtures/errors/bad-gulp-version/node_modules/ +!test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/ build *.node components diff --git a/README.md b/README.md index 1e9089e0..bfb6c6d1 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,8 @@ Supported configurations properties: | flags.tasksDepth | Set default depth of task dependency tree. | | flags.silent | Silence logging by default | | flags.series | Run tasks given on the CLI in series (the default is parallel) | +| message(data) | A function used to translate messages that pass through gulp-cli. Can receive an object like `{ tag: Symbol(), ...props }` where the `tag` is a symbol from `@gulpjs/messages`. The string returned from this function will be logged. If `false` is explicitly returned, no message will be logged. | +| timestamp(data) | A function used to provide timestamps for gulp-cli. Can receive an object like `{ tag: Symbol(), ...props }` where the `tag` is a symbol from `@gulpjs/messages`. The string returned from this function will be output before any messages. If `false` is explicitly returned, no timestamp will be output. | ## Flags diff --git a/index.js b/index.js index 7b286c60..3491a7a6 100644 --- a/index.js +++ b/index.js @@ -8,18 +8,20 @@ var yargs = require('yargs'); var Liftoff = require('liftoff'); var interpret = require('interpret'); var v8flags = require('v8flags'); +var messages = require('@gulpjs/messages'); var findRange = require('semver-greatest-satisfied-range'); -var chalk = require('chalk'); var exit = require('./lib/shared/exit'); -var tildify = require('./lib/shared/tildify'); + var arrayFind = require('./lib/shared/array-find'); var makeTitle = require('./lib/shared/make-title'); +var makeHelp = require('./lib/shared/options/make-help'); var cliOptions = require('./lib/shared/options/cli-options'); var completion = require('./lib/shared/completion'); var cliVersion = require('./package.json').version; var toConsole = require('./lib/shared/log/to-console'); var mergeCliOpts = require('./lib/shared/config/cli-flags'); +var buildTranslations = require('./lib/shared/translate'); // Get supported ranges var ranges = fs.readdirSync(path.join(__dirname, '/lib/versioned/')); @@ -31,7 +33,6 @@ process.env.INIT_CWD = process.cwd(); var cli = new Liftoff({ name: 'gulp', processTitle: makeTitle('gulp', process.argv.slice(2)), - completions: completion, extensions: interpret.jsVariants, v8flags: v8flags, configFiles: [ @@ -49,38 +50,34 @@ var cli = new Liftoff({ ], }); -var usage = - '\n' + chalk.bold('Usage:') + - ' gulp ' + chalk.blue('[options]') + ' tasks'; - var parser = yargs .help(false) .version(false) .detectLocale(false) - .usage(usage) + .showHelpOnFail(false) + .exitProcess(false) + .fail(onFail) .options(cliOptions); var opts = parser.parse(); // Set up event listeners for logging temporarily. -toConsole(log, opts); +// TODO: Rework console logging before we can set up proper config +// Possibly by batching messages in gulplog until listeners are attached +var cleanupListeners = toConsole(log, opts, buildTranslations()); cli.on('preload:before', function(name) { - log.info('Preloading external module:', chalk.magenta(name)); + log.info({ tag: messages.PRELOAD_BEFORE, name: name }); }); cli.on('preload:success', function(name) { - log.info('Preloaded external module:', chalk.magenta(name)); + log.info({ tag: messages.PRELOAD_SUCCESS, name: name }); }); cli.on('preload:failure', function(name, error) { - log.warn( - chalk.yellow('Failed to preload external module:'), - chalk.magenta(name) - ); - /* istanbul ignore else */ + log.warn({ tag: messages.PRELOAD_FAILURE, name: name }); if (error) { - log.warn(chalk.yellow(error.toString())); + log.warn({ tag: messages.PRELOAD_ERROR, error: error }); } }); @@ -90,26 +87,20 @@ cli.on('loader:success', function(name) { // However, we don't want to show the mjs-stub loader in the logs /* istanbul ignore else */ if (path.basename(name, '.js') !== 'mjs-stub') { - log.info('Loaded external module:', chalk.magenta(name)); + log.info({ tag: messages.LOADER_SUCCESS, name: name }); } }); cli.on('loader:failure', function(name, error) { - log.warn( - chalk.yellow('Failed to load external module:'), - chalk.magenta(name) - ); - /* istanbul ignore else */ + log.warn({ tag: messages.LOADER_FAILURE, name: name }); if (error) { - log.warn(chalk.yellow(error.toString())); + log.warn({ tag: messages.LOADER_ERROR, error: error }); } }); cli.on('respawn', function(flags, child) { - var nodeFlags = chalk.magenta(flags.join(', ')); - var pid = chalk.magenta(child.pid); - log.info('Node flags detected:', nodeFlags); - log.info('Respawned to PID:', pid); + log.info({ tag: messages.NODE_FLAGS, flags: flags }); + log.info({ tag: messages.RESPAWNED, pid: child.pid }); }); function run() { @@ -117,7 +108,6 @@ function run() { cwd: opts.cwd, configPath: opts.gulpfile, preload: opts.preload, - completion: opts.completion, }, onPrepare); } @@ -127,22 +117,50 @@ function isDefined(cfg) { return cfg != null; } +function onFail(message, error) { + // Run Liftoff#prepare to get the env. Primarily to load themes. + cli.prepare({}, function (env) { + // We only use the first config found, which is a departure from + // the previous implementation that merged with the home + var cfg = arrayFind(env.config, isDefined); + var translate = buildTranslations(cfg); + + var errorMsg = translate.message({ tag: messages.ARGV_ERROR, message: message, error: error }); + if (errorMsg) { + console.error(errorMsg); + } + + makeHelp(parser, translate).showHelp(console.error); + exit(1); + }); +} + function onPrepare(env) { // We only use the first config found, which is a departure from // the previous implementation that merged with the home var cfg = arrayFind(env.config, isDefined); var flags = mergeCliOpts(opts, cfg); - // Set up event listeners for logging after configuring. - toConsole(log, flags); + // Remove the previous listeners since we have appropriate config now + cleanupListeners(); + + var translate = buildTranslations(cfg); + + // Set up event listeners for logging again after configuring. + toConsole(log, flags, translate); cli.execute(env, cfg.nodeFlags, function (env) { - onExecute(env, cfg, flags); + onExecute(env, flags, translate); }); } // The actual logic -function onExecute(env, cfg, flags) { +function onExecute(env, flags, translate) { + // Moved the completion logic outside of Liftoff since we need to include translations + if (flags.completion) { + return completion(flags.completion, translate); + } + // This translates the --continue flag in gulp // To the settle env variable for undertaker // We use the process.env so the user's gulpfile @@ -152,7 +170,7 @@ function onExecute(env, cfg, flags) { } if (flags.help) { - parser.showHelp(console.log); + makeHelp(parser, translate).showHelp(console.log); exit(0); } @@ -164,36 +182,31 @@ function onExecute(env, cfg, flags) { } if (!env.modulePath) { - /* istanbul ignore next */ var missingNodeModules = fs.existsSync(path.join(env.cwd, 'package.json')) && !fs.existsSync(path.join(env.cwd, 'node_modules')); - /* istanbul ignore next */ - var missingGulpMessage = - missingNodeModules - ? 'Local modules not found in' - : 'Local gulp not found in'; - log.error( - chalk.red(missingGulpMessage), - chalk.magenta(tildify(env.cwd)) - ); var hasYarn = fs.existsSync(path.join(env.cwd, 'yarn.lock')); - /* istanbul ignore next */ - var installCommand = - missingNodeModules - ? hasYarn - ? 'yarn install' - : 'npm install' - : hasYarn - ? 'yarn add gulp' - : 'npm install gulp'; - log.error(chalk.red('Try running: ' + installCommand)); + if (missingNodeModules) { + log.error({ tag: messages.MISSING_NODE_MODULES, cwd: env.cwd }); + if (hasYarn) { + log.error({ tag: messages.YARN_INSTALL }) + } else { + log.error({ tag: messages.NPM_INSTALL }) + } + } else { + log.error({ tag: messages.MISSING_GULP, cwd: env.cwd }); + if (hasYarn) { + log.error({ tag: messages.YARN_INSTALL_GULP }); + } else { + log.error({ tag: messages.NPM_INSTALL_GULP }); + } + } exit(1); } if (!env.configPath) { - log.error(chalk.red('No gulpfile found')); + log.error({ tag: messages.MISSING_GULPFILE }); exit(1); } @@ -201,23 +214,18 @@ function onExecute(env, cfg, flags) { // we let them chdir as needed if (process.cwd() !== env.cwd) { process.chdir(env.cwd); - log.info( - 'Working directory changed to', - chalk.magenta(tildify(env.cwd)) - ); + log.info({ tag: messages.CWD_CHANGED, cwd: env.cwd }); } // Find the correct CLI version to run var range = findRange(env.modulePackage.version, ranges); if (!range) { - log.error( - chalk.red('Unsupported gulp version', env.modulePackage.version) - ); + log.error({ tag: messages.UNSUPPORTED_GULP_VERSION, version: env.modulePackage.version }); exit(1); } // Load and execute the CLI version var versionedDir = path.join(__dirname, '/lib/versioned/', range, '/'); - require(versionedDir)(env, cfg, flags); + require(versionedDir)(env, flags, translate); } diff --git a/lib/shared/completion.js b/lib/shared/completion.js index 3a47023d..d637d140 100644 --- a/lib/shared/completion.js +++ b/lib/shared/completion.js @@ -3,20 +3,18 @@ var fs = require('fs'); var path = require('path'); -module.exports = function(name) { +var messages = require('@gulpjs/messages'); + +module.exports = function(name, translate) { if (typeof name !== 'string') { - throw new Error('Missing completion type'); + throw new Error(translate.message({ tag: messages.COMPLETION_TYPE_MISSING })); } var file = path.join(__dirname, '../../completion', name); try { console.log(fs.readFileSync(file, 'utf8')); process.exit(0); } catch (err) { - console.log( - 'echo "gulp autocompletion rules for', - '\'' + name + '\'', - 'not found"' - ); + console.log(translate.message({ tag: messages.COMPLETION_TYPE_UNKNOWN, name: name })); process.exit(5); } }; diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 4721774d..0590ef4a 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -1,10 +1,11 @@ 'use strict'; -var log = require('gulplog'); -var chalk = require('chalk'); +var stringWidth = require('string-width'); +var messages = require('@gulpjs/messages'); + var isObject = require('../is-object'); -function logTasks(tree, opts, getTask) { +function logTasks(tree, opts, getTask, translate) { if (opts.sortTasks) { tree.nodes = tree.nodes.sort(compareByLabel); } @@ -34,16 +35,19 @@ function logTasks(tree, opts, getTask) { tree.nodes.forEach(function(node, idx, arr) { var isLast = idx === arr.length - 1; var w = createTreeLines(node, lines, opts, 1, '', isLast); - maxLabelWidth = Math.max(maxLabelWidth, w || 0); + maxLabelWidth = Math.max(maxLabelWidth, w); }); lines.forEach(function(line) { var s = line.label; if (line.desc) { - var spaces = ' '.repeat(maxLabelWidth - line.label.length) + ' '; + var spaces = ' '.repeat(maxLabelWidth - line.width) + ' '; s += spaces + line.desc; } - log.info(s); + if (s) { + // We don't need timestamps here + console.log(s); + } }); } @@ -60,7 +64,8 @@ function logTasks(tree, opts, getTask) { var maxLabelWidth = addTaskToLines(task, lines, isLast, isLeaf); if (!isLeaf) { - bars += (isLast ? ' ' : '│ '); + bars += (isLast ? ' ' : translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_VERTICAL })); + bars += ' ' node.nodes.forEach(function(node, idx, arr) { var isLast = idx === arr.length - 1; createTreeLines(node, lines, opts, depth + 1, bars, isLast); @@ -71,25 +76,31 @@ function logTasks(tree, opts, getTask) { } function addTaskToLines(task, lines, isLast, isLeaf) { - var taskBars = task.bars + (isLast ? '└' : '├') + '─'; + var taskBars = task.bars + (isLast + ? translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT }) + : translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT })) + + translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_HORIZONTAL }); if (isLeaf) { - taskBars += '─ '; + taskBars += translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_HORIZONTAL }); } else { - taskBars += '┬ '; + taskBars += translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL }); } + taskBars += ' '; var line = {}; if (task.depth === 1) { - line.label = chalk.white(taskBars) + chalk.white(task.label); + line.label = taskBars + translate.message({ tag: messages.TASK_NAME, name: task.label }); } else { - line.label = chalk.white(taskBars) + chalk.cyan(task.label); + line.label = taskBars + translate.message({ tag: messages.TASK_NAME, name: task.label }); } + line.width = stringWidth(line.label); + if (typeof task.desc === 'string' && task.desc) { - line.desc = chalk.white(task.desc); + line.desc = translate.message({ tag: messages.TASK_DESCRIPTION, description: task.desc }); } lines.push(line); - var maxLabelWidth = line.label.length + var maxLabelWidth = line.width; if (!isObject(task.flags)) { return maxLabelWidth; @@ -97,29 +108,33 @@ function logTasks(tree, opts, getTask) { var flagBars = task.bars; if (isLast) { - flagBars += ' '; + flagBars += ' '; } else { - flagBars += '│ '; + flagBars += translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_VERTICAL }); } + flagBars += ' '; if (isLeaf) { - flagBars += ' '; + flagBars += ' '; } else { - flagBars += '│ '; + flagBars += translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_VERTICAL }); } + flagBars += ' '; Object.entries(task.flags).sort(flagSorter).forEach(addFlagsToLines); function addFlagsToLines(ent) { if (typeof ent[0] !== 'string' || !ent[0]) return; var line = {}; - lines.push(line); - line.label = chalk.white(flagBars) + chalk.magenta(ent[0]); + line.label = flagBars + translate.message({ tag: messages.TASK_FLAG, flag: ent[0] }); + line.width = stringWidth(line.label); - maxLabelWidth = Math.max(maxLabelWidth, line.label.length); + maxLabelWidth = Math.max(maxLabelWidth, line.width); - if (typeof ent[1] !== 'string' || !ent[1]) return; - line.desc = chalk.white('…' + ent[1]); + if (typeof ent[1] === 'string' && ent[1] !== '') { + line.desc = translate.message({ tag: messages.TASK_FLAG_DESCRIPTION, description: ent[1] }); + } + lines.push(line); } return maxLabelWidth; diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index 43650af1..a3be2c48 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -1,58 +1,109 @@ 'use strict'; -var fancyLog = require('fancy-log'); - /* istanbul ignore next */ function noop() {} -// The sorting of the levels is -// significant. -var levels = [ - 'error', // -L: Logs error events. - 'warn', // -LL: Logs warn and error events. - 'info', // -LLL: Logs info, warn and error events. - 'debug', // -LLLL: Logs all log levels. -]; - -function cleanup(log) { - levels.forEach(removeListeners); - - function removeListeners(level) { - if (level === 'error') { - log.removeListener(level, noop); - log.removeListener(level, fancyLog.error); - } else { - log.removeListener(level, fancyLog); - } - } -} - -function toConsole(log, opts) { - // Remove previous listeners to enable to call this twice. - cleanup(log); - +function toConsole(log, opts, translate) { // Return immediately if logging is // not desired. if (opts.tasksSimple || opts.tasksJson || opts.help || opts.version || opts.silent) { // Keep from crashing process when silent. log.on('error', noop); - return; + return function () { + log.removeListener('error', noop); + }; } // Default loglevel to info level (3). var loglevel = opts.logLevel || 3; - levels - .filter(function(item, i) { - return i < loglevel; - }) - .forEach(function(level) { - if (level === 'error') { - log.on(level, fancyLog.error); - } else { - log.on(level, fancyLog); + // -L: Logs error events. + if (loglevel > 0) { + log.on('error', onError); + } + + // -LL: Logs warn and error events. + if (loglevel > 1) { + log.on('warn', onWarn); + } + + // -LLL: Logs info, warn and error events. + if (loglevel > 2) { + log.on('info', onInfo); + } + + if (loglevel > 3) { + log.on('debug', onDebug); + } + + return function () { + log.removeListener('error', onError); + log.removeListener('warn', onWarn); + log.removeListener('info', onInfo); + log.removeListener('debug', onDebug); + }; + + function onError(msg) { + // Get message and timestamp before printing anything to avoid + // logging a half message if there's an error in one of them + var message = translate.message(msg); + var timestamp = translate.timestamp(msg); + + if (message) { + // Ensure timestamp is not written without a message + if (timestamp) { + process.stderr.write(timestamp + ' '); } - }); + console.error(message); + } + } + + // onWarn, onInfo, and onDebug are currently all the same + // implementation but separated to change independently + function onWarn(msg) { + // Get message and timestamp before printing anything to avoid + // logging a half message if there's an error in one of them + var message = translate.message(msg); + var timestamp = translate.timestamp(msg); + + if (message) { + // Ensure timestamp is not written without a message + if (timestamp) { + process.stdout.write(timestamp + ' '); + } + console.log(message); + } + } + + function onInfo(msg) { + // Get message and timestamp before printing anything to avoid + // logging a half message if there's an error in one of them + var message = translate.message(msg); + var timestamp = translate.timestamp(msg); + + if (message) { + // Ensure timestamp is not written without a message + if (timestamp) { + process.stdout.write(timestamp + ' '); + } + console.log(message); + } + } + + function onDebug(msg) { + // Get message and timestamp before printing anything to avoid + // logging a half message if there's an error in one of them + var message = translate.message(msg); + var timestamp = translate.timestamp(msg); + + if (message) { + // Ensure timestamp is not written without a message + if (timestamp) { + process.stdout.write(timestamp + ' '); + } + console.log(message); + } + } } module.exports = toConsole; diff --git a/lib/shared/options/cli-options.js b/lib/shared/options/cli-options.js index 8105d461..b84c7948 100644 --- a/lib/shared/options/cli-options.js +++ b/lib/shared/options/cli-options.js @@ -1,118 +1,93 @@ 'use strict'; -var chalk = require('chalk'); +var messages = require('@gulpjs/messages'); var options = { help: { alias: 'h', type: 'boolean', - desc: chalk.gray( - 'Show this help.'), + tag: messages.FLAG_HELP, }, version: { alias: 'v', type: 'boolean', - desc: chalk.gray( - 'Print the global and local gulp versions.'), + tag: messages.FLAG_VERSION, }, preload: { type: 'string', requiresArg: true, - desc: chalk.gray( - 'Will preload a module before running the gulpfile. ' + - 'This is useful for transpilers but also has other applications.'), + tag: messages.FLAG_PRELOAD, }, gulpfile: { alias: 'f', type: 'string', requiresArg: true, - desc: chalk.gray( - 'Manually set path of gulpfile. Useful if you have multiple gulpfiles. ' + - 'This will set the CWD to the gulpfile directory as well.'), + tag: messages.FLAG_GULPFILE, }, cwd: { type: 'string', requiresArg: true, - desc: chalk.gray( - 'Manually set the CWD. The search for the gulpfile, ' + - 'as well as the relativity of all requires will be from here.'), + tag: messages.FLAG_CWD, }, tasks: { alias: 'T', type: 'boolean', - desc: chalk.gray( - 'Print the task dependency tree for the loaded gulpfile.'), + tag: messages.FLAG_TASKS, }, 'tasks-simple': { type: 'boolean', - desc: chalk.gray( - 'Print a plaintext list of tasks for the loaded gulpfile.'), + tag: messages.FLAG_TASKS_SIMPLE, }, 'tasks-json': { - desc: chalk.gray( - 'Print the task dependency tree, ' + - 'in JSON format, for the loaded gulpfile.'), + tag: messages.FLAG_TASKS_JSON, }, 'tasks-depth': { alias: 'depth', type: 'number', requiresArg: true, default: undefined, // To detect if this cli option is specified. - desc: chalk.gray( - 'Specify the depth of the task dependency tree.'), + tag: messages.FLAG_TASKS_DEPTH, }, 'compact-tasks': { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: chalk.gray( - 'Reduce the output of task dependency tree by printing ' + - 'only top tasks and their child tasks.'), + tag: messages.FLAG_COMPACT_TASKS, }, 'sort-tasks': { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: chalk.gray( - 'Will sort top tasks of task dependency tree.'), + tag: messages.FLAG_SORT_TASKS, }, color: { type: 'boolean', - desc: chalk.gray( - 'Will force gulp and gulp plugins to display colors, ' + - 'even when no color support is detected.'), + tag: messages.FLAG_COLOR, }, 'no-color': { type: 'boolean', - desc: chalk.gray( - 'Will force gulp and gulp plugins to not display colors, ' + - 'even when color support is detected.'), + tag: messages.FLAG_NO_COLOR, }, silent: { alias: 'S', type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: chalk.gray( - 'Suppress all gulp logging.'), + tag: messages.FLAG_SILENT, }, continue: { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: chalk.gray( - 'Continue execution of tasks upon failure.'), + tag: messages.FLAG_CONTINUE, }, series: { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: chalk.gray( - 'Run tasks given on the CLI in series (the default is parallel).'), + tag: messages.FLAG_SERIES, }, 'log-level': { alias: 'L', // Type isn't needed because count acts as a boolean count: true, default: undefined, // To detect if this cli option is specified. - desc: chalk.gray( - 'Set the loglevel. -L for least verbose and -LLLL for most verbose. ' + - '-LLL is default.'), + tag: messages.FLAG_LOG_LEVEL, } }; diff --git a/lib/shared/options/make-help.js b/lib/shared/options/make-help.js new file mode 100644 index 00000000..7a56387f --- /dev/null +++ b/lib/shared/options/make-help.js @@ -0,0 +1,24 @@ +'use strict'; + +var cliOptions = require('./cli-options'); + +var messages = require('@gulpjs/messages'); + +function makeHelp(parser, translate) { + var usage = translate.message({ tag: messages.USAGE }); + if (usage) { + parser.usage(usage); + } + + Object.keys(cliOptions).forEach(function (flag) { + var opt = cliOptions[flag]; + var description = translate.message({ tag: opt.tag }); + if (description) { + parser.describe(flag, description); + } + }); + + return parser; +} + +module.exports = makeHelp; diff --git a/lib/shared/translate.js b/lib/shared/translate.js new file mode 100644 index 00000000..00c29ae6 --- /dev/null +++ b/lib/shared/translate.js @@ -0,0 +1,302 @@ +'use strict'; + +var util = require('util'); + +var chalk = require('chalk'); +var messages = require('@gulpjs/messages'); + +var tildify = require('./tildify'); +var formatTime = require('./log/format-hrtime'); + +function Timestamp() { + this.now = new Date(); +} + +Timestamp.prototype[util.inspect.custom] = function (depth, opts) { + var timestamp = this.now.toLocaleTimeString('en', { hour12: false }); + return '[' + opts.stylize(timestamp, 'date') + ']'; +}; + +function getDefaultMessage(data) { + switch (data.tag) { + case messages.PRELOAD_BEFORE: { + return 'Preloading external module: ' + chalk.magenta(data.name); + } + case messages.PRELOAD_SUCCESS: { + return 'Preloaded external module: ' + chalk.magenta(data.name) + } + case messages.PRELOAD_FAILURE: { + return chalk.yellow('Failed to preload external module: ') + chalk.magenta(data.name); + } + case messages.PRELOAD_ERROR: { + return chalk.yellow(data.error.toString()); + } + case messages.LOADER_SUCCESS: { + return 'Loaded external module: ' + chalk.magenta(data.name); + } + case messages.LOADER_FAILURE: { + return chalk.yellow('Failed to load external module: ') + chalk.magenta(data.name); + } + case messages.LOADER_ERROR: { + return chalk.yellow(data.error.toString()); + } + case messages.NODE_FLAGS: { + var nodeFlags = chalk.magenta(data.flags.join(', ')); + return 'Node flags detected: ' + nodeFlags; + } + case messages.RESPAWNED: { + var pid = chalk.magenta(data.pid); + return 'Respawned to PID: ' + pid; + } + case messages.MISSING_GULPFILE: { + return chalk.red('No gulpfile found'); + } + case messages.CWD_CHANGED: { + return 'Working directory changed to ' + chalk.magenta(tildify(data.cwd)); + } + case messages.UNSUPPORTED_GULP_VERSION: { + return chalk.red('Unsupported gulp version', data.version) + } + case messages.DESCRIPTION: { + return 'Tasks for ' + chalk.magenta(tildify(data.path)); + } + case messages.GULPFILE: { + return 'Using gulpfile ' + chalk.magenta(tildify(data.path)); + } + case messages.TASK_START: { + return "Starting '" + chalk.cyan(data.task) + "'..." + } + case messages.TASK_STOP: { + return "Finished '" + chalk.cyan(data.task) + "' after " + chalk.magenta(formatTime(data.duration)); + } + case messages.TASK_FAILURE: { + return "'" + chalk.cyan(data.task) + "' " + chalk.red('errored after') + ' ' + chalk.magenta(formatTime(data.duration)); + } + case messages.TASK_MISSING: { + if (data.similar) { + return chalk.red('Task never defined: ' + data.task + ' - did you mean? ' + data.similar.join(', ')) + + '\nTo list available tasks, try running: gulp --tasks'; + } else { + return chalk.red('Task never defined: ' + data.task) + + '\nTo list available tasks, try running: gulp --tasks'; + } + } + case messages.TASK_SYNC: { + return chalk.red('The following tasks did not complete: ') + chalk.cyan(data.tasks) + "\n" + + chalk.red('Did you forget to signal async completion?'); + } + case messages.MISSING_NODE_MODULES: { + return chalk.red('Local modules not found in') + ' ' + chalk.magenta(tildify(data.cwd)); + } + case messages.MISSING_GULP: { + return chalk.red('Local gulp not found in') + ' ' + chalk.magenta(tildify(data.cwd)); + } + case messages.YARN_INSTALL: { + return chalk.red('Try running: yarn install'); + } + case messages.NPM_INSTALL: { + return chalk.red('Try running: npm install'); + } + case messages.YARN_INSTALL_GULP: { + return chalk.red('Try running: yarn add gulp'); + } + case messages.NPM_INSTALL_GULP: { + return chalk.red('Try running: npm install gulp'); + } + case messages.COMPLETION_TYPE_MISSING: { + return 'Missing completion type'; + } + case messages.COMPLETION_TYPE_UNKNOWN: { + return 'echo "gulp autocompletion rules for' + " '" + data.name + "' " + 'not found"' + } + case messages.ARGV_ERROR: { + return data.message; + } + case messages.EXEC_ERROR: { + return data.message; + } + case messages.TASK_ERROR: { + return data.message; + } + case messages.USAGE: { + return '\n' + chalk.bold('Usage:') + ' gulp ' + chalk.blue('[options]') + ' tasks'; + } + case messages.FLAG_HELP: { + return chalk.gray('Show this help.'); + } + case messages.FLAG_VERSION: { + return chalk.gray('Print the global and local gulp versions.'); + } + case messages.FLAG_PRELOAD: { + return chalk.gray( + 'Will preload a module before running the gulpfile. ' + + 'This is useful for transpilers but also has other applications.' + ); + } + case messages.FLAG_GULPFILE: { + return chalk.gray( + 'Manually set path of gulpfile. Useful if you have multiple gulpfiles. ' + + 'This will set the CWD to the gulpfile directory as well.' + ) + } + case messages.FLAG_CWD: { + return chalk.gray( + 'Manually set the CWD. The search for the gulpfile, ' + + 'as well as the relativity of all requires will be from here.' + ); + } + case messages.FLAG_TASKS: { + return chalk.gray('Print the task dependency tree for the loaded gulpfile.'); + } + case messages.FLAG_TASKS_SIMPLE: { + return chalk.gray('Print a plaintext list of tasks for the loaded gulpfile.'); + } + case messages.FLAG_TASKS_JSON: { + return chalk.gray( + 'Print the task dependency tree, ' + + 'in JSON format, for the loaded gulpfile.' + ); + } + case messages.FLAG_TASKS_DEPTH: { + return chalk.gray('Specify the depth of the task dependency tree.'); + } + case messages.FLAG_COMPACT_TASKS: { + return chalk.gray( + 'Reduce the output of task dependency tree by printing ' + + 'only top tasks and their child tasks.' + ); + } + case messages.FLAG_SORT_TASKS: { + return chalk.gray('Will sort top tasks of task dependency tree.'); + } + case messages.FLAG_COLOR: { + return chalk.gray( + 'Will force gulp and gulp plugins to display colors, ' + + 'even when no color support is detected.' + ); + } + case messages.FLAG_NO_COLOR: { + return chalk.gray( + 'Will force gulp and gulp plugins to not display colors, ' + + 'even when color support is detected.' + ); + } + case messages.FLAG_SILENT: { + return chalk.gray('Suppress all gulp logging.'); + } + case messages.FLAG_CONTINUE: { + return chalk.gray('Continue execution of tasks upon failure.'); + } + case messages.FLAG_SERIES: { + return chalk.gray('Run tasks given on the CLI in series (the default is parallel).'); + } + case messages.FLAG_LOG_LEVEL: { + return chalk.gray( + 'Set the loglevel. -L for least verbose and -LLLL for most verbose. ' + + '-LLL is default.' + ); + } + case messages.TASK_NAME: { + return chalk.cyan(data.name); + } + case messages.TASK_DESCRIPTION: { + return chalk.white(data.description); + } + case messages.TASK_FLAG: { + return chalk.magenta(data.flag); + } + case messages.TASK_FLAG_DESCRIPTION: { + return chalk.white('…' + data.description); + } + case messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT: { + return chalk.white('└'); + } + case messages.BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT: { + return chalk.white('├'); + } + case messages.BOX_DRAWINGS_LIGHT_HORIZONTAL: { + return chalk.white('─'); + } + case messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL: { + return chalk.white('┬'); + } + case messages.BOX_DRAWINGS_LIGHT_VERTICAL: { + return chalk.white('│'); + } + default: { + return data; + } + } +} + +function getDefaultTimestamp() { + return util.inspect(new Timestamp(), { colors: !!chalk.supportsColor }); +} + +function buildTranslations(cfg) { + cfg = cfg || {}; + + return { + message: function (data) { + // Don't allow an `undefined` message through + if (typeof data === 'undefined') { + data = Object.create(null); + } + + var message; + if (typeof cfg.message === 'function') { + try { + message = cfg.message(data); + } catch (err) { + console.error('A problem occurred with the user-defined `message()` function.'); + console.error('Please correct your `.gulp.*` config file.'); + } + } + + // If the user has provided a message, return it + if (message) { + return message; + } + + // Users can filter messages by explicitly returning `false` + if (message === false) { + return ''; + } + + // If the user hasn't returned a message or silenced it with `false` + // get the default message. Will return the first argument if the message + // is not defined in the `@gulpjs/messages` package + return getDefaultMessage(data); + }, + timestamp: function (data) { + // Don't allow an `undefined` message through + if (typeof data === 'undefined') { + data = Object.create(null); + } + + var time; + if (typeof cfg.timestamp === 'function') { + try { + time = cfg.timestamp(data); + } catch (err) { + console.error('A problem occurred with the user-defined `timestamp()` function.'); + console.error('Please correct your `.gulp.*` config file.'); + } + } + + // If the user has provided a timestamp, return it + if (time) { + return time; + } + + // Users can filter timestamps by explicitly returning `false` + if (time === false) { + return ''; + } + + return getDefaultTimestamp(); + } + } +} + +module.exports = buildTranslations; diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 397bd579..bce66146 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -4,12 +4,11 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); -var chalk = require('chalk'); +var messages = require('@gulpjs/messages'); var taskTree = require('./task-tree'); var copyTree = require('../../shared/log/copy-tree'); -var tildify = require('../../shared/tildify'); var logTasks = require('../../shared/log/tasks'); var exit = require('../../shared/exit'); var logEvents = require('./log/events'); @@ -17,7 +16,7 @@ var logTasksSimple = require('./log/tasks-simple'); var registerExports = require('../../shared/register-exports'); var requireOrImport = require('../../shared/require-or-import'); -function execute(env, cfg, opts) { +function execute(env, opts, translate) { var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -35,7 +34,7 @@ function execute(env, cfg, opts) { exit(1); } - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info({ tag: messages.GULPFILE, path: env.configPath }); var gulpInst = require(env.modulePath); logEvents(gulpInst); @@ -51,22 +50,14 @@ function execute(env, cfg, opts) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - if (cfg.description && typeof cfg.description === 'string') { - tree.label = cfg.description; - } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); - } + tree.label = translate.message({ tag: messages.DESCRIPTION, path: env.configPath }); return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; - }); + }, translate); } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - if (cfg.description && typeof cfg.description === 'string') { - tree.label = cfg.description; - } else { - tree.label = 'Tasks for ' + tildify(env.configPath); - } + tree.label = translate.message({ tag: messages.DESCRIPTION, path: env.configPath }); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^3.7.0/log/events.js b/lib/versioned/^3.7.0/log/events.js index a20de7ce..3fb63398 100644 --- a/lib/versioned/^3.7.0/log/events.js +++ b/lib/versioned/^3.7.0/log/events.js @@ -1,8 +1,7 @@ 'use strict'; var log = require('gulplog'); -var formatTime = require('../../../shared/log/format-hrtime'); -var chalk = require('chalk'); +var messages = require('@gulpjs/messages'); var exit = require('../../../shared/exit'); var formatError = require('../format-error'); @@ -26,33 +25,20 @@ function logEvents(gulpInst) { gulpInst.on('task_start', function(e) { // TODO: batch these // so when 5 tasks start at once it only logs one time with all 5 - log.info('Starting', '\'' + chalk.cyan(e.task) + '\'...'); + log.info({ tag: messages.TASK_START, task: e.task }); }); gulpInst.on('task_stop', function(e) { - var time = formatTime(e.hrDuration); - log.info( - 'Finished', '\'' + chalk.cyan(e.task) + '\'', - 'after', chalk.magenta(time) - ); + log.info({ tag: messages.TASK_STOP, task: e.task, duration: e.hrDuration }); }); gulpInst.on('task_err', function(e) { - var msg = formatError(e); - var time = formatTime(e.hrDuration); - log.error( - '\'' + chalk.cyan(e.task) + '\'', - chalk.red('errored after'), - chalk.magenta(time) - ); - log.error(msg); + log.error({ tag: messages.TASK_FAILURE, task: e.task, duration: e.hrDuration }); + log.error({ tag: messages.TASK_ERROR, message: formatError(e) }); }); gulpInst.on('task_not_found', function(err) { - log.error( - chalk.red('Task \'' + err.task + '\' is not in your gulpfile') - ); - log.error('Please check the documentation for proper gulpfile formatting'); + log.error({ tag: messages.TASK_MISSING, task: err.task }); exit(1); }); } diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index c1888bb3..4adb9164 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -4,10 +4,9 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); +var messages = require('@gulpjs/messages'); -var chalk = require('chalk'); var exit = require('../../shared/exit'); -var tildify = require('../../shared/tildify'); var logTasks = require('../../shared/log/tasks'); var logEvents = require('./log/events'); @@ -20,7 +19,7 @@ var copyTree = require('../../shared/log/copy-tree'); var getTask = require('./log/get-task'); var requireOrImport = require('../../shared/require-or-import'); -function execute(env, cfg, opts) { +function execute(env, opts, translate) { var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -54,21 +53,13 @@ function execute(env, cfg, opts) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - if (cfg.description && typeof cfg.description === 'string') { - tree.label = cfg.description; - } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); - } + tree.label = translate.message({ tag: messages.DESCRIPTION, path: env.configPath }); - return logTasks(tree, opts, getTask(gulpInst)); + return logTasks(tree, opts, getTask(gulpInst), translate); } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - if (cfg.description && typeof cfg.description === 'string') { - tree.label = cfg.description; - } else { - tree.label = 'Tasks for ' + tildify(env.configPath); - } + tree.label = translate.message({ tag: messages.DESCRIPTION, path: env.configPath }); var output = JSON.stringify(copyTree(tree, opts)); @@ -78,7 +69,7 @@ function execute(env, cfg, opts) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info({ tag: messages.GULPFILE, path: env.configPath }); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -88,10 +79,9 @@ function execute(env, cfg, opts) { } catch (err) { normalizeError(err); if (err.task) { - log.error(chalk.red(err.message)); - log.error(chalk.red('To list available tasks, try running: gulp --tasks')); - } else /* istanbul ignore next */ { - log.error(chalk.red(err.message)); + log.error({ tag: messages.TASK_MISSING, task: err.task, similar: err.similar }); + } else { + log.error({ tag: messages.EXEC_ERROR, message: err.message, error: err }); } exit(1); } diff --git a/lib/versioned/^4.0.0/log/events.js b/lib/versioned/^4.0.0/log/events.js index 0fb82c5c..af20f656 100644 --- a/lib/versioned/^4.0.0/log/events.js +++ b/lib/versioned/^4.0.0/log/events.js @@ -1,9 +1,8 @@ 'use strict'; var log = require('gulplog'); -var formatTime = require('../../../shared/log/format-hrtime'); +var messages = require('@gulpjs/messages'); -var chalk = require('chalk'); var formatError = require('../format-error'); // Wire up logging events @@ -16,32 +15,22 @@ function logEvents(gulpInst) { // TODO: batch these // so when 5 tasks start at once it only logs one time with all 5 var level = evt.branch ? 'debug' : 'info'; - log[level]('Starting', '\'' + chalk.cyan(evt.name) + '\'...'); + log[level]({ tag: messages.TASK_START, task: evt.name }); }); gulpInst.on('stop', function(evt) { - var time = formatTime(evt.duration); /* istanbul ignore next */ var level = evt.branch ? 'debug' : 'info'; - log[level]( - 'Finished', '\'' + chalk.cyan(evt.name) + '\'', - 'after', chalk.magenta(time) - ); + log[level]({ tag: messages.TASK_STOP, task: evt.name, duration: evt.duration }); }); gulpInst.on('error', function(evt) { - var msg = formatError(evt); - var time = formatTime(evt.duration); var level = evt.branch ? 'debug' : 'error'; - log[level]( - '\'' + chalk.cyan(evt.name) + '\'', - chalk.red('errored after'), - chalk.magenta(time) - ); + log[level]({ tag: messages.TASK_FAILURE, task: evt.name, duration: evt.duration }); // If we haven't logged this before, log it and add to list if (loggedErrors.indexOf(evt.error) === -1) { - log.error(msg); + log.error({ tag: messages.TASK_ERROR, message: formatError(evt) }); loggedErrors.push(evt.error); } }); diff --git a/lib/versioned/^4.0.0/log/sync-task.js b/lib/versioned/^4.0.0/log/sync-task.js index ff380f10..70c38a78 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -1,7 +1,7 @@ 'use strict'; var log = require('gulplog'); -var chalk = require('chalk'); +var messages = require('@gulpjs/messages'); var tasks = {}; @@ -18,13 +18,7 @@ function warn() { process.exitCode = 1; - log.warn( - chalk.red('The following tasks did not complete:'), - chalk.cyan(taskNames) - ); - log.warn( - chalk.red('Did you forget to signal async completion?') - ); + log.warn({ tag: messages.TASK_SYNC, tasks: taskNames }); } function start(e) { diff --git a/package.json b/package.json index dace639b..d67c575d 100644 --- a/package.json +++ b/package.json @@ -30,15 +30,16 @@ "cover": "nyc mocha --async-only --timeout 5000 test/lib test" }, "dependencies": { + "@gulpjs/messages": "^1.0.0", "chalk": "^4.1.2", "copy-props": "^4.0.0", - "fancy-log": "^2.0.0", - "gulplog": "^2.0.1", + "gulplog": "^2.1.0", "interpret": "^3.1.1", "liftoff": "^5.0.0", "mute-stdout": "^2.0.0", "replace-homedir": "^2.0.0", "semver-greatest-satisfied-range": "^2.0.0", + "string-width": "^4.2.3", "v8flags": "^4.0.0", "yargs": "^16.2.0" }, diff --git a/test/config-description.js b/test/config-description.js deleted file mode 100644 index 2a185459..00000000 --- a/test/config-description.js +++ /dev/null @@ -1,72 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var exec = require('child_process').exec; -var path = require('path'); -var fs = require('fs'); - -var sliceLines = require('./tool/slice-lines'); -var eraseTime = require('./tool/erase-time'); -var gulp = require('./tool/gulp-cmd'); - -var baseDir = path.join(__dirname, 'fixtures', 'config'); -var expectedDir = path.join(__dirname, 'expected', 'config'); - -describe('config: description', function() { - - it('Should configure with a .gulp.* file in cwd', function(done) { - var opts = { cwd: path.join(baseDir, 'foo/bar') }; - exec(gulp('--tasks'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); - expect(eraseTime(stdout)).toEqual(expected); - done(err); - } - }); - - it('Should configure with a .gulp.* file in cwd found up', function(done) { - var opts = { cwd: path.join(baseDir, 'foo/bar/baz') }; - exec(gulp('--tasks'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); - done(err); - } - }); - - it('Should configure with a .gulp.* file in cwd even if it is not a project root', function(done) { - var opts = { cwd: path.join(baseDir, 'foo/bar/quux') }; - exec(gulp('--tasks'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output2.txt'), 'utf-8'); - expect(sliceLines(stdout, 2)).toEqual(expected); - done(err); - } - }); - - it('Should configure with a .gulp.* file in cwd by --cwd', function(done) { - var opts = { cwd: path.join(baseDir, 'qux') }; - exec(gulp( - '--tasks', - '--gulpfile ../foo/bar/gulpfile.js', - '--cwd .' - ), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'), 'utf-8'); - expect(eraseTime(stdout)).toEqual(expected); - done(err); - } - }); -}); diff --git a/test/config-message-function.js b/test/config-message-function.js new file mode 100644 index 00000000..e39c1ede --- /dev/null +++ b/test/config-message-function.js @@ -0,0 +1,475 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); +var fs = require('fs'); +var os = require('os'); + +var tildify = require('../lib/shared/tildify'); + +var baseDir = path.join(__dirname, 'fixtures/config/theming'); +var expectedDir = path.join(__dirname, 'expected/config/theming'); + +var eraseTime = require('./tool/erase-time'); +var eraseLapse = require('./tool/erase-lapse'); +var gulp = require('./tool/gulp-cmd'); + +describe('config: message function', function() { + + it('can change USAGE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'USAGE'); + var expected = fs.readFileSync(path.join(expectedDir, 'usage.txt'), 'utf8'); + + var opts = { cwd: cwd }; + exec(gulp('--help'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('can change flag descriptions with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'flags'); + var expected = fs.readFileSync(path.join(expectedDir, 'flags.txt'), 'utf8'); + + var opts = { cwd: cwd }; + exec(gulp('--help'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('can change DESCRIPTION with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'DESCRIPTION'); + var expected = '**DESCRIPTION**\n' + + '└── default\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('can remove DESCRIPTION line output with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'DESCRIPTION/remove'); + var expected = '└── default\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('can change DESCRIPTION for tasks-json with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'DESCRIPTION'); + var expected = JSON.stringify({ + label: '**DESCRIPTION**', + nodes: [{ + label: 'default', + type: 'task', + nodes: [], + }], + }) + '\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks-json'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('can change PRELOAD_BEFORE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'PRELOAD_BEFORE'); + var expected = 'PRELOADING **./preload**!\n'; + + var opts = { cwd: cwd }; + exec(gulp('--preload ./preload'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change PRELOAD_SUCCESS with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'PRELOAD_SUCCESS'); + var expected = 'PRELOADED **./preload**!\n'; + + var opts = { cwd: cwd }; + exec(gulp('--preload ./preload'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change LOADER_SUCCESS with .gulp.*', function(done) { + this.timeout(0); + + var cwd = path.join(baseDir, 'LOADER_SUCCESS'); + var expected = 'LOADED **@babel/register**!\n'; + + var opts = { cwd: cwd }; + exec(gulp('-f gulpfile.babel.js'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change NODE_FLAGS with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'NODE_FLAGS'); + var expected = 'RESPAWNED BY **--lazy**!\n'; + + var opts = { cwd: cwd }; + exec(gulp('--lazy'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change RESPAWNED with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'RESPAWNED'); + var expected = 'RESPAWN!\n'; + + var opts = { cwd: cwd }; + exec(gulp('--lazy'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change CWD_CHANGED with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'CWD_CHANGED'); + var expected = 'CHANGE CWD TO **' + cwd + '**\n'; + + var opts = { cwd: baseDir }; + exec(gulp('--cwd ' + cwd), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change GULPFILE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'GULPFILE'); + var expected = 'USING GULPFILE **abcxyz**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change TASK_START with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'TASK_START'); + var expected = 'START **default**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change TASK_STOP with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'TASK_STOP'); + var expected = 'STOP **default**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(err); + } + }); + + it('can change PRELOAD_FAILURE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'PRELOAD_FAILURE'); + var expected = 'FAILED TO PRELOAD **null-module**\n' + + var opts = { cwd: cwd }; + exec(gulp('--preload null-module'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change LOADER_FAILURE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'LOADER_FAILURE'); + var expected = 'FAIL TO LOAD **coffeescript/register**\n'; + + var opts = { cwd: cwd }; + exec(gulp('-f gulpfile.coffee'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).not.toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(); + } + }); + + it('can change TASK_SYNC with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'TASK_SYNC'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'TASK **default** DID NOT COMPLETE\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(); + } + }); + + it('can change ARGV_ERROR with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'ARGV_ERROR'); + var expected = fs.readFileSync(path.join(expectedDir, 'bad-flag.txt'), 'utf8'); + + var opts = { cwd: cwd }; + exec(gulp('-f'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expected); + done(); + } + }); + + it('can change MISSING_GULP with .gulp.*', function(done) { + var dir = path.join(baseDir, 'MISSING_GULP'); + var cwd = os.tmpdir(); + fs.copyFileSync(path.join(dir, '.gulp.js'), path.join(cwd, '.gulp.js')); + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + if (os.platform() === 'darwin') { + cwd = path.join('/private', cwd); + } + var expected = 'GULP NOT FOUND IN **' + cwd + '**\n'; + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expected); + done(); + } finally { + fs.unlinkSync(path.join(cwd, '.gulp.js')); + } + } + }); + + it('can change MISSING_NODE_MODULES with .gulp.*', function(done) { + var dir = path.join(baseDir, 'MISSING_NODE_MODULES'); + var cwd = os.tmpdir(); + fs.copyFileSync(path.join(dir, '.gulp.js'), path.join(cwd, '.gulp.js')); + fs.copyFileSync(path.join(dir, 'package.json'), path.join(cwd, 'package.json')); + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + if (os.platform() === 'darwin') { + cwd = path.join('/private', cwd); + } + var expected = 'LOCAL MODULE NOT FOUND **' + cwd + '**\n'; + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual(expected); + done(); + } finally { + fs.unlinkSync(path.join(cwd, '.gulp.js')); + fs.unlinkSync(path.join(cwd, 'package.json')); + } + } + }); + + it('can change MISSING_GULPFILE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'MISSING_GULPFILE'); + var expected = 'NO GULPFILE\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual(expected); + done(); + } + }); + + it('can change UNSUPPORTED_GULP_VERSION with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'UNSUPPORTED_GULP_VERSION'); + var expected = 'BAD GULP VERSION **1.2.3**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual(expected); + done(); + } + }); + + it('can change TASK_FAILURE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'TASK_FAILURE'); + var expectedStderr = 'TASK FAILURE: **default**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expectedStderr); + done(); + } + }); + + it('can change TASK_ERROR with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'TASK_ERROR'); + var expectedStderr = '**TASK ERROR**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expectedStderr); + done(); + } + }); + + it('can change TASK_MISSING with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'TASK_MISSING'); + var expectedStdout = 'Using gulpfile!\n'; + var expectedStderr = 'TASK IS NOT FOUND: **defaults** SIMILAR ##default##'; + + var opts = { cwd: cwd }; + exec(gulp('defaults'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(eraseTime(stderr)).toMatch(expectedStderr); + expect(eraseTime(stdout)).toEqual(expectedStdout); + done(); + } + }); + + // Would need to hook gulp to test this + it.skip('can change EXEC_ERROR with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'EXEC_ERROR'); + var expected = 'FAIL TO RUN\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(eraseTime(stderr)).toEqual(expected); + expect(stdout).toEqual(''); + done(); + } + }); + + it('can change COMPLETION_TYPE_MISSING with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'COMPLETION_TYPE_MISSING'); + var expected = 'NO COMPLETION TYPE'; + + var opts = { cwd: cwd }; + exec(gulp('--completion'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toMatch(expected); + expect(stdout).toEqual(''); + done(); + } + }); + + it('can change COMPLETION_TYPE_UNKNOWN with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'COMPLETION_TYPE_UNKNOWN'); + var expected = 'GULP COMPLETION TYPE **xxx** IS NOT FOUND\n'; + + var opts = { cwd: cwd }; + exec(gulp('--completion=xxx'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(); + } + }); +}); diff --git a/test/execution-errors.js b/test/execution-errors.js index bd607e43..7b2fd1ec 100644 --- a/test/execution-errors.js +++ b/test/execution-errors.js @@ -4,6 +4,7 @@ var expect = require('expect'); var exec = require('child_process').exec; var path = require('path'); var os = require('os'); +var fs = require('fs'); var tildify = require('../lib/shared/tildify'); @@ -57,7 +58,7 @@ describe('execution error', function() { } }); - it('should output an error if gulp is not found', function(done) { + it('should output an error if gulp is not found (npm)', function(done) { var opts = { cwd: os.tmpdir() }; exec(gulp(), opts, cb); @@ -70,6 +71,79 @@ describe('execution error', function() { } }); + it('should output an error if gulp is not found (yarn)', function(done) { + var cwd = os.tmpdir(); + var yarnOrig= path.join(__dirname, 'fixtures/errors/yarn/yarn.lock'); + var yarnLock = path.join(cwd, 'yarn.lock'); + + fs.copyFileSync(yarnOrig, yarnLock); + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(sliceLines(stderr, 0, 1)).toMatch('Local gulp not found in '); + expect(sliceLines(stderr, 1, 2)).toEqual('Try running: yarn add gulp'); + done(); + } finally { + fs.unlinkSync(yarnLock); + } + } + }); + + it('should output an error if local modules are not found (npm)', function(done) { + var cwd = os.tmpdir(); + var pkgOrig = path.join(__dirname, 'fixtures/errors/package.json'); + var pkgJson = path.join(cwd, 'package.json'); + + fs.copyFileSync(pkgOrig, pkgJson); + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(sliceLines(stderr, 0, 1)).toMatch('Local modules not found in '); + expect(sliceLines(stderr, 1, 2)).toEqual('Try running: npm install'); + done(); + } finally { + fs.unlinkSync(pkgJson); + } + } + }); + + it('should output an error if local modules are not found (yarn)', function(done) { + var cwd = os.tmpdir(); + var pkgOrig = path.join(__dirname, 'fixtures/errors/package.json'); + var pkgJson = path.join(cwd, 'package.json'); + var yarnOrig= path.join(__dirname, 'fixtures/errors/yarn/yarn.lock'); + var yarnLock = path.join(cwd, 'yarn.lock'); + + fs.copyFileSync(pkgOrig, pkgJson); + fs.copyFileSync(yarnOrig, yarnLock); + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(sliceLines(stderr, 0, 1)).toMatch('Local modules not found in '); + expect(sliceLines(stderr, 1, 2)).toEqual('Try running: yarn install'); + done(); + } finally { + fs.unlinkSync(pkgJson); + fs.unlinkSync(yarnLock); + } + } + }); + it('should log a same error once', function(done) { var dir = path.join(__dirname, 'fixtures/gulpfiles'); var gulpfileName = 'gulpfile-dedup-errorlog.js'; diff --git a/test/expected/config/theming/bad-flag.txt b/test/expected/config/theming/bad-flag.txt new file mode 100644 index 00000000..5d37e6fa --- /dev/null +++ b/test/expected/config/theming/bad-flag.txt @@ -0,0 +1,41 @@ +**Not enough arguments following: f** + +Usage: gulp [options] tasks + +Options: + -h, --help Show this help. [boolean] + -v, --version Print the global and local gulp versions.[boolean] + --preload Will preload a module before running the gulpfile. + This is useful for transpilers but also has other + applications. [string] + -f, --gulpfile Manually set path of gulpfile. Useful if you have + multiple gulpfiles. This will set the CWD to the + gulpfile directory as well. [string] + --cwd Manually set the CWD. The search for the gulpfile, + as well as the relativity of all requires will be + from here. [string] + -T, --tasks Print the task dependency tree for the loaded + gulpfile. [boolean] + --tasks-simple Print a plaintext list of tasks for the loaded + gulpfile. [boolean] + --tasks-json Print the task dependency tree, in JSON format, + for the loaded gulpfile. + --tasks-depth, --depth Specify the depth of the task dependency tree. + [number] + --compact-tasks Reduce the output of task dependency tree by + printing only top tasks and their child tasks. + [boolean] + --sort-tasks Will sort top tasks of task dependency tree. + [boolean] + --color Will force gulp and gulp plugins to display + colors, even when no color support is detected. + [boolean] + --no-color Will force gulp and gulp plugins to not display + colors, even when color support is detected. + [boolean] + -S, --silent Suppress all gulp logging. [boolean] + --continue Continue execution of tasks upon failure.[boolean] + --series Run tasks given on the CLI in series (the default + is parallel). [boolean] + -L, --log-level Set the loglevel. -L for least verbose and -LLLL + for most verbose. -LLL is default. [count] diff --git a/test/expected/config/theming/flags.txt b/test/expected/config/theming/flags.txt new file mode 100644 index 00000000..a9da43fc --- /dev/null +++ b/test/expected/config/theming/flags.txt @@ -0,0 +1,18 @@ +Options: + -h, --help **HELP** [boolean] + -v, --version **VERSION** [boolean] + --preload **PRELOAD** [string] + -f, --gulpfile **GULPFILE** [string] + --cwd **CWD** [string] + -T, --tasks **TASKS** [boolean] + --tasks-simple **TASKS SIMPLE** [boolean] + --tasks-json **TASKS JSON** + --tasks-depth, --depth **TASKS DEPTH** [number] + --compact-tasks **COMPACT TASKS** [boolean] + --sort-tasks **SORT_TASKS** [boolean] + --color **COLOR** [boolean] + --no-color **NO COLOR** [boolean] + -S, --silent **SILENT** [boolean] + --continue **CONTINUE** [boolean] + --series **SERIES** [boolean] + -L, --log-level **LOG LEVEL** [count] diff --git a/test/expected/config/theming/usage.txt b/test/expected/config/theming/usage.txt new file mode 100644 index 00000000..b03f78bd --- /dev/null +++ b/test/expected/config/theming/usage.txt @@ -0,0 +1,39 @@ +GULP USAGE + +Options: + -h, --help Show this help. [boolean] + -v, --version Print the global and local gulp versions.[boolean] + --preload Will preload a module before running the gulpfile. + This is useful for transpilers but also has other + applications. [string] + -f, --gulpfile Manually set path of gulpfile. Useful if you have + multiple gulpfiles. This will set the CWD to the + gulpfile directory as well. [string] + --cwd Manually set the CWD. The search for the gulpfile, + as well as the relativity of all requires will be + from here. [string] + -T, --tasks Print the task dependency tree for the loaded + gulpfile. [boolean] + --tasks-simple Print a plaintext list of tasks for the loaded + gulpfile. [boolean] + --tasks-json Print the task dependency tree, in JSON format, + for the loaded gulpfile. + --tasks-depth, --depth Specify the depth of the task dependency tree. + [number] + --compact-tasks Reduce the output of task dependency tree by + printing only top tasks and their child tasks. + [boolean] + --sort-tasks Will sort top tasks of task dependency tree. + [boolean] + --color Will force gulp and gulp plugins to display + colors, even when no color support is detected. + [boolean] + --no-color Will force gulp and gulp plugins to not display + colors, even when color support is detected. + [boolean] + -S, --silent Suppress all gulp logging. [boolean] + --continue Continue execution of tasks upon failure.[boolean] + --series Run tasks given on the CLI in series (the default + is parallel). [boolean] + -L, --log-level Set the loglevel. -L for least verbose and -LLLL + for most verbose. -LLL is default. [count] diff --git a/test/expected/flags-tasks-depth1.txt b/test/expected/flags-tasks-depth1.txt new file mode 100644 index 00000000..d973a446 --- /dev/null +++ b/test/expected/flags-tasks-depth1.txt @@ -0,0 +1,4 @@ +gulp-cli/test/fixtures/gulpfiles +├── taskC +├── taskB +└── default diff --git a/test/fixtures/.gulp.js b/test/fixtures/.gulp.js index a1dacc5f..c2ca66b9 100644 --- a/test/fixtures/.gulp.js +++ b/test/fixtures/.gulp.js @@ -1,3 +1,9 @@ +var messages = require('@gulpjs/messages'); + module.exports = { - description: "gulp-cli/test/fixtures" + message: function (data) { + if (data.tag === messages.DESCRIPTION) { + return "gulp-cli/test/fixtures"; + } + } }; diff --git a/test/fixtures/config/theming/ARGV_ERROR/.gulp.js b/test/fixtures/config/theming/ARGV_ERROR/.gulp.js new file mode 100644 index 00000000..674530d6 --- /dev/null +++ b/test/fixtures/config/theming/ARGV_ERROR/.gulp.js @@ -0,0 +1,9 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.ARGV_ERROR) { + return '**' + data.message + '**'; + } + } +}; diff --git a/test/fixtures/config/theming/ARGV_ERROR/gulpfile.js b/test/fixtures/config/theming/ARGV_ERROR/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/ARGV_ERROR/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js b/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js new file mode 100644 index 00000000..0d1b6b4d --- /dev/null +++ b/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js @@ -0,0 +1,9 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.COMPLETION_TYPE_MISSING) { + return 'NO COMPLETION TYPE'; + } + } +}; diff --git a/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/gulpfile.js b/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js b/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js new file mode 100644 index 00000000..5db07839 --- /dev/null +++ b/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js @@ -0,0 +1,9 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.COMPLETION_TYPE_UNKNOWN) { + return 'GULP COMPLETION TYPE **' + data.name + '** IS NOT FOUND'; + } + } +}; diff --git a/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/gulpfile.js b/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/CWD_CHANGED/.gulp.js b/test/fixtures/config/theming/CWD_CHANGED/.gulp.js new file mode 100644 index 00000000..abdb16ba --- /dev/null +++ b/test/fixtures/config/theming/CWD_CHANGED/.gulp.js @@ -0,0 +1,12 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.CWD_CHANGED) { + return 'CHANGE CWD TO **' + data.cwd + '**'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/CWD_CHANGED/gulpfile.js b/test/fixtures/config/theming/CWD_CHANGED/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/CWD_CHANGED/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/DESCRIPTION/.gulp.js b/test/fixtures/config/theming/DESCRIPTION/.gulp.js new file mode 100644 index 00000000..6bfacc09 --- /dev/null +++ b/test/fixtures/config/theming/DESCRIPTION/.gulp.js @@ -0,0 +1,9 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.DESCRIPTION) { + return '**DESCRIPTION**'; + } + } +}; diff --git a/test/fixtures/config/theming/DESCRIPTION/gulpfile.js b/test/fixtures/config/theming/DESCRIPTION/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/DESCRIPTION/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js b/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js new file mode 100644 index 00000000..8031c96d --- /dev/null +++ b/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js @@ -0,0 +1,9 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.DESCRIPTION) { + return false; + } + } +}; diff --git a/test/fixtures/config/theming/DESCRIPTION/remove/gulpfile.js b/test/fixtures/config/theming/DESCRIPTION/remove/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/DESCRIPTION/remove/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/EXEC_ERROR/.gulp.js b/test/fixtures/config/theming/EXEC_ERROR/.gulp.js new file mode 100644 index 00000000..853d150c --- /dev/null +++ b/test/fixtures/config/theming/EXEC_ERROR/.gulp.js @@ -0,0 +1,13 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.EXEC_ERROR) { + return 'FAIL TO RUN'; + } + + if (data.tag === messages.GULPFILE) { + throw new Error('Crash before task execution'); + } + } +}; diff --git a/test/fixtures/config/theming/EXEC_ERROR/gulpfile.js b/test/fixtures/config/theming/EXEC_ERROR/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/EXEC_ERROR/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/GULPFILE/.gulp.js b/test/fixtures/config/theming/GULPFILE/.gulp.js new file mode 100644 index 00000000..cbc5684f --- /dev/null +++ b/test/fixtures/config/theming/GULPFILE/.gulp.js @@ -0,0 +1,13 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.GULPFILE) { + return 'USING GULPFILE **abcxyz**'; + } + + // Silence all other messages for test + return false; + } +}; + diff --git a/test/fixtures/config/theming/GULPFILE/gulpfile.js b/test/fixtures/config/theming/GULPFILE/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/GULPFILE/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js b/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js new file mode 100644 index 00000000..6ae4c154 --- /dev/null +++ b/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js @@ -0,0 +1,14 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.LOADER_FAILURE) { + return 'FAIL TO LOAD **' + data.name + '**'; + } + + if (data.tag === messages.LOADER_ERROR) { + // Silence for test + return false; + } + } +}; diff --git a/test/fixtures/config/theming/LOADER_FAILURE/gulpfile.coffee b/test/fixtures/config/theming/LOADER_FAILURE/gulpfile.coffee new file mode 100644 index 00000000..1f8b8541 --- /dev/null +++ b/test/fixtures/config/theming/LOADER_FAILURE/gulpfile.coffee @@ -0,0 +1 @@ +console.log 'hello' diff --git a/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js b/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js new file mode 100644 index 00000000..2079b8ac --- /dev/null +++ b/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js @@ -0,0 +1,12 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.LOADER_SUCCESS) { + return 'LOADED **' + data.name + '**!'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/LOADER_SUCCESS/gulpfile.babel.js b/test/fixtures/config/theming/LOADER_SUCCESS/gulpfile.babel.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/LOADER_SUCCESS/gulpfile.babel.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/MISSING_GULP/.gulp.js b/test/fixtures/config/theming/MISSING_GULP/.gulp.js new file mode 100644 index 00000000..a01c5ca4 --- /dev/null +++ b/test/fixtures/config/theming/MISSING_GULP/.gulp.js @@ -0,0 +1,16 @@ +module.exports = { + message: function (data) { + // Using `Symbol.for()` to avoid node_modules + if (data.tag === Symbol.for('GULP_CLI_MISSING_GULP')) { + return 'GULP NOT FOUND IN **' + data.cwd + '**'; + } + + if (data.tag === Symbol.for('GULP_CLI_NPM_INSTALL_GULP')) { + // Silence for test + return false; + } + }, + timestamp: function () { + return false; + } +}; diff --git a/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js b/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js new file mode 100644 index 00000000..f5c441a7 --- /dev/null +++ b/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js @@ -0,0 +1,9 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.MISSING_GULPFILE) { + return 'NO GULPFILE'; + } + } +}; diff --git a/test/fixtures/config/theming/MISSING_NODE_MODULES/.gulp.js b/test/fixtures/config/theming/MISSING_NODE_MODULES/.gulp.js new file mode 100644 index 00000000..80cca25d --- /dev/null +++ b/test/fixtures/config/theming/MISSING_NODE_MODULES/.gulp.js @@ -0,0 +1,14 @@ +module.exports = { + message: function (data) { + // Using `Symbol.for()` to avoid node_modules + if (data.tag === Symbol.for('GULP_CLI_MISSING_NODE_MODULES')) { + return 'LOCAL MODULE NOT FOUND **' + data.cwd + '**'; + } + + if (data.tag === Symbol.for('GULP_CLI_NPM_INSTALL')) { + // Silence for test + return false; + } + } +}; + diff --git a/test/fixtures/config/theming/MISSING_NODE_MODULES/package.json b/test/fixtures/config/theming/MISSING_NODE_MODULES/package.json new file mode 100644 index 00000000..71897b01 --- /dev/null +++ b/test/fixtures/config/theming/MISSING_NODE_MODULES/package.json @@ -0,0 +1,7 @@ +{ + "name": "node-modules-not-found", + "private": true, + "version": "1.0.0", + "description": "", + "main": ".gulp.js" +} diff --git a/test/fixtures/config/theming/NODE_FLAGS/.gulp.js b/test/fixtures/config/theming/NODE_FLAGS/.gulp.js new file mode 100644 index 00000000..33127d58 --- /dev/null +++ b/test/fixtures/config/theming/NODE_FLAGS/.gulp.js @@ -0,0 +1,12 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.NODE_FLAGS) { + return 'RESPAWNED BY **' + data.flags + '**!'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/NODE_FLAGS/gulpfile.js b/test/fixtures/config/theming/NODE_FLAGS/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/NODE_FLAGS/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js b/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js new file mode 100644 index 00000000..a9ccf495 --- /dev/null +++ b/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js @@ -0,0 +1,12 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.PRELOAD_BEFORE) { + return 'PRELOADING **' + data.name + '**!'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/PRELOAD_BEFORE/gulpfile.js b/test/fixtures/config/theming/PRELOAD_BEFORE/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/PRELOAD_BEFORE/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/PRELOAD_BEFORE/preload.js b/test/fixtures/config/theming/PRELOAD_BEFORE/preload.js new file mode 100644 index 00000000..3b5d0c74 --- /dev/null +++ b/test/fixtures/config/theming/PRELOAD_BEFORE/preload.js @@ -0,0 +1 @@ +global.preload = 'hello preload!'; diff --git a/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js b/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js new file mode 100644 index 00000000..fc2a1570 --- /dev/null +++ b/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js @@ -0,0 +1,12 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.PRELOAD_FAILURE) { + return 'FAILED TO PRELOAD **' + data.name + '**'; + } + + // Silence everything else for test + return false; + } +}; diff --git a/test/fixtures/config/theming/PRELOAD_FAILURE/gulpfile.js b/test/fixtures/config/theming/PRELOAD_FAILURE/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/PRELOAD_FAILURE/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js b/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js new file mode 100644 index 00000000..177818cc --- /dev/null +++ b/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js @@ -0,0 +1,12 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.PRELOAD_SUCCESS) { + return 'PRELOADED **' + data.name + '**!'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/PRELOAD_SUCCESS/gulpfile.js b/test/fixtures/config/theming/PRELOAD_SUCCESS/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/PRELOAD_SUCCESS/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/PRELOAD_SUCCESS/preload.js b/test/fixtures/config/theming/PRELOAD_SUCCESS/preload.js new file mode 100644 index 00000000..3b5d0c74 --- /dev/null +++ b/test/fixtures/config/theming/PRELOAD_SUCCESS/preload.js @@ -0,0 +1 @@ +global.preload = 'hello preload!'; diff --git a/test/fixtures/config/theming/RESPAWNED/.gulp.js b/test/fixtures/config/theming/RESPAWNED/.gulp.js new file mode 100644 index 00000000..1b79a3c7 --- /dev/null +++ b/test/fixtures/config/theming/RESPAWNED/.gulp.js @@ -0,0 +1,12 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.RESPAWNED) { + return 'RESPAWN!'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/RESPAWNED/gulpfile.js b/test/fixtures/config/theming/RESPAWNED/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/RESPAWNED/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/TASK_ERROR/.gulp.js b/test/fixtures/config/theming/TASK_ERROR/.gulp.js new file mode 100644 index 00000000..77f9004a --- /dev/null +++ b/test/fixtures/config/theming/TASK_ERROR/.gulp.js @@ -0,0 +1,16 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.TASK_ERROR) { + return '**TASK ERROR**'; + } + + // Silence everything else for test + return false; + }, + timestamp: function () { + // Silence timestamps for test + return false; + } +}; diff --git a/test/fixtures/config/theming/TASK_ERROR/gulpfile.js b/test/fixtures/config/theming/TASK_ERROR/gulpfile.js new file mode 100644 index 00000000..eeb90fd6 --- /dev/null +++ b/test/fixtures/config/theming/TASK_ERROR/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + throw new Error('FAIL!'); +} diff --git a/test/fixtures/config/theming/TASK_FAILURE/.gulp.js b/test/fixtures/config/theming/TASK_FAILURE/.gulp.js new file mode 100644 index 00000000..af699b5e --- /dev/null +++ b/test/fixtures/config/theming/TASK_FAILURE/.gulp.js @@ -0,0 +1,16 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.TASK_FAILURE) { + return 'TASK FAILURE: **' + data.task + '**'; + } + + // Silence everything else for test + return false; + }, + timestamp: function () { + // Silence timestamps for test + return false; + } +}; diff --git a/test/fixtures/config/theming/TASK_FAILURE/gulpfile.js b/test/fixtures/config/theming/TASK_FAILURE/gulpfile.js new file mode 100644 index 00000000..eeb90fd6 --- /dev/null +++ b/test/fixtures/config/theming/TASK_FAILURE/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + throw new Error('FAIL!'); +} diff --git a/test/fixtures/config/theming/TASK_MISSING/.gulp.js b/test/fixtures/config/theming/TASK_MISSING/.gulp.js new file mode 100644 index 00000000..153f09fa --- /dev/null +++ b/test/fixtures/config/theming/TASK_MISSING/.gulp.js @@ -0,0 +1,13 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.GULPFILE) { + return 'Using gulpfile!'; + } + + if (data.tag === messages.TASK_MISSING) { + return 'TASK IS NOT FOUND: **' + data.task + '** SIMILAR ##' + data.similar.join('') + '##'; + } + } +}; diff --git a/test/fixtures/config/theming/TASK_MISSING/gulpfile.js b/test/fixtures/config/theming/TASK_MISSING/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/TASK_MISSING/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/TASK_START/.gulp.js b/test/fixtures/config/theming/TASK_START/.gulp.js new file mode 100644 index 00000000..671c2c5c --- /dev/null +++ b/test/fixtures/config/theming/TASK_START/.gulp.js @@ -0,0 +1,12 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.TASK_START) { + return 'START **' + data.task + '**'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/TASK_START/gulpfile.js b/test/fixtures/config/theming/TASK_START/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/TASK_START/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/TASK_STOP/.gulp.js b/test/fixtures/config/theming/TASK_STOP/.gulp.js new file mode 100644 index 00000000..23eee49b --- /dev/null +++ b/test/fixtures/config/theming/TASK_STOP/.gulp.js @@ -0,0 +1,12 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.TASK_STOP) { + return 'STOP **' + data.task + '**'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/TASK_STOP/gulpfile.js b/test/fixtures/config/theming/TASK_STOP/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/TASK_STOP/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/TASK_SYNC/.gulp.js b/test/fixtures/config/theming/TASK_SYNC/.gulp.js new file mode 100644 index 00000000..a4911fe5 --- /dev/null +++ b/test/fixtures/config/theming/TASK_SYNC/.gulp.js @@ -0,0 +1,9 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.TASK_SYNC) { + return 'TASK **' + data.tasks + '** DID NOT COMPLETE'; + } + } +}; diff --git a/test/fixtures/config/theming/TASK_SYNC/gulpfile.js b/test/fixtures/config/theming/TASK_SYNC/gulpfile.js new file mode 100644 index 00000000..1e950f9a --- /dev/null +++ b/test/fixtures/config/theming/TASK_SYNC/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + //done(); +} diff --git a/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js new file mode 100644 index 00000000..47159f8f --- /dev/null +++ b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js @@ -0,0 +1,9 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.UNSUPPORTED_GULP_VERSION) { + return 'BAD GULP VERSION **' + data.version + '**'; + } + } +}; diff --git a/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/gulpfile.js b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/index.js b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/index.js new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/package.json b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/package.json new file mode 100644 index 00000000..3585a2f6 --- /dev/null +++ b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/package.json @@ -0,0 +1,5 @@ +{ + "name": "gulp", + "description": "Test Package for Testing!", + "version": "1.2.3" +} diff --git a/test/fixtures/config/theming/USAGE/.gulp.js b/test/fixtures/config/theming/USAGE/.gulp.js new file mode 100644 index 00000000..0c064d41 --- /dev/null +++ b/test/fixtures/config/theming/USAGE/.gulp.js @@ -0,0 +1,9 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.USAGE) { + return 'GULP USAGE'; + } + } +}; diff --git a/test/fixtures/config/theming/flags/.gulp.js b/test/fixtures/config/theming/flags/.gulp.js new file mode 100644 index 00000000..72020819 --- /dev/null +++ b/test/fixtures/config/theming/flags/.gulp.js @@ -0,0 +1,76 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.FLAG_HELP) { + return '**HELP**'; + } + + if (data.tag === messages.FLAG_VERSION) { + return '**VERSION**'; + } + + if (data.tag === messages.FLAG_PRELOAD) { + return '**PRELOAD**'; + } + + if (data.tag === messages.FLAG_GULPFILE) { + return '**GULPFILE**'; + } + + if (data.tag === messages.FLAG_CWD) { + return '**CWD**'; + } + + if (data.tag === messages.FLAG_TASKS) { + return '**TASKS**'; + } + + if (data.tag === messages.FLAG_TASKS_SIMPLE) { + return '**TASKS SIMPLE**'; + } + + if (data.tag === messages.FLAG_TASKS_JSON) { + return '**TASKS JSON**'; + } + + if (data.tag === messages.FLAG_TASKS_DEPTH) { + return '**TASKS DEPTH**'; + } + + if (data.tag === messages.FLAG_COMPACT_TASKS) { + return '**COMPACT TASKS**'; + } + + if (data.tag === messages.FLAG_SORT_TASKS) { + return '**SORT_TASKS**'; + } + + if (data.tag === messages.FLAG_COLOR) { + return '**COLOR**'; + } + + if (data.tag === messages.FLAG_NO_COLOR) { + return '**NO COLOR**'; + } + + if (data.tag === messages.FLAG_SILENT) { + return '**SILENT**'; + } + + if (data.tag === messages.FLAG_CONTINUE) { + return '**CONTINUE**'; + } + + if (data.tag === messages.FLAG_SERIES) { + return '**SERIES**'; + } + + if (data.tag === messages.FLAG_LOG_LEVEL) { + return '**LOG LEVEL**'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/errors/yarn/yarn.lock b/test/fixtures/errors/yarn/yarn.lock new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/gulpfiles/.gulp.js b/test/fixtures/gulpfiles/.gulp.js index 7aa69cc2..33b2e061 100644 --- a/test/fixtures/gulpfiles/.gulp.js +++ b/test/fixtures/gulpfiles/.gulp.js @@ -1,3 +1,9 @@ +var messages = require('@gulpjs/messages'); + module.exports = { - description: "gulp-cli/test/fixtures/gulpfiles" + message: function (data) { + if (data.tag === messages.DESCRIPTION) { + return "gulp-cli/test/fixtures/gulpfiles"; + } + } }; diff --git a/test/fixtures/logging.js b/test/fixtures/logging.js index 6f5c5566..7b28ae8a 100644 --- a/test/fixtures/logging.js +++ b/test/fixtures/logging.js @@ -2,10 +2,13 @@ var log = require('gulplog'); var yargs = require('yargs'); var toConsole = require('../../lib/shared/log/to-console'); var cliOptions = require('../../lib/shared/options/cli-options'); +var buildTranslations = require('../../lib/shared/translate'); var opts = yargs.options(cliOptions).parse(); -toConsole(log, opts); +var translate = buildTranslations(); + +toConsole(log, opts, translate); log.debug('test debug'); log.info('test info'); diff --git a/test/flags-help.js b/test/flags-help.js index b1947b41..3007e288 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -58,4 +58,15 @@ describe('flag: --help', function() { } }); + it('show error message and help if options are invalid', function(done) { + var opts = { cwd: baseDir }; + exec(gulp('-f'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual('Not enough arguments following: f\n' + outputText); + done(); + } + }); }); diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 270b5ffc..68bd2a6a 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -31,7 +31,7 @@ describe('flag: --tasks', function() { } }); - it('print the task list with description and flags', function(done) { + it('prints the task list with description and flags', function(done) { var opts = { cwd: baseDir }; exec(gulp( '--tasks', @@ -50,7 +50,7 @@ describe('flag: --tasks', function() { } }); - it('print the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) { + it('prints the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) { var opts = { cwd: baseDir }; exec(gulp( '--tasks', @@ -122,6 +122,24 @@ describe('flag: --tasks', function() { } }); + it('prints the top task only if negative tasks depth is specified', function(done) { + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--tasks-depth -1' + ), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + var filepath = path.join(expectedDir, 'flags-tasks-depth1.txt'); + var expected = fs.readFileSync(filepath, 'utf-8'); + expect(sliceLines(stdout, 1)).toEqual(expected); + done(err); + } + }); + it('prints the task list with --depth flag', function(done) { var opts = { cwd: baseDir }; exec(gulp( diff --git a/test/lib/config-cli-flags.js b/test/lib/config-cli-flags.js index e70a0d92..d78e07a1 100644 --- a/test/lib/config-cli-flags.js +++ b/test/lib/config-cli-flags.js @@ -3,7 +3,7 @@ var expect = require('expect'); var mergeCliOpts = require('../../lib/shared/config/cli-flags'); -describe('lib: config/cli-flags', function() { +describe('lib: cli-flags', function() { it('Should copy only config props specified to cli flags', function(done) { var opts = {}; diff --git a/test/lib/format-hrtime.js b/test/lib/format-hrtime.js index 71eb9989..d520c3a1 100644 --- a/test/lib/format-hrtime.js +++ b/test/lib/format-hrtime.js @@ -3,7 +3,7 @@ var expect = require('expect'); var formatHrtime = require('../../lib/shared/log/format-hrtime'); -describe('format-hrtime', function() { +describe('lib: format-hrtime', function() { describe('should convert hrtime to string: unit is "h"', function() { it('should be no decimal part if integer part greater than 10', function(done) { expect(formatHrtime([36000, 100])).toEqual('10 h'); diff --git a/test/lib/check-task-not-found.js b/test/lib/normalize-error.js similarity index 100% rename from test/lib/check-task-not-found.js rename to test/lib/normalize-error.js From f06ff30eb6dfa7db0a3b2935a76d79609a54016e Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sat, 23 Mar 2024 14:06:00 -0700 Subject: [PATCH 16/19] feat: Add versioned handler for gulp v5 (#265) --- lib/versioned/^5.0.0/format-error.js | 24 +++++++ lib/versioned/^5.0.0/index.js | 89 ++++++++++++++++++++++++ lib/versioned/^5.0.0/log/events.js | 39 +++++++++++ lib/versioned/^5.0.0/log/get-task.js | 43 ++++++++++++ lib/versioned/^5.0.0/log/sync-task.js | 46 ++++++++++++ lib/versioned/^5.0.0/log/tasks-simple.js | 7 ++ 6 files changed, 248 insertions(+) create mode 100644 lib/versioned/^5.0.0/format-error.js create mode 100644 lib/versioned/^5.0.0/index.js create mode 100644 lib/versioned/^5.0.0/log/events.js create mode 100644 lib/versioned/^5.0.0/log/get-task.js create mode 100644 lib/versioned/^5.0.0/log/sync-task.js create mode 100644 lib/versioned/^5.0.0/log/tasks-simple.js diff --git a/lib/versioned/^5.0.0/format-error.js b/lib/versioned/^5.0.0/format-error.js new file mode 100644 index 00000000..3d8a7718 --- /dev/null +++ b/lib/versioned/^5.0.0/format-error.js @@ -0,0 +1,24 @@ +'use strict'; + +// Format orchestrator errors +/* istanbul ignore next */ +function formatError(e) { + if (!e.error) { + return e.message; + } + + // PluginError + if (typeof e.error.showStack === 'boolean') { + return e.error.toString(); + } + + // Normal error + if (e.error.stack) { + return e.error.stack; + } + + // Unknown (string, number, etc.) + return new Error(String(e.error)).stack; +} + +module.exports = formatError; diff --git a/lib/versioned/^5.0.0/index.js b/lib/versioned/^5.0.0/index.js new file mode 100644 index 00000000..d3258b3b --- /dev/null +++ b/lib/versioned/^5.0.0/index.js @@ -0,0 +1,89 @@ +'use strict'; + +var fs = require('fs'); + +var log = require('gulplog'); +var stdout = require('mute-stdout'); +var messages = require('@gulpjs/messages'); + +var exit = require('../../shared/exit'); + +var logTasks = require('../../shared/log/tasks'); +var logEvents = require('./log/events'); +var logSyncTask = require('./log/sync-task'); +var logTasksSimple = require('./log/tasks-simple'); +var registerExports = require('../../shared/register-exports'); + +var copyTree = require('../../shared/log/copy-tree'); +var getTask = require('./log/get-task'); +var requireOrImport = require('../../shared/require-or-import'); + +function execute(env, opts, translate) { + var tasks = opts._; + var toRun = tasks.length ? tasks : ['default']; + + if (opts.tasksSimple || opts.tasks || opts.tasksJson) { + // Mute stdout if we are listing tasks + stdout.mute(); + } + + var gulpInst = require(env.modulePath); + logEvents(gulpInst); + logSyncTask(gulpInst, opts); + + // This is what actually loads up the gulpfile + requireOrImport(env.configPath, function(err, exported) { + // Before import(), if require() failed we got an unhandled exception on the module level. + // So console.error() & exit() were added here to mimic the old behavior as close as possible. + if (err) { + console.error(err); + exit(1); + } + + registerExports(gulpInst, exported); + + // Always unmute stdout after gulpfile is required + stdout.unmute(); + + var tree; + if (opts.tasksSimple) { + tree = gulpInst.tree(); + return logTasksSimple(tree.nodes); + } + if (opts.tasks) { + tree = gulpInst.tree({ deep: true }); + tree.label = translate.message({ tag: messages.DESCRIPTION, path: env.configPath }); + + return logTasks(tree, opts, getTask(gulpInst), translate); + } + if (opts.tasksJson) { + tree = gulpInst.tree({ deep: true }); + tree.label = translate.message({ tag: messages.DESCRIPTION, path: env.configPath }); + + var output = JSON.stringify(copyTree(tree, opts)); + + if (typeof opts.tasksJson === 'boolean' && opts.tasksJson) { + return console.log(output); + } + return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); + } + try { + log.info({ tag: messages.GULPFILE, path: env.configPath }); + var runMethod = opts.series ? 'series' : 'parallel'; + gulpInst[runMethod](toRun)(function(err) { + if (err) { + exit(1); + } + }); + } catch (err) { + if (err.task) { + log.error({ tag: messages.TASK_MISSING, task: err.task, similar: err.similar }); + } else { + log.error({ tag: messages.EXEC_ERROR, message: err.message, error: err }); + } + exit(1); + } + }); +} + +module.exports = execute; diff --git a/lib/versioned/^5.0.0/log/events.js b/lib/versioned/^5.0.0/log/events.js new file mode 100644 index 00000000..af20f656 --- /dev/null +++ b/lib/versioned/^5.0.0/log/events.js @@ -0,0 +1,39 @@ +'use strict'; + +var log = require('gulplog'); +var messages = require('@gulpjs/messages'); + +var formatError = require('../format-error'); + +// Wire up logging events +function logEvents(gulpInst) { + + var loggedErrors = []; + + gulpInst.on('start', function(evt) { + /* istanbul ignore next */ + // TODO: batch these + // so when 5 tasks start at once it only logs one time with all 5 + var level = evt.branch ? 'debug' : 'info'; + log[level]({ tag: messages.TASK_START, task: evt.name }); + }); + + gulpInst.on('stop', function(evt) { + /* istanbul ignore next */ + var level = evt.branch ? 'debug' : 'info'; + log[level]({ tag: messages.TASK_STOP, task: evt.name, duration: evt.duration }); + }); + + gulpInst.on('error', function(evt) { + var level = evt.branch ? 'debug' : 'error'; + log[level]({ tag: messages.TASK_FAILURE, task: evt.name, duration: evt.duration }); + + // If we haven't logged this before, log it and add to list + if (loggedErrors.indexOf(evt.error) === -1) { + log.error({ tag: messages.TASK_ERROR, message: formatError(evt) }); + loggedErrors.push(evt.error); + } + }); +} + +module.exports = logEvents; diff --git a/lib/versioned/^5.0.0/log/get-task.js b/lib/versioned/^5.0.0/log/get-task.js new file mode 100644 index 00000000..144acb47 --- /dev/null +++ b/lib/versioned/^5.0.0/log/get-task.js @@ -0,0 +1,43 @@ +'use strict'; + +var isObject = require('../../../shared/is-object'); + +function getTask(gulpInst) { + return function(name) { + var task = gulpInst.task(name); + return { + description: getDescription(task), + flags: getFlags(task), + }; + }; +} + +function getDescription(task) { + if (typeof task.description === 'string') { + return task.description; + } + /* istanbul ignore else */ + if (typeof task.unwrap === 'function') { + var origFn = task.unwrap(); + if (typeof origFn.description === 'string') { + return origFn.description; + } + } + return undefined; +} + +function getFlags(task) { + if (isObject(task.flags)) { + return task.flags; + } + /* istanbul ignore else */ + if (typeof task.unwrap === 'function') { + var origFn = task.unwrap(); + if (isObject(origFn.flags)) { + return origFn.flags; + } + } + return undefined; +} + +module.exports = getTask; diff --git a/lib/versioned/^5.0.0/log/sync-task.js b/lib/versioned/^5.0.0/log/sync-task.js new file mode 100644 index 00000000..70c38a78 --- /dev/null +++ b/lib/versioned/^5.0.0/log/sync-task.js @@ -0,0 +1,46 @@ +'use strict'; + +var log = require('gulplog'); +var messages = require('@gulpjs/messages'); + +var tasks = {}; + +function warn() { + var taskKeys = Object.keys(tasks); + + if (!taskKeys.length) { + return; + } + + var taskNames = taskKeys.map(function(key) { + return tasks[key]; + }).join(', '); + + process.exitCode = 1; + + log.warn({ tag: messages.TASK_SYNC, tasks: taskNames }); +} + +function start(e) { + tasks[e.uid] = e.name; +} + +function clear(e) { + delete tasks[e.uid]; +} + +function clearAll() { + tasks = {}; +} + +function logSyncTask(gulpInst, opts) { + + process.once('exit', warn); + gulpInst.on('start', start); + gulpInst.on('stop', clear); + // When not running in --continue mode, we need to clear everything on error to avoid + // false positives. + gulpInst.on('error', opts.continue ? clear : clearAll); +} + +module.exports = logSyncTask; diff --git a/lib/versioned/^5.0.0/log/tasks-simple.js b/lib/versioned/^5.0.0/log/tasks-simple.js new file mode 100644 index 00000000..65cde515 --- /dev/null +++ b/lib/versioned/^5.0.0/log/tasks-simple.js @@ -0,0 +1,7 @@ +'use strict'; + +function logTasksSimple(nodes) { + console.log(nodes.join('\n').trim()); +} + +module.exports = logTasksSimple; From affeda9e01569511cd34f1fe7f66d5ad75339624 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 24 Mar 2024 12:23:14 -0700 Subject: [PATCH 17/19] feat: Add deprecated warning for gulplog v1 messages (#266) --- lib/shared/log/to-console.js | 26 +++++++++++++++++++ lib/shared/translate.js | 3 +++ package.json | 5 ++-- test/config-message-function.js | 15 +++++++++++ .../theming/GULPLOG_DEPRECATED/.gulp.js | 14 ++++++++++ .../theming/GULPLOG_DEPRECATED/gulpfile.js | 6 +++++ 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js create mode 100644 test/fixtures/config/theming/GULPLOG_DEPRECATED/gulpfile.js diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index a3be2c48..3cdf1ca2 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -1,5 +1,7 @@ 'use strict'; +var messages = require('@gulpjs/messages'); + /* istanbul ignore next */ function noop() {} @@ -17,6 +19,9 @@ function toConsole(log, opts, translate) { // Default loglevel to info level (3). var loglevel = opts.logLevel || 3; + var deprecatedPrinted = false; + log.on('deprecated', onDeprecated); + // -L: Logs error events. if (loglevel > 0) { log.on('error', onError); @@ -37,12 +42,33 @@ function toConsole(log, opts, translate) { } return function () { + log.removeListener('deprecated', onDeprecated); log.removeListener('error', onError); log.removeListener('warn', onWarn); log.removeListener('info', onInfo); log.removeListener('debug', onDebug); }; + function onDeprecated() { + if (!deprecatedPrinted) { + var msg = { tag: messages.GULPLOG_DEPRECATED }; + // Get message and timestamp before printing anything to avoid + // logging a half message if there's an error in one of them + var message = translate.message(msg); + var timestamp = translate.timestamp(msg); + + if (message) { + // Ensure timestamp is not written without a message + if (timestamp) { + process.stderr.write(timestamp + ' '); + } + console.error(message); + } + + deprecatedPrinted = true; + } + } + function onError(msg) { // Get message and timestamp before printing anything to avoid // logging a half message if there's an error in one of them diff --git a/lib/shared/translate.js b/lib/shared/translate.js index 00c29ae6..1c1939c8 100644 --- a/lib/shared/translate.js +++ b/lib/shared/translate.js @@ -103,6 +103,9 @@ function getDefaultMessage(data) { case messages.NPM_INSTALL_GULP: { return chalk.red('Try running: npm install gulp'); } + case messages.GULPLOG_DEPRECATED: { + return chalk.yellow("gulplog v1 is deprecated. Please help your plugins update!"); + } case messages.COMPLETION_TYPE_MISSING: { return 'Missing completion type'; } diff --git a/package.json b/package.json index d67c575d..99529c1c 100644 --- a/package.json +++ b/package.json @@ -30,10 +30,10 @@ "cover": "nyc mocha --async-only --timeout 5000 test/lib test" }, "dependencies": { - "@gulpjs/messages": "^1.0.0", + "@gulpjs/messages": "^1.1.0", "chalk": "^4.1.2", "copy-props": "^4.0.0", - "gulplog": "^2.1.0", + "gulplog": "^2.2.0", "interpret": "^3.1.1", "liftoff": "^5.0.0", "mute-stdout": "^2.0.0", @@ -47,6 +47,7 @@ "@babel/core": "^7.20.2", "@babel/preset-env": "^7.20.2", "@babel/register": "^7.18.9", + "@gulpjs/gulplog-v1": "npm:gulplog@1.0.0", "eslint": "^7.32.0", "eslint-config-gulp": "^5.0.1", "expect": "^27.5.1", diff --git a/test/config-message-function.js b/test/config-message-function.js index e39c1ede..3a6eae5a 100644 --- a/test/config-message-function.js +++ b/test/config-message-function.js @@ -472,4 +472,19 @@ describe('config: message function', function() { done(); } }); + + it('can change GULPLOG_DEPRECATED with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'GULPLOG_DEPRECATED'); + var expected = 'GULPLOG V1 IS DEPRECATED\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expected); + done(); + } + }); }); diff --git a/test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js b/test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js new file mode 100644 index 00000000..413c704b --- /dev/null +++ b/test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js @@ -0,0 +1,14 @@ +var messages = require('@gulpjs/messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.GULPLOG_DEPRECATED) { + return 'GULPLOG V1 IS DEPRECATED'; + } + + return false; + }, + timestamp: function () { + return false; + } +}; diff --git a/test/fixtures/config/theming/GULPLOG_DEPRECATED/gulpfile.js b/test/fixtures/config/theming/GULPLOG_DEPRECATED/gulpfile.js new file mode 100644 index 00000000..aa34f0c8 --- /dev/null +++ b/test/fixtures/config/theming/GULPLOG_DEPRECATED/gulpfile.js @@ -0,0 +1,6 @@ +var gulplog = require('@gulpjs/gulplog-v1'); + +exports.default = function(done) { + gulplog.error('Some error here'); + done(); +} From f49515419e900f7e329f798c2e582d279e2b8c81 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 24 Mar 2024 13:04:43 -0700 Subject: [PATCH 18/19] chore: Renamed prepublish script to manpage --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 99529c1c..bda2028c 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ], "scripts": { "lint": "eslint .", - "prepublish": "marked-man --name gulp docs/CLI.md > gulp.1", + "manpage": "marked-man --name gulp docs/CLI.md > gulp.1", "pretest": "npm run lint", "test": "mocha --async-only --timeout 5000 test/lib test", "cover": "nyc mocha --async-only --timeout 5000 test/lib test" From e422eb17a6c2dc84f61ec7a116725aa58445da57 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 24 Mar 2024 13:08:53 -0700 Subject: [PATCH 19/19] chore: Release 3.0.0 (#248) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 34 ++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..cdc5f6f7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,34 @@ +# Changelog + +## [3.0.0](https://www.github.com/gulpjs/gulp-cli/compare/v2.3.0...v3.0.0) (2024-03-24) + + +### ⚠ BREAKING CHANGES + +* Only allow js variants for `.gulp` config files (#261) +* Upgrade to Liftoff v5 and avoid merging flags/config/env (#259) +* Remove support for alpha versions of gulp 4 (#255) +* Remove `--verify` flag (#251) +* Replace `--require` flag with `--preload` +* Normalize repository, dropping node <10.13 support (#239) + +### Features + +* Add deprecated warning for gulplog v1 messages ([#266](https://www.github.com/gulpjs/gulp-cli/issues/266)) ([affeda9](https://www.github.com/gulpjs/gulp-cli/commit/affeda9e01569511cd34f1fe7f66d5ad75339624)) +* Add versioned handler for gulp v5 ([#265](https://www.github.com/gulpjs/gulp-cli/issues/265)) ([f06ff30](https://www.github.com/gulpjs/gulp-cli/commit/f06ff30eb6dfa7db0a3b2935a76d79609a54016e)) +* Support theming and translations via config files ([#260](https://www.github.com/gulpjs/gulp-cli/issues/260)) ([e16d675](https://www.github.com/gulpjs/gulp-cli/commit/e16d675606867a5a3a64c24e7fa48bb0a664723d)) +* Upgrade to Liftoff v5 and avoid merging flags/config/env ([#259](https://www.github.com/gulpjs/gulp-cli/issues/259)) ([ed86da7](https://www.github.com/gulpjs/gulp-cli/commit/ed86da75fddfe0965d9bcc0a299e74f961f50957)) + + +### Bug Fixes + +* Ensure the logger is wired up before running liftoff ([#258](https://www.github.com/gulpjs/gulp-cli/issues/258)) ([36f05d5](https://www.github.com/gulpjs/gulp-cli/commit/36f05d5a8bb5c56437204a37f12fc4b2e31c5430)) + + +### Miscellaneous Chores + +* Normalize repository, dropping node <10.13 support ([#239](https://www.github.com/gulpjs/gulp-cli/issues/239)) ([3544dc6](https://www.github.com/gulpjs/gulp-cli/commit/3544dc65138c6409758c28e083ea1d93640246d8)) +* Only allow js variants for `.gulp` config files ([#261](https://www.github.com/gulpjs/gulp-cli/issues/261)) ([e5c7983](https://www.github.com/gulpjs/gulp-cli/commit/e5c79839e87154aa5bc5d8888eeba29314b17fc6)) +* Remove `--verify` flag ([#251](https://www.github.com/gulpjs/gulp-cli/issues/251)) ([7aeee5d](https://www.github.com/gulpjs/gulp-cli/commit/7aeee5d82e09099696f44fae25d315ef31c14030)) +* Remove support for alpha versions of gulp 4 ([#255](https://www.github.com/gulpjs/gulp-cli/issues/255)) ([cb03b9a](https://www.github.com/gulpjs/gulp-cli/commit/cb03b9a6698ead4537d77bd0478947366b7d29a6)) +* Replace `--require` flag with `--preload` ([3544dc6](https://www.github.com/gulpjs/gulp-cli/commit/3544dc65138c6409758c28e083ea1d93640246d8)) diff --git a/package.json b/package.json index bda2028c..6e140c77 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-cli", - "version": "2.3.0", + "version": "3.0.0", "description": "Command line interface for gulp", "author": "Gulp Team (https://gulpjs.com/)", "contributors": [],