-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make src a passthrough, clean up mode logic in dest, jshint, stylize
- Loading branch information
Contra
committed
Jun 10, 2014
1 parent
c9b2c07
commit d0ba8bb
Showing
23 changed files
with
291 additions
and
191 deletions.
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
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,19 @@ | ||
{ | ||
"camelcase": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"freeze": true, | ||
"indent": 2, | ||
"newcap": false, | ||
"quotmark": "single", | ||
"maxdepth": 3, | ||
"maxstatements": 50, | ||
"maxlen": 80, | ||
"eqnull": true, | ||
"funcscope": true, | ||
"strict": true, | ||
"undef": true, | ||
"unused": true, | ||
"node": true, | ||
"mocha": true | ||
} |
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,5 +1,7 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
src: require('./lib/src'), | ||
dest: require('./lib/dest'), | ||
watch: require('glob-watcher') | ||
}; | ||
}; |
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,42 +1,55 @@ | ||
'use strict'; | ||
|
||
var defaults = require('lodash.defaults'); | ||
var map = require('map-stream'); | ||
var path = require('path'); | ||
var mkdirp = require('mkdirp'); | ||
var fs = require('graceful-fs'); | ||
|
||
var writeContents = require('./writeContents'); | ||
|
||
var defaultMode = 0777 & (~process.umask()); | ||
// 511 = 0777 | ||
var processMode = 511 & (~process.umask()); | ||
|
||
function dest(outFolder, opt) { | ||
if (typeof outFolder !== 'string') { | ||
throw new Error('Invalid output folder'); | ||
} | ||
|
||
module.exports = function(outFolder, opt) { | ||
if (typeof outFolder !== 'string') throw new Error('Invalid output folder'); | ||
var options = defaults({}, opt, { | ||
cwd: process.cwd() | ||
}); | ||
|
||
if (!opt) opt = {}; | ||
if (!opt.cwd) opt.cwd = process.cwd(); | ||
if (typeof opt.mode === 'string') opt.mode = parseInt(opt.mode, 8); | ||
if (typeof options.mode === 'string') { | ||
options.mode = parseInt(options.mode, 8); | ||
} | ||
|
||
var cwd = path.resolve(opt.cwd); | ||
var cwd = path.resolve(options.cwd); | ||
var basePath = path.resolve(cwd, outFolder); | ||
var folderMode = (opt.mode || defaultMode); | ||
var defaultMode = (options.mode || processMode); | ||
|
||
function saveFile (file, cb) { | ||
var writePath = path.resolve(basePath, file.relative); | ||
var writeFolder = path.dirname(writePath); | ||
|
||
if (typeof opt.mode !== 'undefined') { | ||
if (!file.stat) file.stat = {}; | ||
file.stat.mode = opt.mode; | ||
} | ||
|
||
// wire up new properties | ||
file.stat = file.stat ? file.stat : new fs.Stats(); | ||
file.stat.mode = (options.mode || file.stat.mode || processMode); | ||
file.cwd = cwd; | ||
file.base = basePath; | ||
file.path = writePath; | ||
|
||
// mkdirp the folder the file is going in | ||
// then write to it | ||
mkdirp(writeFolder, folderMode, function(err){ | ||
if (err) return cb(err); | ||
mkdirp(writeFolder, defaultMode, function(err){ | ||
if (err) { | ||
return cb(err); | ||
} | ||
writeContents(writePath, file, cb); | ||
}); | ||
} | ||
|
||
var stream = map(saveFile); | ||
return stream; | ||
}; | ||
} | ||
|
||
module.exports = dest; |
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
'use strict'; | ||
|
||
var fs = require('graceful-fs'); | ||
|
||
function writeBuffer(writePath, file, cb) { | ||
var opt = { | ||
mode: file.stat.mode | ||
}; | ||
|
||
fs.writeFile(writePath, file.contents, opt, cb); | ||
} | ||
|
||
module.exports = writeBuffer; |
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,9 @@ | ||
'use strict'; | ||
|
||
var mkdirp = require('mkdirp'); | ||
|
||
function writeDir (writePath, file, cb) { | ||
mkdirp(writePath, file.stat.mode, cb); | ||
} | ||
|
||
module.exports = writeDir; |
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,22 @@ | ||
'use strict'; | ||
|
||
var streamFile = require('../../src/getContents/streamFile'); | ||
var fs = require('graceful-fs'); | ||
|
||
function writeStream (writePath, file, cb) { | ||
var opt = { | ||
mode: file.stat.mode | ||
}; | ||
|
||
var outStream = fs.createWriteStream(writePath, opt); | ||
|
||
file.contents.once('error', cb); | ||
outStream.once('error', cb); | ||
outStream.once('finish', function() { | ||
streamFile(file, cb); | ||
}); | ||
|
||
file.contents.pipe(outStream); | ||
} | ||
|
||
module.exports = writeStream; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
'use strict'; | ||
|
||
var fs = require('graceful-fs'); | ||
var stripBom = require('strip-bom'); | ||
|
||
function bufferFile(file, cb) { | ||
fs.readFile(file.path, function (err, data) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
file.contents = stripBom(data); | ||
cb(null, file); | ||
}); | ||
} | ||
|
||
module.exports = bufferFile; |
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,22 +1,26 @@ | ||
'use strict'; | ||
|
||
var map = require('map-stream'); | ||
|
||
var readDir = require('./readDir'); | ||
var bufferFile = require('./bufferFile'); | ||
var streamFile = require('./streamFile'); | ||
|
||
module.exports = function(opt) { | ||
function getContents(opt) { | ||
return map(function (file, cb) { | ||
// don't fail to read a directory | ||
if (file.stat && file.stat.isDirectory()) { | ||
if (file.isDirectory()) { | ||
return readDir(file, cb); | ||
} | ||
|
||
// read and pass full contents | ||
if (opt.buffer) { | ||
if (opt.buffer !== false) { | ||
return bufferFile(file, cb); | ||
} | ||
|
||
// dont buffer anything - just pass streams | ||
return streamFile(file, cb); | ||
}); | ||
}; | ||
} | ||
|
||
module.exports = getContents; |
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,8 @@ | ||
'use strict'; | ||
|
||
function readDir(file, cb) { | ||
// do nothing for now | ||
cb(null, file); | ||
} | ||
|
||
module.exports = readDir; |
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,8 +1,13 @@ | ||
'use strict'; | ||
|
||
var fs = require('graceful-fs'); | ||
var stripBom = require('strip-bom'); | ||
|
||
module.exports = function (file, cb) { | ||
function streamFile(file, cb) { | ||
file.contents = fs.createReadStream(file.path) | ||
.pipe(stripBom.stream()); | ||
|
||
cb(null, file); | ||
}; | ||
} | ||
|
||
module.exports = streamFile; |
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,13 +1,21 @@ | ||
'use strict'; | ||
|
||
var map = require('map-stream'); | ||
var fs = require('graceful-fs'); | ||
|
||
module.exports = function(opt) { | ||
return map(function (file, cb) { | ||
fs.stat(file.path, function (err, stat) { | ||
if (stat) { | ||
file.stat = stat; | ||
} | ||
cb(err, file); | ||
}); | ||
function getStats() { | ||
return map(fetchStats); | ||
} | ||
|
||
function fetchStats(file, cb) { | ||
fs.stat(file.path, function (err, stat) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
|
||
file.stat = stat; | ||
cb(null, file); | ||
}); | ||
}; | ||
} | ||
|
||
module.exports = getStats; |
Oops, something went wrong.