mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
added requirejs phase to build process, broke the plugin task into build + plugin (which runs build)
This commit is contained in:
parent
59e569f845
commit
b5a9c719f3
12 changed files with 188 additions and 42 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ trash
|
|||
src/bower_components/K4D3
|
||||
src/bower_components/elasticsearch
|
||||
build
|
||||
target
|
59
Gruntfile.js
59
Gruntfile.js
|
@ -1,33 +1,42 @@
|
|||
/* jshint node:true */
|
||||
module.exports = function (grunt) {
|
||||
|
||||
// set the config once before calling load-grunt-config
|
||||
// and once durring so that we have access to it via
|
||||
// grunt.config.get() within the config files
|
||||
var config = {
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
root: __dirname,
|
||||
src: __dirname + '/src', // unbuild version of build
|
||||
build: __dirname + '/build', // copy of source, but optimized
|
||||
app: __dirname + '/src/kibana', // source directory for the app
|
||||
target: __dirname + '/target', // location of the compressed build targets
|
||||
buildApp: __dirname + '/build/kibana', // build directory for the app
|
||||
|
||||
unitTestDir: __dirname + '/test/unit',
|
||||
testUtilsDir: __dirname + '/test/utils',
|
||||
bowerComponentsDir: __dirname + '/src/bower_components',
|
||||
|
||||
k4d3Repo: 'git@github.com:elasticsearch/K4D3.git',
|
||||
k4d3Dir: '<%= bowerComponentsDir %>/K4D3',
|
||||
esjsRepo: 'git@github.com:elasticsearch/elasticsearch-js.git',
|
||||
esjsDir: '<%= bowerComponentsDir %>/elasticsearch',
|
||||
|
||||
meta: {
|
||||
banner: '/*! <%= package.name %> - v<%= package.version %> - ' +
|
||||
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
|
||||
'<%= package.homepage ? " * " + package.homepage + "\\n" : "" %>' +
|
||||
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= package.author.company %>;' +
|
||||
' Licensed <%= package.license %> */\n'
|
||||
}
|
||||
};
|
||||
|
||||
grunt.config.merge(config);
|
||||
|
||||
// load plugins
|
||||
require('load-grunt-config')(grunt, {
|
||||
configPath: __dirname + '/tasks/config',
|
||||
init: true,
|
||||
config: {
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
root: __dirname,
|
||||
src: __dirname + '/src',
|
||||
app: __dirname + '/src/kibana',
|
||||
build: __dirname + '/build',
|
||||
|
||||
unitTestDir: __dirname + '/test/unit',
|
||||
testUtilsDir: __dirname + '/test/utils',
|
||||
bowerComponentsDir: __dirname + '/src/bower_components',
|
||||
|
||||
k4d3Repo: 'git@github.com:elasticsearch/K4D3.git',
|
||||
k4d3Dir: '<%= bowerComponentsDir %>/K4D3',
|
||||
esjsRepo: 'git@github.com:elasticsearch/elasticsearch-js.git',
|
||||
esjsDir: '<%= bowerComponentsDir %>/elasticsearch',
|
||||
|
||||
meta: {
|
||||
banner: '/*! <%= package.name %> - v<%= package.version %> - ' +
|
||||
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
|
||||
'<%= package.homepage ? " * " + package.homepage + "\\n" : "" %>' +
|
||||
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= package.author.company %>;' +
|
||||
' Licensed <%= package.license %> */\n'
|
||||
}
|
||||
}
|
||||
config: config
|
||||
});
|
||||
|
||||
// load task definitions
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
"requirejs": "~2.1.10",
|
||||
"angular": "~1.2.14",
|
||||
"lodash": "~2.4.1",
|
||||
"d3": "~3.4.1",
|
||||
"angular-route": "~1.2.14",
|
||||
"gridster": "~0.5.0",
|
||||
"angular-mocks": "~1.2.14",
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
"event-stream": "~3.1.5",
|
||||
"expect.js": "~0.2.0",
|
||||
"grunt": "~0.4.2",
|
||||
"grunt-contrib-clean": "~0.5.0",
|
||||
"grunt-contrib-compress": "~0.9.1",
|
||||
"grunt-contrib-copy": "~0.5.0",
|
||||
"grunt-contrib-jade": "~0.10.0",
|
||||
"grunt-contrib-jshint": "~0.8.0",
|
||||
"grunt-contrib-less": "~0.10.0",
|
||||
|
@ -22,8 +25,8 @@
|
|||
"load-grunt-config": "~0.7.0",
|
||||
"lodash": "~2.4.1",
|
||||
"mocha": "~1.17.1",
|
||||
"grunt-contrib-compress": "~0.9.1",
|
||||
"grunt-contrib-copy": "~0.5.0"
|
||||
"requirejs": "~2.1.14",
|
||||
"rjs-build-analysis": "0.0.3"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "grunt test",
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
<meta name="viewport" content="width=device-width">
|
||||
<title>Kibana 4</title>
|
||||
<!-- load the root require context -->
|
||||
<script src="bower_components/d3/d3.js"></script>
|
||||
|
||||
<script src="bower_components/requirejs/require.js"></script>
|
||||
|
||||
<script src="kibana/require.config.js"></script>
|
||||
|
|
12
tasks/build.js
Normal file
12
tasks/build.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
module.exports = function (grunt) {
|
||||
grunt.registerTask('build', [
|
||||
'clean:target',
|
||||
'clean:build',
|
||||
'require_css_deps:copy',
|
||||
'less',
|
||||
'requirejs',
|
||||
'clean:unneeded_source_in_build',
|
||||
'compress:build_zip',
|
||||
'compress:build_tarball'
|
||||
]);
|
||||
};
|
30
tasks/config/clean.js
Normal file
30
tasks/config/clean.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
module.exports = function (grunt) {
|
||||
var notIncludedComponents = '{K4D3,font-awesome,requirejs}';
|
||||
return {
|
||||
build: '<%= build %>',
|
||||
target: '<%= target %>',
|
||||
unneeded_source_in_build: {
|
||||
src: [
|
||||
// select all top level folders in bower_components
|
||||
'<%= build %>/bower_components/*',
|
||||
// exclude the following top level components
|
||||
'!<%= build %>/bower_components/' + notIncludedComponents,
|
||||
|
||||
// remove the contents of K4D3, font-awesome, and requirejs except necessary files
|
||||
'<%= build %>/bower_components/' + notIncludedComponents + '/*',
|
||||
'!<%= build %>/bower_components/K4D3/build',
|
||||
'!<%= build %>/bower_components/requirejs/require.js',
|
||||
'!<%= build %>/bower_components/font-awesome/fonts',
|
||||
|
||||
// remove extra builds from K4D3
|
||||
'<%= build %>/bower_components/K4D3/build/*',
|
||||
'!<%= build %>/bower_components/K4D3/build/k4.d3.js',
|
||||
|
||||
'<%= build %>/**/_empty_',
|
||||
'<%= build %>/**/*.less',
|
||||
'<%= appBuild %>/{css-builder,normalize}.js',
|
||||
'<%= app %>/{css-builder,normalize}.js',
|
||||
]
|
||||
}
|
||||
};
|
||||
};
|
|
@ -1,17 +1,26 @@
|
|||
module.exports = function (config) {
|
||||
return {
|
||||
plugin: {
|
||||
module.exports = function (grunt) {
|
||||
var _ = require('lodash');
|
||||
var archiveName = function (plugin) {
|
||||
return '<%= target %>/<%= pkg.name %>-' + (plugin ? 'plugin-' : '') + '<%= pkg.version %>';
|
||||
};
|
||||
|
||||
return _.mapValues({
|
||||
build_zip: archiveName() + '.zip',
|
||||
build_tarball: archiveName() + '.zip',
|
||||
plugin: archiveName(true) + '.tar.gz'
|
||||
}, function (filename, task) {
|
||||
return {
|
||||
options: {
|
||||
archive: '<%= build %>/<%= pkg.name %>-plugin-<%= pkg.version %>.tar.gz'
|
||||
archive: filename
|
||||
},
|
||||
files : [
|
||||
files: [
|
||||
{
|
||||
expand: true,
|
||||
cwd: 'src',
|
||||
cwd: '<%= build %>',
|
||||
src: ['**/*'],
|
||||
dest: '<%= pkg.name %>/_site'
|
||||
dest: '<%= pkg.name %>' + (task === 'plugin' ? '/_site' : '')
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = function (config) {
|
||||
module.exports = function (grunt) {
|
||||
return {
|
||||
// just lint the source dir
|
||||
source: {
|
||||
|
|
70
tasks/config/requirejs.js
Normal file
70
tasks/config/requirejs.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
module.exports = function (grunt) {
|
||||
var config = {
|
||||
build: {
|
||||
options: {
|
||||
appDir: '<%= src %>',
|
||||
dir: '<%= build %>',
|
||||
mainConfigFile: '<%= app %>/require.config.js',
|
||||
modules: [
|
||||
{
|
||||
name: 'kibana',
|
||||
excludeShallow: [
|
||||
'../config',
|
||||
'k4d3'
|
||||
],
|
||||
include: [
|
||||
'controllers/kibana'
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
optimize: 'none',
|
||||
optimizeCss: 'none',
|
||||
optimizeAllPluginResources: false,
|
||||
|
||||
removeCombined: true,
|
||||
findNestedDependencies: true,
|
||||
normalizeDirDefines: 'all',
|
||||
inlineText: true,
|
||||
skipPragmas: true,
|
||||
|
||||
done: function (done, output) {
|
||||
var analysis = require('rjs-build-analysis');
|
||||
var tree = analysis.parse(output);
|
||||
var duplicates = analysis.duplicates(tree);
|
||||
|
||||
if (duplicates.length > 0) {
|
||||
grunt.log.subhead('Duplicates found in requirejs build:');
|
||||
grunt.log.warn(duplicates);
|
||||
return done(new Error('r.js built duplicate modules, please check the excludes option.'));
|
||||
} else {
|
||||
var relative = [];
|
||||
var bundles = tree.bundles || [];
|
||||
bundles.forEach(function (bundle) {
|
||||
bundle.children.forEach(function (child) {
|
||||
if (child.match(/\.\.\//)) relative.push(child + ' is relative to ' + bundle.parent);
|
||||
});
|
||||
});
|
||||
|
||||
if (relative.length) {
|
||||
grunt.log.subhead('Relative modules found in requirejs build:');
|
||||
grunt.log.warn(relative);
|
||||
return done(new Error('r.js build contains relative modules, duplicates probably exist'));
|
||||
}
|
||||
}
|
||||
|
||||
done();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// include each app
|
||||
var main = config.build.options.modules[0];
|
||||
var configFile = require('requirejs')(grunt.config.get('src') + '/config.js');
|
||||
configFile.apps.forEach(function (app) {
|
||||
main.include.push('apps/' + app.id + '/index');
|
||||
});
|
||||
|
||||
return config;
|
||||
};
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = function (grunt) {
|
||||
grunt.registerTask('plugin', [
|
||||
'less',
|
||||
'compress'
|
||||
'build',
|
||||
'compress:plugin'
|
||||
]);
|
||||
};
|
15
tasks/require_css_deps.js
Normal file
15
tasks/require_css_deps.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
module.exports = function (grunt) {
|
||||
var join = require('path').join;
|
||||
|
||||
grunt.registerTask('require_css_deps:copy', function () {
|
||||
[
|
||||
'css-builder.js',
|
||||
'normalize.js'
|
||||
].forEach(function (dep) {
|
||||
grunt.file.copy(
|
||||
join(grunt.config.get('bowerComponentsDir'), 'require-css', dep),
|
||||
join(grunt.config.get('app'), dep)
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue