Skip to content

Commit 94f9cd4

Browse files
committed
generalize shortcut paths browserify transform
1 parent 3a874e5 commit 94f9cd4

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

tasks/util/shortcut_paths.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var path = require('path');
2+
3+
var transformTools = require('browserify-transform-tools');
4+
5+
var constants = require('./constants');
6+
7+
/**
8+
* Transform require paths starting with '@' to appropriate folder paths
9+
*/
10+
11+
var shortcutsConfig = {
12+
'@src': constants.pathToSrc,
13+
'@mocks': constants.pathToMocks
14+
};
15+
16+
module.exports = transformTools.makeRequireTransform('requireTransform',
17+
{ evaluateArguments: true, jsFilesOnly: true },
18+
function(args, opts, cb) {
19+
var pathIn = args[0];
20+
var pathOut;
21+
22+
Object.keys(shortcutsConfig).forEach(function(k) {
23+
if(pathIn.indexOf(k) !== -1) {
24+
var tail = pathIn.split(k)[1];
25+
pathOut = 'require(\''+ shortcutsConfig[k] + tail + '\')';
26+
}
27+
});
28+
29+
if(pathOut) return cb(null, pathOut);
30+
else return cb();
31+
});

test/jasmine/karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func.defaultConfig = {
5757
singleRun: false,
5858

5959
browserify: {
60-
transform: ['./transform.js'],
60+
transform: ['../../tasks/util/shortcut_paths.js'],
6161
extensions: ['.js'],
6262
watch: true,
6363
debug: true

test/jasmine/transform.js

-21
This file was deleted.

0 commit comments

Comments
 (0)