gulpfile.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. 'use strict';
  2. const gulp = require('gulp');
  3. gulp.task('clean', () => {
  4. let del = require('del');
  5. return del(['lib/*.js', 'postcss.js', 'build/', 'api/']);
  6. });
  7. // Build
  8. gulp.task('compile', () => {
  9. let sourcemaps = require('gulp-sourcemaps');
  10. let changed = require('gulp-changed');
  11. let babel = require('gulp-babel');
  12. return gulp.src('lib/*.es6')
  13. .pipe(changed('lib', { extension: '.js' }))
  14. .pipe(sourcemaps.init())
  15. .pipe(babel({
  16. presets: [
  17. [
  18. 'env',
  19. {
  20. targets: {
  21. browsers: 'last 2 version',
  22. node: 4
  23. },
  24. loose: true
  25. }
  26. ]
  27. ],
  28. plugins: ['add-module-exports', 'precompile-charcodes']
  29. }))
  30. .pipe(sourcemaps.write())
  31. .pipe(gulp.dest('lib'));
  32. });
  33. gulp.task('build:lib', ['compile'], () => {
  34. return gulp.src(['lib/*.js', 'lib/*.d.ts']).pipe(gulp.dest('build/lib'));
  35. });
  36. gulp.task('build:package', () => {
  37. const editor = require('gulp-json-editor');
  38. return gulp.src('./package.json')
  39. .pipe(editor((json) => {
  40. delete json.babel;
  41. delete json.scripts;
  42. delete json.jest;
  43. delete json.eslintConfig;
  44. delete json['size-limit'];
  45. delete json['pre-commit'];
  46. delete json['lint-staged'];
  47. delete json.devDependencies;
  48. return json;
  49. }))
  50. .pipe(gulp.dest('build'));
  51. });
  52. gulp.task('build:docs', () => {
  53. let ignore = require('fs').readFileSync('.npmignore').toString()
  54. .trim().split(/\n+/)
  55. .concat([
  56. 'package.json', '.npmignore', 'lib/*', 'test/*',
  57. 'node_modules/**/*', 'docs/api.md', 'docs/plugins.md',
  58. 'docs/writing-a-plugin.md'
  59. ]).map( i => '!' + i );
  60. return gulp.src(['**/*'].concat(ignore))
  61. .pipe(gulp.dest('build'));
  62. });
  63. gulp.task('build', done => {
  64. let runSequence = require('run-sequence');
  65. runSequence('clean', ['build:lib', 'build:docs', 'build:package'], done);
  66. });
  67. // Tests
  68. gulp.task('integration', ['build'], done => {
  69. let postcss = require('./build');
  70. let real = require('postcss-parser-tests/real');
  71. real(done, css => {
  72. return postcss.parse(css).toResult({ map: { annotation: false } });
  73. });
  74. });
  75. gulp.task('version', ['build:lib'], () => {
  76. let Processor = require('./lib/processor');
  77. let instance = new Processor();
  78. let pkg = require('./package');
  79. if ( pkg.version !== instance.version ) {
  80. throw new Error('Version in Processor is not equal to package.json');
  81. }
  82. });
  83. // Common
  84. gulp.task('default', ['version', 'integration']);