-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
76 lines (66 loc) · 2.02 KB
/
index.js
File metadata and controls
76 lines (66 loc) · 2.02 KB
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
var ph = require('./lib/paths_helpers');
var pf = require('./lib/paths_factory');
var pfuncs = require('./lib/paths_functions');
function Paths(options) {
this.getOptions = function getOptions() {
return options;
};
this.getFactory = function getFactory(opt) {
return pf(opt || this.getOptions());
};
ph.extend(true, this, pfuncs(this.getFactory()));
}
module.exports = {
populateOptions: function populateOptions(options) {
var envDirs = options.envDirs;
var _envDirs = {
dev: options.dirNames.dev,
prod: options.dirNames.prod
};
Object.keys(envDirs).forEach(function(key){
if (envDirs[key] && !_envDirs[key]) {
_envDirs[key] = options.dirNames[key];
}
});
options.envDirs = _envDirs;
Object.keys(options.envDirs).forEach(function(key){
if (!options.dirMaps[key]) {
options.dirMaps[key] = 'dist';
}
});
if (!options.dirNames.bower) {
var bowerc = {};
try {
bowerc = JSON.parse(fs.readFileSync(ph.join(options.projectDir,'.bowerrc')));
} catch(e) {}
options.dirNames.bower = bowerc.directory || 'bower_components';
}
return options;
},
getOptionsDefault: function getOptionsDefault() {
var options = {
strict: true,
projectDir: process.cwd(),
env: 'dev',
envDirs: {},
dirNames: {
project: '',
dist: 'dist',
tmp: '.tmp',
dev: 'dev',
prod: 'prod'
},
dirMaps: {},
distIgnore: {
app: true
}
};
return options;
},
create: function(opt) {
var options = {};
ph.extend(true, options, this.getOptionsDefault());
ph.extend(true, options, opt);
return new Paths(this.populateOptions(options));
}
};