move grunt methods to utils module

This commit is contained in:
Iuri Matias 2017-02-18 14:37:07 -05:00
parent 833102d175
commit 58b1f504d5
3 changed files with 12 additions and 5 deletions

View File

@ -1,5 +1,4 @@
var fs = require('fs'); var fs = require('fs');
var grunt = require('grunt');
var merge = require('merge'); var merge = require('merge');
var Plugins = require('./plugins.js'); var Plugins = require('./plugins.js');
var utils = require('./utils.js'); var utils = require('./utils.js');
@ -149,7 +148,7 @@ Config.prototype.loadChainTrackerFile = function() {
Config.prototype.loadFiles = function(files) { Config.prototype.loadFiles = function(files) {
var self = this; var self = this;
var originalFiles = grunt.file.expand({nonull: true}, files); var originalFiles = utils.filesMatchinPattern(files);
var readFiles = []; var readFiles = [];
// get embark.js object first // get embark.js object first
@ -187,7 +186,7 @@ Config.prototype.loadFiles = function(files) {
} }
filesFromPlugins.filter(function(file) { filesFromPlugins.filter(function(file) {
if (grunt.file.isMatch(files, file.intendedPath)) { if (utils.fileMatchesPattern(files, file.intendedPath)) {
readFiles.push(file); readFiles.push(file);
} }
}); });

View File

@ -1,5 +1,4 @@
/*jshint esversion: 6, loopfunc: true */ /*jshint esversion: 6, loopfunc: true */
var grunt = require('grunt');
var fs = require('fs'); var fs = require('fs');
var utils = require('./utils.js'); var utils = require('./utils.js');
@ -146,7 +145,7 @@ Plugin.prototype.runFilePipeline = function() {
Plugin.prototype.runPipeline = function(args) { Plugin.prototype.runPipeline = function(args) {
// TODO: should iterate the pipelines // TODO: should iterate the pipelines
var pipeline = this.pipeline[0]; var pipeline = this.pipeline[0];
var shouldRunPipeline = grunt.file.isMatch(pipeline.matcthingFiles, args.targetFile); var shouldRunPipeline = utils.fileMatchesPattern(pipeline.matcthingFiles, args.targetFile);
if (shouldRunPipeline) { if (shouldRunPipeline) {
return pipeline.cb.call(this, args); return pipeline.cb.call(this, args);
} else { } else {

View File

@ -1,9 +1,18 @@
var path = require('path'); var path = require('path');
var grunt = require('grunt');
function joinPath() { function joinPath() {
return path.join.apply(path.join, arguments); return path.join.apply(path.join, arguments);
} }
function filesMatchinPattern(files) {
return grunt.file.expand({nonull: true}, files);
}
function fileMatchesPattern(patterns, intendedPath) {
return grunt.file.isMatch(patterns, intendedPath);
}
module.exports = { module.exports = {
joinPath: joinPath joinPath: joinPath
}; };