Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

230 Zeilen
6.1KB

  1. var gulp = require('gulp'),
  2. concat = require('gulp-concat'),
  3. uglify = require('gulp-uglify'),
  4. util = require('gulp-util'),
  5. jshint = require('gulp-jshint'),
  6. size = require('gulp-size'),
  7. connect = require('gulp-connect'),
  8. replace = require('gulp-replace'),
  9. htmlv = require('gulp-html-validator'),
  10. insert = require('gulp-insert'),
  11. inquirer = require('inquirer'),
  12. semver = require('semver'),
  13. exec = require('child_process').exec,
  14. fs = require('fs'),
  15. package = require('./package.json'),
  16. bower = require('./bower.json'),
  17. karma = require('gulp-karma'),
  18. browserify = require('browserify'),
  19. streamify = require('gulp-streamify'),
  20. source = require('vinyl-source-stream'),
  21. merge = require('merge-stream'),
  22. collapse = require('bundle-collapser/plugin');
  23. var srcDir = './src/';
  24. var outDir = './dist/';
  25. var header = "/*!\n" +
  26. " * Chart.js\n" +
  27. " * http://chartjs.org/\n" +
  28. " * Version: {{ version }}\n" +
  29. " *\n" +
  30. " * Copyright 2016 Nick Downie\n" +
  31. " * Released under the MIT license\n" +
  32. " * https://github.com/chartjs/Chart.js/blob/master/LICENSE.md\n" +
  33. " */\n";
  34. var preTestFiles = [
  35. './node_modules/moment/min/moment.min.js',
  36. ];
  37. var testFiles = [
  38. './test/mockContext.js',
  39. './test/*.js',
  40. // Disable tests which need to be rewritten based on changes introduced by
  41. // the following changes: https://github.com/chartjs/Chart.js/pull/2346
  42. '!./test/core.layoutService.tests.js',
  43. '!./test/defaultConfig.tests.js',
  44. ];
  45. gulp.task('build', buildTask);
  46. gulp.task('coverage', coverageTask);
  47. gulp.task('watch', watchTask);
  48. gulp.task('bump', bumpTask);
  49. gulp.task('release', ['build'], releaseTask);
  50. gulp.task('jshint', jshintTask);
  51. gulp.task('test', ['jshint', 'validHTML', 'unittest']);
  52. gulp.task('size', ['library-size', 'module-sizes']);
  53. gulp.task('server', serverTask);
  54. gulp.task('validHTML', validHTMLTask);
  55. gulp.task('unittest', unittestTask);
  56. gulp.task('unittestWatch', unittestWatchTask);
  57. gulp.task('library-size', librarySizeTask);
  58. gulp.task('module-sizes', moduleSizesTask);
  59. gulp.task('_open', _openTask);
  60. gulp.task('dev', ['server', 'default']);
  61. gulp.task('default', ['build', 'watch']);
  62. function buildTask() {
  63. var bundled = browserify('./src/chart.js', { standalone: 'Chart' })
  64. .plugin(collapse)
  65. .bundle()
  66. .pipe(source('Chart.bundle.js'))
  67. .pipe(insert.prepend(header))
  68. .pipe(streamify(replace('{{ version }}', package.version)))
  69. .pipe(gulp.dest(outDir))
  70. .pipe(streamify(uglify()))
  71. .pipe(insert.prepend(header))
  72. .pipe(streamify(replace('{{ version }}', package.version)))
  73. .pipe(streamify(concat('Chart.bundle.min.js')))
  74. .pipe(gulp.dest(outDir));
  75. var nonBundled = browserify('./src/chart.js', { standalone: 'Chart' })
  76. .ignore('moment')
  77. .plugin(collapse)
  78. .bundle()
  79. .pipe(source('Chart.js'))
  80. .pipe(insert.prepend(header))
  81. .pipe(streamify(replace('{{ version }}', package.version)))
  82. .pipe(gulp.dest(outDir))
  83. .pipe(streamify(uglify()))
  84. .pipe(insert.prepend(header))
  85. .pipe(streamify(replace('{{ version }}', package.version)))
  86. .pipe(streamify(concat('Chart.min.js')))
  87. .pipe(gulp.dest(outDir));
  88. return merge(bundled, nonBundled);
  89. }
  90. /*
  91. * Usage : gulp bump
  92. * Prompts: Version increment to bump
  93. * Output: - New version number written into package.json & bower.json
  94. */
  95. function bumpTask(complete) {
  96. util.log('Current version:', util.colors.cyan(package.version));
  97. var choices = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'].map(function(versionType) {
  98. return versionType + ' (v' + semver.inc(package.version, versionType) + ')';
  99. });
  100. inquirer.prompt({
  101. type: 'list',
  102. name: 'version',
  103. message: 'What version update would you like?',
  104. choices: choices
  105. }, function(res) {
  106. var increment = res.version.split(' ')[0],
  107. newVersion = semver.inc(package.version, increment),
  108. oldVersion = package.version;
  109. // Set the new versions into the bower/package object
  110. package.version = newVersion;
  111. bower.version = newVersion;
  112. // Write these to their own files, then build the output
  113. fs.writeFileSync('package.json', JSON.stringify(package, null, 2));
  114. fs.writeFileSync('bower.json', JSON.stringify(bower, null, 2));
  115. var oldCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+oldVersion+'/Chart.min.js',
  116. newCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+newVersion+'/Chart.min.js';
  117. gulp.src(['./README.md'])
  118. .pipe(replace(oldCDN, newCDN))
  119. .pipe(gulp.dest('./'));
  120. complete();
  121. });
  122. }
  123. function releaseTask() {
  124. exec('git tag -a v' + package.version);
  125. }
  126. function jshintTask() {
  127. return gulp.src(srcDir + '**/*.js')
  128. .pipe(jshint('config.jshintrc'))
  129. .pipe(jshint.reporter('jshint-stylish'))
  130. .pipe(jshint.reporter('fail'));
  131. }
  132. function validHTMLTask() {
  133. return gulp.src('samples/*.html')
  134. .pipe(htmlv());
  135. }
  136. function startTest() {
  137. var files = ['./src/**/*.js'];
  138. Array.prototype.unshift.apply(files, preTestFiles);
  139. Array.prototype.push.apply(files, testFiles);
  140. return files;
  141. }
  142. function unittestTask() {
  143. return gulp.src(startTest())
  144. .pipe(karma({
  145. configFile: 'karma.conf.ci.js',
  146. action: 'run'
  147. }));
  148. }
  149. function unittestWatchTask() {
  150. return gulp.src(startTest())
  151. .pipe(karma({
  152. configFile: 'karma.conf.js',
  153. action: 'watch'
  154. }));
  155. }
  156. function coverageTask() {
  157. return gulp.src(startTest())
  158. .pipe(karma({
  159. configFile: 'karma.coverage.conf.js',
  160. action: 'run'
  161. }));
  162. }
  163. function librarySizeTask() {
  164. return gulp.src('dist/Chart.bundle.min.js')
  165. .pipe(size({
  166. gzip: true
  167. }));
  168. }
  169. function moduleSizesTask() {
  170. return gulp.src(srcDir + '**/*.js')
  171. .pipe(uglify({
  172. preserveComments: 'some'
  173. }))
  174. .pipe(size({
  175. showFiles: true,
  176. gzip: true
  177. }));
  178. }
  179. function watchTask() {
  180. if (util.env.test) {
  181. return gulp.watch('./src/**', ['build', 'unittest', 'unittestWatch']);
  182. }
  183. return gulp.watch('./src/**', ['build']);
  184. }
  185. function serverTask() {
  186. connect.server({
  187. port: 8000
  188. });
  189. }
  190. // Convenience task for opening the project straight from the command line
  191. function _openTask() {
  192. exec('open http://localhost:8000');
  193. exec('subl .');
  194. }