You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.9 KiB

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