@file-services/utils
Advanced tools
Comparing version 0.2.0 to 0.2.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function createSyncFileSystem(baseFs) { | ||
const { statSync, path, mkdirSync } = baseFs; | ||
const { statSync, path, mkdirSync, writeFileSync } = baseFs; | ||
function fileExistsSync(filePath, statFn = statSync) { | ||
@@ -37,9 +37,22 @@ try { | ||
} | ||
function populateDirectorySync(directoryPath, contents) { | ||
ensureDirectorySync(directoryPath); | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
writeFileSync(nodePath, nodeValue); | ||
} | ||
else { | ||
populateDirectorySync(nodePath, nodeValue); | ||
} | ||
} | ||
} | ||
return Object.assign({}, baseFs, { fileExistsSync, | ||
directoryExistsSync, | ||
ensureDirectorySync }); | ||
ensureDirectorySync, | ||
populateDirectorySync }); | ||
} | ||
exports.createSyncFileSystem = createSyncFileSystem; | ||
function createAsyncFileSystem(baseFs) { | ||
const { stat, path, mkdir } = baseFs; | ||
const { stat, path, mkdir, writeFile } = baseFs; | ||
async function fileExists(filePath, statFn = stat) { | ||
@@ -77,7 +90,20 @@ try { | ||
} | ||
async function populateDirectory(directoryPath, contents) { | ||
await ensureDirectory(directoryPath); | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
await writeFile(nodePath, nodeValue); | ||
} | ||
else { | ||
await populateDirectory(nodePath, nodeValue); | ||
} | ||
} | ||
} | ||
return Object.assign({}, baseFs, { fileExists, | ||
directoryExists, | ||
ensureDirectory }); | ||
ensureDirectory, | ||
populateDirectory }); | ||
} | ||
exports.createAsyncFileSystem = createAsyncFileSystem; | ||
//# sourceMappingURL=create-extended-api.js.map |
export function createSyncFileSystem(baseFs) { | ||
const { statSync, path, mkdirSync } = baseFs; | ||
const { statSync, path, mkdirSync, writeFileSync } = baseFs; | ||
function fileExistsSync(filePath, statFn = statSync) { | ||
@@ -35,8 +35,21 @@ try { | ||
} | ||
function populateDirectorySync(directoryPath, contents) { | ||
ensureDirectorySync(directoryPath); | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
writeFileSync(nodePath, nodeValue); | ||
} | ||
else { | ||
populateDirectorySync(nodePath, nodeValue); | ||
} | ||
} | ||
} | ||
return Object.assign({}, baseFs, { fileExistsSync, | ||
directoryExistsSync, | ||
ensureDirectorySync }); | ||
ensureDirectorySync, | ||
populateDirectorySync }); | ||
} | ||
export function createAsyncFileSystem(baseFs) { | ||
const { stat, path, mkdir } = baseFs; | ||
const { stat, path, mkdir, writeFile } = baseFs; | ||
async function fileExists(filePath, statFn = stat) { | ||
@@ -74,6 +87,19 @@ try { | ||
} | ||
async function populateDirectory(directoryPath, contents) { | ||
await ensureDirectory(directoryPath); | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
await writeFile(nodePath, nodeValue); | ||
} | ||
else { | ||
await populateDirectory(nodePath, nodeValue); | ||
} | ||
} | ||
} | ||
return Object.assign({}, baseFs, { fileExists, | ||
directoryExists, | ||
ensureDirectory }); | ||
ensureDirectory, | ||
populateDirectory }); | ||
} | ||
//# sourceMappingURL=create-extended-api.js.map |
{ | ||
"name": "@file-services/utils", | ||
"description": "Common file system utility functions.", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"main": "cjs/index.js", | ||
@@ -17,6 +17,6 @@ "module": "esm/index.js", | ||
"dependencies": { | ||
"@file-services/types": "^0.2.0" | ||
"@file-services/types": "^0.2.1" | ||
}, | ||
"devDependencies": { | ||
"@file-services/test-kit": "^0.2.0" | ||
"@file-services/test-kit": "^0.2.1" | ||
}, | ||
@@ -34,3 +34,3 @@ "files": [ | ||
}, | ||
"gitHead": "5fe82335a0d97b095d5e522866abb96d160d7ab3" | ||
"gitHead": "e4a29c8bf0de8d773f0e6e1646d028063cc62952" | ||
} |
@@ -1,5 +0,11 @@ | ||
import { IBaseFileSystemAsync, IBaseFileSystemSync, IFileSystemAsync, IFileSystemSync } from '@file-services/types' | ||
import { | ||
IBaseFileSystemAsync, | ||
IBaseFileSystemSync, | ||
IFileSystemAsync, | ||
IFileSystemSync, | ||
IDirectoryContents | ||
} from '@file-services/types' | ||
export function createSyncFileSystem(baseFs: IBaseFileSystemSync): IFileSystemSync { | ||
const { statSync, path, mkdirSync } = baseFs | ||
const { statSync, path, mkdirSync, writeFileSync } = baseFs | ||
@@ -38,2 +44,15 @@ function fileExistsSync(filePath: string, statFn = statSync): boolean { | ||
function populateDirectorySync(directoryPath: string, contents: IDirectoryContents): void { | ||
ensureDirectorySync(directoryPath) | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName) | ||
if (typeof nodeValue === 'string') { | ||
writeFileSync(nodePath, nodeValue) | ||
} else { | ||
populateDirectorySync(nodePath, nodeValue) | ||
} | ||
} | ||
} | ||
return { | ||
@@ -43,3 +62,4 @@ ...baseFs, | ||
directoryExistsSync, | ||
ensureDirectorySync | ||
ensureDirectorySync, | ||
populateDirectorySync | ||
} | ||
@@ -49,3 +69,3 @@ } | ||
export function createAsyncFileSystem(baseFs: IBaseFileSystemAsync): IFileSystemAsync { | ||
const { stat, path, mkdir } = baseFs | ||
const { stat, path, mkdir, writeFile } = baseFs | ||
@@ -84,2 +104,15 @@ async function fileExists(filePath: string, statFn = stat): Promise<boolean> { | ||
async function populateDirectory(directoryPath: string, contents: IDirectoryContents): Promise<void> { | ||
await ensureDirectory(directoryPath) | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName) | ||
if (typeof nodeValue === 'string') { | ||
await writeFile(nodePath, nodeValue) | ||
} else { | ||
await populateDirectory(nodePath, nodeValue) | ||
} | ||
} | ||
} | ||
return { | ||
@@ -89,4 +122,5 @@ ...baseFs, | ||
directoryExists, | ||
ensureDirectory | ||
ensureDirectory, | ||
populateDirectory | ||
} | ||
} |
@@ -5,7 +5,4 @@ { | ||
"module": "commonjs", | ||
"outDir": "../cjs", | ||
"types": [ | ||
"node" | ||
] | ||
"outDir": "../cjs" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
28496
479
Updated@file-services/types@^0.2.1