This repository has been archived by the owner on Aug 8, 2021. It is now read-only.
/
app.js
163 lines (129 loc) · 4.62 KB
/
app.js
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Generated by CoffeeScript 1.9.3
/*
This is main entry point for Clinch - API and setting here
*/
(function() {
var Clinch, DIContainer, _,
slice = [].slice;
_ = require('lodash');
DIContainer = require("./di_container");
module.exports = Clinch = (function() {
function Clinch(_options_) {
this._options_ = _options_ != null ? _options_ : {};
this._do_logging_ = !!this._options_.log;
this._di_cont_obj_ = new DIContainer();
this._configureComponents();
}
/*
This method create browser package with given configuration
actually its just proxy all to packer
*/
Clinch.prototype.buildPackage = function() {
var i, in_settings, main_cb, packer;
in_settings = 2 <= arguments.length ? slice.call(arguments, 0, i = arguments.length - 1) : (i = 0, []), main_cb = arguments[i++];
packer = this._di_cont_obj_.getComponent('Packer');
return packer.buildPackage(this._composePackageSettings(in_settings), main_cb);
};
/*
Silly mistype, will be deprecated soon
*/
Clinch.prototype.buldPackage = function() {
console.info("Depricated! use 'clinch.buildPackage' instead (sorry for mistype)");
return this.buildPackage.apply(this, arguments);
};
/*
This method force flush all caches
yes, we are have three different caches
*/
Clinch.prototype.flushCache = function() {
var component_name, i, len, ref;
ref = ['FileLoader', 'FileProcessor', 'Gatherer'];
for (i = 0, len = ref.length; i < len; i++) {
component_name = ref[i];
this._di_cont_obj_.getComponent(component_name).resetCaches();
null;
}
return null;
};
/*
This method may return list of all files, used in package
may be used for `watch` functionality on those files
*/
Clinch.prototype.getPackageFilesList = function(package_config, main_cb) {
var bundler;
bundler = this._di_cont_obj_.getComponent('BundleProcessor');
return bundler.buildRawPackageData(package_config, function(err, raw_data) {
if (err) {
return main_cb(err);
}
return main_cb(null, _.keys(bundler.joinBundleSets(raw_data).names_map));
});
};
/*
This method add separate clinch plugin, just shortcut
*/
Clinch.prototype.addPlugin = function(arg) {
var extension, processor;
extension = arg.extension, processor = arg.processor;
return this.registerProcessor(extension, processor);
};
/*
This method add third party file processor to Clinch
*/
Clinch.prototype.registerProcessor = function(file_extention, processor_fn) {
var processor_obj;
if (!_.isString(file_extention)) {
throw TypeError("file extension must be a String but get |" + file_extention + "|");
}
if (!_.isFunction(processor_fn)) {
throw TypeError("processor must be a Function but get |" + processor_fn + "|");
}
processor_obj = {};
processor_obj[file_extention] = processor_fn;
this._di_cont_obj_.addComponentsSettings('FileProcessor', 'third_party_compilers', processor_obj);
return this;
};
/*
This internal method used to configure components in DiC
*/
Clinch.prototype._configureComponents = function() {
/*
set packer settings, default setting are
strict : on
inject : on
runtime : off
cache_modules : on
*/
var i, len, packer_settings, ref, setting_name;
packer_settings = {
log: !!this._options_.log
};
ref = ['strict', 'inject', 'runtime', 'cache_modules'];
for (i = 0, len = ref.length; i < len; i++) {
setting_name = ref[i];
if (this._options_[setting_name] != null) {
packer_settings[setting_name] = this._options_[setting_name];
}
}
this._di_cont_obj_.setComponentsSettings({
Packer: packer_settings
});
return null;
};
/*
This internal method to compose bundle settings from package_name, package_config
backward compatibility and new feature in one place
*/
Clinch.prototype._composePackageSettings = function(in_settings) {
var package_config, package_name;
in_settings.reverse();
package_config = in_settings[0], package_name = in_settings[1];
if ((package_name != null) && (package_config.package_name == null)) {
console.info('Depricated! Use "package_name" in package_config instead!');
package_config.package_name = package_name;
}
return package_config;
};
return Clinch;
})();
}).call(this);