-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose packages' output namer for gulpTam
- Loading branch information
Showing
4 changed files
with
48 additions
and
30 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
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,32 @@ | ||
var path = require('path'); | ||
var getRealPkgSrc = require('./get-real-pkg-src'); | ||
|
||
function trans(files, dist, srcLength) { | ||
return files.map(function (file) { | ||
return path.resolve(dist, file.substr(srcLength)); | ||
}); | ||
} | ||
|
||
function getCompiledPath(scss) { | ||
return scss.substr(0, scss.length - 4) + 'css'; | ||
} | ||
|
||
module.exports = function (assets, pkg) { | ||
|
||
var srcLength = (pkg.realSrc || getRealPkgSrc(assets, pkg)).length; | ||
|
||
var pkgDist = pkg.dist || pkg.name; | ||
var dist = path.resolve(assets.dist, pkgDist); | ||
|
||
return function (command) { | ||
if (command.behavior === 'copy') { | ||
command.output = trans(command.files, dist, srcLength); | ||
} else if (command.behavior === 'compile') { | ||
command.output = trans(command.files, dist, srcLength).map(getCompiledPath); | ||
} else if (command.behavior === 'compress') { | ||
command.output = [path.resolve(dist, pkg.name + '.' + command.args.type)]; | ||
} else { | ||
throw new Error('Unrecognized behavior [' + command.behavior + ']!'); | ||
} | ||
}; | ||
}; |
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,37 +1,10 @@ | ||
var path = require('path'); | ||
var namer = require('./namer'); | ||
|
||
// NOTE: It does NOT actually output. It just generates the output paths. | ||
// It does not return. The argument `commands` will change. | ||
module.exports = function (assets, pkg, commands) { | ||
|
||
if (commands.length === 0) { | ||
return; | ||
} | ||
|
||
var srcLength = pkg.realSrc.length; | ||
var pkgDist = pkg.dist || pkg.name; | ||
var dist = path.resolve(assets.dist, pkgDist); | ||
|
||
function trans(files) { | ||
return files.map(function (file) { | ||
return path.resolve(dist, file.substr(srcLength)); | ||
}); | ||
} | ||
|
||
function getCompiledPath(scss) { | ||
return scss.substr(0, scss.length - 4) + 'css'; | ||
} | ||
|
||
commands.forEach(function (command) { | ||
if (command.behavior === 'copy') { | ||
command.output = trans(command.files); | ||
} else if (command.behavior === 'compile') { | ||
command.output = trans(command.files).map(getCompiledPath); | ||
} else if (command.behavior === 'compress') { | ||
command.output = [path.resolve(dist, pkg.name + '.' + command.args.type)]; | ||
} else { | ||
throw new Error('Unrecognized behavior [' + command.behavior + ']!'); | ||
} | ||
}); | ||
|
||
commands.forEach(namer(assets, pkg)); | ||
}; |
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