bart-tile/gulpfile.js

165 lines
3.8 KiB
JavaScript
Raw Normal View History

2020-05-10 04:24:46 -07:00
var gulp = require('gulp');
2020-05-10 04:30:23 -07:00
var cssimport = require('gulp-cssimport');
2020-05-10 04:24:46 -07:00
var rollup = require('gulp-better-rollup');
2020-05-10 04:30:23 -07:00
var cssnano = require('cssnano');
var postcss = require('gulp-postcss');
2020-05-10 04:24:46 -07:00
var sucrase = require('@sucrase/gulp-plugin');
var minify = require('gulp-minify');
var resolve = require('rollup-plugin-node-resolve');
var commonjs = require('rollup-plugin-commonjs');
var rootImport = require('rollup-plugin-root-import');
var globals = require('rollup-plugin-node-globals');
/***
Main config options
***/
var urbitrc = require('./.urbitrc');
/***
End main config options
***/
2020-05-10 04:30:23 -07:00
gulp.task('css-bundle', function() {
let plugins = [
cssnano()
];
return gulp
.src('src/index.css')
.pipe(cssimport())
.pipe(postcss(plugins))
.pipe(gulp.dest('./urbit/app/barttile/css'));
});
gulp.task('jsx-transform', function(cb) {
return gulp.src('src/**/*.js')
.pipe(sucrase({
transforms: ['jsx']
}))
.pipe(gulp.dest('dist'));
});
2020-05-10 04:24:46 -07:00
gulp.task('tile-jsx-transform', function(cb) {
return gulp.src('tile/**/*.js')
.pipe(sucrase({
transforms: ['jsx']
}))
.pipe(gulp.dest('dist'));
});
2020-05-10 04:30:23 -07:00
gulp.task('js-imports', function(cb) {
return gulp.src('dist/index.js')
.pipe(rollup({
plugins: [
commonjs({
namedExports: {
'node_modules/react/index.js': [ 'Component' ],
'node_modules/react-is/index.js': [ 'isValidElementType' ],
}
}),
rootImport({
root: `${__dirname}/dist/js`,
useEntry: 'prepend',
extensions: '.js'
}),
globals(),
resolve()
]
}, 'umd'))
.on('error', function(e){
console.log(e);
cb();
})
.pipe(gulp.dest('./urbit/app/barttile/js/'))
.on('end', cb);
});
2020-05-10 04:24:46 -07:00
gulp.task('tile-js-imports', function(cb) {
return gulp.src('dist/tile.js')
.pipe(rollup({
plugins: [
commonjs({
namedExports: {
'node_modules/react/index.js': [ 'Component' ],
}
}),
rootImport({
root: `${__dirname}/dist/js`,
useEntry: 'prepend',
extensions: '.js'
}),
globals(),
resolve()
]
}, 'umd'))
.on('error', function(e){
console.log(e);
cb();
})
2020-05-10 04:30:23 -07:00
.pipe(gulp.dest('./urbit/app/barttile/js/'))
2020-05-10 04:24:46 -07:00
.on('end', cb);
});
2020-05-10 04:30:23 -07:00
gulp.task('js-minify', function () {
return gulp.src('./urbit/app/barttile/js/index.js')
.pipe(minify())
.pipe(gulp.dest('./urbit/app/barttile/js/'));
});
2020-05-10 04:24:46 -07:00
gulp.task('tile-js-minify', function () {
2020-05-10 04:30:23 -07:00
return gulp.src('./urbit/app/barttile/js/tile.js')
2020-05-10 04:24:46 -07:00
.pipe(minify())
2020-05-10 04:30:23 -07:00
.pipe(gulp.dest('./urbit/app/barttile/js/'));
2020-05-10 04:24:46 -07:00
});
gulp.task('urbit-copy', function () {
let ret = gulp.src('urbit/**/*');
urbitrc.URBIT_PIERS.forEach(function(pier) {
ret = ret.pipe(gulp.dest(pier));
});
return ret;
});
2020-05-10 04:30:23 -07:00
gulp.task('js-bundle-dev', gulp.series('jsx-transform', 'js-imports'));
2020-05-10 04:24:46 -07:00
gulp.task('tile-js-bundle-dev', gulp.series('tile-jsx-transform', 'tile-js-imports'));
2020-05-10 04:30:23 -07:00
gulp.task('js-bundle-prod', gulp.series('jsx-transform', 'js-imports', 'js-minify'))
gulp.task('tile-js-bundle-prod',
2020-05-10 04:24:46 -07:00
gulp.series('tile-jsx-transform', 'tile-js-imports', 'tile-js-minify'));
2020-05-10 04:30:23 -07:00
gulp.task('bundle-dev',
gulp.series(
gulp.parallel(
'css-bundle',
'js-bundle-dev',
'tile-js-bundle-dev'
),
'urbit-copy'
)
);
gulp.task('bundle-prod',
gulp.series(
gulp.parallel(
'css-bundle',
'js-bundle-prod',
'tile-js-bundle-prod',
),
'urbit-copy'
)
);
gulp.task('default', gulp.series('bundle-dev'));
2020-05-10 04:24:46 -07:00
gulp.task('watch', gulp.series('default', function() {
gulp.watch('tile/**/*.js', gulp.parallel('tile-js-bundle-dev'));
2020-05-10 04:30:23 -07:00
gulp.watch('src/**/*.js', gulp.parallel('js-bundle-dev'));
gulp.watch('src/**/*.css', gulp.parallel('css-bundle'));
2020-05-10 04:24:46 -07:00
gulp.watch('urbit/**/*', gulp.parallel('urbit-copy'));
}));