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.

215 lines
6.1 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. /*******************************
  2. Create Distributions
  3. *******************************/
  4. /*
  5. This will create individual distribution repositories for each SUI distribution
  6. * copy distribution files to release
  7. * update package.json file
  8. */
  9. var
  10. gulp = require('gulp'),
  11. // node dependencies
  12. console = require('better-console'),
  13. del = require('del'),
  14. fs = require('fs'),
  15. path = require('path'),
  16. runSequence = require('run-sequence'),
  17. mergeStream = require('merge-stream'),
  18. // admin dependencies
  19. concatFileNames = require('gulp-concat-filenames'),
  20. debug = require('gulp-debug'),
  21. flatten = require('gulp-flatten'),
  22. git = require('gulp-git'),
  23. jsonEditor = require('gulp-json-editor'),
  24. plumber = require('gulp-plumber'),
  25. rename = require('gulp-rename'),
  26. replace = require('gulp-replace'),
  27. tap = require('gulp-tap'),
  28. // config
  29. config = require('../../config/user'),
  30. release = require('../../config/admin/release'),
  31. project = require('../../config/project/release'),
  32. // shorthand
  33. version = project.version,
  34. output = config.paths.output
  35. ;
  36. module.exports = function(callback) {
  37. var
  38. stream,
  39. index,
  40. tasks = []
  41. ;
  42. for(index in release.distributions) {
  43. var
  44. distribution = release.distributions[index]
  45. ;
  46. // streams... designed to save time and make coding fun...
  47. (function(distribution) {
  48. var
  49. distLowerCase = distribution.toLowerCase(),
  50. outputDirectory = path.join(release.outputRoot, distLowerCase),
  51. packageFile = path.join(outputDirectory, release.files.npm),
  52. repoName = release.distRepoRoot + distribution,
  53. regExp = {
  54. match : {
  55. files : '{files}',
  56. version : '{version}'
  57. }
  58. },
  59. task = {
  60. all : distribution + ' copying files',
  61. repo : distribution + ' create repo',
  62. meteor : distribution + ' create meteor package.js',
  63. package : distribution + ' create package.json'
  64. },
  65. gatherFiles,
  66. createList
  67. ;
  68. // get files for meteor
  69. gatherFiles = function(dir) {
  70. var
  71. dir = dir || path.resolve('.'),
  72. list = fs.readdirSync(dir),
  73. omitted = [
  74. '.git',
  75. 'node_modules',
  76. 'package.js',
  77. 'LICENSE',
  78. 'README.md',
  79. 'package.json',
  80. 'bower.json',
  81. '.gitignore'
  82. ]
  83. files = []
  84. ;
  85. list.forEach(function(file) {
  86. var
  87. isOmitted = (omitted.indexOf(file) > -1),
  88. filePath = path.join(dir, file),
  89. stat = fs.statSync(filePath)
  90. ;
  91. if(!isOmitted) {
  92. if(stat && stat.isDirectory()) {
  93. files = files.concat(gatherFiles(filePath));
  94. }
  95. else {
  96. files.push(filePath.replace(outputDirectory + path.sep, ''));
  97. }
  98. }
  99. })
  100. return files
  101. };
  102. // spaces out list correctly
  103. createList = function(files) {
  104. var filenames = '';
  105. for(file in files) {
  106. if(file == (files.length - 1) ) {
  107. filenames += "'" + files[file] + "'";
  108. }
  109. else {
  110. filenames += "'" + files[file] + "',\n ";
  111. }
  112. }
  113. return filenames;
  114. };
  115. gulp.task(task.meteor, function() {
  116. var
  117. files = gatherFiles(outputDirectory)
  118. filenames = createList(files)
  119. ;
  120. gulp.src(release.templates.meteor[distLowerCase])
  121. .pipe(plumber())
  122. .pipe(flatten())
  123. .pipe(replace(regExp.match.version, version))
  124. .pipe(replace(regExp.match.files, filenames))
  125. .pipe(rename(release.files.meteor))
  126. .pipe(gulp.dest(outputDirectory))
  127. ;
  128. });
  129. if(distribution == 'CSS') {
  130. gulp.task(task.repo, function() {
  131. var
  132. themes,
  133. component,
  134. releases
  135. ;
  136. themes = gulp.src('dist/themes/default/**/*', { base: 'dist/' })
  137. .pipe(gulp.dest(outputDirectory))
  138. ;
  139. components = gulp.src('dist/components/*', { base: 'dist/' })
  140. .pipe(gulp.dest(outputDirectory))
  141. ;
  142. releases = gulp.src('dist/*', { base: 'dist/' })
  143. .pipe(gulp.dest(outputDirectory))
  144. ;
  145. return mergeStream(themes, components, releases);
  146. });
  147. }
  148. else if(distribution == 'LESS') {
  149. gulp.task(task.repo, function() {
  150. var
  151. definitions,
  152. themeImport,
  153. themeConfig,
  154. siteTheme,
  155. themes
  156. ;
  157. definitions = gulp.src('src/definitions/**/*', { base: 'src/' })
  158. .pipe(gulp.dest(outputDirectory))
  159. ;
  160. themeImport = gulp.src('src/theme.less', { base: 'src/' })
  161. .pipe(gulp.dest(outputDirectory))
  162. ;
  163. themeConfig = gulp.src('src/theme.config.example', { base: 'src/' })
  164. .pipe(gulp.dest(outputDirectory))
  165. ;
  166. siteTheme = gulp.src('src/_site/**/*', { base: 'src/' })
  167. .pipe(gulp.dest(outputDirectory))
  168. ;
  169. themes = gulp.src('src/themes/**/*', { base: 'src/' })
  170. .pipe(gulp.dest(outputDirectory))
  171. ;
  172. return mergeStream(definitions, themeImport, themeConfig, siteTheme, themes);
  173. });
  174. }
  175. // extend package.json
  176. gulp.task(task.package, function() {
  177. return gulp.src(packageFile)
  178. .pipe(plumber())
  179. .pipe(jsonEditor(function(package) {
  180. if(version) {
  181. package.version = version;
  182. }
  183. return package;
  184. }))
  185. .pipe(gulp.dest(outputDirectory))
  186. ;
  187. });
  188. tasks.push(task.meteor);
  189. tasks.push(task.repo);
  190. tasks.push(task.package);
  191. })(distribution);
  192. }
  193. runSequence(tasks, callback);
  194. };