forked from otterspoor/postman-to-mockoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·42 lines (33 loc) · 950 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
37
38
39
40
41
42
#!/usr/bin/env node
"use strict";
const fs = require("fs");
const path = require("path");
const { transformPostmanToMockoon } = require("./transform")
var outfile = process.argv.slice(2);
if (outfile.length < 1) {
console.error("USAGE: postman-to-mockoon input-file output-file");
return false;
}
let filepath = outfile[0];
if (!outfile[1]) {
outfile[1] = `${path.dirname(filepath)}/mockoon_${path.posix.basename(
filepath
)}`;
}
if (!fs.existsSync(filepath)) {
console.log(`Cannot access file at ${filepath}`);
return false;
}
const {
Mockoon,
Environment,
} = require("./lib/models/");
let rawdata = fs.readFileSync(filepath);
let postman = JSON.parse(rawdata);
let mockoon = Mockoon()
let env = Environment()
transformPostmanToMockoon({ postman, mockoon, env })
fs.writeFile(outfile[1], JSON.stringify(mockoon, null, 4), function (err) {
if (err) throw err;
console.log(`Mockoon file saved to ${outfile[1]}`);
});