This repository has been archived by the owner on Jan 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGruntfile.coffee
172 lines (132 loc) · 5.05 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
Path = require('path')
Util = require('bumble-util')
GitStatusUtils = require('git-status-utils')
CSS_FILES_TO_DISTRIB = [
'css/distrib/*.css'
]
BUMBLE_DOCS_SCRIPTS = './node_modules/bumble-docs/bin/'
bumbleScriptCommand = (scriptFile, args="")->
return "coffee #{Path.join(BUMBLE_DOCS_SCRIPTS, scriptFile)} #{args}"
module.exports = (grunt) ->
# load plugins
# this loads all of the grunt-... packages in package.json. clever
require('load-grunt-tasks')(grunt)
pkg = grunt.file.readJSON("package.json")
# initialize grunt
grunt.initConfig
pkg: pkg
# args to initConfig method are the tasks
clean:
distrib: ["dist/#{pkg.name}.*"]
lib: ["lib/*"]
docsVendorLibs: ["docs/vendor/*"]
copy:
docVendorLibs:
files: [
{ src: "node_modules/react-bootstrap/dist/react-bootstrap.min.js", dest: "docs/vendor/react-bootstrap.js"}
{ src: "node_modules/react-virtualized/dist/umd/react-virtualized.js", dest: "docs/vendor/react-virtualized-9.18.5.js"}
{ src: "dist/react-datum-datagrid.js", dest: "docs/vendor/react-datum-datagrid.js"}
]
# .js & .jsx use babel to build
babel:
options:
# Not using es2015 preset = ship es6 without transforming
presets: ['stage-2', 'react']
build:
files: [{
expand: true
cwd: 'src'
src: ['**/*.js']
dest: 'lib'
ext: '.js'
}]
coffee:
build:
files: [
expand: true
cwd: 'src'
src: ['**/*.coffee']
dest: 'lib'
ext: '.js'
]
cjsx:
build:
files: [
expand: true
cwd: 'src'
src: ['**/*.cjsx']
dest: 'lib'
ext: '.js'
]
cssmin:
options:
shorthandCompacting: false,
keepBreaks: true
distrib:
files:[
{src: CSS_FILES_TO_DISTRIB, dest: "dist/#{pkg.name}.css"}
]
shell:
buildExamples:
command: bumbleScriptCommand('buildExamples.coffee')
buildDocIndex:
command: bumbleScriptCommand('buildDocIndex.coffee')
buildApiDocs:
command: bumbleScriptCommand('buildApiDocs.coffee')
test:
command: 'node_modules/bumble-test/bin/testRunner.coffee'
execOptions:
env: {NODE_ENV: 'test'}
coverage:
command: 'node_modules/.bin/istanbul report text-summary lcov'
# end shell
coveralls:
options:
force: true
upload:
src: 'coverage/lcov.info'
availabletasks:
tasks:
options:
filter: 'include'
tasks: ['build', 'test', 'watch', 'clean', 'docs']
descriptions:
build: "Builds everything except docs & examples"
test: "Run tests in /test directory"
watch: "Watch for changing files and calls build."
docs: "Build the docs. To publish to github.io, use 'grunt build ghpages'"
"gh-pages": "Publish the build docs to github.io"
clean: "Remove all compiled files. Use `grunt clean build` to rebuild everything from scratch"
watch:
build:
files: ["src/**/*", "css/**/*", "lib/**/*", "scripts/**/*", "examples/**/*", "webpack.config.coffee"]
tasks: ["build"]
webpack:
distrib: require("./webpack.config.coffee")
optimize: require("./webpack.config.min.coffee")
# tasks
grunt.registerTask 'test', ["shell:test", "shell:coverage"]
grunt.registerTask 'distrib', ['cssmin:distrib', 'webpack:distrib', 'webpack:optimize']
grunt.registerTask 'docs', ['clean:docsVendorLibs', 'copy:docVendorLibs', 'shell:buildExamples', 'shell:buildDocIndex', 'shell:buildApiDocs']
grunt.registerTask 'build', ['npmInstall', 'newer:cjsx:build', 'newer:coffee:build', 'newer:babel:build', 'distrib', 'docs']
grunt.registerTask 'default', ['availabletasks']
LAST_NPM_INSTALL_FILE = './.lastNpmInstall'
grunt.registerTask 'npmInstall', 'runs npm install if node_modules not up to date with package.json', ->
Util.npmInstall()
grunt.registerTask 'gh-pages', 'publishes complied docs to github.io', ->
@gitStatus = GitStatusUtils.getStatus '.'
if @gitStatus.stagedChanges.length > 0 || @gitStatus.unstagedChanges.length > 0
console.log "Cowardly refusing to publish to gh-pages. Uncommitted changes exist on current branch"
return false
if @gitStatus.branch != 'master'
console.log "Cowardly refusing to publish to gh-pages from branch (#{@gitStatus.branch}) other than master"
return false
Util.systemCmd 'git co gh-pages'
Util.systemCmd 'git reset --hard origin/master'
Util.systemCmd 'git pull origin master'
Util.systemCmd 'grunt build'
# /docs dir is normally ignored by git via .gitignore, but in the gh-pages
# branch /docs needs to be checked in
Util.systemCmd 'git add -f docs'
Util.systemCmd 'git push -f origin gh-pages'
Util.systemCmd 'git co master'