2016-03-30 23:45:54 +02:00
|
|
|
const packageJson = require('./package.json');
|
|
|
|
const autoprefixer = require('autoprefixer');
|
|
|
|
const babelify = require('babelify'); // eslint-disable-line no-unused-vars
|
|
|
|
const browserify = require('browserify');
|
|
|
|
const eventStream = require('event-stream');
|
|
|
|
const glob = require('glob');
|
|
|
|
const gulp = require('gulp');
|
2016-04-12 04:36:55 +02:00
|
|
|
const coffee = require('gulp-coffee');
|
|
|
|
const concat = require('gulp-concat');
|
|
|
|
const merge = require('merge-stream');
|
|
|
|
const order = require('gulp-order');
|
2016-03-30 23:45:54 +02:00
|
|
|
const babel = require('gulp-babel');
|
|
|
|
const diff = require('gulp-diff');
|
|
|
|
const gulpif = require('gulp-if');
|
|
|
|
const notify = require('gulp-notify');
|
|
|
|
const postcss = require('gulp-postcss');
|
|
|
|
const sass = require('gulp-sass');
|
|
|
|
const sourcemaps = require('gulp-sourcemaps');
|
|
|
|
const uglify = require('gulp-uglify');
|
|
|
|
const gulpUtil = require('gulp-util');
|
|
|
|
const path = require('path');
|
|
|
|
const source = require('vinyl-source-stream');
|
|
|
|
const buffer = require('vinyl-buffer');
|
|
|
|
const semver = require('semver');
|
|
|
|
const sprity = require('sprity');
|
|
|
|
const watchify = require('watchify');
|
2016-04-19 11:04:43 +02:00
|
|
|
const flatten = require('gulp-flatten');
|
2016-03-30 23:45:54 +02:00
|
|
|
|
|
|
|
const isDev = typeof process.env.npm_config_development !== 'undefined';
|
|
|
|
|
|
|
|
process.env.NODE_ENV = isDev ? 'development' : 'production';
|
|
|
|
|
|
|
|
const PATHS = {
|
|
|
|
MODULES: './node_modules',
|
|
|
|
ADMIN: './admin',
|
2016-04-19 11:04:43 +02:00
|
|
|
ADMIN_IMAGES: './admin/client/dist/images',
|
|
|
|
ADMIN_CSS_SRC: './admin/client/src/styles',
|
|
|
|
ADMIN_CSS_DIST: './admin/client/dist/styles',
|
2016-03-30 23:45:54 +02:00
|
|
|
ADMIN_THIRDPARTY: './admin/thirdparty',
|
2016-04-19 11:04:43 +02:00
|
|
|
ADMIN_JS_SRC: './admin/client/src',
|
|
|
|
ADMIN_JS_DIST: './admin/client/dist/js',
|
|
|
|
ADMIN_SPRITES_SRC: './admin/client/src/sprites',
|
|
|
|
ADMIN_SPRITES_DIST: './admin/client/dist/images/sprites',
|
2016-03-30 23:45:54 +02:00
|
|
|
FRAMEWORK: '.',
|
2016-04-19 11:04:43 +02:00
|
|
|
FRAMEWORK_CSS_SRC: './client/src/styles',
|
|
|
|
FRAMEWORK_CSS_DIST: './client/dist/styles',
|
2016-03-30 23:45:54 +02:00
|
|
|
FRAMEWORK_THIRDPARTY: './thirdparty',
|
2016-04-19 11:04:43 +02:00
|
|
|
INSTALL_CSS_SRC: './dev/install/client/src/styles',
|
|
|
|
INSTALL_CSS_DIST: './dev/install/client/dist/styles',
|
|
|
|
FRAMEWORK_JS_SRC: './client/src',
|
|
|
|
FRAMEWORK_JS_DIST: './client/dist/js',
|
2016-01-11 02:25:30 +01:00
|
|
|
};
|
|
|
|
|
2016-04-19 11:04:43 +02:00
|
|
|
// Map of *.scss locations to their compile target folders
|
|
|
|
const scssFolders = {
|
|
|
|
[PATHS.FRAMEWORK_CSS_SRC]: PATHS.FRAMEWORK_CSS_DIST,
|
|
|
|
[PATHS.ADMIN_CSS_SRC]: PATHS.ADMIN_CSS_DIST,
|
|
|
|
[PATHS.INSTALL_CSS_SRC]: PATHS.INSTALL_CSS_DIST,
|
|
|
|
};
|
2016-02-10 23:13:32 +01:00
|
|
|
|
2016-03-30 23:45:54 +02:00
|
|
|
const browserifyOptions = {
|
|
|
|
debug: true,
|
2016-04-19 11:04:43 +02:00
|
|
|
paths: [PATHS.ADMIN_JS_SRC, PATHS.FRAMEWORK_JS_SRC],
|
2016-03-26 06:41:24 +01:00
|
|
|
};
|
2016-03-23 22:34:14 +01:00
|
|
|
|
2016-03-30 23:45:54 +02:00
|
|
|
const babelifyOptions = {
|
2016-04-04 02:01:43 +02:00
|
|
|
presets: ['es2015', 'es2015-ie', 'react'],
|
|
|
|
plugins: ['transform-object-assign'],
|
2016-03-30 23:45:54 +02:00
|
|
|
ignore: /(node_modules|thirdparty)/,
|
|
|
|
comments: false,
|
2016-03-23 22:34:14 +01:00
|
|
|
};
|
2016-01-06 04:06:47 +01:00
|
|
|
|
2016-04-19 07:18:07 +02:00
|
|
|
const uglifyOptions = {
|
|
|
|
mangle: false,
|
|
|
|
};
|
|
|
|
|
2016-02-03 02:32:45 +01:00
|
|
|
// Used for autoprefixing css properties (same as Bootstrap Aplha.2 defaults)
|
2016-03-30 23:45:54 +02:00
|
|
|
const supportedBrowsers = [
|
|
|
|
'Chrome >= 35',
|
|
|
|
'Firefox >= 31',
|
|
|
|
'Edge >= 12',
|
|
|
|
'Explorer >= 9',
|
|
|
|
'iOS >= 8',
|
|
|
|
'Safari >= 8',
|
|
|
|
'Android 2.3',
|
|
|
|
'Android >= 4',
|
|
|
|
'Opera >= 12',
|
2016-02-03 02:32:45 +01:00
|
|
|
];
|
|
|
|
|
2016-03-30 23:45:54 +02:00
|
|
|
const blueimpFileUploadConfig = {
|
|
|
|
src: `${PATHS.MODULES}/blueimp-file-upload`,
|
2016-04-11 11:23:48 +02:00
|
|
|
dest: `${PATHS.FRAMEWORK_THIRDPARTY}/jquery-fileupload`,
|
2016-03-30 23:45:54 +02:00
|
|
|
files: [
|
|
|
|
'/cors/jquery.postmessage-transport.js',
|
|
|
|
'/cors/jquery.xdr-transport.js',
|
|
|
|
'/jquery.fileupload-ui.js',
|
|
|
|
'/jquery.fileupload.js',
|
2016-04-11 11:23:48 +02:00
|
|
|
'/jquery.iframe-transport.js',
|
|
|
|
],
|
2016-01-06 04:06:47 +01:00
|
|
|
};
|
|
|
|
|
2016-04-11 11:23:48 +02:00
|
|
|
const blueimpLoadImageConfig = {
|
|
|
|
src: `${PATHS.MODULES}/blueimp-load-image`,
|
|
|
|
dest: `${PATHS.FRAMEWORK_THIRDPARTY}/javascript-loadimage`,
|
|
|
|
files: ['/load-image.js'],
|
2016-01-06 04:06:47 +01:00
|
|
|
};
|
|
|
|
|
2016-04-11 11:23:48 +02:00
|
|
|
const blueimpTmplConfig = {
|
|
|
|
src: `${PATHS.MODULES}/blueimp-tmpl`,
|
|
|
|
dest: `${PATHS.FRAMEWORK_THIRDPARTY}/javascript-templates`,
|
|
|
|
files: ['/tmpl.js'],
|
2016-01-06 04:06:47 +01:00
|
|
|
};
|
|
|
|
|
2016-04-11 11:23:48 +02:00
|
|
|
const jquerySizesConfig = {
|
|
|
|
src: `${PATHS.MODULES}/jquery-sizes`,
|
|
|
|
dest: `${PATHS.ADMIN_THIRDPARTY}/jsizes`,
|
|
|
|
files: ['/lib/jquery.sizes.js'],
|
2016-01-06 04:06:47 +01:00
|
|
|
};
|
|
|
|
|
2016-04-11 11:23:48 +02:00
|
|
|
const tinymceConfig = {
|
|
|
|
src: `${PATHS.MODULES}/tinymce`,
|
|
|
|
dest: `${PATHS.FRAMEWORK_THIRDPARTY}/tinymce`,
|
2016-03-30 23:45:54 +02:00
|
|
|
files: [
|
|
|
|
'/tinymce.min.js', // Exclude unminified file to keep repository size down
|
|
|
|
'/jquery.tinymce.min.js',
|
|
|
|
'/themes/**',
|
|
|
|
'/skins/**',
|
2016-04-11 11:23:48 +02:00
|
|
|
'/plugins/**',
|
|
|
|
],
|
2016-04-03 22:15:27 +02:00
|
|
|
};
|
|
|
|
|
2016-01-06 04:06:47 +01:00
|
|
|
/**
|
|
|
|
* Copies files from a source directory to a destination directory.
|
|
|
|
*
|
|
|
|
* @param object libConfig
|
|
|
|
* @param string libConfig.src - The source directory
|
|
|
|
* @param string libConfig.dest - The destination directory
|
2016-04-11 11:23:48 +02:00
|
|
|
* @param array libConfig.files - The list of files to copy from the source to
|
|
|
|
* the destination directory
|
2016-01-06 04:06:47 +01:00
|
|
|
*/
|
|
|
|
function copyFiles(libConfig) {
|
2016-04-11 11:23:48 +02:00
|
|
|
libConfig.files.forEach((file) => {
|
|
|
|
const dir = path.parse(file).dir;
|
2016-01-06 04:06:47 +01:00
|
|
|
|
2016-03-30 23:45:54 +02:00
|
|
|
gulp.src(libConfig.src + file)
|
|
|
|
.pipe(gulp.dest(libConfig.dest + dir));
|
|
|
|
});
|
2016-01-06 04:06:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Diffs files in a source directory against a destination directory.
|
|
|
|
*
|
|
|
|
* @param object libConfig
|
|
|
|
* @param string libConfig.src - The source directory
|
|
|
|
* @param string libConfig.dest - The destination directory
|
2016-04-11 11:23:48 +02:00
|
|
|
* @param array libConfig.files - The list of files to copy from the source
|
|
|
|
* to the destination directory
|
2016-01-06 04:06:47 +01:00
|
|
|
*/
|
|
|
|
function diffFiles(libConfig) {
|
2016-04-11 11:23:48 +02:00
|
|
|
libConfig.files.forEach((file) => {
|
|
|
|
const dir = path.parse(file).dir;
|
2016-03-30 23:45:54 +02:00
|
|
|
|
|
|
|
gulp.src(libConfig.src + file)
|
|
|
|
.pipe(diff(libConfig.dest + dir))
|
|
|
|
.pipe(diff.reporter({ fail: true, quiet: true }))
|
2016-04-11 11:23:48 +02:00
|
|
|
.on('error', () => {
|
|
|
|
console.error(new Error( // eslint-disable-line
|
|
|
|
`Sanity check failed. ${libConfig.dest}${file} has been modified.`
|
|
|
|
));
|
2016-03-30 23:45:54 +02:00
|
|
|
process.exit(1);
|
|
|
|
});
|
|
|
|
});
|
2016-01-06 04:06:47 +01:00
|
|
|
}
|
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
/**
|
|
|
|
* Transforms the passed JavaScript files to UMD modules.
|
|
|
|
*
|
|
|
|
* @param array files - The files to transform.
|
|
|
|
* @param string dest - The output directory.
|
|
|
|
* @return object
|
|
|
|
*/
|
|
|
|
function transformToUmd(files, dest) {
|
2016-04-11 11:23:48 +02:00
|
|
|
return eventStream.merge(files.map((file) => { // eslint-disable-line
|
2016-03-30 23:45:54 +02:00
|
|
|
return gulp.src(file)
|
|
|
|
.pipe(babel({
|
|
|
|
presets: ['es2015'],
|
2016-04-11 11:23:48 +02:00
|
|
|
moduleId: `ss.${path.parse(file).name}`,
|
2016-03-30 23:45:54 +02:00
|
|
|
plugins: ['transform-es2015-modules-umd'],
|
2016-04-11 11:23:48 +02:00
|
|
|
comments: false,
|
2016-03-30 23:45:54 +02:00
|
|
|
}))
|
|
|
|
.on('error', notify.onError({
|
|
|
|
message: 'Error: <%= error.message %>',
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest(dest));
|
|
|
|
}));
|
2016-01-11 02:25:30 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 04:06:47 +01:00
|
|
|
// Make sure the version of Node being used is valid.
|
|
|
|
if (!semver.satisfies(process.versions.node, packageJson.engines.node)) {
|
2016-04-11 11:23:48 +02:00
|
|
|
console.error( // eslint-disable-line
|
|
|
|
`Invalid Node.js version. You need to be using ${packageJson.engines.node}. ` +
|
|
|
|
'If you want to manage multiple Node.js versions try https://github.com/creationix/nvm'
|
|
|
|
);
|
2016-03-30 23:45:54 +02:00
|
|
|
process.exit(1);
|
2016-01-06 04:06:47 +01:00
|
|
|
}
|
|
|
|
|
2016-02-10 23:13:32 +01:00
|
|
|
if (isDev) {
|
2016-03-30 23:45:54 +02:00
|
|
|
browserifyOptions.cache = {};
|
|
|
|
browserifyOptions.packageCache = {};
|
|
|
|
browserifyOptions.plugin = [watchify];
|
2016-01-11 02:25:30 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 22:34:14 +01:00
|
|
|
gulp.task('build', ['umd', 'bundle']);
|
2016-01-11 02:25:30 +01:00
|
|
|
|
2016-03-23 22:34:14 +01:00
|
|
|
gulp.task('bundle', ['bundle-lib', 'bundle-legacy', 'bundle-framework']);
|
2016-01-11 02:25:30 +01:00
|
|
|
|
|
|
|
gulp.task('bundle-lib', function bundleLib() {
|
2016-04-11 11:23:48 +02:00
|
|
|
const bundleFileName = 'bundle-lib.js';
|
2016-03-30 23:45:54 +02:00
|
|
|
|
2016-04-14 00:43:38 +02:00
|
|
|
const es6 = browserify(Object.assign({}, browserifyOptions,
|
2016-04-19 11:04:43 +02:00
|
|
|
{ entries: `${PATHS.ADMIN_JS_SRC}/bundles/lib.js` }
|
2016-04-11 11:23:48 +02:00
|
|
|
))
|
2016-03-30 23:45:54 +02:00
|
|
|
.on('update', bundleLib)
|
2016-04-11 11:23:48 +02:00
|
|
|
.on('log', (msg) =>
|
|
|
|
gulpUtil.log('Finished', `bundled ${bundleFileName} ${msg}`)
|
|
|
|
)
|
2016-03-30 23:45:54 +02:00
|
|
|
.transform('babelify', babelifyOptions)
|
2016-06-16 05:04:14 +02:00
|
|
|
.require('deep-freeze-strict',
|
|
|
|
{ expose: 'deep-freeze-strict' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
|
|
|
.require('react',
|
|
|
|
{ expose: 'react' }
|
|
|
|
)
|
|
|
|
.require('react-addons-css-transition-group',
|
|
|
|
{ expose: 'react-addons-css-transition-group' }
|
|
|
|
)
|
|
|
|
.require('react-addons-test-utils',
|
|
|
|
{ expose: 'react-addons-test-utils' }
|
|
|
|
)
|
|
|
|
.require('react-dom',
|
|
|
|
{ expose: 'react-dom' }
|
|
|
|
)
|
|
|
|
.require('react-redux',
|
|
|
|
{ expose: 'react-redux' }
|
|
|
|
)
|
|
|
|
.require('redux',
|
|
|
|
{ expose: 'redux' }
|
|
|
|
)
|
|
|
|
.require('redux-thunk',
|
|
|
|
{ expose: 'redux-thunk' }
|
|
|
|
)
|
2016-06-16 05:04:14 +02:00
|
|
|
.require('page.js',
|
|
|
|
{ expose: 'page.js' }
|
|
|
|
)
|
2016-04-12 00:24:16 +02:00
|
|
|
.require(`${PATHS.MODULES}/bootstrap/dist/js/umd/collapse.js`,
|
|
|
|
{ expose: 'bootstrap-collapse' }
|
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/Form/Form`,
|
|
|
|
{ expose: 'components/Form/Form' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-05-09 06:00:43 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/Form/FormConstants`,
|
|
|
|
{ expose: 'components/Form/FormConstants' }
|
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/FormAction/FormAction`,
|
|
|
|
{ expose: 'components/FormAction/FormAction' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/FormBuilder/FormBuilder`,
|
|
|
|
{ expose: 'components/FormBuilder/FormBuilder' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/GridField/GridField`,
|
|
|
|
{ expose: 'components/GridField/GridField' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/GridField/GridFieldCell`,
|
|
|
|
{ expose: 'components/GridField/GridFieldCell' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/GridField/GridFieldHeader`,
|
|
|
|
{ expose: 'components/GridField/GridFieldHeader' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/GridField/GridFieldHeaderCell`,
|
|
|
|
{ expose: 'components/GridField/GridFieldHeaderCell' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/GridField/GridFieldRow`,
|
|
|
|
{ expose: 'components/GridField/GridFieldRow' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/GridField/GridFieldTable`,
|
|
|
|
{ expose: 'components/GridField/GridFieldTable' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/HiddenField/HiddenField`,
|
|
|
|
{ expose: 'components/HiddenField/HiddenField' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/TextField/TextField`,
|
|
|
|
{ expose: 'components/TextField/TextField' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-26 00:47:07 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/Toolbar/Toolbar`,
|
|
|
|
{ expose: 'components/Toolbar/Toolbar' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/components/Breadcrumb/Breadcrumb`,
|
|
|
|
{ expose: 'components/Breadcrumb/Breadcrumb' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-19 11:04:43 +02:00
|
|
|
.require(`${PATHS.FRAMEWORK_JS_SRC}/i18n.js`,
|
2016-04-11 11:23:48 +02:00
|
|
|
{ expose: 'i18n' }
|
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/lib/Config`,
|
|
|
|
{ expose: 'lib/Config' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-19 11:04:43 +02:00
|
|
|
.require(`${PATHS.FRAMEWORK_JS_SRC}/jQuery.js`,
|
2016-04-11 11:23:48 +02:00
|
|
|
{ expose: 'jQuery' }
|
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/lib/ReducerRegister.js`,
|
|
|
|
{ expose: 'lib/ReducerRegister' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-06-16 05:04:14 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/lib/RouteRegister.js`,
|
|
|
|
{ expose: 'lib/RouteRegister' }
|
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/lib/Router.js`,
|
|
|
|
{ expose: 'lib/Router' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/lib/SilverStripeComponent`,
|
|
|
|
{ expose: 'lib/SilverStripeComponent' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-04-21 11:59:44 +02:00
|
|
|
.require(`${PATHS.ADMIN_JS_SRC}/lib/Backend`,
|
|
|
|
{ expose: 'lib/Backend' }
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
2016-03-30 23:45:54 +02:00
|
|
|
.bundle()
|
2016-04-11 11:23:48 +02:00
|
|
|
.on('error', notify.onError({ message: `${bundleFileName}: <%= error.message %>` }))
|
2016-03-30 23:45:54 +02:00
|
|
|
.pipe(source(bundleFileName))
|
2016-04-12 04:36:55 +02:00
|
|
|
.pipe(buffer());
|
|
|
|
|
2016-04-14 00:43:38 +02:00
|
|
|
const chosen = gulp.src([
|
|
|
|
`${PATHS.MODULES}/chosen/coffee/lib/*.coffee`,
|
|
|
|
`${PATHS.MODULES}/chosen/coffee/chosen.jquery.coffee`,
|
|
|
|
])
|
2016-04-12 04:36:55 +02:00
|
|
|
.pipe(concat('chosen.js'))
|
|
|
|
.pipe(coffee());
|
|
|
|
|
|
|
|
return merge(es6, chosen)
|
2016-04-14 00:43:38 +02:00
|
|
|
.pipe(order([`**/${bundleFileName}`, '**/chosen.js']))
|
2016-03-30 23:45:54 +02:00
|
|
|
.pipe(sourcemaps.init({ loadMaps: true }))
|
2016-04-14 00:43:38 +02:00
|
|
|
.pipe(concat(bundleFileName, { newLine: '\r\n;\r\n' }))
|
2016-04-19 07:18:07 +02:00
|
|
|
.pipe(uglify(uglifyOptions))
|
2016-03-30 23:45:54 +02:00
|
|
|
.pipe(sourcemaps.write('./'))
|
2016-04-19 11:04:43 +02:00
|
|
|
.pipe(gulp.dest(PATHS.ADMIN_JS_DIST));
|
2016-02-09 00:26:39 +01:00
|
|
|
});
|
|
|
|
|
2016-03-23 22:34:14 +01:00
|
|
|
gulp.task('bundle-legacy', function bundleLeftAndMain() {
|
2016-04-11 11:23:48 +02:00
|
|
|
const bundleFileName = 'bundle-legacy.js';
|
2016-03-30 23:45:54 +02:00
|
|
|
|
2016-04-11 11:23:48 +02:00
|
|
|
return browserify(Object.assign({}, browserifyOptions,
|
2016-04-19 11:04:43 +02:00
|
|
|
{ entries: `${PATHS.ADMIN_JS_SRC}/bundles/legacy.js` }
|
2016-04-11 11:23:48 +02:00
|
|
|
))
|
2016-03-30 23:45:54 +02:00
|
|
|
.on('update', bundleLeftAndMain)
|
2016-04-11 11:23:48 +02:00
|
|
|
.on('log', (msg) =>
|
|
|
|
gulpUtil.log('Finished', `bundled ${bundleFileName} ${msg}`)
|
|
|
|
)
|
2016-03-30 23:45:54 +02:00
|
|
|
.transform('babelify', babelifyOptions)
|
2016-04-06 00:36:18 +02:00
|
|
|
.external('config')
|
2016-03-30 23:45:54 +02:00
|
|
|
.external('jQuery')
|
|
|
|
.external('i18n')
|
2016-04-21 11:59:44 +02:00
|
|
|
.external('lib/Router')
|
2016-03-30 23:45:54 +02:00
|
|
|
.bundle()
|
2016-04-11 11:23:48 +02:00
|
|
|
.on('update', bundleLeftAndMain)
|
|
|
|
.on('error', notify.onError({ message: `${bundleFileName}: <%= error.message %>` }))
|
2016-03-30 23:45:54 +02:00
|
|
|
.pipe(source(bundleFileName))
|
|
|
|
.pipe(buffer())
|
|
|
|
.pipe(sourcemaps.init({ loadMaps: true }))
|
2016-04-19 07:18:07 +02:00
|
|
|
.pipe(uglify(uglifyOptions))
|
2016-03-30 23:45:54 +02:00
|
|
|
.pipe(sourcemaps.write('./'))
|
2016-04-19 11:04:43 +02:00
|
|
|
.pipe(gulp.dest(PATHS.ADMIN_JS_DIST));
|
2016-03-16 01:30:39 +01:00
|
|
|
});
|
|
|
|
|
2016-03-23 22:34:14 +01:00
|
|
|
gulp.task('bundle-framework', function bundleBoot() {
|
2016-04-11 11:23:48 +02:00
|
|
|
const bundleFileName = 'bundle-framework.js';
|
2016-03-30 23:45:54 +02:00
|
|
|
|
2016-04-11 11:23:48 +02:00
|
|
|
return browserify(Object.assign({}, browserifyOptions,
|
2016-04-19 11:04:43 +02:00
|
|
|
{ entries: `${PATHS.ADMIN_JS_SRC}/boot/index.js` }
|
2016-04-11 11:23:48 +02:00
|
|
|
))
|
2016-03-30 23:45:54 +02:00
|
|
|
.on('update', bundleBoot)
|
2016-04-11 11:23:48 +02:00
|
|
|
.on('log', (msg) => {
|
|
|
|
gulpUtil.log('Finished', `bundled ${bundleFileName} ${msg}`);
|
|
|
|
})
|
2016-03-30 23:45:54 +02:00
|
|
|
.transform('babelify', babelifyOptions)
|
2016-04-26 00:47:07 +02:00
|
|
|
.external('components/Toolbar/Toolbar')
|
2016-04-21 11:59:44 +02:00
|
|
|
.external('components/FormBuilder/FormBuilder')
|
|
|
|
.external('components/FormAction/FormAction')
|
2016-06-16 05:04:14 +02:00
|
|
|
.external('deep-freeze-strict')
|
2016-04-21 11:59:44 +02:00
|
|
|
.external('components/GridField/GridField')
|
2016-03-30 23:45:54 +02:00
|
|
|
.external('i18n')
|
|
|
|
.external('jQuery')
|
|
|
|
.external('page.js')
|
|
|
|
.external('react-addons-test-utils')
|
|
|
|
.external('react-dom')
|
|
|
|
.external('react-redux')
|
|
|
|
.external('react')
|
2016-04-21 11:59:44 +02:00
|
|
|
.external('lib/ReducerRegister')
|
2016-03-30 23:45:54 +02:00
|
|
|
.external('redux-thunk')
|
|
|
|
.external('redux')
|
2016-04-21 11:59:44 +02:00
|
|
|
.external('lib/Backend')
|
|
|
|
.external('lib/SilverStripeComponent')
|
2016-04-12 00:24:16 +02:00
|
|
|
.external('bootstrap-collapse')
|
2016-03-30 23:45:54 +02:00
|
|
|
.bundle()
|
2016-04-11 11:23:48 +02:00
|
|
|
.on('update', bundleBoot)
|
|
|
|
.on('error', notify.onError({ message: `${bundleFileName}: <%= error.message %>` }))
|
2016-03-30 23:45:54 +02:00
|
|
|
.pipe(source(bundleFileName))
|
|
|
|
.pipe(buffer())
|
|
|
|
.pipe(sourcemaps.init({ loadMaps: true }))
|
2016-04-19 07:18:07 +02:00
|
|
|
.pipe(uglify(uglifyOptions))
|
2016-03-30 23:45:54 +02:00
|
|
|
.pipe(sourcemaps.write('./'))
|
2016-04-19 11:04:43 +02:00
|
|
|
.pipe(gulp.dest(PATHS.ADMIN_JS_DIST));
|
2016-01-06 04:06:47 +01:00
|
|
|
});
|
|
|
|
|
2016-04-11 11:23:48 +02:00
|
|
|
gulp.task('sanity', () => {
|
2016-03-30 23:45:54 +02:00
|
|
|
diffFiles(blueimpFileUploadConfig);
|
|
|
|
diffFiles(blueimpLoadImageConfig);
|
|
|
|
diffFiles(blueimpTmplConfig);
|
|
|
|
diffFiles(jquerySizesConfig);
|
|
|
|
diffFiles(tinymceConfig);
|
2016-01-06 04:06:47 +01:00
|
|
|
});
|
2016-01-11 02:25:30 +01:00
|
|
|
|
2016-04-11 11:23:48 +02:00
|
|
|
gulp.task('thirdparty', () => {
|
2016-03-30 23:45:54 +02:00
|
|
|
copyFiles(blueimpFileUploadConfig);
|
|
|
|
copyFiles(blueimpLoadImageConfig);
|
|
|
|
copyFiles(blueimpTmplConfig);
|
|
|
|
copyFiles(jquerySizesConfig);
|
|
|
|
copyFiles(tinymceConfig);
|
2016-01-11 02:25:30 +01:00
|
|
|
});
|
|
|
|
|
2016-04-11 11:23:48 +02:00
|
|
|
gulp.task('umd', ['umd-admin', 'umd-framework'], () => {
|
2016-03-30 23:45:54 +02:00
|
|
|
if (isDev) {
|
2016-04-19 11:04:43 +02:00
|
|
|
gulp.watch(`${PATHS.ADMIN_JS_SRC}/legacy/*.js`, ['umd-admin']);
|
|
|
|
gulp.watch(`${PATHS.FRAMEWORK_JS_SRC}/*.js`, ['umd-framework']);
|
2016-03-30 23:45:54 +02:00
|
|
|
}
|
2016-03-07 04:13:55 +01:00
|
|
|
});
|
2016-01-11 02:25:30 +01:00
|
|
|
|
2016-04-11 11:23:48 +02:00
|
|
|
gulp.task('umd-admin', () => {
|
|
|
|
const files = glob.sync(
|
2016-04-19 11:04:43 +02:00
|
|
|
`${PATHS.ADMIN_JS_SRC}/legacy/*.js`,
|
|
|
|
{ ignore: `${PATHS.ADMIN_JS_SRC}/LeftAndMain.!(Ping).js` }
|
2016-04-11 11:23:48 +02:00
|
|
|
);
|
2016-01-11 02:25:30 +01:00
|
|
|
|
2016-04-19 11:04:43 +02:00
|
|
|
return transformToUmd(files, PATHS.ADMIN_JS_DIST);
|
2016-01-11 02:25:30 +01:00
|
|
|
});
|
|
|
|
|
2016-04-11 11:23:48 +02:00
|
|
|
gulp.task('umd-framework', () => { // eslint-disable-line
|
|
|
|
return transformToUmd(glob.sync(
|
2016-04-19 11:04:43 +02:00
|
|
|
`${PATHS.FRAMEWORK_JS_SRC}/*.js`),
|
|
|
|
PATHS.FRAMEWORK_JS_DIST
|
2016-04-11 11:23:48 +02:00
|
|
|
);
|
2016-01-11 02:25:30 +01:00
|
|
|
});
|
|
|
|
|
2016-02-10 23:13:32 +01:00
|
|
|
/*
|
|
|
|
* Takes individual images and compiles them together into sprites
|
|
|
|
*/
|
2016-04-11 11:23:48 +02:00
|
|
|
gulp.task('sprites', () => { // eslint-disable-line
|
2016-03-30 23:45:54 +02:00
|
|
|
return sprity.src({
|
2016-04-19 11:04:43 +02:00
|
|
|
src: `${PATHS.ADMIN_SPRITES_SRC}/**/*.{png,jpg}`,
|
|
|
|
cssPath: '../images/sprites',
|
|
|
|
style: './_sprity.scss',
|
2016-03-30 23:45:54 +02:00
|
|
|
processor: 'sass',
|
|
|
|
split: true,
|
2016-04-11 11:23:48 +02:00
|
|
|
margin: 0,
|
2016-03-30 23:45:54 +02:00
|
|
|
})
|
2016-04-11 11:23:48 +02:00
|
|
|
.pipe(
|
|
|
|
gulpif(
|
|
|
|
'*.png',
|
2016-04-19 11:04:43 +02:00
|
|
|
gulp.dest(PATHS.ADMIN_SPRITES_DIST),
|
|
|
|
gulp.dest(`${PATHS.ADMIN_CSS_SRC}/legacy`)
|
2016-04-11 11:23:48 +02:00
|
|
|
)
|
|
|
|
);
|
2016-02-10 23:13:32 +01:00
|
|
|
});
|
|
|
|
|
2016-04-11 11:23:48 +02:00
|
|
|
gulp.task('css', ['compile:css'], () => {
|
2016-03-30 23:45:54 +02:00
|
|
|
if (isDev) {
|
2016-04-19 11:04:43 +02:00
|
|
|
Object.keys(scssFolders).forEach((sourceFolder) => {
|
|
|
|
gulp.watch(`${sourceFolder}/**/*.scss`, ['compile:css']);
|
2016-03-30 23:45:54 +02:00
|
|
|
});
|
|
|
|
}
|
2016-04-11 11:23:48 +02:00
|
|
|
});
|
2016-02-03 02:32:45 +01:00
|
|
|
|
2016-02-10 23:13:32 +01:00
|
|
|
/*
|
|
|
|
* Compiles scss into css
|
|
|
|
* Watches for changes if --development flag is given
|
|
|
|
*/
|
2016-04-11 11:23:48 +02:00
|
|
|
gulp.task('compile:css', () => {
|
2016-04-19 11:04:43 +02:00
|
|
|
const tasks = Object.keys(scssFolders).map((sourceFolder) => { // eslint-disable-line
|
|
|
|
const targetFolder = scssFolders[sourceFolder];
|
|
|
|
return gulp.src(`${sourceFolder}/**/*.scss`)
|
2016-03-30 23:45:54 +02:00
|
|
|
.pipe(sourcemaps.init())
|
2016-04-12 04:36:55 +02:00
|
|
|
.pipe(
|
|
|
|
sass({
|
2016-04-11 23:15:04 +02:00
|
|
|
outputStyle: 'compressed',
|
2016-04-14 00:43:38 +02:00
|
|
|
importer: (url, prev, done) => {
|
2016-04-12 04:36:55 +02:00
|
|
|
if (url.match(/^compass\//)) {
|
2016-04-19 11:04:43 +02:00
|
|
|
done({ file: 'client/src/styles/_compasscompat.scss' });
|
2016-04-14 00:43:38 +02:00
|
|
|
} else {
|
2016-04-12 04:36:55 +02:00
|
|
|
done();
|
|
|
|
}
|
2016-04-14 00:43:38 +02:00
|
|
|
},
|
2016-04-12 04:36:55 +02:00
|
|
|
})
|
2016-03-30 23:45:54 +02:00
|
|
|
.on('error', notify.onError({
|
2016-04-11 11:23:48 +02:00
|
|
|
message: 'Error: <%= error.message %>',
|
2016-03-30 23:45:54 +02:00
|
|
|
}))
|
|
|
|
)
|
|
|
|
.pipe(postcss([autoprefixer({ browsers: supportedBrowsers })]))
|
|
|
|
.pipe(sourcemaps.write())
|
2016-04-19 11:04:43 +02:00
|
|
|
.pipe(flatten()) // avoid legacy/ paths in CSS output
|
|
|
|
.pipe(gulp.dest(targetFolder));
|
2016-03-30 23:45:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return tasks;
|
2016-02-10 23:13:32 +01:00
|
|
|
});
|