-
Notifications
You must be signed in to change notification settings - Fork 31
/
gulpfile.js
executable file
·57 lines (49 loc) · 1.57 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const fs = require('fs');
const util = require('util');
const less = require('gulp-less');
const postcss = require('gulp-postcss');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const gulp = require('gulp');
const STYLE_SOURCE_DIR = './src/less';
const STYLE_DIST_DIR = './dist/styles';
const pkg = require('./package.json');
const writeFile = util.promisify(fs.writeFile);
function buildLess() {
return gulp
.src([`${STYLE_SOURCE_DIR}/index.less`])
.pipe(sourcemaps.init())
.pipe(less({ javascriptEnabled: true, paths: ['*.css', '*.less'] }))
.pipe(postcss([require('autoprefixer')]))
.pipe(sourcemaps.write('./'))
.pipe(rename('react-code-view.css'))
.pipe(gulp.dest(`${STYLE_DIST_DIR}`));
}
function buildCSS() {
return gulp
.src(`${STYLE_DIST_DIR}/react-code-view.css`)
.pipe(sourcemaps.init())
.pipe(postcss())
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${STYLE_DIST_DIR}`));
}
function copyDocs() {
return gulp
.src(['./README.md', './CHANGELOG.md', './LICENSE', 'package.json'])
.pipe(gulp.dest('dist'));
}
function copyLoader() {
return gulp.src(['./webpack-md-loader/*']).pipe(gulp.dest('dist/webpack-md-loader'));
}
function createPkgFile(done) {
pkg.scripts = {};
writeFile('dist/package.json', JSON.stringify(pkg, null, 2) + '\n')
.then(() => {
done();
})
.catch(err => {
if (err) console.error(err.toString());
});
}
exports.build = gulp.series(buildLess, buildCSS, copyDocs, copyLoader, createPkgFile);