github.com/fanux/shipyard@v0.0.0-20161009071005-6515ce223235/controller/static/semantic/tasks/config/project/config.js (about) 1 /******************************* 2 Set-up 3 *******************************/ 4 5 var 6 extend = require('extend'), 7 fs = require('fs'), 8 path = require('path'), 9 10 defaults = require('../defaults') 11 ; 12 13 14 /******************************* 15 Exports 16 *******************************/ 17 18 module.exports = { 19 20 getPath: function(file, directory) { 21 var 22 configPath, 23 walk = function(directory) { 24 var 25 nextDirectory = path.resolve( path.join(directory, path.sep, '..') ), 26 currentPath = path.normalize( path.join(directory, file) ) 27 ; 28 if( fs.existsSync(currentPath) ) { 29 // found file 30 configPath = path.normalize(directory); 31 return; 32 } 33 else { 34 // reached file system root, let's stop 35 if(nextDirectory == directory) { 36 return; 37 } 38 // otherwise recurse 39 walk(nextDirectory, file); 40 } 41 } 42 ; 43 44 // start walk from outside require-dot-files directory 45 file = file || defaults.files.config; 46 directory = directory || path.join(__dirname, path.sep, '..'); 47 walk(directory); 48 return configPath || ''; 49 }, 50 51 // adds additional derived values to a config object 52 addDerivedValues: function(config) { 53 54 config = config || extend(false, {}, defaults); 55 56 /*-------------- 57 File Paths 58 ---------------*/ 59 60 var 61 configPath = this.getPath(), 62 sourcePaths = {}, 63 outputPaths = {}, 64 folder 65 ; 66 67 // resolve paths (config location + base + path) 68 for(folder in config.paths.source) { 69 if(config.paths.source.hasOwnProperty(folder)) { 70 sourcePaths[folder] = path.resolve(path.join(configPath, config.base, config.paths.source[folder])); 71 } 72 } 73 for(folder in config.paths.output) { 74 if(config.paths.output.hasOwnProperty(folder)) { 75 outputPaths[folder] = path.resolve(path.join(configPath, config.base, config.paths.output[folder])); 76 } 77 } 78 79 // set config paths to full paths 80 config.paths.source = sourcePaths; 81 config.paths.output = outputPaths; 82 83 // resolve "clean" command path 84 config.paths.clean = path.resolve( path.join(configPath, config.base, config.paths.clean) ); 85 86 /*-------------- 87 CSS URLs 88 ---------------*/ 89 90 // determine asset paths in css by finding relative path between themes and output 91 // force forward slashes 92 93 config.paths.assets = { 94 source : '../../themes', // source asset path is always the same 95 uncompressed : path.relative(config.paths.output.uncompressed, config.paths.output.themes).replace(/\\/g,'/'), 96 compressed : path.relative(config.paths.output.compressed, config.paths.output.themes).replace(/\\/g,'/'), 97 packaged : path.relative(config.paths.output.packaged, config.paths.output.themes).replace(/\\/g,'/') 98 }; 99 100 101 /*-------------- 102 Permission 103 ---------------*/ 104 105 if(config.permission) { 106 config.hasPermissions = true; 107 } 108 else { 109 // pass blank object to avoid causing errors 110 config.permission = {}; 111 config.hasPermissions = false; 112 } 113 114 /*-------------- 115 Globs 116 ---------------*/ 117 118 if(!config.globs) { 119 config.globs = {}; 120 } 121 122 // takes component object and creates file glob matching selected components 123 config.globs.components = (typeof config.components == 'object') 124 ? (config.components.length > 1) 125 ? '{' + config.components.join(',') + '}' 126 : config.components[0] 127 : '{' + defaults.components.join(',') + '}' 128 ; 129 130 return config; 131 132 } 133 134 }; 135