Indentation

This commit is contained in:
sayali 2021-02-01 15:46:22 -08:00
parent 6d367099be
commit 002e73e184
2 changed files with 209 additions and 209 deletions

View File

@ -1,260 +1,260 @@
'use strict'; 'use strict';
var gulp = require('gulp'), var gulp = require('gulp'),
minifycss = require('gulp-minify-css'), minifycss = require('gulp-minify-css'),
concat = require('gulp-concat'), concat = require('gulp-concat'),
less = require('gulp-less'), less = require('gulp-less'),
gulpif = require('gulp-if'), gulpif = require('gulp-if'),
gutil = require('gulp-util'), gutil = require('gulp-util'),
foreach = require('gulp-foreach'), foreach = require('gulp-foreach'),
path = require('path'), path = require('path'),
merge = require('merge-stream'), merge = require('merge-stream'),
del = require('del'), del = require('del'),
size = require('gulp-size'), size = require('gulp-size'),
plumber = require('gulp-plumber'), plumber = require('gulp-plumber'),
autoprefixer = require('gulp-autoprefixer'), autoprefixer = require('gulp-autoprefixer'),
jshint = require('gulp-jshint'), jshint = require('gulp-jshint'),
inject = require('gulp-inject'), inject = require('gulp-inject'),
cache = require('gulp-cache'), cache = require('gulp-cache'),
ngAnnotate = require('gulp-ng-annotate'), ngAnnotate = require('gulp-ng-annotate'),
csso = require('gulp-csso'), csso = require('gulp-csso'),
useref = require('gulp-useref'), useref = require('gulp-useref'),
filter = require('gulp-filter'), filter = require('gulp-filter'),
rev = require('gulp-rev'), rev = require('gulp-rev'),
imagemin = require('gulp-imagemin'), imagemin = require('gulp-imagemin'),
minifyHtml = require('gulp-minify-html'), minifyHtml = require('gulp-minify-html'),
bowerFiles = require('main-bower-files'), bowerFiles = require('main-bower-files'),
karma = require('karma'), karma = require('karma'),
replace = require('gulp-replace'), replace = require('gulp-replace'),
argv = require('yargs').argv; argv = require('yargs').argv;
// http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript // http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript
function escapeRegExp(string) { function escapeRegExp(string) {
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1'); return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
} }
function replaceAll(string, find, replace) { function replaceAll(string, find, replace) {
return string.replace(new RegExp(escapeRegExp(find), 'g'), replace); return string.replace(new RegExp(escapeRegExp(find), 'g'), replace);
} }
function stringSrc(filename, string) { function stringSrc(filename, string) {
let src = require('stream').Readable({objectMode: true}); let src = require('stream').Readable({objectMode: true});
src._read = function () { src._read = function () {
this.push(new gutil.File({cwd: '', base: '', path: filename, contents: new Buffer(string)})); this.push(new gutil.File({cwd: '', base: '', path: filename, contents: new Buffer(string)}));
this.push(null); this.push(null);
}; };
return src; return src;
} }
gulp.task('clean', function (done) { gulp.task('clean', function (done) {
del(['.tmp', 'lemur/static/dist'], done); del(['.tmp', 'lemur/static/dist'], done);
done(); done();
}); });
gulp.task('default', gulp.series(['clean'], function () { gulp.task('default', gulp.series(['clean'], function () {
gulp.start('fonts', 'styles'); gulp.start('fonts', 'styles');
})); }));
gulp.task('test', function (done) { gulp.task('test', function (done) {
new karma.Server({ new karma.Server({
configFile: __dirname + '/karma.conf.js', configFile: __dirname + '/karma.conf.js',
singleRun: true singleRun: true
}, function (err) { }, function (err) {
if (err === 0) { if (err === 0) {
done(); done();
} else { } else {
// if karma server failed to start raise error // if karma server failed to start raise error
done(new gutil.PluginError('karma', { done(new gutil.PluginError('karma', {
message: 'Karma Tests failed' message: 'Karma Tests failed'
})); }));
} }
}).start(); }).start();
}); });
gulp.task('dev:fonts', function () { gulp.task('dev:fonts', function () {
let fileList = [ let fileList = [
'bower_components/bootstrap/dist/fonts/*', 'bower_components/bootstrap/dist/fonts/*',
'bower_components/fontawesome/fonts/*' 'bower_components/fontawesome/fonts/*'
]; ];
return gulp.src(fileList) return gulp.src(fileList)
.pipe(gulp.dest('.tmp/fonts')); // returns a stream making it async .pipe(gulp.dest('.tmp/fonts')); // returns a stream making it async
}); });
gulp.task('dev:styles', function () { gulp.task('dev:styles', function () {
let baseContent = '@import "bower_components/bootstrap/less/bootstrap.less";@import "bower_components/bootswatch/$theme$/variables.less";@import "bower_components/bootswatch/$theme$/bootswatch.less";@import "bower_components/bootstrap/less/utilities.less";'; let baseContent = '@import "bower_components/bootstrap/less/bootstrap.less";@import "bower_components/bootswatch/$theme$/variables.less";@import "bower_components/bootswatch/$theme$/bootswatch.less";@import "bower_components/bootstrap/less/utilities.less";';
let isBootswatchFile = function (file) { let isBootswatchFile = function (file) {
let suffix = 'bootswatch.less'; let suffix = 'bootswatch.less';
return file.path.indexOf(suffix, file.path.length - suffix.length) !== -1; return file.path.indexOf(suffix, file.path.length - suffix.length) !== -1;
}; };
let isBootstrapFile = function (file) { let isBootstrapFile = function (file) {
let suffix = 'bootstrap-', let suffix = 'bootstrap-',
fileName = path.basename(file.path); fileName = path.basename(file.path);
return fileName.indexOf(suffix) === 0; return fileName.indexOf(suffix) === 0;
}; };
let fileList = [ let fileList = [
'bower_components/bootswatch/sandstone/bootswatch.less', 'bower_components/bootswatch/sandstone/bootswatch.less',
'bower_components/fontawesome/css/font-awesome.css', 'bower_components/fontawesome/css/font-awesome.css',
'bower_components/angular-chart.js/dist/angular-chart.css', 'bower_components/angular-chart.js/dist/angular-chart.css',
'bower_components/angular-loading-bar/src/loading-bar.css', 'bower_components/angular-loading-bar/src/loading-bar.css',
'bower_components/angular-ui-switch/angular-ui-switch.css', 'bower_components/angular-ui-switch/angular-ui-switch.css',
'bower_components/angular-wizard/dist/angular-wizard.css', 'bower_components/angular-wizard/dist/angular-wizard.css',
'bower_components/ng-table/dist/ng-table.css', 'bower_components/ng-table/dist/ng-table.css',
'bower_components/angularjs-toaster/toaster.css', 'bower_components/angularjs-toaster/toaster.css',
'bower_components/angular-ui-select/dist/select.css', 'bower_components/angular-ui-select/dist/select.css',
'lemur/static/app/styles/lemur.css' 'lemur/static/app/styles/lemur.css'
]; ];
return gulp.src(fileList) return gulp.src(fileList)
.pipe(gulpif(isBootswatchFile, foreach(function (stream, file) { .pipe(gulpif(isBootswatchFile, foreach(function (stream, file) {
let themeName = path.basename(path.dirname(file.path)), let themeName = path.basename(path.dirname(file.path)),
content = replaceAll(baseContent, '$theme$', themeName); content = replaceAll(baseContent, '$theme$', themeName);
return stringSrc('bootstrap-' + themeName + '.less', content); return stringSrc('bootstrap-' + themeName + '.less', content);
}))) })))
.pipe(less()) .pipe(less())
.pipe(gulpif(isBootstrapFile, foreach(function (stream, file) { .pipe(gulpif(isBootstrapFile, foreach(function (stream, file) {
let fileName = path.basename(file.path), let fileName = path.basename(file.path),
themeName = fileName.substring(fileName.indexOf('-') + 1, fileName.indexOf('.')); themeName = fileName.substring(fileName.indexOf('-') + 1, fileName.indexOf('.'));
// http://stackoverflow.com/questions/21719833/gulp-how-to-add-src-files-in-the-middle-of-a-pipe // http://stackoverflow.com/questions/21719833/gulp-how-to-add-src-files-in-the-middle-of-a-pipe
// https://github.com/gulpjs/gulp/blob/master/docs/recipes/using-multiple-sources-in-one-task.md // https://github.com/gulpjs/gulp/blob/master/docs/recipes/using-multiple-sources-in-one-task.md
return merge(stream, gulp.src(['.tmp/styles/font-awesome.css', '.tmp/styles/lemur.css'], {allowEmpty: true})) return merge(stream, gulp.src(['.tmp/styles/font-awesome.css', '.tmp/styles/lemur.css'], {allowEmpty: true}))
.pipe(concat('style-' + themeName + '.css')); .pipe(concat('style-' + themeName + '.css'));
}))) })))
.pipe(plumber()) .pipe(plumber())
.pipe(concat('styles.css')) .pipe(concat('styles.css'))
.pipe(minifycss()) .pipe(minifycss())
.pipe(autoprefixer('last 1 version')) .pipe(autoprefixer('last 1 version'))
.pipe(gulp.dest('.tmp/styles')) .pipe(gulp.dest('.tmp/styles'))
.pipe(size()); .pipe(size());
}); });
gulp.task('dev:scripts', function () { gulp.task('dev:scripts', function () {
return gulp.src(['lemur/static/app/angular/**/*.js']) return gulp.src(['lemur/static/app/angular/**/*.js'])
.pipe(jshint()) .pipe(jshint())
.pipe(jshint.reporter('jshint-stylish')) .pipe(jshint.reporter('jshint-stylish'))
.pipe(size()); .pipe(size());
}); });
gulp.task('build:extras', function () { gulp.task('build:extras', function () {
return gulp.src(['lemur/static/app/*.*', '!lemur/static/app/*.html']) return gulp.src(['lemur/static/app/*.*', '!lemur/static/app/*.html'])
.pipe(gulp.dest('lemur/static/dist')); .pipe(gulp.dest('lemur/static/dist'));
}); });
function injectHtml(isDev) { function injectHtml(isDev) {
return gulp.src('lemur/static/app/index.html') return gulp.src('lemur/static/app/index.html')
.pipe( .pipe(
inject(gulp.src(bowerFiles({base: 'app'})), { inject(gulp.src(bowerFiles({base: 'app'})), {
starttag: '<!-- inject:bower:{{ext}} -->', starttag: '<!-- inject:bower:{{ext}} -->',
addRootSlash: false, addRootSlash: false,
ignorePath: isDev ? ['lemur/static/app/', '.tmp/'] : null ignorePath: isDev ? ['lemur/static/app/', '.tmp/'] : null
}) })
) )
.pipe(inject(gulp.src(['lemur/static/app/angular/**/*.js']), { .pipe(inject(gulp.src(['lemur/static/app/angular/**/*.js']), {
starttag: '<!-- inject:{{ext}} -->', starttag: '<!-- inject:{{ext}} -->',
addRootSlash: false, addRootSlash: false,
ignorePath: isDev ? ['lemur/static/app/', '.tmp/'] : null ignorePath: isDev ? ['lemur/static/app/', '.tmp/'] : null
})) }))
.pipe(inject(gulp.src(['.tmp/styles/**/*.css']), { .pipe(inject(gulp.src(['.tmp/styles/**/*.css']), {
starttag: '<!-- inject:{{ext}} -->', starttag: '<!-- inject:{{ext}} -->',
addRootSlash: false, addRootSlash: false,
ignorePath: isDev ? ['lemur/static/app/', '.tmp/'] : null ignorePath: isDev ? ['lemur/static/app/', '.tmp/'] : null
})) }))
.pipe( .pipe(
gulpif(!isDev, gulpif(!isDev,
inject(gulp.src('lemur/static/dist/ngviews/ngviews.min.js', {allowEmpty: true}), { inject(gulp.src('lemur/static/dist/ngviews/ngviews.min.js', {allowEmpty: true}), {
starttag: '<!-- inject:ngviews -->', starttag: '<!-- inject:ngviews -->',
addRootSlash: false addRootSlash: false
}) })
) )
).pipe(gulp.dest('.tmp/')); ).pipe(gulp.dest('.tmp/'));
} }
gulp.task('dev:inject', gulp.series(['dev:styles', 'dev:scripts'], function () { gulp.task('dev:inject', gulp.series(['dev:styles', 'dev:scripts'], function () {
return injectHtml(true); return injectHtml(true);
})); }));
gulp.task('build:ngviews', function () { gulp.task('build:ngviews', function () {
return gulp.src(['lemur/static/app/angular/**/*.html']) return gulp.src(['lemur/static/app/angular/**/*.html'])
.pipe(minifyHtml({ .pipe(minifyHtml({
empty: true, empty: true,
spare: true, spare: true,
quotes: true quotes: true
})) }))
.pipe(gulp.dest('lemur/static/dist/angular')) .pipe(gulp.dest('lemur/static/dist/angular'))
.pipe(size()); .pipe(size());
}); });
gulp.task('build:inject', gulp.series(['dev:styles', 'dev:scripts', 'build:ngviews'], function () { gulp.task('build:inject', gulp.series(['dev:styles', 'dev:scripts', 'build:ngviews'], function () {
return injectHtml(false); return injectHtml(false);
})); }));
gulp.task('build:html', gulp.series(['build:inject'], function () { gulp.task('build:html', gulp.series(['build:inject'], function () {
let jsFilter = filter(['**/*.js'], {'restore': true}); let jsFilter = filter(['**/*.js'], {'restore': true});
let cssFilter = filter(['**/*.css'], {'restore': true}); let cssFilter = filter(['**/*.css'], {'restore': true});
return gulp.src('.tmp/index.html') return gulp.src('.tmp/index.html')
.pipe(jsFilter) .pipe(jsFilter)
.pipe(ngAnnotate()) .pipe(ngAnnotate())
.pipe(jsFilter.restore) .pipe(jsFilter.restore)
.pipe(cssFilter) .pipe(cssFilter)
.pipe(csso()) .pipe(csso())
.pipe(cssFilter.restore) .pipe(cssFilter.restore)
.pipe(useref()) .pipe(useref())
.pipe(gulp.dest('lemur/static/dist')) .pipe(gulp.dest('lemur/static/dist'))
.pipe(size()); .pipe(size());
})); }));
gulp.task('build:fonts', gulp.series(['dev:fonts'], function () { gulp.task('build:fonts', gulp.series(['dev:fonts'], function () {
return gulp.src('.tmp/fonts/**/*') return gulp.src('.tmp/fonts/**/*')
.pipe(gulp.dest('lemur/static/dist/fonts')); .pipe(gulp.dest('lemur/static/dist/fonts'));
})); }));
gulp.task('build:images', function () { gulp.task('build:images', function () {
return gulp.src('lemur/static/app/images/**/*') return gulp.src('lemur/static/app/images/**/*')
.pipe(cache(imagemin({ .pipe(cache(imagemin({
optimizationLevel: 3, optimizationLevel: 3,
progressive: true, progressive: true,
interlaced: true interlaced: true
}))) })))
.pipe(gulp.dest('lemur/static/dist/images')) .pipe(gulp.dest('lemur/static/dist/images'))
.pipe(size()); .pipe(size());
}); });
gulp.task('package:strip', function () { gulp.task('package:strip', function () {
return gulp.src(['lemur/static/dist/scripts/main*']) return gulp.src(['lemur/static/dist/scripts/main*'])
.pipe(replace('http:\/\/localhost:3000', '')) .pipe(replace('http:\/\/localhost:3000', ''))
.pipe(replace('http:\/\/localhost:8000', '')) .pipe(replace('http:\/\/localhost:8000', ''))
.pipe(useref()) .pipe(useref())
.pipe(gulp.dest('lemur/static/dist/scripts')) .pipe(gulp.dest('lemur/static/dist/scripts'))
.pipe(size()); .pipe(size());
}); });
gulp.task('addUrlContextPath:revision', function () { gulp.task('addUrlContextPath:revision', function () {
return gulp.src(['lemur/static/dist/**/*.css', 'lemur/static/dist/**/*.js']) return gulp.src(['lemur/static/dist/**/*.css', 'lemur/static/dist/**/*.js'])
.pipe(rev()) .pipe(rev())
.pipe(gulp.dest('lemur/static/dist')) .pipe(gulp.dest('lemur/static/dist'))
.pipe(rev.manifest()) .pipe(rev.manifest())
.pipe(gulp.dest('lemur/static/dist')); .pipe(gulp.dest('lemur/static/dist'));
}); });
gulp.task('addUrlContextPath:revreplace', gulp.series(['addUrlContextPath:revision'], function () { gulp.task('addUrlContextPath:revreplace', gulp.series(['addUrlContextPath:revision'], function () {
return gulp.src('lemur/static/dist/index.html') return gulp.src('lemur/static/dist/index.html')
.pipe(gulp.dest('lemur/static/dist')); .pipe(gulp.dest('lemur/static/dist'));
})); }));
gulp.task('addUrlContextPath', gulp.series(['addUrlContextPath:revreplace'], function () { gulp.task('addUrlContextPath', gulp.series(['addUrlContextPath:revreplace'], function () {
let urlContextPathExists = !!argv.urlContextPath; let urlContextPathExists = !!argv.urlContextPath;
return gulp.src(['lemur/static/dist/scripts/main*.js', 'lemur/static/dist/angular/**/*.html']) return gulp.src(['lemur/static/dist/scripts/main*.js', 'lemur/static/dist/angular/**/*.html'])
.pipe(gulpif(urlContextPathExists, replace('api/', argv.urlContextPath + '/api/'))) .pipe(gulpif(urlContextPathExists, replace('api/', argv.urlContextPath + '/api/')))
.pipe(gulpif(urlContextPathExists, replace('/angular/', '/' + argv.urlContextPath + '/angular/'))) .pipe(gulpif(urlContextPathExists, replace('/angular/', '/' + argv.urlContextPath + '/angular/')))
.pipe(gulp.dest(function (file) { .pipe(gulp.dest(function (file) {
return file.base; return file.base;
})); }));
})); }));
gulp.task('build', gulp.series(['build:images', 'build:fonts', 'build:html', 'build:extras'])); gulp.task('build', gulp.series(['build:images', 'build:fonts', 'build:html', 'build:extras']));

View File

@ -2,36 +2,36 @@
'use strict'; 'use strict';
module.exports = function (config) { module.exports = function (config) {
config.set({ config.set({
basePath: '../', basePath: '../',
// Fix for "JASMINE is not supported anymore" warning // Fix for "JASMINE is not supported anymore" warning
frameworks: ['jasmine'], frameworks: ['jasmine'],
files: [ files: [
'app/lib/angular/angular.js', 'app/lib/angular/angular.js',
'app/lib/angular/angular-*.js', 'app/lib/angular/angular-*.js',
'test/lib/angular/angular-mocks.js', 'test/lib/angular/angular-mocks.js',
'app/js/**/*.js', 'app/js/**/*.js',
'test/unit/**/*.js' 'test/unit/**/*.js'
], ],
autoWatch: true, autoWatch: true,
browsers: [process.env.TRAVIS ? 'Chrome_travis_ci' : 'Chrome'], browsers: [process.env.TRAVIS ? 'Chrome_travis_ci' : 'Chrome'],
customLaunchers: { customLaunchers: {
'Chrome_travis_ci': { 'Chrome_travis_ci': {
base: 'Chrome', base: 'Chrome',
flags: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu',], flags: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu',],
}, },
}, },
junitReporter: { junitReporter: {
outputFile: 'test_out/unit.xml', outputFile: 'test_out/unit.xml',
suite: 'unit' suite: 'unit'
//... //...
}, },
failOnEmptyTestSuite: false, failOnEmptyTestSuite: false,
}); });
}; };