-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.js
More file actions
60 lines (49 loc) · 1.41 KB
/
convert.js
File metadata and controls
60 lines (49 loc) · 1.41 KB
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
const each = require('lodash/each');
const fs = require('fs');
const path = require('path');
const jsonToEnv = require('./convert-env');
const conversion = (json) => {
const data = parsePostmanEnvironment(json);
const env = jsonToEnv(data);
console.log(env);
}
const getEnvName = (json) => {
return parsePostmanEnvironment(json).name + ".bru";
}
const parsePostmanEnvironment = (str) => {
try {
str = path.join(__dirname, str);
const data = fs.readFileSync(str);
let environment = JSON.parse(data);
return importPostmanEnvironment(environment);
} catch (err) {
console.log(err);
}
}
const importPostmanEnvironmentVariables = (brunoEnvironment, values) => {
brunoEnvironment.variables = brunoEnvironment.variables || [];
each(values, (i) => {
const brunoEnvironmentVariable = {
name: i.key,
value: i.value,
enabled: i.enabled,
secret: isSecret(i.type)
};
brunoEnvironment.variables.push(brunoEnvironmentVariable);
});
};
const importPostmanEnvironment = (environment) => {
const brunoEnvironment = {
name: environment.name,
variables: []
};
importPostmanEnvironmentVariables(brunoEnvironment, environment.values);
return brunoEnvironment;
};
const isSecret = (type) => {
return type === 'secret';
};
module.exports = {
conversion,
getEnvName
};