-
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: add ssh git clone functionality
First approach, waiting feedback to finish feature. Tested on MacOS, testing on Windows needed.
- Loading branch information
1 parent
251b802
commit ee09f2d
Showing
3 changed files
with
76 additions
and
8 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 +1,2 @@ | ||
node_modules | ||
node_modules | ||
.api-mock-runner |
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,15 +1,20 @@ | ||
const OpenApiMocker = require('open-api-mocker') | ||
const OpenApiMocker = require("open-api-mocker"); | ||
const cloneGitRepository = require("./services/clone-git-repository"); | ||
|
||
const main = async () => { | ||
const testRepoSSH = "git@gitlab.sngular.com: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(testRepoSSH); | ||
|
||
const openApiMocker = new OpenApiMocker({ | ||
port: 5000, | ||
schema: `${__dirname}/../tests/schema-examples/basic.yaml`, | ||
watch: true | ||
}) | ||
watch: true, | ||
}); | ||
|
||
await openApiMocker.validate() | ||
await openApiMocker.validate(); | ||
|
||
await openApiMocker.mock() | ||
} | ||
await openApiMocker.mock(); | ||
}; | ||
|
||
main() | ||
main(); |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// TODO: | ||
// - Refactor | ||
// - console.logs | ||
// - tests | ||
// - doc | ||
|
||
const { execSync } = require("child_process"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const readline = require("readline"); | ||
const process = require("process"); | ||
|
||
const TEMP_FOLDER_NAME = ".api-mock-runner"; // TODO: extract to configuration file? | ||
|
||
async function cloneSchemaRepo(repositoryURL) { | ||
resetTempDir(); | ||
cloneRepository(repositoryURL); | ||
printDirectoryContent(); | ||
await waitUserInput(); // FIXME: Temp until command line interface is finished | ||
} | ||
|
||
function resetTempDir() { | ||
removeTempDir(); | ||
fs.mkdirSync(TEMP_FOLDER_NAME); | ||
} | ||
|
||
function removeTempDir() { | ||
if (fs.existsSync(TEMP_FOLDER_NAME)) { | ||
fs.rmSync(TEMP_FOLDER_NAME, { recursive: true }); | ||
} | ||
} | ||
|
||
function cloneRepository(repositoryURL) { | ||
execSync(`git clone ${repositoryURL} .`, { | ||
cwd: path.resolve(process.cwd(), TEMP_FOLDER_NAME), // path to where you want to save the file | ||
}); | ||
} | ||
|
||
function printDirectoryContent() { | ||
console.log("Directory content:"); // FIXME: console.log | ||
fs.readdirSync(TEMP_FOLDER_NAME).forEach((file) => { | ||
console.log(` - ${file}`); | ||
}); | ||
} | ||
|
||
async function waitUserInput() { | ||
const readLineInterface = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
|
||
const message = "Waiting user input to finish..."; | ||
return new Promise((resolve) => | ||
readLineInterface.question(message, answer => { | ||
readLineInterface.close(); | ||
removeTempDir(); | ||
resolve(answer); | ||
}) | ||
); | ||
} | ||
|
||
module.exports = cloneSchemaRepo; |