-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
36 lines (33 loc) · 956 Bytes
/
index.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
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Vadim Loginov @vadimatp
*/
'use strict';
module.exports = function(source) {
var data;
var constantNames;
var i;
var output;
var moduleName;
var standalone;
try {
data = JSON.parse(source);
} catch (e) {
this.emitError(this.resourcePath + ' must be a valid json object');
return '';
}
moduleName = this.query.moduleName || 'constants';
standalone = this.query.standalone !== false;
constantNames = Object.keys(data);
if (!constantNames.length) {
this.emitError(this.resourcePath + ' must be a valid json object');
}
output = '"use strict";export default angular.module("' + moduleName + '"' + (standalone ? ', []' : '') + ')';
for (i in constantNames) {
output += '\n .constant("' + constantNames[i] + '", ';
output += JSON.stringify(data[constantNames[i]]);
output += ')';
}
output += ';';
return output;
};