Skip to content

Commit

Permalink
feat(cli): validate local or remote regex
Browse files Browse the repository at this point in the history
Refs #5 #10
  • Loading branch information
MHCYR committed Oct 5, 2023
1 parent 766ea23 commit 58bbb07
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,52 @@ const main = async () => {
});
if (addRcFileToGitignore) {
// TODO: create function that validates if is already in gitignore
fs.appendFile(`${process.cwd()}/.gitignore`, `\n${RC_FILE_NAME}`, (err) => {
if (err) {
console.error(err);
} else {
console.log(`${RC_FILE_NAME} added to .gitignore`);
fs.appendFile(
`${process.cwd()}/.gitignore`,
`\n${RC_FILE_NAME}`,
(err) => {
if (err) {
console.error(err);
} else {
console.log(`${RC_FILE_NAME} added to .gitignore`);
}
}
});
);
}
}
/*
* TODO:
* validate path type (local or url)
* if remote repo, clone it, add temp dir to gitignore
* run findOasFromDir on the temp or local dir
* CLI shows the list of schemas found
* CLI asks for the schema to mock (select from list)
* Start server on selected port
*/
/*
* TODO:
* validate path type (local or url) [DONE]
* if remote repo, clone it, add temp dir to gitignore
* run findOasFromDir on the temp or local dir
* CLI shows the list of schemas found
* CLI asks for the schema to mock (select from list)
* Start server on selected port
*/

await cloneGitRepository(config.schemasOrigin || testRepoSSH);
/*
* NOTE: Regex explanation
* - /^(git@|https:\/\/)/: This part of the regex specifies that the string must start with either "git@" or "https://".
* - [^\s]+: This part ensures that there is at least one or more characters after "git@" or "https://". It matches any character except whitespace.
* - (\.git)$: The regex ends with "\.git", ensuring that the string must end with ".git".
*/
const isOriginRemoteRegex = /^(git@|https:\/\/)[^\s]+(\.git)$/;

const schemas = await findOasFromDir("./tests");
const isOriginRemote = isOriginRemoteRegex.test(config.schemasOrigin);

const openApiMocker = new OpenApiMocker({
port: config.initialPort,
schema: schemas[0].filePath,
watch: true,
});
await cloneGitRepository(config.schemasOrigin);

const schemas = await findOasFromDir("./tests");

const openApiMocker = new OpenApiMocker({
port: config.initialPort,
schema: schemas[0].filePath,
watch: true,
});

await openApiMocker.validate();
await openApiMocker.validate();

await openApiMocker.mock();
await openApiMocker.mock();
};

main();

0 comments on commit 58bbb07

Please # to comment.