- test
- ...
- webapp
- controller
- i18n
- model
- view
- ...
- Component.js
- index.html
cd path/to/project_root/
npm init
npm install --global gulp-cli
npm install --save-dev del fs gulp gulp-clean-css gulp-htmlmin gulp-if gulp-json-editor gulp-json-minify gulp-pretty-data gulp-rename gulp-replace gulp-uglify gulp-ui5-preload gulp-util
npm install --save-dev gulp-eslint
npm install --save-dev gulp-stylelint gulp-stylelint-checkstyle-reporter
const del = require('del');
const gulp = require('gulp');
gulp.task('cleanDist', () => {
return del(['dist/*']);
});
gulp cleanDist
gulp.task('minify-css', ['cleanDist'], () => {
return gulp.src('webapp/css/*.css')
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(gulp.dest('dist/css'));
});
gulp.task('create-dist', ['ui5preload','minify-css','minify-html']);
// Compress the HTML index.html
gulp.task('minify-html', () => {
return gulp.src('webapp/index.html')
.pipe(replace('/webapp', './'))
.pipe(htmlmin({
caseSensitive: true,
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true
}))
.pipe(gulp.dest('dist'));
});
gulp.task('ui5preload', ['cleanDist'], () => {
// Only the front end UI5 related files are relevant
return gulp.src(['webapp/**/**.+(js|xml)','!webapp/thirdparty/**'])
// only pass .js files to uglify
.pipe(gulpif('**/*.js',uglify()))
// only pass .xml to prettydata
.pipe(gulpif('**/*.xml',prettydata({type:'minify'})))
// Define base path and namespace
.pipe(ui5preload({base:'webapp',namespace:'my.project.ui'}))
// Output the Component-preload.js to the dist folder
.pipe(gulp.dest('dist'));
});
gulp.task('neo-app-json', ['cleanDist'], () => {
return gulp.src('neo-app.json')
.pipe(jsonEditor({
'welcomeFile': '/index.html',
'logoutPage': '/logout/logout.html'
}))
.pipe(gulp.dest('dist'))
});
const del = require('del');
const fs = require('fs');
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const gulpStylelint = require('gulp-stylelint');
const checkstyleReporter = require('gulp-stylelint-checkstyle-reporter').default;
const ui5preload = require('gulp-ui5-preload');
const uglify = require('gulp-uglify');
const prettydata = require('gulp-pretty-data');
const gulpif = require('gulp-if');
const cleanCSS = require('gulp-clean-css');
const replace = require('gulp-replace');
const htmlmin = require('gulp-htmlmin');
const rename = require("gulp-rename");
const jsonMinify = require('gulp-json-minify');
const jsonEditor = require('gulp-json-editor');
// Remove all previous files and logs
gulp.task('cleanReports', () => {
return del(['reports/*']);
});
// Remove all previous files and logs
gulp.task('cleanDist', () => {
return del(['dist/*']);
});
// Ensure there is no Component-preload.js in the src folder
gulp.task('removePreload', () => {
return del(['webapp/Component-preload.js']);
});
gulp.task('clean', ['cleanReports', 'cleanDist', 'removePreload'], () => {
// Create directories if not defined
fs.stat('reports', function(error) {
if (error && error.code === 'ENOENT') {
fs.mkdir('reports');
}
});
fs.stat('reports/checkstyle', function(error) {
if (error && error.code === 'ENOENT') {
fs.mkdir('reports/checkstyle');
}
});
});
// After clean up is done, check the source files with lint tools
gulp.task('eslint', () => {
// ESLint ignores files with 'node_modules' paths.
// So, it's best to have gulp ignore the directory as well.
// Also, Be sure to return the stream from the task;
// Otherwise, the task may end before the stream has finished.
return gulp.src(['{webapp,test}/**/*.js'])
// eslint() attaches the lint output to the 'eslint' property
// of the file object so it can be used by other modules.
.pipe(eslint())
// Format all results at once, at the end
.pipe(eslint.format())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format('checkstyle', fs.createWriteStream('reports/checkstyle/js.xml')))
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError());
});
// CSS Linting
gulp.task('stylelint', () => {
return gulp.src('webapp/css/*.css')
.pipe(gulpStylelint({
failAfterError: true,
reporters: [
{formatter: checkstyleReporter({output: 'reports/checkstyle/css.xml'}), console: false}
],
debug: false
}));
});
// Combine all type of linting into one task.
// All linters will run in parallel
gulp.task('lint', ['eslint', 'stylelint']);
// Create the Component-preload.js task, which will be depended on the lint tasks.
// If one lint tasks exits with an error, the ui5preload task will not be executed
gulp.task('ui5preload', () => {
// Only the front end UI5 related files are relevant
return gulp.src(['webapp/**/**.+(js|xml)'])
// only pass .js files to uglify
.pipe(gulpif('**/*.js',uglify()))
// only pass .xml to prettydata
.pipe(gulpif('**/*.xml',prettydata({type:'minify'})))
// Define base path and namespace
.pipe(ui5preload({base:'webapp',namespace:'sap.hcp.analytics.mco'}))
// Output the Component-preload.js to the dist folder
.pipe(gulp.dest('dist'));
});
// Compress the css file(s)
gulp.task('minify-css', () => {
return gulp.src('webapp/css/*.css')
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(gulp.dest('dist/css'));
});
// Compress the HTML index.html
gulp.task('minify-html', () => {
return gulp.src('webapp/index.html')
.pipe(replace('/webapp', './'))
.pipe(htmlmin({
caseSensitive: true,
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true
}))
.pipe(gulp.dest('dist'));
});
// Compress the json file(s)
gulp.task('minify-json', () => {
return gulp.src('webapp/model/*.json')
.pipe(jsonMinify())
.pipe(gulp.dest('dist/model'))
});
// Change the neo-app.json to productive mode
gulp.task('neo-app-json', () => {
return gulp.src('neo-app.json')
.pipe(jsonEditor({
'welcomeFile': '/index.html',
'logoutPage': '/logout/logout.html'
}))
.pipe(gulp.dest('dist'))
});
// Copy the image files to the dist folder
gulp.task('copy-images', () => {
gulp.src('webapp/img/*')
.pipe(gulp.dest('./dist/img'));
});
//Copy the image files to the dist folder
gulp.task('copy-favicon', () => {
gulp.src('webapp/favicon.ico')
.pipe(gulp.dest('./dist'));
});
// Copy the i18n files to the dist folder
gulp.task('copy-i18n', () => {
gulp.src('webapp/i18n/*.properties')
.pipe(gulp.dest('./dist/i18n'));
});
// Combine compress and copy tasks
gulp.task('create-dist', ['ui5preload','minify-css','minify-html','minify-json','neo-app-json','copy-images','copy-favicon','copy-i18n']);
// Default task which will execute them all in sequence
gulp.task('default', ['create-dist']);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
13 | |
11 | |
10 | |
9 | |
7 | |
7 | |
7 | |
7 | |
6 |