Blame view

js/lib/JSBuilder/src/Build.js 1.74 KB
16035364   Benjamin Renard   First commit
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
Loader.require('Parser');

Build = Ext.extend(Target, {
    getDefaultTarget : function() {
        return (this.get('id') || this.get('name').replace(/ /g, '').toLowerCase()) + '.js';
    },

    onCreate: function(file) {
        Build.superclass.onCreate.apply(this, arguments);

        var project = this.project,
            verbose = project.builder.get('verbose'),
            packages = this.get('packages') || [];

        if (verbose && packages.length) {
            Logger.log('  - ' + packages.length + ' package(s) included in this target.');
        }

        // Loop over all file includes, read the contents, and write
        // it to our target file
        packages.forEach(function(id) {
            var pkg = this.project.getPackageById(id),
                content;

            if (!pkg) {
                return true;
            }

            if (verbose) {
                Logger.log('    + ' + pkg.get('target'));
            }

            pkg = new Stream(pkg.get('targetPath'));
            content = pkg.readFile();
            pkg.close();

            file.writeln(content);
            return true;
        }, this);
    },

    afterCreate : function() {
        var params = Ext.apply({debug: this.get('debug'), debugLevel: 1}, this.get('options') || {});

        Logger.log('  * Parse ' + this.get('target') + ' with options:');

        Ext.iterate(params, function(n, v) {
            Logger.log('    - ' + n + ": " + v);
        });

        Parser.setParams(params);

        var filePath = this.get('targetPath');
        var parsedContent = Parser.parse(filePath);

        var file = new Stream(filePath, 'w');
        file.writeln(parsedContent);
        file.close();

        Build.superclass.afterCreate.apply(this);
    }
});