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.

311 lines
11 KiB

  1. /*******************************
  2. Create Repos
  3. *******************************/
  4. /*
  5. This will create individual component repositories for each SUI component
  6. * copy component files from release
  7. * create commonjs files as index.js for NPM release
  8. * create release notes that filter only items related to component
  9. * custom package.json file from template
  10. * create bower.json from template
  11. * create README from template
  12. * create meteor.js file
  13. */
  14. var
  15. gulp = require('gulp'),
  16. // node dependencies
  17. console = require('better-console'),
  18. fs = require('fs'),
  19. path = require('path'),
  20. runSequence = require('run-sequence'),
  21. // admin dependencies
  22. concatFileNames = require('gulp-concat-filenames'),
  23. flatten = require('gulp-flatten'),
  24. git = require('gulp-git'),
  25. plumber = require('gulp-plumber'),
  26. replace = require('gulp-replace'),
  27. tap = require('gulp-tap'),
  28. // config
  29. config = require('./config/user'),
  30. github = require('../config/admin/github'),
  31. release = require('../config/admin/release'),
  32. // shorthand
  33. output = config.paths.output
  34. ;
  35. module.exports = function(callback) {
  36. var
  37. stream,
  38. index,
  39. tasks = []
  40. ;
  41. for(index in release.components) {
  42. var
  43. component = release.components[index]
  44. ;
  45. // streams... designed to save time and make coding fun...
  46. (function(component) {
  47. var
  48. outputDirectory = release.outputRoot + component,
  49. isJavascript = fs.existsSync(output.compressed + component + '.js'),
  50. isCSS = fs.existsSync(output.compressed + component + '.css'),
  51. capitalizedComponent = component.charAt(0).toUpperCase() + component.slice(1),
  52. packageName = release.packageRoot + component,
  53. repoName = release.repoRoot + capitalizedComponent,
  54. gitURL = 'https://github.com/' + release.org + '/' + repoName + '.git',
  55. repoURL = 'https://github.com/' + release.org + '/' + repoName + '/',
  56. regExp = {
  57. match : {
  58. // templated values
  59. name : '{component}',
  60. titleName : '{Component}',
  61. version : '{version}',
  62. files : '{files}',
  63. // release notes
  64. spacedVersions : /(###.*\n)\n+(?=###)/gm,
  65. spacedLists : /(^- .*\n)\n+(?=^-)/gm,
  66. trim : /^\s+|\s+$/g,
  67. unrelatedNotes : new RegExp('^((?!(^.*(' + component + ').*$|###.*)).)*$', 'gmi'),
  68. whitespace : /\n\s*\n\s*\n/gm,
  69. // npm
  70. export : /\$\.fn\.\w+\s*=\s*function\(parameters\)\s*{/g,
  71. formExport : /\$\.fn\.\w+\s*=\s*function\(fields, parameters\)\s*{/g,
  72. settingsExport : /\$\.fn\.\w+\.settings\s*=/g,
  73. settingsReference : /\$\.fn\.\w+\.settings/g,
  74. jQuery : /jQuery/g,
  75. },
  76. replace : {
  77. // readme
  78. name : component,
  79. titleName : capitalizedComponent,
  80. // release notes
  81. spacedVersions : '',
  82. spacedLists : '$1',
  83. trim : '',
  84. unrelatedNotes : '',
  85. whitespace : '\n\n',
  86. // npm
  87. export : 'module.exports = function(parameters) {\n var _module = module;\n',
  88. formExport : 'module.exports = function(fields, parameters) {\n var _module = module;\n',
  89. settingsExport : 'module.exports.settings =',
  90. settingsReference : '_module.exports.settings',
  91. jQuery : 'require("jquery")'
  92. }
  93. },
  94. task = {
  95. all : component + ' creating',
  96. repo : component + ' create repo',
  97. bower : component + ' create bower.json',
  98. readme : component + ' create README',
  99. npm : component + ' create NPM Module',
  100. notes : component + ' create release notes',
  101. composer : component + ' create composer.json',
  102. package : component + ' create package.json',
  103. meteor : component + ' create package.js',
  104. }
  105. ;
  106. // copy dist files into output folder adjusting asset paths
  107. gulp.task(task.repo, false, function() {
  108. return gulp.src(release.source + component + '.*')
  109. .pipe(plumber())
  110. .pipe(flatten())
  111. .pipe(replace(release.paths.source, release.paths.output))
  112. .pipe(gulp.dest(outputDirectory))
  113. ;
  114. });
  115. // create npm module
  116. gulp.task(task.npm, false, function() {
  117. return gulp.src(release.source + component + '!(*.min|*.map).js')
  118. .pipe(plumber())
  119. .pipe(flatten())
  120. .pipe(replace(regExp.match.export, regExp.replace.export))
  121. .pipe(replace(regExp.match.formExport, regExp.replace.formExport))
  122. .pipe(replace(regExp.match.settingsExport, regExp.replace.settingsExport))
  123. .pipe(replace(regExp.match.settingsReference, regExp.replace.settingsReference))
  124. .pipe(replace(regExp.match.jQuery, regExp.replace.jQuery))
  125. .pipe(rename('index.js'))
  126. .pipe(gulp.dest(outputDirectory))
  127. ;
  128. });
  129. // create readme
  130. gulp.task(task.readme, false, function() {
  131. return gulp.src(release.templates.readme)
  132. .pipe(plumber())
  133. .pipe(flatten())
  134. .pipe(replace(regExp.match.name, regExp.replace.name))
  135. .pipe(replace(regExp.match.titleName, regExp.replace.titleName))
  136. .pipe(gulp.dest(outputDirectory))
  137. ;
  138. });
  139. // extend bower.json
  140. gulp.task(task.bower, false, function() {
  141. return gulp.src(release.templates.bower)
  142. .pipe(plumber())
  143. .pipe(flatten())
  144. .pipe(jeditor(function(bower) {
  145. bower.name = packageName;
  146. bower.description = capitalizedComponent + ' - Semantic UI';
  147. if(isJavascript) {
  148. if(isCSS) {
  149. bower.main = [
  150. component + '.js',
  151. component + '.css'
  152. ];
  153. }
  154. else {
  155. bower.main = [
  156. component + '.js'
  157. ];
  158. }
  159. bower.dependencies = {
  160. jquery: '>=1.8'
  161. };
  162. }
  163. else {
  164. bower.main = [
  165. component + '.css'
  166. ];
  167. }
  168. return bower;
  169. }))
  170. .pipe(gulp.dest(outputDirectory))
  171. ;
  172. });
  173. // extend package.json
  174. gulp.task(task.package, false, function() {
  175. return gulp.src(release.templates.package)
  176. .pipe(plumber())
  177. .pipe(flatten())
  178. .pipe(jeditor(function(package) {
  179. if(isJavascript) {
  180. package.dependencies = {
  181. jquery: 'x.x.x'
  182. };
  183. package.main = 'index.js';
  184. }
  185. package.name = packageName;
  186. if(version) {
  187. package.version = version;
  188. }
  189. package.title = 'Semantic UI - ' + capitalizedComponent;
  190. package.description = 'Single component release of ' + component;
  191. package.repository = {
  192. type : 'git',
  193. url : gitURL
  194. };
  195. return package;
  196. }))
  197. .pipe(gulp.dest(outputDirectory))
  198. ;
  199. });
  200. // extend composer.json
  201. gulp.task(task.composer, false, function() {
  202. return gulp.src(release.templates.composer)
  203. .pipe(plumber())
  204. .pipe(flatten())
  205. .pipe(jeditor(function(composer) {
  206. if(isJavascript) {
  207. composer.dependencies = {
  208. jquery: 'x.x.x'
  209. };
  210. composer.main = component + '.js';
  211. }
  212. composer.name = 'semantic/' + component;
  213. if(version) {
  214. composer.version = version;
  215. }
  216. composer.description = 'Single component release of ' + component;
  217. return composer;
  218. }))
  219. .pipe(gulp.dest(outputDirectory))
  220. ;
  221. });
  222. // create release notes
  223. gulp.task(task.notes, false, function() {
  224. return gulp.src(release.templates.notes)
  225. .pipe(plumber())
  226. .pipe(flatten())
  227. // Remove release notes for lines not mentioning component
  228. .pipe(replace(regExp.match.unrelatedNotes, regExp.replace.unrelatedNotes))
  229. .pipe(replace(regExp.match.whitespace, regExp.replace.whitespace))
  230. .pipe(replace(regExp.match.spacedVersions, regExp.replace.spacedVersions))
  231. .pipe(replace(regExp.match.spacedLists, regExp.replace.spacedLists))
  232. .pipe(replace(regExp.match.trim, regExp.replace.trim))
  233. .pipe(gulp.dest(outputDirectory))
  234. ;
  235. });
  236. // Creates meteor package.js
  237. gulp.task(task.meteor, function() {
  238. var
  239. fileNames = ''
  240. ;
  241. if(isJavascript) {
  242. fileNames += ' \'' + component + '.js\',\n';
  243. }
  244. if(isCSS) {
  245. fileNames += ' \'' + component + '.css\',\n';
  246. }
  247. return gulp.src(outputDirectory + '/assets/**/' + component + '?(s).*', { base: outputDirectory})
  248. .pipe(concatFileNames('dummy.txt', {
  249. newline : '',
  250. root : outputDirectory,
  251. prepend : ' \'',
  252. append : '\','
  253. }))
  254. .pipe(tap(function(file) { fileNames += file.contents; }))
  255. .on('end', function(){
  256. gulp.src(release.templates.meteorComponent)
  257. .pipe(plumber())
  258. .pipe(flatten())
  259. .pipe(replace(regExp.match.name, regExp.replace.name))
  260. .pipe(replace(regExp.match.titleName, regExp.replace.titleName))
  261. .pipe(replace(regExp.match.version, version))
  262. .pipe(replace(regExp.match.files, fileNames))
  263. .pipe(rename(release.files.npm))
  264. .pipe(gulp.dest(outputDirectory))
  265. ;
  266. })
  267. ;
  268. });
  269. // synchronous tasks in orchestrator? I think not
  270. gulp.task(task.all, false, function(callback) {
  271. runSequence([
  272. task.repo,
  273. task.npm,
  274. task.bower,
  275. task.readme,
  276. task.package,
  277. task.composer,
  278. task.notes,
  279. task.meteor
  280. ], callback);
  281. });
  282. tasks.push(task.all);
  283. })(component);
  284. }
  285. runSequence(tasks, callback);
  286. });