-
Notifications
You must be signed in to change notification settings - Fork 820
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c88744f
commit af1d446
Showing
4 changed files
with
56 additions
and
35 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
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,22 +1,23 @@ | ||
import * as fs from 'fs-extra'; | ||
import { ExportPathValidationError } from '../errors'; | ||
|
||
import * as path from 'path'; | ||
/** | ||
* Validates whether the path is a directory | ||
* @throws {ExportPathValidationError} if path not valid | ||
* @param directoryPath to validate | ||
*/ | ||
export function validateExportDirectoryPath(directoryPath: any) { | ||
if (typeof directoryPath !== 'string') { | ||
throw new ExportPathValidationError(`${directoryPath} is not a valid path specified by --out`); | ||
} | ||
export function validateExportDirectoryPath(directoryPath: any, defaultPath: string): string { | ||
const exportPath = directoryPath || defaultPath; | ||
const resolvedDir = path.resolve(exportPath); | ||
|
||
if (!fs.existsSync(directoryPath)) { | ||
throw new ExportPathValidationError(`${directoryPath} does not exist`); | ||
if (!fs.existsSync(resolvedDir)) { | ||
fs.ensureDirSync(resolvedDir); | ||
} else { | ||
const stat = fs.lstatSync(exportPath); | ||
if (!stat.isDirectory()) { | ||
throw new ExportPathValidationError(`${exportPath} is not a valid directory`); | ||
} | ||
} | ||
|
||
const stat = fs.lstatSync(directoryPath); | ||
if (!stat.isDirectory()) { | ||
throw new ExportPathValidationError(`${directoryPath} is not a valid directory`); | ||
} | ||
return resolvedDir; | ||
} |
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
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