This repository was archived by the owner on Mar 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreset.js
151 lines (134 loc) · 3.99 KB
/
preset.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import extend from 'extend'
import Rails from './ruby/rails'
import stringify from 'stringify-object'
//import Util from 'gulp-util'
// NOTE: `source` and `watch` are node-glob options hashes. e.g. gulp.src(source.glob, source.options)
// Baseline is the simplest possible. Take caution in modifying this one or make sure your platform preset overrides everything necessary.
const Baseline = {
javascripts: {
source: {
glob: 'index.js',
options: {cwd: 'js'},
all: '**/*' // include all files, may have yml, sh, json, in addition to js
},
test: {
glob: '**/*.js',
options: {cwd: 'test'}
},
watch: {
glob: '**/*.js',
options: {cwd: 'js'}
},
dest: 'dist'
},
stylesheets: {
source: {
glob: ['*.scss', '!_*.scss'], // do not compile all files, only non-underscored files
options: {cwd: 'scss'},
all: '**/*.scss'
},
watch: {
glob: '**/*.scss',
options: {cwd: 'scss'}
},
dest: 'dist'
},
images: {
source: {options: {cwd: 'images'}},
watch: {options: {cwd: 'images'}},
dest: 'dist'
},
postProcessor: {
source: {options: {cwd: 'dist'}},
watch: {options: {cwd: 'dist'}},
dest: 'dist'
}
}
const PresetNodeSrc = {
javascripts: {
source: { options: {cwd: 'src'}},
watch: {options: {cwd: 'src'}}
}
}
const PresetNodeLib = {
javascripts: {
source: { options: {cwd: 'lib'}},
watch: {options: {cwd: 'lib'}}
}
}
// Rails, the oddball from a structure consideration
const railsJs = 'app/assets/javascripts'
const railsSs = 'app/assets/stylesheets'
const railsImages = 'app/assets/images'
const railsDest = 'public/assets/debug'
const PresetRails = {
javascripts: {
source: {
glob: 'application.js',
options: {cwd: railsJs}
},
watch: {options: {cwd: railsJs}},
dest: railsDest
},
stylesheets: {
source: {options: {cwd: railsSs}},
watch: {options: {cwd: railsSs}},
dest: railsDest
},
images: {
source: {options: {cwd: railsImages}},
watch: {options: {cwd: railsImages}},
dest: railsDest
},
postProcessor: {
source: {options: {cwd: railsDest}},
watch: {options: {cwd: railsDest}},
dest: 'public/assets/digest'
}
}
const Preset = class {
static baseline(overrides = {}) {
return extend(true, {}, Baseline, overrides)
}
static nodeLib(overrides = {}) {
return extend(true, {}, Baseline, PresetNodeLib, overrides)
}
static nodeSrc(overrides = {}) {
return extend(true, {}, Baseline, PresetNodeSrc, overrides)
}
static rails(overrides = {}) {
return extend(true, {}, Baseline, PresetRails, new Rails().baseDirectories(), overrides)
}
/**
* Helper to quickly resolve the config from preset based on the presetType
*
* @param preset
* @param configs - ordered set of overrides
* @returns {source, watch, dest}
*/
static resolveConfig(preset, ...configs) {
if (!preset) {
throw new Error(`Preset must be specified. Please use one from the preset.js or specify a custom preset configuration.`)
}
let configOverrides = extend(true, {}, ...configs)
//Util.log(`config before typeConfig: \n${stringify(configOverrides)}`)
if (!configOverrides || !configOverrides.presetType) {
throw new Error(`presetType must be specified in the config (usually the Default config). See preset.js for a list of types such as javascripts, stylesheets, etc.`)
}
let typeConfig = null
if (configOverrides.presetType !== 'macro') {
typeConfig = preset[configOverrides.presetType]
if (!typeConfig) {
throw new Error(`Unable to resolve configuration for presetType: ${configOverrides.presetType} from preset: ${stringify(preset)}`)
}
}
else {
typeConfig = {}
}
// now that we've determined the typeConfig, overlay the overrides
let resolved = extend(true, {}, typeConfig, configOverrides)
//Util.log(`resolved config with preset: \n${stringify(resolved)}`)
return resolved
}
}
export default Preset