-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrad
executable file
·135 lines (111 loc) · 3.78 KB
/
rad
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env node
var requirejs = require('requirejs'),
util = require('util'),
_ = require('lodash'),
path = require('path'),
fs = require('fs-extra'),
glob = require('globule');
if( _.isUndefined(process.argv[2]) || process.argv.length < 2){
exit(1);
}
var target = process.argv[2];
function dump(val) {
process.stdout.write(util.inspect(val, {hidden: true, colors: true, depth: 5}));
}
function getMainConfig() {
GLOBAL.window = {};
GLOBAL._ = _;
require('./src/scripts/config');
var rjsConfig = {};
Object.keys(GLOBAL.window.packadic.config.requireJS).forEach(function (k) {
rjsConfig[k] = GLOBAL.window.packadic.config.requireJS[k];
});
delete GLOBAL.window;
return rjsConfig;
}
var rconfig = getMainConfig();
var config = {
paths : rconfig.paths,
shim : rconfig.shim,
modules : [
{name: "vendor/ace-editor"},
{
name: 'boot', include: [
'jquery', 'plugins/async', 'autoload', 'string', 'jade', 'code-mirror',
'plugins/cookie', 'theme', 'theme/sidebar',
'templates/sidebar', 'templates/alert', 'templates/box', 'templates/table',
'eventer', 'plugins/bs-material-ripples', 'storage', 'json',
'fn/defined', 'fn/default', 'fn/cre', 'Q'
]
},
{
name : 'demo',
exclude: ['boot'],
include: ['demo/show-html', 'demo/show-class', 'demo/forms', 'demo/button-icon-showcase', 'demo/component-editor']
}
],
dir : target + "/assets/scripts", // to
optimizeCss : false,
uglify : "uglify",
//allowSourceOverwrites: true,
skipDirOptimize : true,
preserveLicenseComments : false,
removeCombined : true,
optimizeAllPluginResources: true,
onModuleBundleComplete: function (data) {
console.log('onModuleBundleComplete', data.name, data.path);
},
onBuildWrite: function (moduleName, path, contents) {
console.log('onBuildWrite', moduleName, path);
return contents;
}
};
config.baseUrl = config.dir + '_base';
if(fs.existsSync(config.baseUrl)){
fs.emptydirSync(config.baseUrl);
}
fs.copySync(config.dir, config.baseUrl);
function addIgnoreDir(path) {
config.paths[path] = 'empty:'; // mind the :
}
delete config.paths['plugins/select2css'];
delete config.paths['plugins/highlightjscss'];
delete config.shim['plugins/select2'];
delete config.shim['plugins/highlightjs'];
requirejs.optimize(config, function (asdf) { console.log(asdf); });
if(config.skipDirOptimize === true) { // we skip slow ass rjs optimize and do it ourselfs
var uglify = require('uglify-js');
var files = [];
_.each(config.paths, function (filePath, b) {
if ( filePath.indexOf('.min') > - 1 ) { // is a minified file, skip
return;
} else {
var checkPath = path.join(config.dir, filePath);
var found = glob.find(
[
checkPath + '*.js', '!' + checkPath + '*.min.js',
checkPath + '**/*.js', '!' + checkPath + '**/*.min.js'
]
);
if(found.length > 0) {
files = files.concat(found);
}
}
});
files.forEach(function(file){
if(file.indexOf('oauth2.js') > -1){
return;
}
try {
var result = uglify.minify(file);
fs.unlink(file);
fs.writeFile(file, result.code);
console.log('Minified ', file);
}catch(e){
console.log(file, e);
}
})
}
if(fs.existsSync(config.baseUrl)){
fs.emptydirSync(config.baseUrl);
}