bmstu-mt-wp/gulpfile.js

111 lines
2.7 KiB
JavaScript
Raw Normal View History

2016-03-23 23:53:37 +03:00
const del = require('del');
const gulp = require('gulp');
const merge = require('merge-stream');
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const zip = require('gulp-zip');
2018-05-21 17:22:42 +03:00
const pages = require('gh-pages');
2018-06-25 18:52:45 +03:00
const sync = require('browser-sync').create();
2016-03-23 23:53:37 +03:00
gulp.task('prepare', () => {
2018-08-24 11:48:59 +03:00
const shower = gulp.src([
'**',
'!docs{,/**}',
'!node_modules{,/**}',
'!prepared{,/**}',
'!CONTRIBUTING.md',
'!LICENSE.md',
'!README.md',
'!gulpfile.js',
'!netlify.toml',
'!package.json',
'!package-lock.json'
])
.pipe(replace(
2018-11-28 03:09:46 +03:00
/(<link rel="stylesheet" href=")(node_modules\/@shower\/)([^\/]*)\/(.*\.css">)/g,
2018-08-24 11:48:59 +03:00
'$1shower/themes/$3/$4', { skipBinary: true }
))
.pipe(replace(
/(<script src=")(node_modules\/shower-core\/)(shower.min.js"><\/script>)/g,
'$1shower/$3', { skipBinary: true }
));
2016-03-23 23:53:37 +03:00
2018-08-24 11:48:59 +03:00
const core = gulp.src([
'shower.min.js'
], {
cwd: 'node_modules/shower-core'
})
.pipe(rename( (path) => {
path.dirname = 'shower/' + path.dirname;
}));
2016-03-23 23:53:37 +03:00
2018-08-24 11:48:59 +03:00
const material = gulp.src([
'**', '!package.json'
], {
2018-11-28 03:09:46 +03:00
cwd: 'node_modules/@shower/material'
2018-08-24 11:48:59 +03:00
})
.pipe(rename( (path) => {
path.dirname = 'shower/themes/material/' + path.dirname;
}))
2016-03-23 23:53:37 +03:00
2018-08-24 11:48:59 +03:00
const ribbon = gulp.src([
'**', '!package.json'
], {
2018-11-28 03:09:46 +03:00
cwd: 'node_modules/@shower/ribbon'
2018-08-24 11:48:59 +03:00
})
.pipe(rename( (path) => {
path.dirname = 'shower/themes/ribbon/' + path.dirname;
}));
2016-03-23 23:53:37 +03:00
2018-08-24 11:48:59 +03:00
const themes = merge(material, ribbon)
.pipe(replace(
/(<script src=")(\/shower-core\/)(shower.min.js"><\/script>)/,
'$1../../$3', { skipBinary: true }
));
2016-03-23 23:53:37 +03:00
2018-08-24 11:48:59 +03:00
return merge(shower, core, themes)
.pipe(gulp.dest('prepared'));
2016-03-23 23:53:37 +03:00
});
2018-06-16 01:54:30 +03:00
gulp.task('clean', () => {
2018-08-24 11:48:59 +03:00
return del('prepared/**');
2018-06-16 01:54:30 +03:00
});
2016-03-23 23:53:37 +03:00
gulp.task('zip', () => {
2018-08-24 11:48:59 +03:00
return gulp.src('prepared/**')
.pipe(zip('archive.zip'))
.pipe(gulp.dest('.'));
2016-03-23 23:53:37 +03:00
});
gulp.task('upload', () => {
2018-08-24 11:48:59 +03:00
return pages.publish('prepared')
2016-03-23 23:53:37 +03:00
});
2018-06-16 01:54:30 +03:00
gulp.task('archive', gulp.series(
2018-08-24 11:48:59 +03:00
'prepare',
'zip',
'clean'
2018-06-16 01:54:30 +03:00
));
2016-03-23 23:53:37 +03:00
2018-06-16 01:54:30 +03:00
gulp.task('publish', gulp.series(
2018-08-24 11:48:59 +03:00
'prepare',
'upload',
'clean'
2018-06-16 01:54:30 +03:00
));
2016-03-23 23:53:37 +03:00
gulp.task('serve', () => {
2018-08-24 11:48:59 +03:00
sync.init({
ui: false,
notify: false,
port: 3000,
server: {
baseDir: '.'
}
});
gulp.watch('index.html').on('change', () => {
sync.reload();
});
});