mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
ESLint fixes in gulpfile
This commit is contained in:
parent
db42ab772f
commit
d65851f0e9
183
gulpfile.js
183
gulpfile.js
@ -1,39 +1,37 @@
|
|||||||
var gulp = require('gulp'),
|
const gulp = require('gulp');
|
||||||
babel = require('gulp-babel'),
|
const babel = require('gulp-babel');
|
||||||
diff = require('gulp-diff'),
|
const notify = require('gulp-notify');
|
||||||
notify = require('gulp-notify'),
|
const sass = require('gulp-sass');
|
||||||
sass = require('gulp-sass'),
|
const sourcemaps = require('gulp-sourcemaps');
|
||||||
sourcemaps = require('gulp-sourcemaps'),
|
const uglify = require('gulp-uglify');
|
||||||
uglify = require('gulp-uglify');
|
const gulpUtil = require('gulp-util');
|
||||||
gulpUtil = require('gulp-util'),
|
const browserify = require('browserify');
|
||||||
browserify = require('browserify'),
|
const babelify = require('babelify');
|
||||||
babelify = require('babelify'),
|
const watchify = require('watchify');
|
||||||
watchify = require('watchify'),
|
const source = require('vinyl-source-stream');
|
||||||
source = require('vinyl-source-stream'),
|
const buffer = require('vinyl-buffer');
|
||||||
buffer = require('vinyl-buffer'),
|
const path = require('path');
|
||||||
path = require('path'),
|
const glob = require('glob');
|
||||||
glob = require('glob'),
|
const eventStream = require('event-stream');
|
||||||
eventStream = require('event-stream'),
|
const semver = require('semver');
|
||||||
semver = require('semver'),
|
const packageJson = require('./package.json');
|
||||||
packageJson = require('./package.json');
|
|
||||||
|
|
||||||
var isDev = typeof process.env.npm_config_development !== 'undefined';
|
|
||||||
|
|
||||||
var PATHS = {
|
|
||||||
MODULES: './node_modules',
|
|
||||||
CMS_JAVASCRIPT_SRC: './javascript/src',
|
|
||||||
CMS_JAVASCRIPT_DIST: './javascript/dist',
|
|
||||||
CMS_SCSS: './scss',
|
|
||||||
CMS_CSS: './css'
|
|
||||||
};
|
|
||||||
|
|
||||||
|
const isDev = typeof process.env.npm_config_development !== 'undefined';
|
||||||
process.env.NODE_ENV = isDev ? 'development' : 'production';
|
process.env.NODE_ENV = isDev ? 'development' : 'production';
|
||||||
|
|
||||||
var babelifyOptions = {
|
const PATHS = {
|
||||||
presets: ['es2015', 'es2015-ie', 'react'],
|
MODULES: './node_modules',
|
||||||
plugins: ['transform-object-assign'],
|
CMS_JAVASCRIPT_SRC: './javascript/src',
|
||||||
ignore: /(node_modules|thirdparty)/,
|
CMS_JAVASCRIPT_DIST: './javascript/dist',
|
||||||
comments: false
|
CMS_SCSS: './scss',
|
||||||
|
CMS_CSS: './css',
|
||||||
|
};
|
||||||
|
|
||||||
|
const babelifyOptions = {
|
||||||
|
presets: ['es2015', 'es2015-ie', 'react'],
|
||||||
|
plugins: ['transform-object-assign'],
|
||||||
|
ignore: /(node_modules|thirdparty)/,
|
||||||
|
comments: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const browserifyOptions = {};
|
const browserifyOptions = {};
|
||||||
@ -52,76 +50,83 @@ if (isDev) {
|
|||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
function transformToUmd(files, dest) {
|
function transformToUmd(files, dest) {
|
||||||
return eventStream.merge(files.map(function (file) {
|
return eventStream.merge(files.map((file) => { // eslint-disable-line arrow-body-style
|
||||||
return gulp.src(file)
|
return gulp.src(file)
|
||||||
.pipe(babel({
|
.pipe(babel({
|
||||||
presets: ['es2015'],
|
presets: ['es2015'],
|
||||||
moduleId: 'ss.' + path.parse(file).name,
|
moduleId: `ss.${path.parse(file).name}`,
|
||||||
plugins: ['transform-es2015-modules-umd'],
|
plugins: ['transform-es2015-modules-umd'],
|
||||||
comments: false
|
comments: false,
|
||||||
}))
|
}))
|
||||||
.on('error', notify.onError({
|
.on('error', notify.onError({
|
||||||
message: 'Error: <%= error.message %>',
|
message: 'Error: <%= error.message %>',
|
||||||
}))
|
}))
|
||||||
.pipe(gulp.dest(dest));
|
.pipe(gulp.dest(dest));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the version of Node being used is valid.
|
// Make sure the version of Node being used is valid.
|
||||||
if (!semver.satisfies(process.versions.node, packageJson.engines.node)) {
|
if (!semver.satisfies(process.versions.node, packageJson.engines.node)) {
|
||||||
console.error('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');
|
console.error( // eslint-disable-line no-console
|
||||||
process.exit(1);
|
`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'
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
gulp.task('build', ['umd-cms', 'umd-watch', 'bundle-legacy']);
|
gulp.task('build', ['umd-cms', 'umd-watch', 'bundle-legacy']);
|
||||||
|
|
||||||
gulp.task('bundle-legacy', function bundleLeftAndMain() {
|
gulp.task('bundle-legacy', function bundleLeftAndMain() {
|
||||||
var bundleFileName = 'bundle-legacy.js';
|
const bundleFileName = 'bundle-legacy.js';
|
||||||
|
|
||||||
return browserify(Object.assign({}, browserifyOptions, { entries: PATHS.CMS_JAVASCRIPT_SRC + '/bundles/legacy.js' }))
|
return browserify(Object.assign(
|
||||||
.on('update', bundleLeftAndMain)
|
{},
|
||||||
.on('log', function (msg) { gulpUtil.log('Finished', 'bundled ' + bundleFileName + ' ' + msg) })
|
browserifyOptions,
|
||||||
.transform('babelify', babelifyOptions)
|
{ entries: `${PATHS.CMS_JAVASCRIPT_SRC}/bundles/legacy.js` })
|
||||||
.external('jQuery')
|
)
|
||||||
.external('i18n')
|
.on('update', bundleLeftAndMain)
|
||||||
.external('router')
|
.on('log', (msg) => gulpUtil.log('Finished', `bundled ${bundleFileName} ${msg}`))
|
||||||
.bundle()
|
.transform(babelify, babelifyOptions)
|
||||||
.on('error', notify.onError({ message: bundleFileName + ': <%= error.message %>' }))
|
.external('jQuery')
|
||||||
.pipe(source(bundleFileName))
|
.external('i18n')
|
||||||
.pipe(buffer())
|
.external('router')
|
||||||
.pipe(sourcemaps.init({ loadMaps: true }))
|
.bundle()
|
||||||
.pipe(uglify())
|
.on('error', notify.onError({ message: `${bundleFileName}: <%= error.message %>` }))
|
||||||
.pipe(sourcemaps.write('./'))
|
.pipe(source(bundleFileName))
|
||||||
.pipe(gulp.dest(PATHS.CMS_JAVASCRIPT_DIST));
|
.pipe(buffer())
|
||||||
|
.pipe(sourcemaps.init({ loadMaps: true }))
|
||||||
|
.pipe(uglify())
|
||||||
|
.pipe(sourcemaps.write('./'))
|
||||||
|
.pipe(gulp.dest(PATHS.CMS_JAVASCRIPT_DIST));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('umd-cms', function () {
|
gulp.task('umd-cms', () => { // eslint-disable-line
|
||||||
return transformToUmd(glob.sync(PATHS.CMS_JAVASCRIPT_SRC + '/*.js'), PATHS.CMS_JAVASCRIPT_DIST);
|
return transformToUmd(glob.sync(`${PATHS.CMS_JAVASCRIPT_SRC}/*.js`), PATHS.CMS_JAVASCRIPT_DIST);
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('umd-watch', function () {
|
gulp.task('umd-watch', () => { // eslint-disable-line
|
||||||
if (isDev) {
|
|
||||||
gulp.watch(PATHS.CMS_JAVASCRIPT_SRC + '/*.js', ['umd-cms']);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('css', ['compile:css'], function () {
|
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
gulp.watch(PATHS.CMS_SCSS + '/**/*.scss', ['compile:css']);
|
gulp.watch(`${PATHS.CMS_JAVASCRIPT_SRC}/*.js`, ['umd-cms']);
|
||||||
gulp.watch(CMS_JAVASCRIPT_SRC + '/**/*.scss', ['compile:css']);
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
gulp.task('compile:css', function () {
|
gulp.task('css', ['compile:css'], () => { // eslint-disable-line
|
||||||
var outputStyle = isDev ? 'expanded' : 'compressed';
|
if (isDev) {
|
||||||
|
gulp.watch(`${PATHS.CMS_SCSS}/**/*.scss`, ['compile:css']);
|
||||||
return gulp.src(PATHS.CMS_SCSS + '/**/*.scss')
|
gulp.watch(`${PATHS.CMS_JAVASCRIPT_SRC}/**/*.scss`, ['compile:css']);
|
||||||
.pipe(sourcemaps.init())
|
}
|
||||||
.pipe(sass({ outputStyle: outputStyle })
|
});
|
||||||
.on('error', notify.onError({
|
|
||||||
message: 'Error: <%= error.message %>'
|
gulp.task('compile:css', () => { // eslint-disable-line
|
||||||
}))
|
const outputStyle = isDev ? 'expanded' : 'compressed';
|
||||||
)
|
|
||||||
.pipe(sourcemaps.write())
|
return gulp.src(`${PATHS.CMS_SCSS}/**/*.scss`)
|
||||||
.pipe(gulp.dest(PATHS.CMS_CSS))
|
.pipe(sourcemaps.init())
|
||||||
|
.pipe(sass({ outputStyle })
|
||||||
|
.on('error', notify.onError({
|
||||||
|
message: 'Error: <%= error.message %>',
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
.pipe(sourcemaps.write())
|
||||||
|
.pipe(gulp.dest(PATHS.CMS_CSS));
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user