-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support All file formats and pass file config in temp file #11
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
40e416a
Use var to point to 'this' to avoid binding in nested functions
Graham42 cf6abbd
Write filesSrc to temp file to get around cli data limit
Graham42 328362f
Fix indentation that was avoided in last commit for diff readability
Graham42 3313e86
Add failing test cases to show file dest issue
Graham42 da2d596
Handle tasks that do file write operations
Graham42 19f1db0
Remove commented line that was missed
Graham42 489b718
Sort test ouput to avoid concurrency issues
Graham42 57eae03
Allow longer timout for job
Graham42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
npm-debug.log | ||
tmp | ||
test/output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,27 @@ | ||
'use strict'; | ||
|
||
var _ = require('lodash'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
|
||
module.exports = function(grunt, childFilesSrcOption, task, target) { | ||
var childFilesSrc = childFilesSrcOption.split(path.delimiter); | ||
var configPath = [task, target]; | ||
var config = grunt.config(configPath); | ||
var kindOf = grunt.util.kindOf; | ||
var type = kindOf(config); | ||
if (type === 'array') { | ||
grunt.config(configPath, childFilesSrc); | ||
} else if (type === 'object') { | ||
if (_.contains(['string', 'array'], kindOf(config.src))) { | ||
// Compact Format | ||
grunt.config(configPath.concat('src'), childFilesSrc); | ||
} else if ('array' === kindOf(config.files)) { | ||
// Files Array Format | ||
grunt.config(configPath.concat('files'), [{src: childFilesSrc}]); | ||
} else if ('object' === kindOf(config.files)) { | ||
// Files Object Format | ||
throw new Error('The config of ' + task + ' is Files Object Format.'); | ||
} else { | ||
throw new Error('The config of ' + task + ' is not supported.'); | ||
var done = grunt.task.current.async(); | ||
fs.readFile(childFilesSrcOption, function (err, data) { | ||
if (err) { throw err; } | ||
var childFilesSrc = JSON.parse(data); | ||
var configPath = [task, target]; | ||
|
||
// replace the original file config with the smaller file set assigned by | ||
// the parallelizer | ||
var targetCfg = grunt.config.get(configPath); | ||
if (targetCfg.hasOwnProperty('dest')){ | ||
delete targetCfg.dest; | ||
} | ||
if (targetCfg.hasOwnProperty('src')){ | ||
delete targetCfg.src; | ||
} | ||
} else { | ||
throw new Error('The config of ' + task + ' is not supported.'); | ||
} | ||
grunt.task.run(configPath.join(':')); | ||
targetCfg.files = childFilesSrc; | ||
grunt.config.set(configPath, targetCfg); | ||
|
||
grunt.task.run(configPath.join(':')); | ||
done(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
module.exports = function(grunt) { | ||
grunt.initConfig({ | ||
writefilesrc: { | ||
test_src: { | ||
dest: '../output/compactFormatWithDest-1.txt', | ||
src: '../fixtures/*.txt', | ||
} | ||
}, | ||
|
||
parallelize: { | ||
writefilesrc: { | ||
test_src: 2, | ||
} | ||
} | ||
}); | ||
|
||
// Load this tasks. | ||
grunt.loadTasks('../../tasks'); | ||
// Load tasks for testing. | ||
grunt.loadTasks('../tasks'); | ||
// Set defaut task. | ||
grunt.registerTask('default', ['parallelize:writefilesrc:test_src']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
module.exports = function(grunt) { | ||
grunt.initConfig({ | ||
writefilesrc: { | ||
test: { | ||
files: [ | ||
{ dest: '../output/filesArrayFormatWithDest-1.txt', src: '../fixtures/*.txt', }, | ||
], | ||
}, | ||
test_multi: { | ||
files: [ | ||
{ dest: '../output/filesArrayFormatWithDest-2.txt', src: '../fixtures/1.txt', }, | ||
{ dest: '../output/filesArrayFormatWithDest-3.txt', src: ['../fixtures/3.txt', '../fixtures/4.txt'], }, | ||
], | ||
}, | ||
}, | ||
|
||
parallelize: { | ||
writefilesrc: { | ||
test: 2, | ||
test_multi: 2, | ||
} | ||
} | ||
}); | ||
|
||
// Load this tasks. | ||
grunt.loadTasks('../../tasks'); | ||
// Load tasks for testing. | ||
grunt.loadTasks('../tasks'); | ||
// Set defaut task. | ||
grunt.registerTask('default', ['parallelize:writefilesrc:test', 'parallelize:writefilesrc:test_multi']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
module.exports = function(grunt) { | ||
grunt.initConfig({ | ||
writefilesrc: { | ||
test: { | ||
files: { | ||
'../output/filesObjectFormatWithDest-1.txt': '../fixtures/*.txt', | ||
}, | ||
}, | ||
test_multi: { | ||
files: { | ||
'../output/filesObjectFormatWithDest-2.txt': '../fixtures/1.txt', | ||
'../output/filesObjectFormatWithDest-3.txt': ['../fixtures/3.txt', '../fixtures/4.txt'], | ||
}, | ||
}, | ||
}, | ||
|
||
parallelize: { | ||
writefilesrc: { | ||
test: 2, | ||
test_multi: 2, | ||
} | ||
} | ||
}); | ||
|
||
// Load this tasks. | ||
grunt.loadTasks('../../tasks'); | ||
// Load tasks for testing. | ||
grunt.loadTasks('../tasks'); | ||
// Set defaut task. | ||
grunt.registerTask('default', ['parallelize:writefilesrc:test', 'parallelize:writefilesrc:test_multi']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["../fixtures/1.txt","../fixtures/2.txt","../fixtures/3.txt","../fixtures/4.txt"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["../fixtures/1.txt","../fixtures/2.txt","../fixtures/3.txt","../fixtures/4.txt"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["../fixtures/1.txt"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["../fixtures/3.txt","../fixtures/4.txt"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["../fixtures/1.txt","../fixtures/2.txt","../fixtures/3.txt","../fixtures/4.txt"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["../fixtures/1.txt"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["../fixtures/3.txt","../fixtures/4.txt"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* grunt-parallelize | ||
* https://github.com/teppeis/grunt-parallelize | ||
* | ||
* Copyright (c) 2013 Teppei Sato <teppeis@gmail.com> | ||
* Licensed under the MIT license. | ||
*/ | ||
'use strict'; | ||
|
||
/* | ||
* Write src files to dest file for test. | ||
*/ | ||
function createMultiTask(grunt, name) { | ||
grunt.registerMultiTask(name, 'Check the files exits.', function() { | ||
var done = this.async(); | ||
grunt.util.async.forEachSeries(this.files, function(file, next) { | ||
if (!file.dest) { | ||
throw new Error('Missing dest'); | ||
} | ||
|
||
grunt.file.write(file.dest, JSON.stringify(file.src) + '\n', {encoding: 'utf8'}); | ||
next(); | ||
}, function(err) { | ||
done(err); | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = function(grunt) { | ||
createMultiTask(grunt, 'writefilesrc'); | ||
}; | ||
|
||
module.exports.createMultiTask = createMultiTask; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change could pass failure result. but ok, I'll fix it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in #14