forked from webinos/Webinos-Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grunt.js
155 lines (139 loc) · 5.39 KB
/
grunt.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
149
150
151
152
153
154
155
/*******************************************************************************
* Code contributed to the webinos project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2012 webinos
******************************************************************************/
module.exports = function(grunt) {
var fs = require('fs');
var os = require('os');
var path = require('path');
grunt.initConfig({
// config props
generated: {
normal: 'webinos/web_root/webinos.js',
min: 'webinos/web_root/webinos.min.js'
},
// dir names to exclude from "clean-certs" target
excludepaths: ['auth_api', 'context_manager', 'logs', 'wrt'],
header: "if(typeof webinos === 'undefined'){",
footer: "}",
// targets
lint: ['grunt.js', 'webinos/**/*.js'],
concat: {
dist: {
src: [
'<banner:header>',
'webinos/core/wrt/lib/webinos.util.js',
'node_modules/webinos-jsonrpc2/lib/registry.js',
'node_modules/webinos-jsonrpc2/lib/rpc.js',
'webinos/core/manager/messaging/lib/messagehandler.js',
'webinos/core/wrt/lib/webinos.session.js',
'webinos/core/wrt/lib/webinos.servicedisco.js',
'webinos/core/wrt/lib/webinos.js',
'webinos/core/api/file/lib/virtual-path.js',
'webinos/core/wrt/lib/webinos.file.js',
'webinos/core/wrt/lib/webinos.webnotification.js',
'webinos/core/wrt/lib/webinos.actuator.js',
'webinos/core/wrt/lib/webinos.tv.js',
'webinos/core/wrt/lib/webinos.oauth.js',
'webinos/core/wrt/lib/webinos.get42.js',
'webinos/core/wrt/lib/webinos.geolocation.js',
'webinos/core/wrt/lib/webinos.sensors.js',
'webinos/core/wrt/lib/webinos.events.js',
'webinos/core/wrt/lib/webinos.app2app.js',
'webinos/core/wrt/lib/webinos.appstatesync.js',
'webinos/core/wrt/lib/webinos.applauncher.js',
'webinos/core/wrt/lib/webinos.vehicle.js',
'webinos/core/wrt/lib/webinos.deviceorientation.js',
'webinos/core/wrt/lib/webinos.context.js',
'webinos/core/wrt/lib/webinos.authentication.js',
'webinos/core/wrt/lib/webinos.contacts.js',
'webinos/core/wrt/lib/webinos.devicestatus.js',
'webinos/core/wrt/lib/webinos.discovery.js',
'webinos/core/wrt/lib/webinos.payment.js',
'webinos/core/wrt/lib/webinos.mediacontent.js',
'webinos/core/wrt/lib/webinos.nfc.js',
'<banner:footer>'
],
dest: '<config:generated.normal>'
}
},
uglify: {
mangle: {
toplevel: false
}
},
min: {
dist: {
src: ['<config:generated.normal>'],
dest: '<config:generated.min>'
}
},
clean: ['<config:generated.normal>', '<config:generated.min>']
});
// plugin provides "clean" task
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.registerTask(
'check-rpc',
'Check if webinos-jsonrpc2 is in local node_modules, required for concat task',
function() {
var isInstalled = (fs.existsSync || path.existsSync)('./node_modules/webinos-jsonrpc2/');
if (!isInstalled) {
console.log();
console.log('\nError: webinos-jsonrpc2 must be in local node_modules.\n');
console.log();
return false;
}
grunt.task.run('concat');
});
grunt.registerTask('clean-certs', 'Cleans certificates from user dir', function() {
var winPath = ['AppData', 'Roaming', 'webinos'];
var unixPath = ['.webinos'];
var webinosRelPath = os.platform() === 'win32' ? winPath : unixPath;
var relPath = ['..'].concat(webinosRelPath);
// the path to .webinos/ dir
var webinosConfPath = grunt.file.userDir.apply(null, relPath);
// get subdirs from .webinos/
var webinosConfSubdirs = fs.readdirSync(webinosConfPath);
// exclude certain subdirs that are not to be deleted
var paths = grunt.config.get('excludepaths');
webinosConfSubdirs = webinosConfSubdirs.filter(function(subdir) {
for (var i=0; i < paths.length; i++) {
if (subdir === paths[i]) return false;
}
return true;
});
// build full path for the subdirs
webinosConfSubdirs = webinosConfSubdirs.map(function(p) {
return grunt.file.userDir.apply(null, relPath.concat([p]));
});
webinosConfSubdirs = webinosConfSubdirs.filter(function(p) {
return p ? true : false;
});
if (!webinosConfSubdirs.length) {
grunt.log.writeln('There are no certificates to remove.');
return;
}
var oldClean = grunt.config.get('clean');
grunt.config.set('clean', webinosConfSubdirs);
// finally call clean task to remove all subdirs from .webinos with certs
var done = this.async();
grunt.task.run('clean');
done();
grunt.config.set('clean', oldClean);
});
grunt.registerTask('minify', 'check-rpc min');
grunt.registerTask('default', 'check-rpc');
};