| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
'use strict'; |
| 8 |
|
| 9 |
const self = module.exports = { |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
expandResources: function ( resources ) { |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
const targets = { default: [] }; |
| 46 |
resources.forEach( ( filepath ) => { |
| 47 |
if ( typeof filepath !== 'object' ) { |
| 48 |
filepath = { default: filepath }; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
const buffer = targets.default.slice(); |
| 53 |
for ( const variant in filepath ) { |
| 54 |
if ( !targets[ variant ] ) { |
| 55 |
targets[ variant ] = buffer.slice(); |
| 56 |
} |
| 57 |
targets[ variant ].push( filepath[ variant ] ); |
| 58 |
} |
| 59 |
} ); |
| 60 |
return targets; |
| 61 |
}, |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
makeBuildList: function ( modules, targets ) { |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
function expandBuildList( buildlist, filelist ) { |
| 80 |
filelist = filelist || {}; |
| 81 |
filelist.scripts = filelist.scripts || []; |
| 82 |
filelist.styles = filelist.styles || []; |
| 83 |
|
| 84 |
for ( const build in buildlist ) { |
| 85 |
const moduleName = buildlist[ build ]; |
| 86 |
|
| 87 |
for ( const script in modules[ moduleName ].scripts ) { |
| 88 |
if ( !modules[ moduleName ].scripts[ script ].debug ) { |
| 89 |
filelist.scripts.push( modules[ moduleName ].scripts[ script ] ); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
for ( const style in modules[ moduleName ].styles ) { |
| 94 |
if ( !modules[ moduleName ].styles[ style ].debug ) { |
| 95 |
filelist.styles.push( modules[ moduleName ].styles[ style ] ); |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
return filelist; |
| 100 |
} |
| 101 |
|
| 102 |
return expandBuildList( self.buildDependencyList( modules, targets ) ); |
| 103 |
}, |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
buildDependencyList: function ( modules, load, list ) { |
| 116 |
list = list || []; |
| 117 |
|
| 118 |
for ( let i = 0; i < load.length; i++ ) { |
| 119 |
const module = load[ i ]; |
| 120 |
|
| 121 |
if ( !Object.prototype.hasOwnProperty.call( modules, module ) ) { |
| 122 |
throw new Error( 'Dependency ' + module + ' not found' ); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
if ( modules[ module ].dependencies ) { |
| 127 |
self.buildDependencyList( modules, modules[ module ].dependencies, list ); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
if ( !list.includes( module ) ) { |
| 132 |
list.push( module ); |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
return list; |
| 137 |
} |
| 138 |
}; |