-
Notifications
You must be signed in to change notification settings - Fork 7
/
Gruntfile.js
148 lines (136 loc) · 3.56 KB
/
Gruntfile.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
const fs = require('fs');
const documentation = require('./src/Documentation');
const runtimeSecret = process.env.FBP_PROTOCOL_SECRET || 'noflo';
module.exports = function () {
const pkg = this.file.readJSON('package.json');
// Project configuration
this.initConfig({
pkg,
yaml: {
options: {
strict: true,
},
schemas: {
files: [{
expand: true,
cwd: 'schema/yaml',
src: ['*.yml'],
dest: 'schema/json/',
ext: '.json',
},
],
},
},
// Automated recompilation and testing when developing
watch: {
test: {
files: ['test/**/*.js', 'src/*.js', 'schema/*.js'],
tasks: ['test'],
},
yaml: {
files: ['schema/yaml/**/*.yml'],
tasks: ['yaml', 'json-to-js', 'test'],
},
},
mochaTest: {
test: {
src: ['test/schema/*.js'],
},
options: {
greph: process.env.TESTS,
},
},
// FBP Network Protocol tests
exec: {
preheat_noflo_cache: './node_modules/.bin/noflo-cache-preheat',
fbp_init_noflo: `node bin/fbp-init --command "noflo-nodejs --secret=${runtimeSecret} --host localhost --port=8080 --open=false" --name="NoFlo Node.js"`,
fbp_test: {
command: 'node bin/fbp-test --colors',
options: {
env: {
FBP_PROTOCOL_SECRET: runtimeSecret,
PATH: process.env.PATH,
},
},
},
},
// Building the website
jekyll: {
options: {
src: 'spec/',
dest: 'dist/',
layouts: 'spec/_layouts',
},
dist: {
options: {
dest: 'dist/',
},
},
serve: {
options: {
dest: 'dist/',
serve: true,
watch: true,
host: process.env.HOSTNAME || 'localhost',
port: process.env.PORT || 4000,
},
},
},
});
// Grunt plugins used for testing
this.loadNpmTasks('grunt-contrib-watch');
this.loadNpmTasks('grunt-exec');
this.loadNpmTasks('grunt-mocha-test');
// Create json schemas from yaml
this.loadNpmTasks('grunt-yaml');
this.loadNpmTasks('grunt-jekyll');
// Our local tasks
this.registerTask('build', [
'yaml',
'json-to-js',
'build-markdown',
'jekyll:dist',
]);
this.registerTask('test', [
'build',
'mochaTest',
'exec:preheat_noflo_cache',
'exec:fbp_init_noflo',
'exec:fbp_test',
]);
this.registerTask('default', ['test']);
this.registerTask('json-to-js', function () {
const done = this.async();
documentation.getSchemas((err, schemas) => {
if (err) {
done(err);
return;
}
const schemaJs = `module.exports = ${JSON.stringify(schemas)}`;
fs.writeFileSync('./schema/schemas.js', schemaJs, 'utf8');
done();
});
});
this.registerTask('build-markdown', function () {
const done = this.async();
documentation.renderMessages((err, messages) => {
if (err) {
done(err);
return;
}
documentation.renderCapabilities((err2, capabilities) => {
if (err2) {
done(err2);
return;
}
const changelog = fs.readFileSync('CHANGES.md', 'utf8');
let file = fs.readFileSync('spec/protocol.js.md', 'utf8');
file = file.replace('<%= messages %>\n', messages);
file = file.replace('<%= capabilities %>', capabilities);
file = file.replace('<%= changelog %>', changelog);
fs.writeFileSync('spec/protocol.md', file, 'utf8');
done();
});
});
});
};