@stryke/fs 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,10 +7,12 @@ exports.createDirectory = createDirectory;
7
7
  exports.createDirectorySync = createDirectorySync;
8
8
  exports.extractFileFromTar = extractFileFromTar;
9
9
  exports.extractFileFromTarGzip = extractFileFromTarGzip;
10
- var _exists = require("@stryke/path/utilities/exists");
11
- var _nanotar = require("nanotar");
10
+ exports.removeDirectory = removeDirectory;
11
+ exports.removeDirectorySync = removeDirectorySync;
12
12
  var _nodeFs = require("node:fs");
13
13
  var _promises = require("node:fs/promises");
14
+ var _exists = require("@stryke/path/utilities/exists");
15
+ var _nanotar = require("nanotar");
14
16
  function createDirectorySync(r) {
15
17
  if (!(0, _exists.existsSync)(r)) return (0, _nodeFs.mkdirSync)(r, {
16
18
  recursive: !0
@@ -21,17 +23,27 @@ async function createDirectory(r) {
21
23
  recursive: !0
22
24
  });
23
25
  }
24
- async function extractFileFromTar(r, a, t) {
25
- const e = (0, _nanotar.parseTar)(await (0, _promises.readFile)(r)).find(i => i.name === a);
26
+ function removeDirectorySync(r) {
27
+ if ((0, _exists.existsSync)(r)) return (0, _nodeFs.rmdirSync)(r, {
28
+ recursive: !0
29
+ });
30
+ }
31
+ async function removeDirectory(r) {
32
+ if ((0, _exists.existsSync)(r)) return (0, _promises.rmdir)(r, {
33
+ recursive: !0
34
+ });
35
+ }
36
+ async function extractFileFromTar(r, i, t) {
37
+ const e = (0, _nanotar.parseTar)(await (0, _promises.readFile)(r)).find(n => n.name === i);
26
38
  if (!e?.data) return;
27
39
  (await (0, _exists.exists)(t)) || (await (0, _promises.mkdir)(t, {
28
40
  recursive: !0
29
- })), await (0, _nodeFs.createWriteStream)(t).write(e.data);
41
+ })), (0, _nodeFs.createWriteStream)(t).write(e.data);
30
42
  }
31
- async function extractFileFromTarGzip(r, a, t) {
32
- const e = (await (0, _nanotar.parseTarGzip)(await (0, _promises.readFile)(r))).find(i => i.name === a);
43
+ async function extractFileFromTarGzip(r, i, t) {
44
+ const e = (await (0, _nanotar.parseTarGzip)(await (0, _promises.readFile)(r))).find(n => n.name === i);
33
45
  if (!e?.data) return;
34
46
  (await (0, _exists.exists)(t)) || (await (0, _promises.mkdir)(t, {
35
47
  recursive: !0
36
- })), await (0, _nodeFs.createWriteStream)(t).write(e.data);
48
+ })), (0, _nodeFs.createWriteStream)(t).write(e.data);
37
49
  }
@@ -1,17 +1,31 @@
1
1
  /**
2
2
  * Create a directory if it does not exist.
3
3
  *
4
- * @param filePath - The directory path to check
4
+ * @param path - The directory path to check
5
5
  * @returns An indicator specifying if the directory exists
6
6
  */
7
7
  export declare function createDirectorySync(path: string): string | undefined;
8
8
  /**
9
9
  * Create a directory if it does not exist.
10
10
  *
11
- * @param filePath - The directory path to check
11
+ * @param path - The directory path to check
12
12
  * @returns An indicator specifying if the directory exists
13
13
  */
14
14
  export declare function createDirectory(path: string): Promise<string | undefined>;
15
+ /**
16
+ * Remove a directory if it exists.
17
+ *
18
+ * @param path - The directory path to check
19
+ * @returns An indicator specifying if the directory exists
20
+ */
21
+ export declare function removeDirectorySync(path: string): void;
22
+ /**
23
+ * Remove a directory if it exists.
24
+ *
25
+ * @param path - The directory path to check
26
+ * @returns An indicator specifying if the directory exists
27
+ */
28
+ export declare function removeDirectory(path: string): Promise<void>;
15
29
  /**
16
30
  * Extracts a file from a given tarball to the specified destination.
17
31
  *
@@ -1 +1 @@
1
- import{exists as n,existsSync as f}from"@stryke/path/utilities/exists";import{parseTar as w,parseTarGzip as p}from"nanotar";import{createWriteStream as c,mkdirSync as y}from"node:fs";import{mkdir as s,readFile as o}from"node:fs/promises";export function createDirectorySync(r){if(!f(r))return y(r,{recursive:!0})}export async function createDirectory(r){if(!await n(r))return s(r,{recursive:!0})}export async function extractFileFromTar(r,a,t){const e=w(await o(r)).find(i=>i.name===a);if(!e?.data)return;await n(t)||await s(t,{recursive:!0}),await c(t).write(e.data)}export async function extractFileFromTarGzip(r,a,t){const e=(await p(await o(r))).find(i=>i.name===a);if(!e?.data)return;await n(t)||await s(t,{recursive:!0}),await c(t).write(e.data)}
1
+ import{createWriteStream as u,mkdirSync as y,rmdirSync as g}from"node:fs";import{mkdir as c,readFile as o,rmdir as p}from"node:fs/promises";import{exists as s,existsSync as a}from"@stryke/path/utilities/exists";import{parseTar as w,parseTarGzip as x}from"nanotar";export function createDirectorySync(r){if(!a(r))return y(r,{recursive:!0})}export async function createDirectory(r){if(!await s(r))return c(r,{recursive:!0})}export function removeDirectorySync(r){if(a(r))return g(r,{recursive:!0})}export async function removeDirectory(r){if(a(r))return p(r,{recursive:!0})}export async function extractFileFromTar(r,i,t){const e=w(await o(r)).find(n=>n.name===i);if(!e?.data)return;await s(t)||await c(t,{recursive:!0}),u(t).write(e.data)}export async function extractFileFromTarGzip(r,i,t){const e=(await x(await o(r))).find(n=>n.name===i);if(!e?.data)return;await s(t)||await c(t,{recursive:!0}),u(t).write(e.data)}
@@ -47,6 +47,17 @@ Object.keys(_helpers).forEach(function (key) {
47
47
  }
48
48
  });
49
49
  });
50
+ var _listFiles = require("./list-files.cjs");
51
+ Object.keys(_listFiles).forEach(function (key) {
52
+ if (key === "default" || key === "__esModule") return;
53
+ if (key in exports && exports[key] === _listFiles[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _listFiles[key];
58
+ }
59
+ });
60
+ });
50
61
  var _readFile = require("./read-file.cjs");
51
62
  Object.keys(_readFile).forEach(function (key) {
52
63
  if (key === "default" || key === "__esModule") return;
@@ -2,6 +2,7 @@ export * from "./chmod-x";
2
2
  export * from "./constants";
3
3
  export * from "./copy-files";
4
4
  export * from "./helpers";
5
+ export * from "./list-files";
5
6
  export * from "./read-file";
6
7
  export * from "./remove-file";
7
8
  export * from "./write-file";
@@ -1 +1 @@
1
- export*from"./chmod-x";export*from"./constants";export*from"./copy-files";export*from"./helpers";export*from"./read-file";export*from"./remove-file";export*from"./write-file";
1
+ export*from"./chmod-x";export*from"./constants";export*from"./copy-files";export*from"./helpers";export*from"./list-files";export*from"./read-file";export*from"./remove-file";export*from"./write-file";
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.listFiles = listFiles;
7
+ var _promises = require("node:fs/promises");
8
+ var _isFile = require("@stryke/path/utilities/is-file");
9
+ var _joinPaths = require("@stryke/path/utilities/join-paths");
10
+ async function listFiles(a) {
11
+ const s = [],
12
+ t = async r => {
13
+ const n = await (0, _promises.readdir)(r);
14
+ await Promise.all(n.map(async o => {
15
+ const i = (0, _joinPaths.joinPaths)(r, o);
16
+ (0, _isFile.isDirectory)(i) ? await t(i) : s.push(i);
17
+ }));
18
+ };
19
+ return await t(a), s;
20
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The file listing library used by Storm Software for building TypeScript applications.
3
+ *
4
+ * @param directoryPath - The directory path to list files from
5
+ * @returns A list of file paths
6
+ */
7
+ export declare function listFiles(directoryPath: string): Promise<string[]>;
@@ -0,0 +1 @@
1
+ import{readdir as e}from"node:fs/promises";import{isDirectory as m}from"@stryke/path/utilities/is-file";import{joinPaths as c}from"@stryke/path/utilities/join-paths";export async function listFiles(a){const s=[],t=async r=>{const n=await e(r);await Promise.all(n.map(async o=>{const i=c(r,o);m(i)?await t(i):s.push(i)}))};return await t(a),s}
@@ -10,7 +10,7 @@ const removeFileSync = r => {
10
10
  if (!r || !(0, _nodeFs.existsSync)(r)) throw new Error("Invalid file path provided to remove data");
11
11
  (0, _nodeFs.rmSync)(r);
12
12
  },
13
- removeFile = r => {
13
+ removeFile = async r => {
14
14
  if (!r || !(0, _nodeFs.existsSync)(r)) throw new Error("Invalid file path provided to remove data");
15
15
  return (0, _promises.rm)(r);
16
16
  };
@@ -1 +1 @@
1
- import{existsSync as o,rmSync as e}from"node:fs";import{rm as i}from"node:fs/promises";export const removeFileSync=r=>{if(!r||!o(r))throw new Error("Invalid file path provided to remove data");e(r)},removeFile=r=>{if(!r||!o(r))throw new Error("Invalid file path provided to remove data");return i(r)};
1
+ import{existsSync as o,rmSync as e}from"node:fs";import{rm as i}from"node:fs/promises";export const removeFileSync=r=>{if(!r||!o(r))throw new Error("Invalid file path provided to remove data");e(r)},removeFile=async r=>{if(!r||!o(r))throw new Error("Invalid file path provided to remove data");return i(r)};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/fs",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "description": "A package containing various file system utilities that expand the functionality of NodeJs's `fs` module.",
6
6
  "repository": {
@@ -17,9 +17,9 @@
17
17
  "chalk": "^5.4.1",
18
18
  "nanotar": "^0.2.0",
19
19
  "semver": "7.7.1",
20
- "@stryke/json": ">=0.4.0",
21
- "@stryke/path": ">=0.2.0",
22
- "@stryke/types": ">=0.5.0"
20
+ "@stryke/json": ">=0.4.2",
21
+ "@stryke/path": ">=0.3.1",
22
+ "@stryke/types": ">=0.5.1"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^22.13.1",
@@ -191,6 +191,20 @@
191
191
  "default": "./dist/files/read-file.mjs"
192
192
  }
193
193
  },
194
+ "./files/list-files": {
195
+ "import": {
196
+ "types": "./dist/files/list-files.d.ts",
197
+ "default": "./dist/files/list-files.mjs"
198
+ },
199
+ "require": {
200
+ "types": "./dist/files/list-files.d.ts",
201
+ "default": "./dist/files/list-files.cjs"
202
+ },
203
+ "default": {
204
+ "types": "./dist/files/list-files.d.ts",
205
+ "default": "./dist/files/list-files.mjs"
206
+ }
207
+ },
194
208
  "./files/index": {
195
209
  "import": {
196
210
  "types": "./dist/files/index.d.ts",