@stryke/fs 0.30.0 → 0.30.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.
@@ -3,14 +3,38 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.copyFilesSync = exports.copyFiles = exports.copyFileSync = exports.copyFile = void 0;
6
+ exports.copyFile = copyFile;
7
+ exports.copyFileSync = copyFileSync;
8
+ exports.copyFiles = copyFiles;
9
+ exports.copyFilesSync = copyFilesSync;
10
+ var _path = require("@stryke/path");
11
+ var _mlly = require("mlly");
7
12
  var _nodeFs = require("node:fs");
8
13
  var _promises = require("node:fs/promises");
9
- const copyFile = async (n, o) => (0, _promises.copyFile)(n, o, _nodeFs.constants.COPYFILE_FICLONE),
10
- copyFileSync = (n, o) => (0, _nodeFs.copyFileSync)(n, o, _nodeFs.constants.COPYFILE_FICLONE),
11
- copyFiles = async (n, o, t) => (0, _promises.cp)(n, o, t),
12
- copyFilesSync = (n, o, t) => (0, _nodeFs.cpSync)(n, o, t);
13
- exports.copyFilesSync = copyFilesSync;
14
- exports.copyFiles = copyFiles;
15
- exports.copyFileSync = copyFileSync;
16
- exports.copyFile = copyFile;
14
+ var _helpers = require("./helpers.cjs");
15
+ var _isFile = require("./is-file.cjs");
16
+ var _listFiles = require("./list-files.cjs");
17
+ async function copyFile(t, r) {
18
+ return (0, _promises.copyFile)(t, r);
19
+ }
20
+ function copyFileSync(t, r) {
21
+ return (0, _nodeFs.copyFileSync)(t, r);
22
+ }
23
+ async function copyFiles(t, r) {
24
+ const i = t instanceof URL ? (0, _mlly.fileURLToPath)(t) : t,
25
+ o = r instanceof URL ? (0, _mlly.fileURLToPath)(r) : r;
26
+ return (0, _isFile.isFile)(i) ? copyFile(i, o) : (await (0, _helpers.createDirectory)(o), Promise.all((await (0, _listFiles.listFiles)(i)).map(async n => {
27
+ const c = (0, _path.joinPaths)(i, n),
28
+ s = (0, _path.joinPaths)(o, n);
29
+ (0, _isFile.isDirectory)(n) ? await copyFiles(c, s) : await copyFile(c, s);
30
+ })));
31
+ }
32
+ function copyFilesSync(t, r) {
33
+ const i = t instanceof URL ? (0, _mlly.fileURLToPath)(t) : t,
34
+ o = r instanceof URL ? (0, _mlly.fileURLToPath)(r) : r;
35
+ return (0, _isFile.isFile)(i) ? copyFileSync(i, o) : ((0, _helpers.createDirectorySync)(o), (0, _listFiles.listFilesSync)(i).map(n => {
36
+ const c = (0, _path.joinPaths)(i, n),
37
+ s = (0, _path.joinPaths)(o, n);
38
+ (0, _isFile.isDirectory)(n) ? copyFilesSync(c, s) : copyFileSync(c, s);
39
+ }));
40
+ }
@@ -1,35 +1,32 @@
1
- import type { CopyOptions, CopySyncOptions } from "node:fs";
2
1
  /**
3
2
  * Copy a file from one location to another
4
3
  *
5
- * @param file - The file to copy
6
- * @param to - The destination location
4
+ * @param source - The file to copy, this can be a file, directory, URL, or glob pattern
5
+ * @param destination - The destination location
7
6
  * @returns An indicator specifying if the copy was successful
8
7
  */
9
- export declare const copyFile: (file: string, to: string) => Promise<void>;
8
+ export declare function copyFile(source: string | URL, destination: string | URL): Promise<void>;
10
9
  /**
11
10
  * Synchronously copy a file from one location to another
12
11
  *
13
- * @param file - The file to copy
14
- * @param to - The destination location
12
+ * @param source - The file to copy, this can be a file, directory, URL, or glob pattern
13
+ * @param destination - The destination location
15
14
  * @returns An indicator specifying if the copy was successful
16
15
  */
17
- export declare const copyFileSync: (file: string, to: string) => void;
16
+ export declare function copyFileSync(source: string | URL, destination: string | URL): void;
18
17
  /**
19
18
  * Copy files from one location to another
20
19
  *
21
- * @param from - The source location
22
- * @param to - The destination location
23
- * @param options - The copy options
20
+ * @param source - The source location, this can be a file, directory, URL, or glob pattern
21
+ * @param destination - The destination location
24
22
  * @returns An indicator specifying if the copy was successful
25
23
  */
26
- export declare const copyFiles: (from: string, to: string, options?: CopyOptions) => Promise<void>;
24
+ export declare function copyFiles(source: string | URL, destination: string | URL): Promise<void | void[]>;
27
25
  /**
28
26
  * Synchronously copy files from one location to another
29
27
  *
30
- * @param from - The source location
31
- * @param to - The destination location
32
- * @param options - The copy options
28
+ * @param source - The source location, this can be a file, directory, URL, or glob pattern
29
+ * @param destination - The destination location
33
30
  * @returns An indicator specifying if the copy was successful
34
31
  */
35
- export declare const copyFilesSync: (from: string, to: string, options?: CopySyncOptions) => void;
32
+ export declare function copyFilesSync(source: string | URL, destination: string | URL): void | void[];
@@ -1 +1 @@
1
- import{constants as p,copyFileSync as r,cpSync as s}from"node:fs";import{cp as c,copyFile as i}from"node:fs/promises";export const copyFile=async(n,o)=>i(n,o,p.COPYFILE_FICLONE),copyFileSync=(n,o)=>r(n,o,p.COPYFILE_FICLONE),copyFiles=async(n,o,t)=>c(n,o,t),copyFilesSync=(n,o,t)=>s(n,o,t);
1
+ import{joinPaths as e}from"@stryke/path";import{fileURLToPath as f}from"mlly";import{copyFileSync as m}from"node:fs";import{copyFile as y}from"node:fs/promises";import{createDirectory as l,createDirectorySync as L}from"./helpers";import{isDirectory as p,isFile as a}from"./is-file";import{listFiles as R,listFilesSync as U}from"./list-files";export async function copyFile(t,r){return y(t,r)}export function copyFileSync(t,r){return m(t,r)}export async function copyFiles(t,r){const i=t instanceof URL?f(t):t,o=r instanceof URL?f(r):r;return a(i)?copyFile(i,o):(await l(o),Promise.all((await R(i)).map(async n=>{const c=e(i,n),s=e(o,n);p(n)?await copyFiles(c,s):await copyFile(c,s)})))}export function copyFilesSync(t,r){const i=t instanceof URL?f(t):t,o=r instanceof URL?f(r):r;return a(i)?copyFileSync(i,o):(L(o),U(i).map(n=>{const c=e(i,n),s=e(o,n);p(n)?copyFilesSync(c,s):copyFileSync(c,s)}))}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/fs",
3
- "version": "0.30.0",
3
+ "version": "0.30.1",
4
4
  "type": "module",
5
5
  "description": "A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.",
6
6
  "repository": {
@@ -395,5 +395,5 @@
395
395
  "main": "./dist/index.cjs",
396
396
  "module": "./dist/index.mjs",
397
397
  "types": "./dist/index.d.ts",
398
- "gitHead": "897c39f136bf41e3ad49b8e8c5a6431968e0b07e"
398
+ "gitHead": "e4e84e05b3cd3c057f3817b6cc40de600caa6fe5"
399
399
  }