-
Notifications
You must be signed in to change notification settings - Fork 9
/
Gruntfile.coffee
145 lines (127 loc) · 4.11 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
path = require 'path'
deref = require 'json-schema-deref-sync'
module.exports = ->
# Project configuration
pkg = @file.readJSON 'package.json'
repo = pkg.repository.url.replace 'git://', 'https://'+process.env.GH_TOKEN+'@'
@initConfig
pkg: @file.readJSON 'package.json'
yaml:
schemas:
files: [
expand: true
cwd: 'schemata/'
src: '*.yaml'
dest: 'schema/'
]
aglio:
blueprint:
files:
'dist/index.html': ['blueprint/index.apib']
'dist/authentication.html': ['blueprint/authentication.apib']
'dist/passport.html': ['blueprint/passport.apib']
'dist/api.html': ['blueprint/api.apib']
'dist/designsystem.html': ['blueprint/designsystem.apib']
'dist/examplecode.html': ['blueprint/examplecode.apib']
'dist/notifications.html': ['blueprint/notifications.apib']
options:
includePath: __dirname
theme: 'templates/aglio/thegrid'
# Coding standards
yamllint:
schemas: ['schemata/*.yaml']
examples: ['examples/*.yml']
coffeelint:
components: ['Gruntfile.coffee', 'spec/*.coffee']
options:
'max_line_length':
'level': 'ignore'
mochaTest:
nodejs:
src: ['spec/*.coffee']
options:
reporter: 'spec'
require: 'coffee-script/register'
copy:
schemas:
files: [
expand: true, src: ['schema/*.json'], dest: 'dist/', filter: 'isFile'
]
cname:
files: [
src: ['CNAME'], dest: 'dist/'
]
favicon:
files: [
src: ['favicon.ico'], dest: 'dist/'
]
designsystems:
files: [
expand: true, cwd: 'code-examples', src: ['designsystems/*.js'], dest: 'dist/'
]
fullschemas:
files: [
expand: true, src: ['full-schema/*.json'], dest: 'dist/', filter: 'isFile'
]
'gh-pages':
options:
base: 'dist'
clone: 'gh-pages'
message: 'Updating'
repo: repo
user:
name: 'Grid bot'
email: '[email protected]'
silent: true
src: '**/*'
# Grunt plugins used for building
@loadNpmTasks 'grunt-yaml'
@loadNpmTasks 'grunt-aglio'
@loadNpmTasks 'grunt-contrib-copy'
# Grunt plugins used for testing
@loadNpmTasks 'grunt-yamllint'
@loadNpmTasks 'grunt-coffeelint'
@loadNpmTasks 'grunt-mocha-test'
# Grunt plugins used for deploying
@loadNpmTasks 'grunt-gh-pages'
# Custom task for generating JSON files for valid examples to be included in Blueprint
@registerTask 'build_examples', 'Create files for examples', =>
examples = @file.expand ['examples/*.yml']
examples.forEach (e) =>
data = @file.readYAML e
return unless data
basename = path.basename e, '.yml'
for d in data
continue unless d._name
filename = "examples/#{basename}-#{d._name}.json"
@file.write filename, JSON.stringify d._data, null, 2
@log.writeln "Created example file '#{filename}'"
# Custom task for generating full JSON schemas by dereferencing original schemas
@registerTask 'build_fullschemas', 'Create full schemas dereferencing them', =>
options =
baseFolder: 'schema'
failOnMissing: true
@file.mkdir 'full-schema'
schemas = @file.expand ['schema/*.json']
schemas.forEach (e) =>
schema = @file.readJSON e
fullschema = deref schema, options
throw fullschema if fullschema instanceof Error
basename = path.basename e
filename = "full-schema/#{basename}"
@file.write filename, JSON.stringify fullschema, null, 2
@log.writeln "Created full schema #{filename}"
# Our local tasks
@registerTask 'build', 'Build', (target = 'all') =>
@task.run 'yaml'
@file.mkdir 'dist'
@task.run 'build_examples'
@task.run 'build_fullschemas'
@task.run 'copy'
@task.run 'aglio'
@registerTask 'test', 'Build and run tests', (target = 'all') =>
@task.run 'coffeelint'
@task.run 'yamllint'
@task.run 'build'
@task.run 'mochaTest'
@registerTask 'default', ['test']