Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Commit

Permalink
fix: 优化ignore的逻辑判断,去除使用is-glob的参数验证
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyc726 committed Aug 28, 2017
1 parent e63a50c commit 47af4d1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 27 deletions.
14 changes: 7 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp

var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);

var _isEmpty2 = require('lodash/isEmpty');

var _isEmpty3 = _interopRequireDefault(_isEmpty2);

var _forEach2 = require('lodash/forEach');

var _forEach3 = _interopRequireDefault(_forEach2);
Expand All @@ -18,10 +22,6 @@ var _merge3 = _interopRequireDefault(_merge2);

var _htmlMinifier = require('html-minifier');

var _isGlob = require('is-glob');

var _isGlob2 = _interopRequireDefault(_isGlob);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var DEFAULT_CONFIG = {
Expand All @@ -35,11 +35,11 @@ exports.default = function (options, modified, total, fisDeployNextEvent) {
ignorePattern = config.ignorePattern,
minifyOptions = (0, _objectWithoutProperties3.default)(config, ['templatePattern', 'ignorePattern']);

var isTemplatePatternGlobVerified = (0, _isGlob2.default)(templatePattern);
var isIgnorePatternGlobVerified = (0, _isGlob2.default)(ignorePattern);
var isTemplatePatternVerified = !(0, _isEmpty3.default)(templatePattern);
var isIgnorePatternVerified = !(0, _isEmpty3.default)(ignorePattern);

(0, _forEach3.default)(modified, function (modifiedFile) {
if (modifiedFile.release && (!isTemplatePatternGlobVerified ? modifiedFile.isHtmlLike : fis.util.glob(templatePattern, modifiedFile.subpath)) && isIgnorePatternGlobVerified && !fis.util.glob(ignorePattern, modifiedFile.subpath)) {
if (modifiedFile.release && (!isTemplatePatternVerified ? modifiedFile.isHtmlLike : fis.util.glob(templatePattern, modifiedFile.subpath)) && (!isIgnorePatternVerified || isIgnorePatternVerified && !fis.util.glob(ignorePattern, modifiedFile.subpath))) {
var fileContent = modifiedFile.getContent();
modifiedFile.setContent((0, _htmlMinifier.minify)(fileContent, minifyOptions));
}
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
},
"dependencies": {
"html-minifier": "^3.5.3",
"glob": "^7.1.2",
"is-glob": "^4.0.0",
"lodash": "^4.17.4"
},
"devDependencies": {
Expand Down
18 changes: 10 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/

import { minify } from 'html-minifier';
import isGlob from 'is-glob';
import { merge, forEach } from 'lodash';
import { merge, forEach, isEmpty } from 'lodash';

/**
* @type {Object} DEFAULT_CONFIG - 插件默认配置
Expand All @@ -34,8 +33,8 @@ const DEFAULT_CONFIG = {
export default (options, modified, total, fisDeployNextEvent) => {
const config = merge(DEFAULT_CONFIG, options);
const { templatePattern, ignorePattern, ...minifyOptions } = config;
const isTemplatePatternGlobVerified = isGlob(templatePattern);
const isIgnorePatternGlobVerified = isGlob(ignorePattern);
const isTemplatePatternVerified = !isEmpty(templatePattern);
const isIgnorePatternVerified = !isEmpty(ignorePattern);
/**
* @see http://fis.baidu.com/fis3/api/fis.file-File.html
*
Expand Down Expand Up @@ -68,15 +67,18 @@ export default (options, modified, total, fisDeployNextEvent) => {
modifiedFile.release &&
(
// 如果没有过滤的正则,则依据`isHtmlLike`来鉴别
(!isTemplatePatternGlobVerified) ?
(!isTemplatePatternVerified) ?
modifiedFile.isHtmlLike :
// eslint-disable-next-line no-undef
fis.util.glob(templatePattern, modifiedFile.subpath)
) &&
(
isIgnorePatternGlobVerified &&
// eslint-disable-next-line no-undef
!fis.util.glob(ignorePattern, modifiedFile.subpath)
!isIgnorePatternVerified ||
(
isIgnorePatternVerified &&
// eslint-disable-next-line no-undef
!fis.util.glob(ignorePattern, modifiedFile.subpath)
)
)
) {
const fileContent = modifiedFile.getContent();
Expand Down
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2292,10 +2292,6 @@ is-extglob@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-1.0.0.tgz#ac468177c4943405a092fc8f29760c6ffc6206c0"

is-extglob@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"

is-finite@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-finite/-/is-finite-1.0.2.tgz#cc6677695602be550ef11e8b4aa6305342b6d0aa"
Expand All @@ -2318,12 +2314,6 @@ is-glob@^2.0.0, is-glob@^2.0.1:
dependencies:
is-extglob "^1.0.0"

is-glob@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.0.tgz#9521c76845cc2610a85203ddf080a958c2ffabc0"
dependencies:
is-extglob "^2.1.1"

is-my-json-valid@^2.12.4:
version "2.16.1"
resolved "https://registry.yarnpkg.com/is-my-json-valid/-/is-my-json-valid-2.16.1.tgz#5a846777e2c2620d1e69104e5d3a03b1f6088f11"
Expand Down

0 comments on commit 47af4d1

Please sign in to comment.