-
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.
Refactored the plugin to use the new
initialize()
method and `this.…
…engine` property
- Loading branch information
1 parent
9eb7508
commit f19d3fc
Showing
4 changed files
with
59 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { File, Plugin, Run } from "@code-engine/types"; | ||
import { resolve } from "path"; | ||
import { clean } from "./clean"; | ||
import { FileSystemConfig } from "./config"; | ||
import { normalizeConfig } from "./normalize-config"; | ||
import { writeFile } from "./write-file"; | ||
|
||
/** | ||
* A CodeEngine plugin that writes files to the filesystem. | ||
*/ | ||
export function filesystem(conf?: FileSystemConfig): Plugin { | ||
let config = normalizeConfig(conf); | ||
let dir: string; | ||
|
||
return { | ||
name: "Filesystem Destination", | ||
|
||
filter: config.filter, | ||
|
||
initialize() { | ||
// Resolve the output directory, relative to the CodeEngine CWD | ||
dir = resolve(this.engine.cwd, config.path); | ||
}, | ||
|
||
/** | ||
* Writes a file to the filesystem, creating parent directories if needed. | ||
*/ | ||
async processFile(file: File, run: Run) { | ||
await writeFile(dir, file, config.fs); | ||
}, | ||
|
||
/** | ||
* Cleans the destination directory by deleting all of its contents. | ||
*/ | ||
async clean() { | ||
await clean(dir, config.fs); | ||
}, | ||
}; | ||
} |
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