code-engine-destination-filesystem
Advanced tools
Comparing version 0.0.6 to 0.0.7
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ono_1 = require("ono"); | ||
const path_1 = require("path"); | ||
@@ -12,9 +13,39 @@ const trash = require("trash"); | ||
let dir = path_1.resolve(context.cwd, config.path); | ||
// Move the output directory to the OS trash. | ||
// This is safer than permanently deleting it, | ||
// and allows users to roll-back to previous output if they want. | ||
await trash(dir, { glob: false }); | ||
let exists = await directoryExists(dir, config); | ||
if (exists) { | ||
// Move the output directory to the OS trash. | ||
// This is safer than permanently deleting it, | ||
// and allows users to roll-back to previous output if they want. | ||
await trash(dir, { glob: false }); | ||
} | ||
}; | ||
} | ||
exports.clean = clean; | ||
/** | ||
* Determines whether the specified directory exists. | ||
* An error is thrown if the path exists and is not a directory. | ||
*/ | ||
async function directoryExists(dir, config) { | ||
try { | ||
let stats = await config.fs.promises.stat(dir); | ||
if (stats.isDirectory()) { | ||
// The directory exists | ||
return true; | ||
} | ||
else { | ||
throw ono_1.ono({ code: "ENOTDIR", path: dir }, `The destination path is not a directory: ${dir}`); | ||
} | ||
} | ||
catch (err) { | ||
let error = err; | ||
if (error.code === "ENOENT") { | ||
// The directory does not exist | ||
return false; | ||
} | ||
else { | ||
// Some other error occurred | ||
throw err; | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=clean.js.map |
/// <reference types="node" /> | ||
import { Filter } from "@code-engine/types"; | ||
import { MakeDirectoryOptions, NoParamCallback, WriteFileOptions } from "fs"; | ||
import { MakeDirectoryOptions, NoParamCallback, Stats, WriteFileOptions } from "fs"; | ||
/** | ||
@@ -32,2 +32,6 @@ * Configuration for the fileystem destination plugin. | ||
/** | ||
* Returns filesystem information about a directory entry. | ||
*/ | ||
stat(path: string, callback: Callback<Stats>): void; | ||
/** | ||
* Creates a directory. Also creates its parent directories if the `recursive` option is set. | ||
@@ -41,1 +45,5 @@ */ | ||
} | ||
/** | ||
* An error-first callback function. | ||
*/ | ||
export declare type Callback<T> = (err: Error | null, result: T) => void; |
/// <reference types="node" /> | ||
import { MakeDirectoryOptions, WriteFileOptions } from "fs"; | ||
import { MakeDirectoryOptions, Stats, WriteFileOptions } from "fs"; | ||
import { FS } from "./config"; | ||
@@ -9,2 +9,3 @@ /** | ||
promises: { | ||
stat(path: string): Promise<Stats>; | ||
mkdir(path: string, option: MakeDirectoryOptions): Promise<void>; | ||
@@ -11,0 +12,0 @@ writeFile(path: string, data: Buffer, options: WriteFileOptions): Promise<void>; |
@@ -17,5 +17,7 @@ "use strict"; | ||
fs = { | ||
stat: validate_1.validate.type.function(config.fs.stat, "fs.stat", nodeFS.stat), | ||
mkdir: validate_1.validate.type.function(config.fs.mkdir, "fs.mkdir", nodeFS.mkdir), | ||
writeFile: validate_1.validate.type.function(config.fs.writeFile, "fs.writeFile", nodeFS.writeFile), | ||
promises: { | ||
stat: util_1.promisify(validate_1.validate.type.function(config.fs.stat, "fs.stat", nodeFS.stat)), | ||
mkdir: util_1.promisify(validate_1.validate.type.function(config.fs.mkdir, "fs.mkdir", nodeFS.mkdir)), | ||
@@ -22,0 +24,0 @@ writeFile: util_1.promisify(validate_1.validate.type.function(config.fs.writeFile, "fs.writeFile", nodeFS.writeFile)), |
{ | ||
"name": "code-engine-destination-filesystem", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "A CodeEngine plugin that reads files from the filesystem", | ||
@@ -70,4 +70,5 @@ "keywords": [ | ||
"@code-engine/validate": "^1.0.0", | ||
"ono": "^5.1.0", | ||
"trash": "^6.1.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16077
233
3
+ Addedono@^5.1.0
+ Addedono@5.1.0(transitive)