Skip to content

Commit

Permalink
Respect file paths in destination
Browse files Browse the repository at this point in the history
Introduces grunt-frienly way of configuring task with glob patterns.
Define 'cwd' and 'dest' directories and list your sources under 'src' with patterns that support nested directories:

  - *.html
  - {,*/}*.html
  - {,**/}*.html

Results are put to 'dest' with respect for their original path under 'cwd'. Fixes the issue of results being dumped into single directory.
  • Loading branch information
Dmitry Belyakov committed Dec 12, 2014
1 parent 2f089dc commit e28dcb6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ Then specify your config:
supportedTypes: { 'phtml': 'html' }
},
dist: {
/** @required - string (or array of) including grunt glob variables */
src: ['./static/*.html', './static/*.css', './static/*.soy'],
/** @optional - if provided a copy will be stored without modifying original file */
dest: './dist/static/'
/** @required - gets sources here, may be same as dest */
cwd: './dist/static/',
/** @required - puts results here with respect to relative paths */
dest: './dist/static/',
/** @required - files to process */
src: ['index.html', '*.css', '{,*/}*.html', '{,**/}*.html'],
}
}
});
Expand Down
14 changes: 10 additions & 4 deletions tasks/grunt-cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ module.exports = function(grunt) {
}

files.forEach(function(file) {
if(!('dest' in file) || !('cwd' in file)) {
var msg = 'Configuration error: please set "cwd" and "dest" properly';
grunt.log.error(msg);
throw msg;
}

file.src.forEach(function (filepath) {
var type = path.extname(filepath).replace(/^\./, ''),
filename = path.basename(filepath),
destfile = (file.dest && file.dest !== filepath) ? path.join(file.dest, filename) : filepath,
content = grunt.file.read(filepath).toString(),
var full_path = path.join(file.cwd, filepath),
type = path.extname(filepath).replace(/^\./, ''),
destfile = path.join(file.dest, filepath),
content = grunt.file.read(full_path).toString(),
job; // sometimes css is interpreted as object

if (!supportedTypes[type]) { //next
Expand Down

0 comments on commit e28dcb6

Please sign in to comment.