1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#!/usr/bin/env node
/*
* We aggregate and minimize the JavaScript sources in order to improve the
* load speed of the application.
*
* We don't want to use the YUI combo loader feature because we want to be able
* to run from only static files and we want to be able to run behind a
* firewall without access to the internet.
*
* The final product will provide three JavaScript files: one for the YUI
* dependencies, one for our custom JavaScript code and one for third party
* JavaScript like D3.
*
* Known issues:
* (1) If we set "bootstrap=false" in the GlobalConfig object, YUI disables the
* loader object. It means it will not even try to download modules. We
* cannot do it because the loader also manages the "use" property which
* defines aliases for some of your modules ('juju-views' and
* 'juju-controllers').
* (2) During development, we've noticed that some of the YUI modules weren't
* included in the list of YUI files (lang/datatype-date-format_en-US,
* parallel, app-transitions-native, gallery-markdown, loader-base). For
* some reason, the loader does not resolve the names of the files for
* these modules. We need to add them manually in this file.
*/
'use strict';
require('yui').YUI().use(['yui'], function(Y) {
var merge = require('../lib/merge-files.js');
var syspath = require('path');
// First we find all of the paths to our custom Javascript in the app
// directory. We need to tell the function to ignore the "assets" directory
// and the debug version of the modules file. I need to use
// "syspath.join(process.cwd(), ...)" or else I have... "Error: Cannot find
// module 'app/config.js'" from node's internal module.js file.
// config-[prod|debug].js should also be passed in the ignore list: these
// files are included in index.html separately as part of charm
// configuration, and should not also be included in the minification.
var paths = merge.readdir(syspath.join(process.cwd(), 'app'),
[syspath.join(process.cwd(), 'app/assets'),
syspath.join(process.cwd(), 'app/modules-debug.js'),
syspath.join(process.cwd(), 'app/config-prod.js'),
syspath.join(process.cwd(), 'app/config-debug.js')]);
// templates.js is a generated file. It is not part of the app directory.
paths.push(syspath.join(process.cwd(), 'build-shared/juju-ui/templates.js'));
merge.combineJs(paths, 'build-shared/juju-ui/assets/modules.js');
// Get the paths to the YUI modules that we use.
var reqs = merge.loadRequires(paths);
// For some reason the loader does not get these requirements.
// (Known issue #2)
reqs.push('lang/datatype-date-format_en-US');
reqs.push('parallel');
reqs.push('app-transitions-native');
reqs.push('gallery-markdown');
reqs.push('gallery-ellipsis');
reqs.push('gallery-timer');
reqs.push('loader-base');
reqs.push('tabview');
// Get all of the YUI files and their dependencies
var filesToLoad = merge.getYUIFiles(reqs);
// Merge third-party files to the filesToLoad list
filesToLoad.js.push.apply(filesToLoad.js, [
'app/assets/javascripts/app-subapp-extension.js',
'app/assets/javascripts/d3-components.js',
'app/assets/javascripts/d3.v2.min.js',
'app/assets/javascripts/ns-routing-app-extension.js',
'app/assets/javascripts/gallery-ellipsis.js',
'app/assets/javascripts/gallery-markdown.js',
'app/assets/javascripts/gallery-timer.js',
'app/assets/javascripts/js-yaml.min.js',
'app/assets/javascripts/event-tracker.js',
'app/assets/javascripts/prettify.js',
'app/assets/javascripts/reconnecting-websocket.js',
'app/assets/javascripts/resizing_textarea.js',
'app/assets/javascripts/sub-app.js'
]);
merge.combineJs(filesToLoad.js, 'build-shared/juju-ui/assets/all-yui.js');
var cssFiles = filesToLoad.css;
cssFiles.push('app/assets/stylesheets/bootstrap-2.0.4.css');
cssFiles.push('app/assets/stylesheets/bootstrap-responsive-2.0.4.css');
cssFiles.push('app/assets/stylesheets/prettify.css');
cssFiles.push('app/assets/stylesheets/cssgrids-responsive-min.css');
merge.combineCSS(cssFiles,
'build-shared/juju-ui/assets/combined-css/all-static.css');
});
|