@@ -3,45 +3,47 @@ let { createFile, generateFingerprint } = require("faucet-pipeline-util");
33let { readFile } = require ( "./promisified-fs" ) ;
44let tree = require ( "./tree" ) ;
55
6- module . exports = ( { source , target , fingerprint , configDir } ) => {
6+ module . exports = config => {
77 return files => {
88 let filesToCopy ;
99
1010 if ( files ) {
11- filesToCopy = filesWithinDirectory ( source , files ) ;
11+ filesToCopy = filesWithinDirectory ( config . source , files ) ;
1212 } else {
13- filesToCopy = tree ( source ) ;
13+ filesToCopy = tree ( config . source ) ;
1414 }
1515
1616 return filesToCopy .
1717 then ( files => files . filter ( file => ! file . startsWith ( "." ) ) ) .
18- then ( sources => {
19- return Promise . all ( sources . map ( fileName => {
20- let sourcePath = path . join ( source , fileName ) ;
21-
22- return readFile ( sourcePath ) . then ( content => {
23- let targetPath = path . join ( target , fileName ) ;
24- let outputPath = targetPath ;
25-
26- if ( fingerprint ) {
27- outputPath = path . join ( target ,
28- generateFingerprint ( fileName , content ) ) ;
29- }
30-
31- return createFile ( outputPath , content ) . then ( _ => {
32- return {
33- changed : true ,
34- target : path . relative ( configDir , targetPath ) ,
35- output : path . relative ( configDir , outputPath ) ,
36- filePath : path . relative ( target , outputPath )
37- } ;
38- } ) ;
39- } ) ;
40- } ) ) ;
41- } ) ;
18+ then ( sources => processFiles ( sources , config ) ) ;
4219 } ;
4320} ;
4421
22+ function processFiles ( fileNames , config ) {
23+ return Promise . all ( fileNames . map ( fileName => processFile ( fileName , config ) ) ) ;
24+ }
25+
26+ function processFile ( fileName , { source, target, fingerprint, configDir } ) {
27+ let sourcePath = path . join ( source , fileName ) ;
28+ let targetPath = path . join ( target , fileName ) ;
29+ let outputPath = targetPath ;
30+
31+ return readFile ( sourcePath ) .
32+ then ( content => {
33+ if ( fingerprint ) {
34+ outputPath = path . join ( target , generateFingerprint ( fileName , content ) ) ;
35+ }
36+
37+ return createFile ( outputPath , content ) ;
38+ } ) .
39+ then ( _ => ( {
40+ changed : true ,
41+ target : path . relative ( configDir , targetPath ) ,
42+ output : path . relative ( configDir , outputPath ) ,
43+ filePath : path . relative ( target , outputPath )
44+ } ) ) ;
45+ }
46+
4547function filesWithinDirectory ( directory , files ) {
4648 return new Promise ( resolve => {
4749 resolve ( files .
0 commit comments