From d83c56ad522042892f9c3631fb484d069bfe3c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=9D=E4=B8=9A=E4=BA=A8?= Date: Wed, 10 Jan 2018 23:40:24 +0800 Subject: [PATCH] remove gulp-util --- .gitignore | 3 ++- index.js | 12 ++++++------ package.json | 10 ++++++---- test.js | 18 +++++++++--------- utils.js | 5 +++++ 5 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 utils.js diff --git a/.gitignore b/.gitignore index 265971d..48e9d95 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ tmp/ -.DS_Store \ No newline at end of file +.DS_Store +/.idea \ No newline at end of file diff --git a/index.js b/index.js index 47eb5eb..32be047 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ 'use strict'; var rimraf = require('rimraf'); var through2 = require('through2'); -var gutil = require('gulp-util'); +var utils = require('./utils'); var path = require('path'); module.exports = function (options) { @@ -15,21 +15,21 @@ module.exports = function (options) { if (!(relative.substr(0, 2) === '..') && relative !== '' || (options ? (options.force && typeof options.force === 'boolean') : false)) { rimraf(filepath, function (error) { if (error) { - this.emit('error', new gutil.PluginError('gulp-clean', 'Unable to delete "' + filepath + '" file (' + error.message + ').')); + this.emit('error', new utils.PluginError('gulp-clean', 'Unable to delete "' + filepath + '" file (' + error.message + ').')); } this.push(file); cb(); }.bind(this)); } else if (relative === '') { var msgCurrent = 'Cannot delete current working directory. (' + filepath + '). Use option force.'; - gutil.log('gulp-clean: ' + msgCurrent); - this.emit('error', new gutil.PluginError('gulp-clean', msgCurrent)); + utils.log('gulp-clean: ' + msgCurrent); + this.emit('error', new utils.PluginError('gulp-clean', msgCurrent)); this.push(file); cb(); } else { var msgOutside = 'Cannot delete files outside the current working directory. (' + filepath + '). Use option force.'; - gutil.log('gulp-clean: ' + msgOutside); - this.emit('error', new gutil.PluginError('gulp-clean', msgOutside)); + utils.log('gulp-clean: ' + msgOutside); + this.emit('error', new utils.PluginError('gulp-clean', msgOutside)); this.push(file); cb(); } diff --git a/package.json b/package.json index 06b8b47..ab3b856 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-clean", - "version": "0.3.2", + "version": "0.4.0", "description": "A gulp plugin for removing files and folders.", "keywords": [ "gulpplugin", @@ -23,9 +23,11 @@ "test": "mocha test.js" }, "dependencies": { - "rimraf": "^2.2.8", - "gulp-util": "^2.2.14", - "through2": "^0.4.2" + "fancy-log": "^1.3.2", + "plugin-error": "^0.1.2", + "rimraf": "^2.6.2", + "through2": "^2.0.3", + "vinyl": "^2.1.0" }, "devDependencies": { "mocha": "^1.19.0", diff --git a/test.js b/test.js index defd78f..9cb4ebd 100644 --- a/test.js +++ b/test.js @@ -2,8 +2,8 @@ 'use strict'; var fs = require('fs'); var path = require('path'); -var gutil = require('gulp-util'); -var clean = require('./'); +var utils = require('./utils'); +var clean = require('./index'); var expect = require('chai').expect; function noop() {} @@ -45,7 +45,7 @@ describe('gulp-clean plugin', function () { }); }); - stream.write(new gutil.File({ + stream.write(new utils.File({ cwd: cwd, base: cwd + '/tmp/', path: cwd + '/tmp/test.js', @@ -67,7 +67,7 @@ describe('gulp-clean plugin', function () { }); }); - stream.write(new gutil.File({ + stream.write(new utils.File({ cwd: cwd, base: cwd + '/tmp/', path: cwd + '/tmp/test/' @@ -91,7 +91,7 @@ describe('gulp-clean plugin', function () { }); }); stream.on('data', noop); - stream.write(new gutil.File({ + stream.write(new utils.File({ cwd: cwd, base: cwd + '/tmp', path: cwd + '/tmp/tree/' @@ -118,7 +118,7 @@ describe('gulp-clean plugin', function () { }); stream.on('data', noop); - stream.write(new gutil.File({ + stream.write(new utils.File({ cwd: cwd, path: cwd })); @@ -146,7 +146,7 @@ describe('gulp-clean plugin', function () { stream.on('data', noop); - stream.write(new gutil.File({ + stream.write(new utils.File({ cwd: path.resolve(cwd), path: path.resolve(cwd + '/../secrets/') })); @@ -176,7 +176,7 @@ describe('gulp-clean plugin', function () { }); }); - stream.write(new gutil.File({ + stream.write(new utils.File({ cwd: path.resolve(cwd), path: path.resolve(cwd + '/../gulp-cleanTemp/') })); @@ -196,7 +196,7 @@ describe('gulp-clean plugin', function () { }); }); - stream.write(new gutil.File({ + stream.write(new utils.File({ cwd: path.resolve(cwd), path: path.resolve(cwd + '/../gulp-cleanTemp/') })); diff --git a/utils.js b/utils.js new file mode 100644 index 0000000..9d99eb8 --- /dev/null +++ b/utils.js @@ -0,0 +1,5 @@ +module.exports = { + PluginError: require('plugin-error'), + log: require('fancy-log'), + File: require('vinyl') +}; \ No newline at end of file