Commit 9c3cd87b by Torkel Ödegaard

more work on two grunt build modes, backend/standalone modes

parent f8ddfec9
...@@ -11,6 +11,19 @@ module.exports = function (grunt) { ...@@ -11,6 +11,19 @@ module.exports = function (grunt) {
docsDir: 'docs/' docsDir: 'docs/'
}; };
config.mode = grunt.option('mode') || 'standalone';
config.modeOptions = {
requirejs: {
paths: { config: '../config.sample' },
excludeConfig: true,
}
};
if (config.mode === 'backend') {
config.modeOptions.requirejs.path = { config: 'components/config' };
config.modeOptions.requirejs.excludeConfig = true;
}
// load plugins // load plugins
require('load-grunt-tasks')(grunt); require('load-grunt-tasks')(grunt);
...@@ -34,5 +47,4 @@ module.exports = function (grunt) { ...@@ -34,5 +47,4 @@ module.exports = function (grunt) {
// pass the config to grunt // pass the config to grunt
grunt.initConfig(config); grunt.initConfig(config);
}; };
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
"dependencies": { "dependencies": {
"grunt-jscs-checker": "^0.4.4", "grunt-jscs-checker": "^0.4.4",
"karma-sinon": "^1.0.3", "karma-sinon": "^1.0.3",
"lodash": "^2.4.1",
"sinon": "^1.10.3" "sinon": "^1.10.3"
} }
} }
...@@ -20,7 +20,7 @@ module.exports = function(grunt) { ...@@ -20,7 +20,7 @@ module.exports = function(grunt) {
'filerev', 'filerev',
'usemin', 'usemin',
'clean:temp', 'clean:temp',
// 'uglify:dest' 'uglify:dest'
]); ]);
grunt.registerTask('build:grafanaVersion', function() { grunt.registerTask('build:grafanaVersion', function() {
......
module.exports = function(config,grunt) { module.exports = function(config,grunt) {
'use strict'; 'use strict';
var _c = { function buildRequireJsOptions() {
build: {
options: {
appDir: '<%= tempDir %>',
dir: '<%= destDir %>',
baseUrl: './app',
mainConfigFile: '<%= tempDir %>/app/components/require.standalone.js', var options = {
modules: [], // populated below, appDir: '<%= tempDir %>',
dir: '<%= destDir %>',
mainConfigFile: '<%= tempDir %>/app/components/require.<%= mode %>.js',
baseUrl: './app',
paths: config.modeOptions.requirejs.paths,
optimize: 'none', modules: [], // populated below,
optimizeCss: 'none',
optimizeAllPluginResources: false,
paths: { config: '../config.sample' }, // fix, fallbacks need to be specified optimize: 'none',
optimizeCss: 'none',
optimizeAllPluginResources: false,
removeCombined: true, removeCombined: true,
findNestedDependencies: true, findNestedDependencies: true,
normalizeDirDefines: 'all', normalizeDirDefines: 'all',
inlineText: true, inlineText: true,
skipPragmas: true, skipPragmas: true,
done: function (done, output) { done: function (done, output) {
var duplicates = require('rjs-build-analysis').duplicates(output); var duplicates = require('rjs-build-analysis').duplicates(output);
if (duplicates.length > 0) { if (duplicates.length > 0) {
grunt.log.subhead('Duplicates found in requirejs build:'); grunt.log.subhead('Duplicates found in requirejs build:');
grunt.log.warn(duplicates); grunt.log.warn(duplicates);
done(new Error('r.js built duplicate modules, please check the excludes option.')); done(new Error('r.js built duplicate modules, please check the excludes option.'));
}
done();
} }
done();
} }
} };
};
// setup the modules require will build // setup the modules require will build
var requireModules = _c.build.options.modules = [ var requireModules = options.modules = [
{ {
// main/common module // main/common module
name: 'app', name: 'app',
include: [ include: [
'css', 'css',
'kbn', 'kbn',
'text', 'text',
'jquery', 'jquery',
'angular', 'angular',
'settings', 'settings',
'bootstrap', 'bootstrap',
'modernizr', 'modernizr',
'timepicker', 'timepicker',
'datepicker', 'datepicker',
'lodash', 'lodash',
'jquery.flot', 'jquery.flot',
'angular-strap', 'angular-strap',
'angular-dragdrop', 'angular-dragdrop',
'services/all', 'services/all',
'features/all', 'features/all',
'directives/all', 'directives/all',
'filters/all', 'filters/all',
'controllers/all', 'controllers/all',
'routes/standalone/all', 'routes/standalone/all',
'routes/backend/all', 'routes/backend/all',
'components/partials', 'components/partials',
] ]
} }
]; ];
var fs = require('fs');
var panelPath = config.srcDir+'/app/panels';
// create a module for each directory in src/app/panels/ var fs = require('fs');
fs.readdirSync(panelPath).forEach(function (panelName) { var panelPath = config.srcDir+'/app/panels';
requireModules[0].include.push('panels/'+panelName+'/module');
requireModules[0].include.push('text!panels/'+panelName+'/module.html');
});
// exclude the literal config definition from all modules // create a module for each directory in src/app/panels/
requireModules fs.readdirSync(panelPath).forEach(function (panelName) {
.forEach(function (module) { requireModules[0].include.push('panels/'+panelName+'/module');
module.excludeShallow = module.excludeShallow || []; requireModules[0].include.push('text!panels/'+panelName+'/module.html');
module.excludeShallow.push('config');
}); });
return _c; if (config.modeOptions.requirejs.excludeConfig) {
// exclude the literal config definition from all modules
requireModules
.forEach(function (module) {
module.excludeShallow = module.excludeShallow || [];
module.excludeShallow.push('config');
});
}
return { options: options };
}
return { build: buildRequireJsOptions() };
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment