-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(main): connect input with clone repo function
Refs #5
- Loading branch information
1 parent
341e61f
commit 8590aa9
Showing
1 changed file
with
19 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import OpenApiMocker from "open-api-mocker"; | ||
import cloneGitRepository from "./services/clone-git-repository.js"; | ||
import { input, confirm } from "@inquirer/prompts"; | ||
import * as fs from "node:fs"; | ||
import path from "path"; | ||
|
@@ -7,7 +9,7 @@ const __filename = fileURLToPath(import.meta.url); | |
|
||
const __dirname = path.dirname(__filename); | ||
|
||
const run = async () => { | ||
const main = async () => { | ||
const config = { | ||
repoUrl: await input({ message: "Enter the repo url" }), | ||
dirPath: await input({ message: "Enter the directory path" }), | ||
|
@@ -20,17 +22,29 @@ const run = async () => { | |
console.table(config); | ||
|
||
if (config.saveConfig) { | ||
// Save config | ||
// create an .apimockrc file on the root of the project | ||
const filePath = `${__dirname}/.apimockrc`; | ||
fs.writeFile(filePath, JSON.stringify(config), (err) => { | ||
if (err) { | ||
console.log(err); | ||
console.error(err); | ||
} else { | ||
console.log("Config saved"); | ||
} | ||
}); | ||
} | ||
|
||
const testRepoSSH = "[email protected]:os3/manatee/sirenia.git"; // TODO: replace by user input | ||
const testRepoHTTPS = "https://gitlab.sngular.com/os3/manatee/sirenia.git"; // TODO: replace by user input | ||
await cloneGitRepository(config.repoUrl || testRepoSSH); | ||
|
||
const openApiMocker = new OpenApiMocker({ | ||
port: 5000, | ||
schema: schemas[0].filePath, | ||
watch: true, | ||
}); | ||
|
||
await openApiMocker.validate(); | ||
|
||
await openApiMocker.mock(); | ||
}; | ||
|
||
run(); | ||
main(); |