2014-09-09 16:52:22 +02:00
|
|
|
var path = require('path');
|
2014-09-11 11:42:30 +02:00
|
|
|
var fs = require('fs');
|
|
|
|
var ini = require('ini');
|
2014-09-09 16:52:22 +02:00
|
|
|
|
2014-09-15 09:03:29 +02:00
|
|
|
var phpCheckStyleConfigPath = path.join(path.resolve(), 'phpcheckstyle.cfg');
|
|
|
|
var phpSourcesDir = path.join(path.resolve(), 'src');
|
|
|
|
var jsSourcesDir = path.join(path.resolve(), 'public_html/js');
|
|
|
|
var cssSourcesDir = path.join(path.resolve(), 'public_html/css');
|
|
|
|
var templatesDir = path.join(path.resolve(), 'public_html/templates');
|
|
|
|
|
|
|
|
var config = readConfig([
|
|
|
|
path.join(path.resolve(), 'data/config.ini'),
|
|
|
|
path.join(path.resolve(), 'data/local.ini')
|
|
|
|
]);
|
|
|
|
|
|
|
|
function readConfig(configPaths) {
|
|
|
|
var iniContent = '';
|
|
|
|
for (var i = 0; i < configPaths.length; i ++) {
|
|
|
|
var configPath = configPaths[i];
|
|
|
|
if (fs.existsSync(configPath)) {
|
|
|
|
iniContent += fs.readFileSync(configPath, 'utf-8');
|
2014-09-11 11:42:30 +02:00
|
|
|
}
|
|
|
|
}
|
2014-09-15 09:03:29 +02:00
|
|
|
var config = ini.parse(iniContent);
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
function readTemplates(grunt) {
|
|
|
|
var templatePaths = grunt.file.expand(templatesDir + '/**/*.tpl');
|
|
|
|
var templates = {};
|
|
|
|
for (var i = 0; i < templatePaths.length; i ++) {
|
|
|
|
var templatePath = templatePaths[i];
|
|
|
|
templates[path.basename(templatePath)] = fs.readFileSync(templatePath);
|
2014-09-11 11:42:30 +02:00
|
|
|
}
|
2014-09-15 09:03:29 +02:00
|
|
|
return templates;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function(grunt) {
|
2014-09-11 11:42:30 +02:00
|
|
|
|
2014-09-09 16:52:22 +02:00
|
|
|
grunt.initConfig({
|
|
|
|
pkg: grunt.file.readJSON('package.json'),
|
|
|
|
|
2014-09-11 11:42:30 +02:00
|
|
|
phpCheckStyleConfigPath: phpCheckStyleConfigPath,
|
|
|
|
phpSourcesDir: phpSourcesDir,
|
|
|
|
jsSourcesDir: jsSourcesDir,
|
|
|
|
cssSourcesDir: cssSourcesDir,
|
|
|
|
|
|
|
|
config: config,
|
2014-09-09 16:52:22 +02:00
|
|
|
|
|
|
|
jshint: {
|
2014-09-11 11:42:30 +02:00
|
|
|
files: [jsSourcesDir + '/**/*.js'],
|
2014-09-09 16:52:22 +02:00
|
|
|
options: {
|
|
|
|
globals: {
|
|
|
|
console: true,
|
|
|
|
module: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
browser:true,
|
|
|
|
latedef: 'nofunc',
|
|
|
|
camelcase: true,
|
|
|
|
eqeqeq: true,
|
|
|
|
curly: true,
|
|
|
|
immed: true,
|
|
|
|
noarg: true,
|
|
|
|
quotmark: 'single',
|
|
|
|
undef: true,
|
|
|
|
unused: 'vars',
|
|
|
|
forin: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
shell: {
|
2014-09-19 13:31:20 +02:00
|
|
|
options: {
|
|
|
|
stdin: false
|
|
|
|
},
|
|
|
|
|
2014-09-09 16:52:22 +02:00
|
|
|
phpcheckstyle: {
|
2014-09-14 12:09:22 +02:00
|
|
|
command: 'php vendor/jbrooksuk/phpcheckstyle/run.php --config <%= phpCheckStyleConfigPath %> --src <%= phpSourcesDir %> --exclude di.php --format console',
|
2014-09-09 16:52:22 +02:00
|
|
|
},
|
2014-09-09 19:10:25 +02:00
|
|
|
|
|
|
|
tests: {
|
2014-09-24 20:13:30 +02:00
|
|
|
command: 'php vendor/phpunit/phpunit/phpunit -v --strict --bootstrap src/AutoLoader.php tests/',
|
2014-09-09 19:10:25 +02:00
|
|
|
},
|
2014-09-14 16:16:15 +02:00
|
|
|
|
|
|
|
upgrade: {
|
2014-09-25 11:51:51 +02:00
|
|
|
command: 'php scripts/upgrade.php',
|
2014-09-14 16:16:15 +02:00
|
|
|
},
|
2014-09-09 16:52:22 +02:00
|
|
|
},
|
2014-09-11 11:42:30 +02:00
|
|
|
|
|
|
|
cssmin: {
|
|
|
|
combine: {
|
|
|
|
files: {
|
|
|
|
'public_html/app.min.css': [cssSourcesDir + '/**/*.css'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
uglify: {
|
|
|
|
dist: {
|
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
},
|
|
|
|
files: {
|
|
|
|
'public_html/app.min.js': [].concat(
|
|
|
|
[jsSourcesDir + '/DI.js'],
|
|
|
|
grunt.file.expand({
|
|
|
|
filter: function(src) {
|
|
|
|
return !src.match(/(DI|Bootstrap)\.js/);
|
|
|
|
}
|
|
|
|
}, jsSourcesDir + '/**/*.js'),
|
|
|
|
[jsSourcesDir + '/Bootstrap.js']),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
processhtml: {
|
|
|
|
options: {
|
|
|
|
data: {
|
|
|
|
serviceName: config.basic.serviceName,
|
2014-09-15 09:03:29 +02:00
|
|
|
templates: readTemplates(grunt),
|
2014-09-11 11:42:30 +02:00
|
|
|
timestamp: grunt.template.today('isoDateTime'),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
dist: {
|
|
|
|
files: {
|
|
|
|
'public_html/app.min.html': ['public_html/index.html']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-09-09 16:52:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
2014-09-11 11:42:30 +02:00
|
|
|
grunt.loadNpmTasks('grunt-processhtml');
|
2014-09-09 16:52:22 +02:00
|
|
|
grunt.loadNpmTasks('grunt-shell');
|
2014-09-11 11:42:30 +02:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-cssmin');
|
|
|
|
|
|
|
|
grunt.registerTask('default', ['checkstyle', 'tests']);
|
|
|
|
grunt.registerTask('checkstyle', ['jshint', 'shell:phpcheckstyle']);
|
2014-09-09 19:10:25 +02:00
|
|
|
grunt.registerTask('tests', ['shell:tests']);
|
2014-09-14 16:16:15 +02:00
|
|
|
grunt.registerTask('update', ['shell:upgrade']);
|
|
|
|
grunt.registerTask('upgrade', ['shell:upgrade']);
|
2014-09-09 16:52:22 +02:00
|
|
|
|
2014-09-11 11:42:30 +02:00
|
|
|
grunt.registerTask('clean', function() {
|
|
|
|
fs.unlink('public_html/app.min.html');
|
|
|
|
fs.unlink('public_html/app.min.js');
|
|
|
|
fs.unlink('public_html/app.min.js.map');
|
|
|
|
fs.unlink('public_html/app.min.css');
|
|
|
|
});
|
|
|
|
grunt.registerTask('build', ['clean', 'uglify', 'cssmin', 'processhtml']);
|
|
|
|
|
2014-09-09 16:52:22 +02:00
|
|
|
};
|