- Fix for safe delete

This commit is contained in:
Ferdi Koomen 2020-09-24 18:05:57 +02:00
parent d76cac7348
commit c450461bd3
3 changed files with 11 additions and 1 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh
rm -rf examples
rm -rf dist
rm swagger-codegen-cli-v2.jar
rm swagger-codegen-cli-v3.jar

View File

@ -0,0 +1,5 @@
import { relative } from 'path';
export function isSubDirectory(parent: string, child: string) {
return relative(child, parent).startsWith('..');
}

View File

@ -3,6 +3,7 @@ import { resolve } from 'path';
import { Client } from '../client/interfaces/Client';
import { HttpClient } from '../index';
import { mkdir, rmdir } from './fileSystem';
import { isSubDirectory } from './isSubdirectory';
import { Templates } from './registerHandlebarTemplates';
import { writeClientCore } from './writeClientCore';
import { writeClientIndex } from './writeClientIndex';
@ -41,6 +42,10 @@ export async function writeClient(
const outputPathSchemas = resolve(outputPath, 'schemas');
const outputPathServices = resolve(outputPath, 'services');
if (!isSubDirectory(process.cwd(), output)) {
throw new Error(`Output folder is not a subdirectory of the current working directory`);
}
await rmdir(outputPath);
await mkdir(outputPath);