2016-05-13 18:09:12 +02:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var gulpLoadPlugins = require('gulp-load-plugins');
|
|
|
|
var browserSync = require('browser-sync');
|
|
|
|
var del = require('del');
|
2018-11-18 05:19:21 +01:00
|
|
|
var fs = require('fs');
|
2018-11-21 13:46:21 +01:00
|
|
|
var git = require('git-rev-sync');
|
2019-03-18 17:44:38 +01:00
|
|
|
var tryFn = require('nice-try');
|
2019-04-07 05:57:40 +02:00
|
|
|
var saveLicense = require('uglify-save-license');
|
2016-05-13 18:09:12 +02:00
|
|
|
|
|
|
|
var $ = gulpLoadPlugins();
|
|
|
|
var reload = browserSync.reload;
|
|
|
|
|
2018-11-19 16:43:01 +01:00
|
|
|
gulp.task('clean', del.bind(null, ['.tmp', 'dist']));
|
|
|
|
|
|
|
|
gulp.task('lint', function () {
|
|
|
|
return gulp.src([
|
|
|
|
'src/scripts/**/*.js'
|
|
|
|
]).pipe(reload({stream: true, once: true}))
|
|
|
|
.pipe($.eslint.format())
|
|
|
|
.pipe($.if(!browserSync.active, $.eslint.failAfterError()))
|
|
|
|
.pipe(gulp.dest('src/scripts'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('prepare-fonts', function () {
|
|
|
|
return gulp.src([
|
|
|
|
'node_modules/font-awesome/fonts/fontawesome-webfont.*'
|
|
|
|
]).pipe(gulp.dest('.tmp/fonts'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('process-fonts', ['prepare-fonts'], function () {
|
|
|
|
return gulp.src([
|
|
|
|
'.tmp/fonts/**/*'
|
|
|
|
]).pipe(gulp.dest('dist/fonts'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('prepare-langs', function () {
|
|
|
|
return gulp.src([
|
|
|
|
'src/langs/**/*'
|
|
|
|
]).pipe(gulp.dest('.tmp/langs'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('process-langs', ['prepare-langs'], function () {
|
|
|
|
return gulp.src([
|
|
|
|
'.tmp/langs/**/*'
|
|
|
|
]).pipe(gulp.dest('dist/langs'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('prepare-styles', function () {
|
2016-12-10 19:11:27 +01:00
|
|
|
return gulp.src([
|
|
|
|
'src/styles/**/*.css'
|
|
|
|
]).pipe($.autoprefixer({browsers: ['> 1%', 'last 2 versions', 'Firefox ESR']}))
|
|
|
|
.pipe(gulp.dest('.tmp/styles'))
|
|
|
|
.pipe(reload({stream: true}));
|
2016-05-13 18:09:12 +02:00
|
|
|
});
|
|
|
|
|
2018-11-19 16:43:01 +01:00
|
|
|
gulp.task('prepare-scripts', function () {
|
2016-12-10 19:11:27 +01:00
|
|
|
return gulp.src([
|
|
|
|
'src/scripts/**/*.js'
|
|
|
|
]).pipe($.plumber())
|
2018-11-21 13:46:21 +01:00
|
|
|
.pipe($.injectVersion({replace: '${ARIANG_VERSION}'}))
|
2019-03-18 17:44:38 +01:00
|
|
|
.pipe($.replace(/\${ARIANG_BUILD_COMMIT}/g, tryFn(git.short) || 'Local'))
|
2016-12-10 19:11:27 +01:00
|
|
|
.pipe(gulp.dest('.tmp/scripts'))
|
|
|
|
.pipe(reload({stream: true}));
|
2016-05-13 18:09:12 +02:00
|
|
|
});
|
|
|
|
|
2018-11-19 16:43:01 +01:00
|
|
|
gulp.task('prepare-views', function () {
|
2016-12-10 19:11:27 +01:00
|
|
|
return gulp.src([
|
|
|
|
'src/views/**/*.html'
|
|
|
|
]).pipe($.htmlmin({collapseWhitespace: true}))
|
|
|
|
.pipe($.angularTemplatecache({module: 'ariaNg', filename: 'views/templates.js', root: 'views/'}))
|
|
|
|
.pipe(gulp.dest('.tmp/scripts'));
|
2016-08-01 16:15:08 +02:00
|
|
|
});
|
|
|
|
|
2018-11-19 16:43:01 +01:00
|
|
|
gulp.task('prepare-html', ['prepare-styles', 'prepare-scripts', 'prepare-views'], function () {
|
2016-12-10 19:11:27 +01:00
|
|
|
return gulp.src([
|
|
|
|
'src/*.html'
|
|
|
|
]).pipe($.useref({searchPath: ['.tmp', 'src', '.']}))
|
|
|
|
.pipe($.if('js/*.js', $.replace(/\/\/# sourceMappingURL=.*/g, '')))
|
|
|
|
.pipe($.if('css/*.css', $.replace(/\/\*# sourceMappingURL=.* \*\/$/g, '')))
|
2019-04-07 05:57:40 +02:00
|
|
|
.pipe($.if(['js/moment-with-locales-*.min.js', 'js/plugins.min.js', 'js/aria-ng.min.js'], $.uglify({output: {comments: saveLicense}})))
|
2016-12-10 19:11:27 +01:00
|
|
|
.pipe($.if(['css/plugins.min.css', 'css/aria-ng.min.css'], $.cssnano({safe: true, autoprefixer: false})))
|
2019-08-20 15:02:28 +02:00
|
|
|
.pipe($.replace(/url\((\.\.\/fonts\/[a-zA-Z0-9\-]+\.woff2)(\?[a-zA-Z0-9\-_=.]+)?\)/g, function(match, fileName) {
|
|
|
|
return 'url(' + fileName + ')'; // remove version of woff2 file (woff2 file should be cached via application cache)
|
|
|
|
}))
|
2016-12-10 19:11:27 +01:00
|
|
|
.pipe($.if(['js/plugins.min.js', 'js/aria-ng.min.js', 'css/plugins.min.css', 'css/aria-ng.min.css'], $.rev()))
|
|
|
|
.pipe($.if('*.html', $.htmlmin({collapseWhitespace: true})))
|
|
|
|
.pipe($.revReplace())
|
2018-11-19 16:43:01 +01:00
|
|
|
.pipe(gulp.dest('.tmp'));
|
2016-05-13 18:09:12 +02:00
|
|
|
});
|
|
|
|
|
2018-11-19 16:43:01 +01:00
|
|
|
gulp.task('process-html', ['prepare-html'], function () {
|
2016-12-10 19:11:27 +01:00
|
|
|
return gulp.src([
|
2018-11-19 16:43:01 +01:00
|
|
|
'.tmp/*.html'
|
|
|
|
]).pipe($.replace(/<!-- AriaNg-Bundle:\w+ -->/, ''))
|
|
|
|
.pipe(gulp.dest('dist'));
|
2016-05-26 17:52:34 +02:00
|
|
|
});
|
|
|
|
|
2018-11-19 16:43:01 +01:00
|
|
|
gulp.task('process-assets', ['process-html'], function () {
|
2016-12-10 19:11:27 +01:00
|
|
|
return gulp.src([
|
2018-11-19 16:43:01 +01:00
|
|
|
'.tmp/css/**/*',
|
|
|
|
'.tmp/js/**/*'
|
|
|
|
],{ base: '.tmp' })
|
|
|
|
.pipe(gulp.dest('dist'));
|
2016-05-13 18:09:12 +02:00
|
|
|
});
|
|
|
|
|
2018-11-19 16:43:01 +01:00
|
|
|
gulp.task('process-assets-bundle', ['prepare-fonts', 'prepare-langs', 'prepare-html'], function () {
|
|
|
|
return gulp.src('.tmp/index.html')
|
|
|
|
.pipe($.replace(/<link rel="stylesheet" href="(css\/[a-zA-Z0-9\-_.]+\.css)">/g, function(match, fileName) {
|
|
|
|
var content = fs.readFileSync('.tmp/' + fileName, 'utf8');
|
|
|
|
return '<style type="text/css">' + content + '</style>';
|
|
|
|
}))
|
|
|
|
.pipe($.replace(/<script src="(js\/[a-zA-Z0-9\-_.]+\.js)"><\/script>/g, function(match, fileName) {
|
|
|
|
var content = fs.readFileSync('.tmp/' + fileName, 'utf8');
|
|
|
|
return '<script type="application/javascript">' + content + '</script>';
|
|
|
|
}))
|
|
|
|
.pipe($.replace(/url\(\.\.\/(fonts\/[a-zA-Z0-9\-]+\.woff)(\?[a-zA-Z0-9\-_=.]+)?\)/g, function(match, fileName) {
|
|
|
|
if (!fs.existsSync('.tmp/' + fileName)) {
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
|
|
|
var contentBuffer = fs.readFileSync('.tmp/' + fileName);
|
|
|
|
var contentBase64 = contentBuffer.toString('base64');
|
|
|
|
return 'url(data:application/x-font-woff;base64,' + contentBase64 + ')';
|
|
|
|
}))
|
|
|
|
.pipe($.replace('<!-- AriaNg-Bundle:languages -->', function() {
|
|
|
|
var langDir = '.tmp/langs/';
|
|
|
|
var result = '';
|
|
|
|
var fileNames = fs.readdirSync(langDir, 'utf8');
|
|
|
|
|
|
|
|
if (fileNames.length > 0) {
|
|
|
|
result = '<script type="application/javascript">' +
|
|
|
|
'angular.module("ariaNg").config(["ariaNgAssetsCacheServiceProvider",function(e){';
|
|
|
|
|
|
|
|
for (var i = 0; i < fileNames.length; i++) {
|
|
|
|
var fileName = fileNames[i];
|
|
|
|
var content = fs.readFileSync(langDir + fileName, 'utf8');
|
|
|
|
|
|
|
|
var lastPointIndex = fileName.lastIndexOf('.');
|
|
|
|
var languageName = fileName.substr(0, lastPointIndex);
|
|
|
|
|
2019-04-09 12:15:58 +02:00
|
|
|
content = content.replace(/\\/g, '\\\\');
|
2019-04-09 11:51:29 +02:00
|
|
|
content = content.replace(/\r/g, '');
|
2018-11-19 16:43:01 +01:00
|
|
|
content = content.replace(/\n/g, '\\n');
|
|
|
|
content = content.replace(/"/g, '\\"');
|
|
|
|
result += 'e.setLanguageAsset(\'' + languageName + '\',"' + content + '");';
|
|
|
|
}
|
|
|
|
|
|
|
|
result += '}]);</script>';
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}))
|
|
|
|
.pipe($.replace(/<[a-z]+( [a-z\-]+="[a-zA-Z0-9\- ]+")* [a-z\-]+="((favicon.ico)|(favicon.png)|(tileicon.png)|(touchicon.png))"\/?>/g, ''))
|
|
|
|
.pipe(gulp.dest('dist'));
|
2016-05-13 18:09:12 +02:00
|
|
|
});
|
|
|
|
|
2018-11-19 16:43:01 +01:00
|
|
|
gulp.task('process-manifest', function () {
|
2016-12-10 19:11:27 +01:00
|
|
|
return gulp.src([
|
|
|
|
'dist/css/**',
|
|
|
|
'dist/js/**',
|
|
|
|
'dist/fonts/fontawesome-webfont.woff2',
|
2017-12-09 16:05:29 +01:00
|
|
|
'dist/*.html',
|
|
|
|
'dist/*.ico',
|
|
|
|
'dist/*.png'
|
2016-12-10 19:11:27 +01:00
|
|
|
], {base: 'dist/'})
|
|
|
|
.pipe($.manifest({
|
|
|
|
hash: true,
|
|
|
|
preferOnline: true,
|
|
|
|
network: ['*'],
|
|
|
|
filename: 'index.manifest',
|
|
|
|
exclude: 'index.manifest'
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('dist'));
|
2016-08-02 18:03:00 +02:00
|
|
|
});
|
|
|
|
|
2018-11-19 16:43:01 +01:00
|
|
|
gulp.task('process-full-extras', function () {
|
2016-12-10 19:11:27 +01:00
|
|
|
return gulp.src([
|
2016-12-11 07:35:38 +01:00
|
|
|
'LICENSE',
|
2016-12-10 19:11:27 +01:00
|
|
|
'src/*.*',
|
|
|
|
'!src/*.html'
|
|
|
|
], {
|
|
|
|
dot: true
|
|
|
|
}).pipe(gulp.dest('dist'));
|
2016-05-13 18:09:12 +02:00
|
|
|
});
|
|
|
|
|
2018-11-19 16:43:01 +01:00
|
|
|
gulp.task('process-tiny-extras', function () {
|
|
|
|
return gulp.src([
|
|
|
|
'LICENSE'
|
|
|
|
]).pipe(gulp.dest('dist'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('info', function () {
|
|
|
|
return gulp.src([
|
|
|
|
'dist/**/*'
|
|
|
|
]).pipe($.size({title: 'build', gzip: true}));
|
|
|
|
});
|
2016-05-13 18:09:12 +02:00
|
|
|
|
2018-11-19 16:43:01 +01:00
|
|
|
gulp.task('build', $.sequence('lint', 'process-fonts', 'process-langs', 'process-assets', 'process-manifest', 'process-full-extras', 'info'));
|
|
|
|
|
|
|
|
gulp.task('build-bundle', $.sequence('lint', 'process-assets-bundle', 'process-tiny-extras', 'info'));
|
|
|
|
|
|
|
|
gulp.task('serve', ['prepare-styles', 'prepare-scripts', 'prepare-fonts'], function () {
|
2016-12-10 19:11:27 +01:00
|
|
|
browserSync({
|
|
|
|
notify: false,
|
|
|
|
port: 9000,
|
|
|
|
server: {
|
|
|
|
baseDir: ['.tmp', 'src'],
|
|
|
|
routes: {
|
2018-08-25 20:03:57 +02:00
|
|
|
'/node_modules': 'node_modules'
|
2016-12-10 19:11:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.watch([
|
|
|
|
'src/*.html',
|
2017-12-09 16:05:29 +01:00
|
|
|
'src/*.ico',
|
|
|
|
'src/*.png',
|
2016-12-10 19:11:27 +01:00
|
|
|
'src/langs/*.txt',
|
|
|
|
'src/views/*.html',
|
|
|
|
'src/imgs/**/*',
|
|
|
|
'.tmp/fonts/**/*'
|
|
|
|
]).on('change', reload);
|
|
|
|
|
2018-11-19 16:43:01 +01:00
|
|
|
gulp.watch('src/styles/**/*.css', ['prepare-styles']);
|
|
|
|
gulp.watch('src/scripts/**/*.js', ['prepare-scripts']);
|
|
|
|
gulp.watch('src/fonts/**/*', ['prepare-fonts']);
|
2016-05-13 18:09:12 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('serve:dist', function () {
|
2016-12-10 19:11:27 +01:00
|
|
|
browserSync({
|
|
|
|
notify: false,
|
|
|
|
port: 9000,
|
|
|
|
server: {
|
|
|
|
baseDir: ['dist']
|
|
|
|
}
|
|
|
|
});
|
2016-05-13 18:09:12 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('default', ['clean'], function () {
|
2016-12-10 19:11:27 +01:00
|
|
|
gulp.start('build');
|
2016-05-13 18:09:12 +02:00
|
|
|
});
|