forked from pimatic/pimatic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
201 lines (171 loc) · 5.49 KB
/
Gruntfile.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
module.exports = (grunt) ->
path = require "path"
# all node_modules:
modules = require("fs").readdirSync ".."
# just the pimatic-* modules:
plugins = (module for module in modules when module.match(/^pimatic-.*/)?)
# files for generating documentation:
grocFiles = [
"./README.md"
"./startup.coffee"
"./config-schema.coffee"
"./lib/*.coffee"
]
# some realy dirty tricks:
orgGrocPath = require("fs").existsSync './node_modules/grunt-groc/node_modules/groc'
ownGrocPath = require("fs").existsSync './node_modules/groc'
if orgGrocPath
orgGroc = require './node_modules/grunt-groc/node_modules/groc'
if ownGrocPath
# Use our own groc implementation
ownGroc = require './node_modules/groc'
for name, prop of ownGroc
orgGroc[name] = prop
else
grunt.log.writeln "Could not use own groc version. Not found!"
else
unless ownGrocPath
grunt.log.writeln "Could not use own groc version. Not found!"
links =
'pimatic framework': '.'
for l in plugins
short = l.replace 'pimatic-', ''
links[short] = l
grocTasks =
pimatic:
src: [
"./README.md"
"./plugins.md"
"./rules.md"
"./startup.coffee"
"./config-schema.coffee"
"./lib/*.coffee"
]
options:
root: "."
out: "doc"
"repository-url": "https://github.com/sweetpi/pimatic"
style: 'pimatic'
links: JSON.stringify links
pluginLinks =
'pimatic framework': '..'
for l in plugins
short = l.replace 'pimatic-', ''
pluginLinks[short] = "../#{l}"
for plugin in plugins
grocTasks[plugin] =
src: [
"../#{plugin}/README.md"
"../#{plugin}/*.coffee"
]
options:
root: "../#{plugin}"
out: "../#{plugin}/doc"
"repository-url": "https://github.com/sweetpi/pimatic"
links: JSON.stringify pluginLinks
ftpTasks = {}
for plugin in ["pimatic"].concat plugins
ftpTasks[plugin] =
auth:
host: "pimatic.org"
port: 21
authKey: 'pimatic.org'
src: path.resolve __dirname, '..', plugin, "doc"
dest: (if plugin is "pimatic" then "/pimatic/docs"
else "/pimatic/docs/#{plugin}")
# package.json files of plugins
pluginPackageJson = ("../#{plugin}/package.json" for plugin in plugins)
# and main package.json files
bumpFiles = ["package.json"].concat pluginPackageJson
# Project configuration.
grunt.initConfig
pkg: grunt.file.readJSON "package.json"
coffeelint:
app: [
"*.coffee"
"../pimatic-*/*.coffee"
"lib/**/*.coffee"
"test/**/*.coffee"
]
options:
no_trailing_whitespace:
level: "ignore"
max_line_length:
value: 100
indentation:
value: 2
level: "error"
no_unnecessary_fat_arrows:
level: 'ignore'
groc: grocTasks
"ftp-deploy": ftpTasks
mochaTest:
test:
options:
reporter: "spec"
require: ['coffee-errors'] #needed for right line numbers in errors
src: ["test/*"]
testPlugin:
options:
reporter: "spec"
require: ['coffee-errors'] #needed for right line numbers in errors
src: ["test/plugins-test.coffee"]
# blanket is used to record coverage
testBlanket:
options:
reporter: "dot"
src: ["test/*"]
coverage:
options:
reporter: "html-cov"
quiet: true
captureFile: "coverage.html"
src: ["test/*"]
bump:
options:
files: bumpFiles
updateConfigs: []
commit: true
commitMessage: "version %VERSION%"
commitFiles: ["-a"] # '-a' for all files
createTag: true
tagName: "v%VERSION%"
tagMessage: "version %VERSION%"
push: true
pushTo: "origin"
gitDescribeOptions: "--tags --always --abbrev=1 --dirty=-d"
grunt.loadNpmTasks 'grunt-bump'
grunt.loadNpmTasks "grunt-coffeelint"
grunt.loadNpmTasks "grunt-groc"
grunt.loadNpmTasks "grunt-ftp-deploy"
grunt.loadNpmTasks "grunt-mocha-test"
grunt.registerTask "blanket", =>
blanket = require "blanket"
blanket(
pattern: (file) ->
if file.match "pimatic/lib" then return true
#if file.match "pimatic/node_modules" then return false
withoutPrefix = file.replace(/.*\/node_modules\/pimatic/, "")
return (not withoutPrefix.match 'node_modules') and (not withoutPrefix.match "/test/")
loader: "./node-loaders/coffee-script"
)
grunt.registerTask "clean-coverage", =>
fs = require "fs"
path = require "path"
replaceAll = (find, replace, str) =>
escapeRegExp = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")
str.replace(new RegExp(escapeRegExp(find), 'g'), replace)
file = "#{__dirname}/coverage.html"
html = fs.readFileSync(file).toString()
html = replaceAll path.dirname(__dirname), "", html
fs.writeFileSync file, html
# Default task(s).
grunt.registerTask "default", ["coffeelint", "mochaTest:test", "groc"]
grunt.registerTask "test", ["coffeelint", "mochaTest:test"]
grunt.registerTask "coverage",
["blanket", "mochaTest:testBlanket", "mochaTest:coverage", "clean-coverage"]
for plugin in plugins
do (plugin) =>
grunt.registerTask "setEnv:#{plugin}", =>
process.env['PIMATIC_PLUGIN_TEST'] = plugin
grunt.registerTask "test:#{plugin}", ["setEnv:#{plugin}", "mochaTest:testPlugin"]