mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Fix for safe delete
This commit is contained in:
parent
d76cac7348
commit
c450461bd3
@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rf examples
|
||||
rm -rf dist
|
||||
rm swagger-codegen-cli-v2.jar
|
||||
rm swagger-codegen-cli-v3.jar
|
||||
|
||||
|
||||
5
src/utils/isSubdirectory.ts
Normal file
5
src/utils/isSubdirectory.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { relative } from 'path';
|
||||
|
||||
export function isSubDirectory(parent: string, child: string) {
|
||||
return relative(child, parent).startsWith('..');
|
||||
}
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user