2019-05-28 23:32:52 +03:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var cssimport = require('gulp-cssimport');
|
|
|
|
var rollup = require('gulp-better-rollup');
|
2019-08-01 23:01:33 +03:00
|
|
|
var cssnano = require('cssnano');
|
|
|
|
var postcss = require('gulp-postcss');
|
2019-05-28 23:32:52 +03:00
|
|
|
var sucrase = require('@sucrase/gulp-plugin');
|
|
|
|
var minify = require('gulp-minify');
|
2019-07-25 01:13:21 +03:00
|
|
|
var rename = require('gulp-rename');
|
2019-08-28 20:39:42 +03:00
|
|
|
var del = require('del');
|
2019-05-28 23:32:52 +03:00
|
|
|
|
|
|
|
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');
|
2019-12-24 07:13:26 +03:00
|
|
|
var rollupReplace = require('@rollup/plugin-replace');
|
2019-05-28 23:32:52 +03:00
|
|
|
|
|
|
|
/***
|
|
|
|
Main config options
|
|
|
|
***/
|
|
|
|
|
2019-07-23 23:08:04 +03:00
|
|
|
var urbitrc = require('../urbitrc');
|
2019-05-28 23:32:52 +03:00
|
|
|
|
|
|
|
/***
|
|
|
|
End main config options
|
|
|
|
***/
|
|
|
|
|
|
|
|
gulp.task('css-bundle', function() {
|
2019-08-01 23:01:33 +03:00
|
|
|
let plugins = [
|
|
|
|
cssnano()
|
|
|
|
];
|
2019-05-28 23:32:52 +03:00
|
|
|
return gulp
|
|
|
|
.src('src/index.css')
|
|
|
|
.pipe(cssimport())
|
2019-08-01 23:01:33 +03:00
|
|
|
.pipe(postcss(plugins))
|
2019-07-23 23:08:04 +03:00
|
|
|
.pipe(gulp.dest('../../arvo/app/chat/css'));
|
2019-05-28 23:32:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('jsx-transform', function(cb) {
|
|
|
|
return gulp.src('src/**/*.js')
|
|
|
|
.pipe(sucrase({
|
|
|
|
transforms: ['jsx']
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('dist'));
|
|
|
|
});
|
|
|
|
|
2019-06-05 01:46:36 +03:00
|
|
|
gulp.task('tile-jsx-transform', function(cb) {
|
|
|
|
return gulp.src('tile/**/*.js')
|
|
|
|
.pipe(sucrase({
|
|
|
|
transforms: ['jsx']
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('dist'));
|
|
|
|
});
|
|
|
|
|
2019-05-28 23:32:52 +03:00
|
|
|
gulp.task('js-imports', function(cb) {
|
|
|
|
return gulp.src('dist/index.js')
|
|
|
|
.pipe(rollup({
|
|
|
|
plugins: [
|
|
|
|
commonjs({
|
|
|
|
namedExports: {
|
2019-12-24 07:13:26 +03:00
|
|
|
'node_modules/react/index.js': ['Component', 'cloneElement',
|
|
|
|
'createContext', 'createElement', 'useState', 'useRef',
|
|
|
|
'useLayoutEffect', 'useMemo', 'useEffect', 'forwardRef', 'useContext', 'Children' ],
|
2019-11-21 04:14:50 +03:00
|
|
|
'node_modules/react-is/index.js': [ 'isValidElementType', 'isElement', 'ForwardRef' ],
|
|
|
|
'node_modules/react-dom/index.js': [ 'createPortal' ]
|
2019-05-28 23:32:52 +03:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
rootImport({
|
|
|
|
root: `${__dirname}/dist/js`,
|
|
|
|
useEntry: 'prepend',
|
|
|
|
extensions: '.js'
|
|
|
|
}),
|
|
|
|
globals(),
|
|
|
|
resolve()
|
|
|
|
]
|
|
|
|
}, 'umd'))
|
|
|
|
.on('error', function(e){
|
|
|
|
console.log(e);
|
|
|
|
cb();
|
|
|
|
})
|
2019-07-23 23:08:04 +03:00
|
|
|
.pipe(gulp.dest('../../arvo/app/chat/js/'))
|
2019-05-28 23:32:52 +03:00
|
|
|
.on('end', cb);
|
|
|
|
});
|
|
|
|
|
2019-06-05 01:46:36 +03: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();
|
|
|
|
})
|
2019-07-23 23:08:04 +03:00
|
|
|
.pipe(gulp.dest('../../arvo/app/chat/js/'))
|
2019-06-05 01:46:36 +03:00
|
|
|
.on('end', cb);
|
|
|
|
});
|
|
|
|
|
2019-12-24 07:13:26 +03:00
|
|
|
gulp.task('js-imports-prod', function(cb) {
|
|
|
|
return gulp.src('dist/index.js')
|
|
|
|
.pipe(rollup({
|
|
|
|
plugins: [
|
|
|
|
rollupReplace({'process.env.NODE_ENV': JSON.stringify('production')}),
|
|
|
|
commonjs({
|
|
|
|
namedExports: {
|
|
|
|
'node_modules/react/index.js': ['Component', 'cloneElement',
|
|
|
|
'createContext', 'createElement', 'useState', 'useRef',
|
|
|
|
'useLayoutEffect', 'useMemo', 'useEffect', 'forwardRef', 'useContext', 'Children' ],
|
|
|
|
'node_modules/react-is/index.js': [ 'isValidElementType', 'isElement', 'ForwardRef' ],
|
|
|
|
'node_modules/react-dom/index.js': [ 'createPortal' ]
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
rootImport({
|
|
|
|
root: `${__dirname}/dist/js`,
|
|
|
|
useEntry: 'prepend',
|
|
|
|
extensions: '.js'
|
|
|
|
}),
|
|
|
|
globals(),
|
|
|
|
resolve()
|
|
|
|
]
|
|
|
|
}, 'umd'))
|
|
|
|
.on('error', function(e){
|
|
|
|
console.log(e);
|
|
|
|
cb();
|
|
|
|
})
|
|
|
|
.pipe(gulp.dest('../../arvo/app/chat/js/'))
|
|
|
|
.on('end', cb);
|
|
|
|
});
|
|
|
|
|
2019-05-28 23:32:52 +03:00
|
|
|
gulp.task('js-minify', function () {
|
2019-07-23 23:08:04 +03:00
|
|
|
return gulp.src('../../arvo/app/chat/js/index.js')
|
2019-05-28 23:32:52 +03:00
|
|
|
.pipe(minify())
|
2019-07-23 23:08:04 +03:00
|
|
|
.pipe(gulp.dest('../../arvo/app/chat/js/'));
|
2019-05-28 23:32:52 +03:00
|
|
|
});
|
|
|
|
|
2019-06-28 23:23:19 +03:00
|
|
|
gulp.task('tile-js-minify', function () {
|
2019-07-23 23:08:04 +03:00
|
|
|
return gulp.src('../../arvo/app/chat/js/tile.js')
|
2019-06-28 23:23:19 +03:00
|
|
|
.pipe(minify())
|
2019-07-23 23:08:04 +03:00
|
|
|
.pipe(gulp.dest('../../arvo/app/chat/js/'));
|
2019-06-28 23:23:19 +03:00
|
|
|
});
|
|
|
|
|
2019-07-25 01:13:21 +03:00
|
|
|
gulp.task('rename-index-min', function() {
|
|
|
|
return gulp.src('../../arvo/app/chat/js/index-min.js')
|
|
|
|
.pipe(rename('index.js'))
|
2019-08-28 20:39:42 +03:00
|
|
|
.pipe(gulp.dest('../../arvo/app/chat/js/'))
|
2019-07-25 01:13:21 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('rename-tile-min', function() {
|
|
|
|
return gulp.src('../../arvo/app/chat/js/tile-min.js')
|
|
|
|
.pipe(rename('tile.js'))
|
2019-08-28 20:39:42 +03:00
|
|
|
.pipe(gulp.dest('../../arvo/app/chat/js/'))});
|
|
|
|
|
|
|
|
gulp.task('clean-min', function() {
|
|
|
|
return del(['../../arvo/app/chat/js/index-min.js', '../../arvo/app/chat/js/tile-min.js'], {force: true})
|
2019-07-25 01:13:21 +03:00
|
|
|
});
|
|
|
|
|
2019-05-28 23:32:52 +03:00
|
|
|
gulp.task('urbit-copy', function () {
|
2019-07-23 23:08:04 +03:00
|
|
|
let ret = gulp.src('../../arvo/**/*');
|
2019-05-28 23:32:52 +03:00
|
|
|
|
|
|
|
urbitrc.URBIT_PIERS.forEach(function(pier) {
|
|
|
|
ret = ret.pipe(gulp.dest(pier));
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('js-bundle-dev', gulp.series('jsx-transform', 'js-imports'));
|
2019-06-05 01:46:36 +03:00
|
|
|
gulp.task('tile-js-bundle-dev', gulp.series('tile-jsx-transform', 'tile-js-imports'));
|
2019-12-24 07:13:26 +03:00
|
|
|
gulp.task('js-bundle-prod', gulp.series('jsx-transform', 'js-imports-prod', 'js-minify'))
|
2019-06-28 23:23:19 +03:00
|
|
|
gulp.task('tile-js-bundle-prod',
|
|
|
|
gulp.series('tile-jsx-transform', 'tile-js-imports', 'tile-js-minify'));
|
2019-05-28 23:32:52 +03:00
|
|
|
|
|
|
|
gulp.task('bundle-dev',
|
|
|
|
gulp.series(
|
|
|
|
gulp.parallel(
|
|
|
|
'css-bundle',
|
2019-06-05 01:46:36 +03:00
|
|
|
'js-bundle-dev',
|
|
|
|
'tile-js-bundle-dev'
|
2019-05-28 23:32:52 +03:00
|
|
|
),
|
|
|
|
'urbit-copy'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
gulp.task('bundle-prod',
|
|
|
|
gulp.series(
|
|
|
|
gulp.parallel(
|
|
|
|
'css-bundle',
|
2019-06-28 23:23:19 +03:00
|
|
|
'js-bundle-prod',
|
|
|
|
'tile-js-bundle-prod',
|
2019-05-28 23:32:52 +03:00
|
|
|
),
|
2019-07-25 01:13:21 +03:00
|
|
|
'rename-index-min',
|
|
|
|
'rename-tile-min',
|
2019-08-28 20:39:42 +03:00
|
|
|
'clean-min',
|
|
|
|
'urbit-copy'
|
2019-05-28 23:32:52 +03:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
gulp.task('default', gulp.series('bundle-dev'));
|
2019-06-05 01:46:36 +03:00
|
|
|
|
2019-05-28 23:32:52 +03:00
|
|
|
gulp.task('watch', gulp.series('default', function() {
|
2019-06-05 01:46:36 +03:00
|
|
|
gulp.watch('tile/**/*.js', gulp.parallel('tile-js-bundle-dev'));
|
|
|
|
|
2019-05-28 23:32:52 +03:00
|
|
|
gulp.watch('src/**/*.js', gulp.parallel('js-bundle-dev'));
|
|
|
|
gulp.watch('src/**/*.css', gulp.parallel('css-bundle'));
|
|
|
|
|
2019-07-23 23:08:04 +03:00
|
|
|
gulp.watch('../../arvo/**/*', gulp.parallel('urbit-copy'));
|
2019-05-28 23:32:52 +03:00
|
|
|
}));
|