-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.coffee
119 lines (104 loc) · 3.59 KB
/
index.coffee
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
require("source-map-support").install()
R = require("ramda")
fs = require("fs")
path = require("path")
isThere = require("is-there")
sourcegate = require("sourcegate")
nocomments = require("strip-json-comments")
task = require("be-goods").gulpTask
logger = require("be-goods").logger
logUse = (what = "") -> console.log what if process.argv[2] is "sourcegate"
obtain = (somewhere) ->
JSON.parse nocomments fs.readFileSync(path.normalize somewhere).toString()
get = (what, module) ->
# gutil.log "Looking for '#{what}' in module '#{module}'"
where = [
"node_modules/#{what}",
"node_modules/#{module}/node_modules/#{what}",
"node_modules/beverage/node_modules/#{module}/node_modules/#{what}"
"node_modules/beverage/node_modules/hal-rc/node_modules/#{what}"
]
last = where.length - 1
for i in [0..last]
try
gotIt = obtain where[i]
logUse "Source #{where[i]}"
return gotIt
catch e
if i is last
logger.error(e)
throw new Error "Could not find preset at: #{where}"
continue
getPreset = (tool, name, module) ->
# the tool is known as recipe
# the name is known as preset
presets =
jscs: "jscs/presets" #{preset}.json will be appended
jshint:
airbnb: "airbnb-style/linters/jshintrc"
eslint:
airbnb: "airbnb-style/linters/.eslintrc"
coffeelint:
"hal-coffeescript-style-guide": "hal-coffeescript-style-guide/coffeelint.json"
if tool is "jscs"
get("#{presets.jscs}/#{name}.json", module)
else if presets[tool]?[name]?
get(presets[tool][name], module)
else {}
module.exports = (o = {}, gulp) ->
empty = [[], {}]
if R.is(Array, o.sourcegate)
if R.isEmpty(o.sourcegate) then return [empty]
else return [empty] # or throw?
o.sourceopt ?= {}
ready = []
watch = []
for sg in o.sourcegate
res = R.clone(empty)
sg.options ?= {}
unless sg.recipe?
# 0. without a recipe, hal-rc just hands sources and options to sourcegate
res = [sg.sources, sg.options]
else
logUse()
logUse("For #{sg.recipe}:")
sources = []
module = sg.module or o.sourceopt.module
prefix = sg.prefix or o.sourceopt.prefix or ''
preset = sg.preset or o.sourceopt.preset
# 1. start with preset (something known / standard)
if preset?
sources.push getPreset(sg.recipe, preset, module)
filerc = if sg.recipe is "coffeelint" then "coffeelint.json" else ".#{sg.recipe}rc"
if module? && module isnt '!'
# 2. override with a module config (anybody can have presets)
# `module is false` means hal-rc's defaults will be used
# `module is '!'` would favor the preset + local non-module overrides
config = "#{prefix}#{filerc}"
if module
config = "node_modules/#{module}/#{config}"
config = path.normalize(config)
logUse "Source #{config}"
unless isThere config
logger.error "Could not find: #{config}"
else
if o.sourceopt.watch
watch.push config
sources.push config
sg.options.write ?= {}
sg.options.write.path = filerc
# 3. sources, whether an object or array, become the final override
sources = sources.concat(sg.sources) if sg.sources?
res = [sources, sg.options]
ready.push res
# optional gulp / tasks
if gulp?
task gulp, "sourcegate", "Write sourcegate targets.", ->
for sg in ready
sourcegate.apply(null, sg)
if o.sourceopt.watch
task gulp, "sourcegate:watch",
"Watch sourcegate sources for changes.", ->
gulp.watch watch, ["sourcegate"]
logUse()
ready