UNPKG

7.61 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.7.1
2(function() {
3 var allFactories, defineFactory, findCommandIfExists, findLocalCommand, findScript, fs, getCommand, isFactoryActive, ld, makeAssetEdgeFn, makeAssetRule, makeStreamlineFactory, path, _ref;
4
5 path = require('path');
6
7 ld = require('lodash');
8
9 fs = require('fs');
10
11 _ref = require('./ninjaCommands'), findCommandIfExists = _ref.findCommandIfExists, findScript = _ref.findScript, findLocalCommand = _ref.findLocalCommand;
12
13 getCommand = function(config, log, commandName, desc) {
14 var answer;
15 if (desc == null) {
16 desc = commandName;
17 }
18 answer = findCommandIfExists(commandName, config);
19 if (!answer) {
20 log.warn("" + commandName + " not found - disabling " + desc + " support.");
21 }
22 return answer;
23 };
24
25 allFactories = [];
26
27 defineFactory = exports.defineFactory = function(name, factory) {
28 factory.name = name;
29 return allFactories.push(factory);
30 };
31
32 isFactoryActive = function(factory, config, log) {
33 var active;
34 active = false;
35 if (!factory.active) {
36 active = true;
37 } else {
38 if (ld.isFunction(factory.active)) {
39 active = factory.active(config, log);
40 } else {
41 active = factory.active;
42 }
43 }
44 return active;
45 };
46
47 exports.forEachFactory = function(fn) {
48 var factory, _i, _len, _results;
49 _results = [];
50 for (_i = 0, _len = allFactories.length; _i < _len; _i++) {
51 factory = allFactories[_i];
52 _results.push(fn(factory));
53 }
54 return _results;
55 };
56
57 exports.forActiveFactory = function(config, log, fn) {
58 var factory, _i, _len, _results;
59 _results = [];
60 for (_i = 0, _len = allFactories.length; _i < _len; _i++) {
61 factory = allFactories[_i];
62 if (isFactoryActive(factory, config, log)) {
63 _results.push(fn(factory));
64 } else {
65 _results.push(void 0);
66 }
67 }
68 return _results;
69 };
70
71 defineFactory("coffee", {
72 initialize: function(ninja, config, log) {
73 return this._command = getCommand(config, log, 'coffee');
74 },
75 active: function(config, log) {
76 return this._command != null;
77 },
78 assignments: function(ninja, config) {
79 return ninja.assign('coffee', this._command);
80 },
81 makeRules: function(ninja, config) {
82 return ninja.rule('coffee').run('$coffee -c -m -o $outDir $in').description('COFFEE $in');
83 },
84 files: ['**/*.coffee', '**/*.litcoffee', '**/*.coffee.md'],
85 makeSrcEdge: function(ninja, source, target) {
86 ninja.edge(target).from(source).using('coffee').assign('outDir', path.dirname(target));
87 return [target];
88 }
89 });
90
91 defineFactory("js", {
92 active: true,
93 files: '**/*.js',
94 assetFiles: 'js/**/[a-z0-9]*.js',
95 makeSrcEdge: function(ninja, source, target) {
96 ninja.edge(target).from(source).using('copy');
97 return [target];
98 },
99 makeAssetEdge: function(ninja, source, target, releaseType) {
100 return this.makeSrcEdge(ninja, source, target);
101 }
102 });
103
104 makeStreamlineFactory = function(name, ext, commandName) {
105 return {
106 initialize: function(ninja, config, log) {
107 this._command = getCommand(config, log, commandName, name);
108 return this.oldStreamline = config.streamlineVersion < 10;
109 },
110 active: function(config, log) {
111 return this._command != null;
112 },
113 assignments: function(ninja, config) {
114 if (this.oldStreamline) {
115 return ninja.assign(name, "node --harmony " + this._command);
116 } else {
117 return ninja.assign(name, this._command);
118 }
119 },
120 makeRules: function(ninja, config) {
121 var streamlineOpts;
122 if (this.oldStreamline) {
123 streamlineOpts = "-lp -c";
124 } else {
125 streamlineOpts = "-m -o $outDir -f -c";
126 }
127 return ninja.rule(name).run("$" + name + " " + config.streamlineOpts + " " + streamlineOpts + " $in").description("" + (name.toUpperCase()) + " $in");
128 },
129 files: "**/*" + ext,
130 makeSrcEdge: function(ninja, source, target) {
131 var base, buildSource, mapFile, targetDir;
132 targetDir = path.dirname(target);
133 base = path.basename(target, ".js");
134 if (this.oldStreamline) {
135 buildSource = path.join(targetDir, "" + base + (path.extname(source)));
136 mapFile = path.join(targetDir, "" + base + ".map");
137 ninja.edge(buildSource).from(source).using("copy");
138 ninja.edge(target).from(buildSource).using(name).assign("mapFile", mapFile);
139 } else {
140 ninja.edge(target).from(source).using(name).assign('outDir', path.dirname(target));
141 }
142 return [target];
143 }
144 };
145 };
146
147 defineFactory("jsStreamline", makeStreamlineFactory('jsStreamline', '._js', '_node'));
148
149 defineFactory("coffeeStreamline", makeStreamlineFactory('coffeeStreamline', '._coffee', '_coffee'));
150
151 makeAssetRule = function(ninja, name, releaseType, cli) {
152 return ninja.rule("" + name + "-" + releaseType).run(cli).depfile('$out.d').description("(" + releaseType + ") " + (name.toUpperCase()) + " $in");
153 };
154
155 makeAssetEdgeFn = function(name) {
156 return function(ninja, source, target, releaseType) {
157 ninja.edge(target).from(source).using("" + name + "-" + releaseType);
158 return [target];
159 };
160 };
161
162 defineFactory("stylus", {
163 initialize: function(ninja, config, log) {
164 return this._command = getCommand(config, log, 'stylus');
165 },
166 active: function(config, log) {
167 return this._command != null;
168 },
169 assignments: function(ninja, config) {
170 return ninja.assign('stylus', this._command);
171 },
172 makeRules: function(ninja, config) {
173 return ['debug', 'release'].forEach(function(releaseType) {
174 var cli;
175 cli = "$node " + (findScript("stylus-dep.js", config)) + " $in --print " + config.stylusOpts;
176 cli += releaseType === 'release' ? ' --compress' : ' --line-numbers';
177 cli += ' --dep-file $out.d';
178 cli += ' > $out';
179 return makeAssetRule(ninja, 'stylus', releaseType, cli);
180 });
181 },
182 assetFiles: '**/[a-z0-9]*.styl',
183 targetExt: '.css',
184 makeAssetEdge: makeAssetEdgeFn('stylus')
185 });
186
187 defineFactory("snockets", {
188 initialize: function(ninja, config, log) {
189 return this._command = getCommand(config, log, 'snockets');
190 },
191 active: function(config, log) {
192 return this._command != null;
193 },
194 assignments: function(ninja, config) {
195 return ninja.assign('snockets', this._command, config);
196 },
197 makeRules: function(ninja, config) {
198 return ['debug', 'release'].forEach(function(releaseType) {
199 var cli;
200 cli = "$snockets $cliOptions $in -o $out --dep-file $out.d";
201 if (releaseType === 'release') {
202 cli += ' --minify';
203 }
204 cli += " && " + (findLocalCommand('i18n-extract', config));
205 cli += ' -f \'(i18n)\' -k \'$$1\' $out > $out.i18n';
206 return makeAssetRule(ninja, 'snockets', releaseType, cli);
207 });
208 },
209 assetFiles: 'js/**/[a-z0-9]*.coffee',
210 makeAssetEdge: makeAssetEdgeFn('snockets')
211 });
212
213 defineFactory("coffeelint", {
214 active: function(config, log) {
215 return !config.noLint;
216 },
217 assignments: function(ninja, config) {
218 return ninja.assign('coffeelint', "$node " + (findScript("coffeelint.js", config)));
219 },
220 makeRules: function(ninja, config) {
221 return ninja.rule("coffeelint").run("$coffeelint $cliOptions $in && touch $out").description("COFFEELINT $in");
222 }
223 });
224
225}).call(this);
226
227//# sourceMappingURL=ninjaFactories.map