-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
56 lines (54 loc) · 1.34 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
module.exports = function(grunt) {
var os = require('os');
grunt.loadNpmTasks('grunt-replace');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
replace: {
dist: {
options: {
patterns: [
{
match: /ORG_ID/g,
replacement: '<%= pkg.properties["org-id"] %>'
},
{
match: /DEVICE_TYPE/g,
replacement: '<%= pkg.properties["device-type"] %>'
},
{
match: /DEVICE_ID/g,
replacement: '<%= grunt.config.get("device-id") %>'
},
{
match: /disableEditor: false/g,
replacement: 'disableEditor: <%= pkg.properties["disable-editor"] %>'
},
{
match: /(uiPort: process.env.PORT .. )(188\d)/g,
replacement: function(match, p1, p2) {
return p1 + (parseInt(p2) + 10);
}
},
{
match: /"broker": "localhost"/g,
replacement: '"broker": "<%= pkg.properties["broker-host"] %>"'
}
]
},
files: [
{
expand: true,
flatten: true,
src: ['src/flow.json','src/settings.js','src/flow_cred.json'],
dest: 'dist/'
}
]
}
}
});
grunt.registerTask('generate-config', function() {
var hostname = os.hostname();
grunt.config.set("device-id", hostname.replace(/(.+?)\..*/g, "$1"));
});
grunt.registerTask('default', ['generate-config','replace']);
};