Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / jsbuilder / src / Build.js
1 Loader.require('Parser');
2
3 Build = Ext.extend(Target, {
4     getDefaultTarget : function() {
5         return (this.get('id') || this.get('name').replace(/ /g, '').toLowerCase()) + '.js';
6     },
7
8     onCreate: function(file) {
9         Build.superclass.onCreate.apply(this, arguments);
10
11         var project = this.project,
12             verbose = project.builder.get('verbose'),
13             packages = this.get('packages') || [];
14
15         if (verbose && packages.length) {
16             Logger.log('  - ' + packages.length + ' package(s) included in this target.');
17         }
18
19         // Loop over all file includes, read the contents, and write
20         // it to our target file
21         packages.forEach(function(id) {
22             var pkg = this.project.getPackageById(id),
23                 content;
24
25             if (!pkg) {
26                 return true;
27             }
28
29             if (verbose) {
30                 Logger.log('    + ' + pkg.get('target'));
31             }
32
33             pkg = new Stream(pkg.get('targetPath'));
34             content = pkg.readFile();
35             pkg.close();
36
37             file.writeln(content);
38             return true;
39         }, this);
40     },
41
42     afterCreate : function() {
43         var params = Ext.apply({debug: this.get('debug'), debugLevel: 1}, this.get('options') || {});
44
45         Logger.log('  * Parse ' + this.get('target') + ' with options:');
46
47         Ext.iterate(params, function(n, v) {
48             Logger.log('    - ' + n + ": " + v);
49         });
50
51         Parser.setParams(params);
52
53         var filePath = this.get('targetPath');
54         var parsedContent = Parser.parse(filePath);
55
56         var file = new Stream(filePath, 'w');
57         file.writeln(parsedContent);
58         file.close();
59
60         Build.superclass.afterCreate.apply(this);
61     }
62 });