Fixed repo cloning logic for live validator
This commit is contained in:
Родитель
c7a21320d3
Коммит
f974a31a06
|
@ -1,3 +1,6 @@
|
|||
### 08/03/2017 0.4.8
|
||||
- [Live Validator] Before cloning the rest api specs repo if directory named 'repo' exists we delete it and then create an empty directory to clone repo inside it.
|
||||
|
||||
### 07/11/2017 0.4.7
|
||||
- Fixed Live validator for reorg branch of azure-rest-api-specs #137
|
||||
|
||||
|
|
|
@ -437,14 +437,28 @@ exports.gitClone = function gitClone(url, directory) {
|
|||
|
||||
// If the directory exists then we assume that the repo to be cloned is already present.
|
||||
if (fs.existsSync(directory)) {
|
||||
if (!fs.lstatSync(directory).isDirectory()) {
|
||||
throw new Error(`"${directory}" must be a directory.`);
|
||||
if (fs.lstatSync(directory).isDirectory()) {
|
||||
try {
|
||||
exports.removeDirSync(directory);
|
||||
} catch (err) {
|
||||
throw new Error(`An error occurred while deleting directory ${directory}: ${util.inspect(err, { depth: null })}.`);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
fs.unlinkSync(directory);
|
||||
} catch (err) {
|
||||
throw new Error(`An error occurred while deleting file ${directory}: ${util.inspect(err, { depth: null })}.`);
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
fs.mkdirSync(directory);
|
||||
}
|
||||
|
||||
try {
|
||||
fs.mkdirSync(directory);
|
||||
} catch (err) {
|
||||
throw new Error(`An error occurred while creating directory ${directory}: ${util.inspect(err, { depth: null })}.`);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
let cmd = `git clone ${url} ${directory}`;
|
||||
let result = execSync(cmd, { encoding: 'utf8' });
|
||||
|
@ -453,6 +467,21 @@ exports.gitClone = function gitClone(url, directory) {
|
|||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Removes given directory recursively.
|
||||
* @param {string} dir directory to be deleted.
|
||||
*/
|
||||
exports.removeDirSync = function removeDirSync(dir) {
|
||||
if (fs.existsSync(dir)) {
|
||||
fs.readdirSync(dir).forEach(function (file) {
|
||||
var current = dir + '/' + file;
|
||||
if (fs.statSync(current).isDirectory()) exports.removeDirSync(current);
|
||||
else fs.unlinkSync(current);
|
||||
})
|
||||
fs.rmdirSync(dir);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Finds the first content-type that contains "/json". Only supported Content-Types are
|
||||
* "text/json" & "application/json" so we perform first best match that contains '/json'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "oav",
|
||||
"version": "0.4.7",
|
||||
"version": "0.4.8",
|
||||
"author": {
|
||||
"name": "Microsoft Corporation",
|
||||
"email": "azsdkteam@microsoft.com",
|
||||
|
|
Загрузка…
Ссылка в новой задаче