forked from unlight/prisma-nestjs-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(configuration): Allow purge output folder
closes: unlight#7
- Loading branch information
Showing
6 changed files
with
45 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import AwaitEventEmitter from 'await-event-emitter'; | ||
import { promises as fs } from 'fs'; | ||
|
||
import { EventArguments } from '../types'; | ||
|
||
export function purgeOutput(emitter: AwaitEventEmitter) { | ||
emitter.on('Begin', begin); | ||
emitter.on('End', end); | ||
} | ||
|
||
function begin({ project, output }: EventArguments) { | ||
const sourceFiles = project.getDirectory(output)?.getDescendantSourceFiles(); | ||
|
||
if (sourceFiles) { | ||
for (const sourceFile of sourceFiles) { | ||
sourceFile.delete(); | ||
} | ||
} | ||
} | ||
|
||
async function end({ project, output }: EventArguments) { | ||
const directories = project | ||
.getDirectory(output) | ||
?.getDescendantDirectories() | ||
.filter(directory => directory.getSourceFiles().length === 0) | ||
.map(directory => directory.getPath()); | ||
|
||
for (const directory of directories || []) { | ||
try { | ||
await fs.rmdir(directory); | ||
// eslint-disable-next-line no-empty | ||
} catch {} | ||
} | ||
} |
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
File renamed without changes.