2019-05-28 23:40:49 +03:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var cssimport = require('gulp-cssimport');
|
|
|
|
var cssnano = require('gulp-cssnano');
|
|
|
|
var rollup = require('gulp-better-rollup');
|
|
|
|
var sucrase = require('@sucrase/gulp-plugin');
|
|
|
|
var minify = require('gulp-minify');
|
|
|
|
var exec = require('child_process').exec;
|
|
|
|
|
|
|
|
var resolve = require('rollup-plugin-node-resolve');
|
|
|
|
var commonjs = require('rollup-plugin-commonjs');
|
|
|
|
var replace = require('rollup-plugin-replace');
|
|
|
|
var json = require('rollup-plugin-json');
|
|
|
|
var builtins = require('rollup-plugin-node-builtins');
|
|
|
|
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
|
|
|
|
***/
|
|
|
|
|
|
|
|
gulp.task('css-bundle', function() {
|
|
|
|
return gulp
|
|
|
|
.src('src/index.css')
|
|
|
|
.pipe(cssimport())
|
|
|
|
.pipe(cssnano())
|
|
|
|
.pipe(gulp.dest('./urbit/app/write/css'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('jsx-transform', function(cb) {
|
|
|
|
return gulp.src('src/**/*.js')
|
|
|
|
.pipe(sucrase({
|
|
|
|
transforms: ['jsx']
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('dist'));
|
|
|
|
});
|
|
|
|
|
2019-06-21 23:16:25 +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:40:49 +03: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' ],
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
replace({
|
|
|
|
'process.env.NODE_ENV': JSON.stringify('development')
|
|
|
|
}),
|
|
|
|
rootImport({
|
|
|
|
root: `${__dirname}/dist/js`,
|
|
|
|
useEntry: 'prepend',
|
|
|
|
extensions: '.js'
|
|
|
|
}),
|
|
|
|
json(),
|
|
|
|
globals(),
|
|
|
|
builtins(),
|
|
|
|
resolve()
|
|
|
|
]
|
|
|
|
}, 'umd'))
|
|
|
|
.on('error', function(e){
|
|
|
|
console.log(e);
|
|
|
|
cb();
|
|
|
|
})
|
|
|
|
.pipe(gulp.dest('./urbit/app/write/js/'))
|
|
|
|
.on('end', cb);
|
|
|
|
});
|
|
|
|
|
2019-06-21 23:16:25 +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'
|
|
|
|
}),
|
|
|
|
json(),
|
|
|
|
globals(),
|
|
|
|
builtins(),
|
|
|
|
resolve()
|
|
|
|
]
|
|
|
|
}, 'umd'))
|
|
|
|
.on('error', function(e){
|
|
|
|
console.log(e);
|
|
|
|
cb();
|
|
|
|
})
|
|
|
|
.pipe(gulp.dest('./urbit/app/write/js/'))
|
|
|
|
.on('end', cb);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-05-28 23:40:49 +03:00
|
|
|
gulp.task('js-minify', function () {
|
|
|
|
return gulp.src('./urbit/app/write/js/index.js')
|
|
|
|
.pipe(minify())
|
|
|
|
.pipe(gulp.dest('./urbit/app/write/js/'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('js-cachebust', function(cb) {
|
|
|
|
return Promise.resolve(
|
|
|
|
exec('git log', function (err, stdout, stderr) {
|
|
|
|
let firstLine = stdout.split("\n")[0];
|
|
|
|
let commitHash = firstLine.split(' ')[1].substr(0, 10);
|
|
|
|
let newFilename = "index-" + commitHash + "-min.js";
|
|
|
|
|
|
|
|
exec('mv ./urbit/app/write/js/index-min.js ./urbit/app/write/js/' + newFilename);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
})
|
|
|
|
|
|
|
|
gulp.task('urbit-copy', function () {
|
|
|
|
let ret = gulp.src('urbit/**/*');
|
|
|
|
|
|
|
|
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-21 23:16:25 +03:00
|
|
|
gulp.task('tile-js-bundle-dev', gulp.series('tile-jsx-transform', 'tile-js-imports'));
|
2019-05-28 23:40:49 +03:00
|
|
|
gulp.task('js-bundle-prod', gulp.series('jsx-transform', 'js-imports', 'js-minify', 'js-cachebust'))
|
|
|
|
|
|
|
|
gulp.task('bundle-dev',
|
|
|
|
gulp.series(
|
|
|
|
gulp.parallel(
|
|
|
|
'css-bundle',
|
2019-06-21 23:16:25 +03:00
|
|
|
'js-bundle-dev',
|
|
|
|
'tile-js-bundle-dev'
|
2019-05-28 23:40:49 +03:00
|
|
|
),
|
|
|
|
'urbit-copy'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
gulp.task('bundle-prod',
|
|
|
|
gulp.series(
|
|
|
|
gulp.parallel(
|
|
|
|
'css-bundle',
|
|
|
|
'js-bundle-prod'
|
|
|
|
),
|
|
|
|
'urbit-copy'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
gulp.task('default', gulp.series('bundle-dev'));
|
2019-06-21 23:16:25 +03:00
|
|
|
|
2019-05-28 23:40:49 +03:00
|
|
|
gulp.task('watch', gulp.series('default', function() {
|
2019-06-21 23:16:25 +03:00
|
|
|
gulp.watch('tile/**/*.js', gulp.parallel('tile-js-bundle-dev'));
|
|
|
|
|
2019-05-28 23:40:49 +03:00
|
|
|
gulp.watch('src/**/*.js', gulp.parallel('js-bundle-dev'));
|
|
|
|
gulp.watch('src/**/*.css', gulp.parallel('css-bundle'));
|
|
|
|
|
|
|
|
gulp.watch('urbit/**/*', gulp.parallel('urbit-copy'));
|
|
|
|
}));
|