Skip to content

Instantly share code, notes, and snippets.

@raininglemons
Last active August 8, 2017 11:56
Show Gist options
  • Save raininglemons/57e05ec52908225ad6da0ef3011d258b to your computer and use it in GitHub Desktop.
Save raininglemons/57e05ec52908225ad6da0ef3011d258b to your computer and use it in GitHub Desktop.
const gulp = require('gulp');
const rename = require('gulp-rename');
const path = require('path');
const named = require('vinyl-named');
const webdav = require('gulp-webdav-sync');
// npm install --save-dev uglify-js@2.6.4
// npm install --save-dev gulp-uglifyjs@0.6.2
const uglifyjs = require('gulp-uglifyjs');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const name = require('project-name');
const { parser } = require('@raininglemons/bpty-commonjs');
const isProduction = process.env.NODE_ENV === 'production';
const formatProject = project => {
project = project.replace(/\//g, '-');
project = project.replace(/@/g, '');
return project.substr(0, 1).toUpperCase() + project.replace(/\-([a-zA-Z]+)/g, resp => resp.substr(1, 1).toUpperCase() + resp.substr(2)).substr(1);
};
const projectName = formatProject(name());
console.log('Compiling project: ' + projectName);
/**
* Builds JS to bpty-commonjs format.
* @type {{namespace: string, base: string}}
*/
const bptyConfig = {
namespace: projectName,
base: 'src/',
};
gulp.task('build-require', function () {
return gulp.src(['./src/*.js', './src/**/*.js', './src/*.jsx', './src/**/*.jsx'])
.pipe(babel({
plugins: [
'transform-flow-strip-types',
'syntax-jsx',
'transform-es2015-modules-commonjs'
],
}))/* */
.pipe(concat(projectName + '.js'))
.pipe(babel({
presets: ['es2015', 'react']
})) /* */
.pipe(uglifyjs({
outSourceMap: true,
sourceMappingURL: '/etc/designs/clientlibs/components/react/' + projectName + '/js/' + projectName + '.js.map',
sourceMap: {
root: "/etc/designs/clientlibs/components/react/" + projectName + "/js/",
url: projectName + ".js.map"
}
})) /* */
.pipe(gulp.dest('./dist/js'));
});
gulp.task('deploy', ['build-require'], function () {
var options = {
protocol: 'http:'
, base: 'dist'
, auth: 'npmuser:npmuser'
, hostname: isProduction ? 'aem.bwinparty.corp' : 'ref.aem.bwinparty.corp'
, port: 4502
, pathname: '/etc/designs/clientlibs/components/react/' + projectName + '/'
, log: 'info'
, logAuth: true
, rejectUnauthorized: false
};
return gulp.src(['./dist/js.txt', './dist/js/*.js'])
.pipe(webdav(options))
});
gulp.task('default', ['build']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment