web-apps/build/Gruntfile.js

396 lines
14 KiB
JavaScript
Raw Normal View History

2016-03-11 00:48:53 +00:00
module.exports = function(grunt) {
var _ = require('lodash'),
defaultConfig,
packageFile;
2016-03-11 00:48:53 +00:00
2017-01-13 15:35:56 +00:00
var copyright = '/*\n' +
' * Copyright (c) Ascensio System SIA <%= grunt.template.today("yyyy") %>. All rights reserved\n' +
' *\n' +
' * <%= pkg.homepage %> \n' +
' *\n' +
2017-01-25 16:30:08 +00:00
' * Version: <%= pkg.version %> (build:<%= pkg.build %>)\n' +
2017-01-13 15:35:56 +00:00
' */\n';
2016-03-11 00:48:53 +00:00
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
2016-03-11 00:48:53 +00:00
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-mocha');
function doRegisterTask(name, callbackConfig) {
return grunt.registerTask(name + '-init', function() {
var additionalConfig = {},
initConfig = {};
if (_.isFunction(callbackConfig)) {
additionalConfig = callbackConfig.call(this, defaultConfig, packageFile);
}
if (!_.isUndefined(packageFile[name]['clean'])) {
initConfig['clean'] = {
options: {
force: true
},
files: packageFile[name]['clean']
}
}
if (!_.isUndefined(packageFile[name]['copy'])) {
initConfig['copy'] = packageFile[name]['copy'];
}
grunt.initConfig(_.assign(initConfig, additionalConfig || {}));
});
}
function doRegisterInitializeAppTask(name, appName, configFile) {
return grunt.registerTask('init-build-' + name, 'Initialize build ' + appName, function(){
defaultConfig = configFile;
packageFile = require('./' + defaultConfig);
if (packageFile)
grunt.log.ok(appName + ' config loaded successfully'.green);
else
grunt.log.error().writeln('Could not load config file'.red);
});
}
grunt.initConfig({
mocha: {
test: {
options: {
reporter: 'Spec'
},
src: [
'../test/common/index.html'
]
}
},
jshint: {
options: {
curly: true,
eqeqeq: true,
eqnull: true,
browser: true,
globals: {
jQuery: true
},
force: true
},
common: ['../apps/common/main/lib/**/*.js']
}
});
doRegisterTask('sdk');
doRegisterTask('api', function(defaultConfig, packageFile){
// var pkg = grunt.file.readJSON(defaultConfig);
// var config = { copy: pkg['api']['copy'] };
// config.copy.options = {
// process: function(content, src, dest) {
// if (/api\.js$/.test(src)) {
// return content.replace(/(\#{2}BN\#)/, "." + (process.env['BUILD_NUMBER'] || packageFile.build));
// }
// return content;
// }
// };
// return config;
});
doRegisterTask('sockjs');
doRegisterTask('xregexp');
doRegisterTask('megapixel');
doRegisterTask('jquery');
doRegisterTask('underscore');
doRegisterTask('zeroclipboard');
doRegisterTask('bootstrap');
doRegisterTask('jszip');
doRegisterTask('jsziputils');
doRegisterTask('jsrsasign');
doRegisterTask('requirejs', function(defaultConfig, packageFile) {
return {
uglify: {
2017-01-25 16:30:08 +00:00
pkg: packageFile,
2016-03-11 00:48:53 +00:00
options: {
banner: '/** vim: et:ts=4:sw=4:sts=4\n' +
' * @license RequireJS 2.1.2 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.\n' +
' * Available via the MIT or new BSD license.\n' +
' * see: http://github.com/jrburke/requirejs for details\n' +
' */\n'
},
build: {
src: packageFile['requirejs']['min']['src'],
dest: packageFile['requirejs']['min']['dest']
}
}
}
});
grunt.registerTask('main-app-init', function() {
grunt.initConfig({
2017-01-25 16:30:08 +00:00
pkg: packageFile,
2016-03-11 00:48:53 +00:00
clean: {
options: {
force: true
},
files: packageFile['main']['clean']
},
less: {
production: {
options: {
compress: true,
2016-11-10 11:57:07 +00:00
ieCompat: false,
modifyVars: packageFile['main']['less']['vars'],
2016-03-11 00:48:53 +00:00
plugins: [
2016-11-10 11:57:07 +00:00
new (require('less-plugin-clean-css'))()
2016-03-11 00:48:53 +00:00
]
},
files: {
"<%= pkg.main.less.files.dest %>": packageFile['main']['less']['files']['src']
}
}
},
requirejs: {
compile: {
options: packageFile['main']['js']['requirejs']['options']
}
},
replace: {
2016-11-10 11:57:07 +00:00
writeVersion: {
2017-01-25 16:30:08 +00:00
src: ['<%= pkg.api.copy.script.dest %>' + '/documents/api.js',
'<%= pkg.main.js.requirejs.options.out %>'],
2016-03-11 00:48:53 +00:00
overwrite: true,
2016-11-10 11:57:07 +00:00
replacements: [{
2017-01-25 16:30:08 +00:00
from: /\{\{PRODUCT_VERSION\}\}/,
2016-11-10 11:57:07 +00:00
to: function(matchedWord, index, fullText, regexMatches) {
2017-01-25 16:30:08 +00:00
return packageFile.version;
2016-11-10 11:57:07 +00:00
}
}]
2016-03-11 00:48:53 +00:00
}
},
concat: {
options: {
stripBanners: true,
2017-01-13 15:35:56 +00:00
banner: copyright
2016-03-11 00:48:53 +00:00
},
dist: {
src: [packageFile['main']['js']['requirejs']['options']['out']],
dest: packageFile['main']['js']['requirejs']['options']['out']
}
},
imagemin: {
options: {
optimizationLevel: 3
},
dynamic: {
files: []
.concat(packageFile['main']['imagemin']['images-app'])
.concat(packageFile['main']['imagemin']['images-common'])
}
},
copy: {
localization: {
files: packageFile['main']['copy']['localization']
},
help: {
files: packageFile['main']['copy']['help']
},
'index-page': {
files: packageFile['main']['copy']['index-page']
}
}
});
});
grunt.registerTask('mobile-app-init', function() {
grunt.initConfig({
2017-01-25 16:30:08 +00:00
pkg: packageFile,
2016-03-11 00:48:53 +00:00
clean: {
options: {
force: true
},
'deploy': packageFile['mobile']['clean']['deploy'],
2017-01-13 15:35:56 +00:00
'template-backup': packageFile.mobile.copy['template-backup'][0].dest
},
requirejs: {
compile: {
options: packageFile['mobile']['js']['requirejs']['options']
}
2016-03-11 00:48:53 +00:00
},
2017-01-13 15:35:56 +00:00
concat: {
2016-03-11 00:48:53 +00:00
options: {
2017-01-13 15:35:56 +00:00
stripBanners: true,
banner: copyright
2016-03-11 00:48:53 +00:00
},
2017-01-13 15:35:56 +00:00
dist: {
src: packageFile.mobile.js.requirejs.options.out,
dest: packageFile.mobile.js.requirejs.options.out
2016-03-11 00:48:53 +00:00
}
},
cssmin: {
styles: {
files: {
"<%= pkg.mobile.css.ios.dist %>" : packageFile['mobile']['css']['ios']['src'],
"<%= pkg.mobile.css.material.dist %>" : packageFile['mobile']['css']['material']['src']
2016-03-11 00:48:53 +00:00
}
}
},
htmlmin: {
dist: {
options: {
removeComments: true,
collapseWhitespace: true
},
files: packageFile['mobile']['htmlmin']['templates']
}
},
2016-03-11 00:48:53 +00:00
copy: {
'template-backup': {
files: packageFile['mobile']['copy']['template-backup']
},
'template-restore': {
files: packageFile['mobile']['copy']['template-restore']
},
'localization': {
2016-03-11 00:48:53 +00:00
files: packageFile['mobile']['copy']['localization']
},
'index-page': {
files: packageFile['mobile']['copy']['index-page']
},
'images-app': {
files: packageFile['mobile']['copy']['images-app']
}
2017-01-25 16:30:08 +00:00
},
replace: {
writeVersion: {
src: ['<%= pkg.mobile.js.requirejs.options.out %>'],
overwrite: true,
replacements: [{
from: /\{\{PRODUCT_VERSION\}\}/,
to: function(matchedWord, index, fullText, regexMatches) {
return packageFile.version;
}
}]
}
2016-03-11 00:48:53 +00:00
}
});
});
grunt.registerTask('embed-app-init', function() {
grunt.initConfig({
2017-01-25 16:30:08 +00:00
pkg: packageFile,
2016-03-11 00:48:53 +00:00
clean: {
options: {
force: true
},
2016-11-08 12:22:15 +00:00
postbuild: packageFile['embed']['clean']['postbuild'],
prebuild: packageFile['embed']['clean']['prebuild']
2016-03-11 00:48:53 +00:00
},
uglify: {
options: {
2017-01-13 15:35:56 +00:00
banner: copyright
2016-03-11 00:48:53 +00:00
},
build: {
src: packageFile['embed']['js']['src'],
dest: packageFile['embed']['js']['dist']
}
},
less: {
production: {
options: {
2016-11-08 12:22:15 +00:00
compress: true,
ieCompat: false
2016-03-11 00:48:53 +00:00
},
files: {
"<%= pkg.embed.less.files.dist %>": packageFile['embed']['less']['files']['src']
}
}
},
copy: {
'index-page': {
files: packageFile['embed']['copy']['index-page']
},
'images-app': {
files: packageFile['embed']['copy']['images-app']
}
}
});
});
grunt.registerTask('increment-build', function() {
var pkg = grunt.file.readJSON(defaultConfig);
pkg.build = parseInt(pkg.build) + 1;
2017-01-25 16:30:08 +00:00
packageFile.version = (process.env['PRODUCT_VERSION'] || pkg.version);
packageFile.build = (process.env['BUILD_NUMBER'] || pkg.build);
2016-03-11 00:48:53 +00:00
grunt.file.write(defaultConfig, JSON.stringify(pkg, null, 4));
});
grunt.registerTask('deploy-api', ['api-init', 'clean', 'copy']);
grunt.registerTask('deploy-sdk', ['sdk-init', 'clean', 'copy']);
grunt.registerTask('deploy-sockjs', ['sockjs-init', 'clean', 'copy']);
grunt.registerTask('deploy-xregexp', ['xregexp-init', 'clean', 'copy']);
grunt.registerTask('deploy-megapixel', ['megapixel-init', 'clean', 'copy']);
grunt.registerTask('deploy-jquery', ['jquery-init', 'clean', 'copy']);
grunt.registerTask('deploy-underscore', ['underscore-init', 'clean', 'copy']);
grunt.registerTask('deploy-bootstrap', ['bootstrap-init', 'clean', 'copy']);
grunt.registerTask('deploy-jszip', ['jszip-init', 'clean', 'copy']);
grunt.registerTask('deploy-jsziputils', ['jsziputils-init', 'clean', 'copy']);
grunt.registerTask('deploy-jsrsasign', ['jsrsasign-init', 'clean', 'copy']);
grunt.registerTask('deploy-requirejs', ['requirejs-init', 'clean', 'uglify']);
2016-11-10 11:57:07 +00:00
grunt.registerTask('deploy-app-main', ['main-app-init', 'clean', 'imagemin', 'less', 'requirejs', 'concat', 'copy', 'replace:writeVersion']);
2017-01-25 16:30:08 +00:00
grunt.registerTask('deploy-app-mobile', ['mobile-app-init', 'clean:deploy', 'cssmin:styles', 'copy:template-backup', 'htmlmin', 'requirejs', 'concat', 'copy:template-restore', 'clean:template-backup', 'copy:localization', 'copy:index-page', 'copy:images-app', 'replace:writeVersion']);
2016-11-10 13:03:40 +00:00
grunt.registerTask('deploy-app-embed', ['embed-app-init', 'clean:prebuild', 'uglify', 'less', 'copy', 'clean:postbuild']);
2016-03-11 00:48:53 +00:00
doRegisterInitializeAppTask('documenteditor', 'DocumentEditor', 'documenteditor.json');
doRegisterInitializeAppTask('spreadsheeteditor', 'SpreadsheetEditor', 'spreadsheeteditor.json');
doRegisterInitializeAppTask('presentationeditor', 'PresentationEditor', 'presentationeditor.json');
grunt.registerTask('deploy-app', 'Deploy application.', function(){
if (packageFile) {
if (packageFile['tasks']['deploy'])
grunt.task.run(packageFile['tasks']['deploy']);
else
grunt.log.error().writeln('Not found "deploy" task in configure'.red);
} else {
grunt.log.error().writeln('Is not load configure file.'.red);
}
});
grunt.registerTask('deploy-documenteditor', ['init-build-documenteditor', 'deploy-app']);
grunt.registerTask('deploy-spreadsheeteditor', ['init-build-spreadsheeteditor', 'deploy-app']);
grunt.registerTask('deploy-presentationeditor', ['init-build-presentationeditor', 'deploy-app']);
2016-03-11 00:48:53 +00:00
grunt.registerTask('default', ['deploy-documenteditor', 'deploy-spreadsheeteditor', 'deploy-presentationeditor']);
};