@stryke/fs 0.30.5 → 0.31.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.
@@ -10,6 +10,7 @@ exports.copyFilesSync = copyFilesSync;
10
10
  var _filePathFns = require("@stryke/path/file-path-fns");
11
11
  var _join = require("@stryke/path/join");
12
12
  var _replace = require("@stryke/path/replace");
13
+ var _typeChecks = require("@stryke/type-checks");
13
14
  var _mlly = require("mlly");
14
15
  var _nodeFs = require("node:fs");
15
16
  var _promises = require("node:fs/promises");
@@ -17,27 +18,29 @@ var _exists = require("./exists.cjs");
17
18
  var _helpers = require("./helpers.cjs");
18
19
  var _isFile = require("./is-file.cjs");
19
20
  var _listFiles = require("./list-files.cjs");
20
- async function copyFile(t, r) {
21
- const i = t instanceof URL ? (0, _mlly.fileURLToPath)(t) : t;
22
- if ((0, _exists.existsSync)(i)) return (0, _promises.copyFile)(i, r);
23
- }
24
- function copyFileSync(t, r) {
25
- const i = t instanceof URL ? (0, _mlly.fileURLToPath)(t) : t;
26
- if ((0, _exists.existsSync)(i)) return (0, _nodeFs.copyFileSync)(i, r);
21
+ async function copyFile(t, s) {
22
+ const i = t instanceof URL ? (0, _mlly.fileURLToPath)(t) : t,
23
+ o = s instanceof URL ? (0, _mlly.fileURLToPath)(s) : s;
24
+ if ((0, _exists.existsSync)((0, _filePathFns.findFilePath)(o)) || (await (0, _helpers.createDirectory)((0, _filePathFns.findFilePath)(o))), (0, _typeChecks.isString)(i) && (0, _exists.existsSync)(i)) return (0, _promises.copyFile)(i, o);
27
25
  }
28
- async function copyFiles(t, r) {
26
+ function copyFileSync(t, s) {
29
27
  const i = t instanceof URL ? (0, _mlly.fileURLToPath)(t) : t,
30
- c = r instanceof URL ? (0, _mlly.fileURLToPath)(r) : r;
31
- return (0, _isFile.isFile)(i) ? copyFile(i, c) : (await (0, _helpers.createDirectory)(c), Promise.all((await (0, _listFiles.listFiles)(i.includes("*") ? i : (0, _join.joinPaths)(i, "**", "*"))).map(async n => {
32
- const o = (0, _join.joinPaths)(c, (0, _replace.replacePath)(n, i));
33
- (0, _exists.existsSync)((0, _filePathFns.findFilePath)(o)) || (await (0, _helpers.createDirectory)((0, _filePathFns.findFilePath)(o))), (0, _isFile.isDirectory)(n) ? await copyFiles(n, o) : await copyFile(n, o);
34
- })));
28
+ o = s instanceof URL ? (0, _mlly.fileURLToPath)(s) : s;
29
+ if ((0, _exists.existsSync)((0, _filePathFns.findFilePath)(o)) || (0, _helpers.createDirectorySync)((0, _filePathFns.findFilePath)(o)), (0, _typeChecks.isString)(i) && (0, _exists.existsSync)(i)) return (0, _nodeFs.copyFileSync)(i, o);
35
30
  }
36
- function copyFilesSync(t, r) {
31
+ async function copyFiles(t, s) {
37
32
  const i = t instanceof URL ? (0, _mlly.fileURLToPath)(t) : t,
38
- c = r instanceof URL ? (0, _mlly.fileURLToPath)(r) : r;
39
- return (0, _isFile.isFile)(i) ? copyFileSync(i, c) : ((0, _helpers.createDirectorySync)(c), (0, _listFiles.listFilesSync)(i.includes("*") ? i : (0, _join.joinPaths)(i, "**", "*")).map(n => {
40
- const o = (0, _join.joinPaths)(c, (0, _replace.replacePath)(n, i));
41
- (0, _exists.existsSync)((0, _filePathFns.findFilePath)(o)) || (0, _helpers.createDirectorySync)((0, _filePathFns.findFilePath)(o)), (0, _isFile.isDirectory)(n) ? copyFilesSync(n, o) : copyFileSync(n, o);
33
+ o = s instanceof URL ? (0, _mlly.fileURLToPath)(s) : s;
34
+ return (0, _typeChecks.isString)(i) && (0, _isFile.isFile)(i) ? copyFile(i, o) : Promise.all((await (0, _listFiles.listFiles)(i)).map(async r => {
35
+ const e = (0, _join.joinPaths)(o, (0, _replace.replacePath)(r, (0, _typeChecks.isString)(i) ? i : i.input));
36
+ (0, _isFile.isDirectory)(r) ? await copyFiles(r, e) : await copyFile(r, e);
42
37
  }));
38
+ }
39
+ function copyFilesSync(t, s) {
40
+ const i = t instanceof URL ? (0, _mlly.fileURLToPath)(t) : t,
41
+ o = s instanceof URL ? (0, _mlly.fileURLToPath)(s) : s;
42
+ return (0, _typeChecks.isString)(i) && (0, _isFile.isFile)(i) ? copyFileSync(i, o) : (0, _listFiles.listFilesSync)(i).map(r => {
43
+ const e = (0, _join.joinPaths)(o, (0, _replace.replacePath)(r, (0, _typeChecks.isString)(i) ? i : i.input));
44
+ (0, _isFile.isDirectory)(r) ? copyFilesSync(r, e) : copyFileSync(r, e);
45
+ });
43
46
  }
@@ -1,3 +1,4 @@
1
+ import type { AssetGlob } from "@stryke/types/file";
1
2
  /**
2
3
  * Copy a file from one location to another
3
4
  *
@@ -5,7 +6,7 @@
5
6
  * @param destination - The destination location
6
7
  * @returns An indicator specifying if the copy was successful
7
8
  */
8
- export declare function copyFile(source: string | URL, destination: string | URL): Promise<void>;
9
+ export declare function copyFile(source: string | URL | AssetGlob, destination: string | URL): Promise<void>;
9
10
  /**
10
11
  * Synchronously copy a file from one location to another
11
12
  *
@@ -13,7 +14,7 @@ export declare function copyFile(source: string | URL, destination: string | URL
13
14
  * @param destination - The destination location
14
15
  * @returns An indicator specifying if the copy was successful
15
16
  */
16
- export declare function copyFileSync(source: string | URL, destination: string | URL): void;
17
+ export declare function copyFileSync(source: string | URL | AssetGlob, destination: string | URL): void;
17
18
  /**
18
19
  * Copy files from one location to another
19
20
  *
@@ -21,7 +22,7 @@ export declare function copyFileSync(source: string | URL, destination: string |
21
22
  * @param destination - The destination location
22
23
  * @returns An indicator specifying if the copy was successful
23
24
  */
24
- export declare function copyFiles(source: string | URL, destination: string | URL): Promise<void | void[]>;
25
+ export declare function copyFiles(source: string | URL | AssetGlob, destination: string | URL): Promise<void | void[]>;
25
26
  /**
26
27
  * Synchronously copy files from one location to another
27
28
  *
@@ -29,4 +30,4 @@ export declare function copyFiles(source: string | URL, destination: string | UR
29
30
  * @param destination - The destination location
30
31
  * @returns An indicator specifying if the copy was successful
31
32
  */
32
- export declare function copyFilesSync(source: string | URL, destination: string | URL): void | void[];
33
+ export declare function copyFilesSync(source: string | URL | AssetGlob, destination: string | URL): void | void[];
@@ -1 +1 @@
1
- import{findFilePath as e}from"@stryke/path/file-path-fns";import{joinPaths as f}from"@stryke/path/join";import{replacePath as m}from"@stryke/path/replace";import{fileURLToPath as s}from"mlly";import{copyFileSync as U}from"node:fs";import{copyFile as y}from"node:fs/promises";import{existsSync as p}from"./exists";import{createDirectory as l,createDirectorySync as a}from"./helpers";import{isDirectory as L,isFile as R}from"./is-file";import{listFiles as F,listFilesSync as g}from"./list-files";export async function copyFile(t,r){const i=t instanceof URL?s(t):t;if(p(i))return y(i,r)}export function copyFileSync(t,r){const i=t instanceof URL?s(t):t;if(p(i))return U(i,r)}export async function copyFiles(t,r){const i=t instanceof URL?s(t):t,c=r instanceof URL?s(r):r;return R(i)?copyFile(i,c):(await l(c),Promise.all((await F(i.includes("*")?i:f(i,"**","*"))).map(async n=>{const o=f(c,m(n,i));p(e(o))||await l(e(o)),L(n)?await copyFiles(n,o):await copyFile(n,o)})))}export function copyFilesSync(t,r){const i=t instanceof URL?s(t):t,c=r instanceof URL?s(r):r;return R(i)?copyFileSync(i,c):(a(c),g(i.includes("*")?i:f(i,"**","*")).map(n=>{const o=f(c,m(n,i));p(e(o))||a(e(o)),L(n)?copyFilesSync(n,o):copyFileSync(n,o)}))}
1
+ import{findFilePath as f}from"@stryke/path/file-path-fns";import{joinPaths as m}from"@stryke/path/join";import{replacePath as l}from"@stryke/path/replace";import{isString as n}from"@stryke/type-checks";import{fileURLToPath as c}from"mlly";import{copyFileSync as R}from"node:fs";import{copyFile as U}from"node:fs/promises";import{existsSync as p}from"./exists";import{createDirectory as y,createDirectorySync as F}from"./helpers";import{isDirectory as a,isFile as L}from"./is-file";import{listFiles as g,listFilesSync as S}from"./list-files";export async function copyFile(t,s){const i=t instanceof URL?c(t):t,o=s instanceof URL?c(s):s;if(p(f(o))||await y(f(o)),n(i)&&p(i))return U(i,o)}export function copyFileSync(t,s){const i=t instanceof URL?c(t):t,o=s instanceof URL?c(s):s;if(p(f(o))||F(f(o)),n(i)&&p(i))return R(i,o)}export async function copyFiles(t,s){const i=t instanceof URL?c(t):t,o=s instanceof URL?c(s):s;return n(i)&&L(i)?copyFile(i,o):Promise.all((await g(i)).map(async r=>{const e=m(o,l(r,n(i)?i:i.input));a(r)?await copyFiles(r,e):await copyFile(r,e)}))}export function copyFilesSync(t,s){const i=t instanceof URL?c(t):t,o=s instanceof URL?c(s):s;return n(i)&&L(i)?copyFileSync(i,o):S(i).map(r=>{const e=m(o,l(r,n(i)?i:i.input));a(r)?copyFilesSync(r,e):copyFileSync(r,e)})}
@@ -9,39 +9,47 @@ exports.listDirectoriesSync = listDirectoriesSync;
9
9
  exports.listFiles = listFiles;
10
10
  exports.listFilesSync = listFilesSync;
11
11
  exports.listSync = listSync;
12
+ var _path = require("@stryke/path");
13
+ var _typeChecks = require("@stryke/type-checks");
12
14
  var _defu = _interopRequireDefault(require("defu"));
13
15
  var _glob = require("glob");
14
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
- const p = {
17
+ const T = {
16
18
  dot: !0
17
19
  };
18
- async function list(i, t) {
19
- return (0, _glob.glob)(i, (0, _defu.default)(t ?? {}, p));
20
+ async function list(t, e) {
21
+ return (0, _glob.glob)((0, _typeChecks.isString)(t) ? t : t.input ? (0, _path.joinPaths)(t.input, t.glob) : t.glob, (0, _defu.default)((0, _typeChecks.isString)(t) ? {} : {
22
+ dot: t.dot,
23
+ ignore: t.ignore
24
+ }, e ?? {}, T));
20
25
  }
21
- function listSync(i, t) {
22
- return _glob.glob.sync(i, (0, _defu.default)(t ?? {}, p));
26
+ function listSync(t, e) {
27
+ return _glob.glob.sync((0, _typeChecks.isString)(t) ? t : t.input ? (0, _path.joinPaths)(t.input, t.glob) : t.glob, (0, _defu.default)((0, _typeChecks.isString)(t) ? {} : {
28
+ dot: t.dot,
29
+ ignore: t.ignore
30
+ }, e ?? {}, T));
23
31
  }
24
- async function listFiles(i, t) {
25
- const s = (await list(i, (0, _defu.default)({
32
+ async function listFiles(t, e) {
33
+ const s = (await list(t, (0, _defu.default)({
26
34
  withFileTypes: !0
27
- }, t ?? {}))).filter(e => e.isFile());
28
- return t?.withFileTypes ? s : s.map(e => e.fullpath());
35
+ }, e ?? {}))).filter(i => i.isFile());
36
+ return e?.withFileTypes ? s : s.map(i => i.fullpath());
29
37
  }
30
- function listFilesSync(i, t) {
31
- const s = listSync(i, (0, _defu.default)({
38
+ function listFilesSync(t, e) {
39
+ const s = listSync(t, (0, _defu.default)({
32
40
  withFileTypes: !0
33
- }, t ?? {})).filter(e => e.isFile());
34
- return t?.withFileTypes ? s : s.map(e => e.fullpath());
41
+ }, e ?? {})).filter(i => i.isFile());
42
+ return e?.withFileTypes ? s : s.map(i => i.fullpath());
35
43
  }
36
- async function listDirectories(i, t) {
37
- const s = (await list(i, (0, _defu.default)({
44
+ async function listDirectories(t, e) {
45
+ const s = (await list(t, (0, _defu.default)({
38
46
  withFileTypes: !0
39
- }, t ?? {}))).filter(e => e.isDirectory());
40
- return t?.withFileTypes ? s : s.map(e => e.fullpath());
47
+ }, e ?? {}))).filter(i => i.isDirectory());
48
+ return e?.withFileTypes ? s : s.map(i => i.fullpath());
41
49
  }
42
- function listDirectoriesSync(i, t) {
43
- const s = listSync(i, (0, _defu.default)({
50
+ function listDirectoriesSync(t, e) {
51
+ const s = listSync(t, (0, _defu.default)({
44
52
  withFileTypes: !0
45
- }, t ?? {})).filter(e => e.isDirectory());
46
- return t?.withFileTypes ? s : s.map(e => e.fullpath());
53
+ }, e ?? {})).filter(i => i.isDirectory());
54
+ return e?.withFileTypes ? s : s.map(i => i.fullpath());
47
55
  }
@@ -1,3 +1,4 @@
1
+ import type { AssetGlob } from "@stryke/types/file";
1
2
  import type { GlobOptions, Path } from "glob";
2
3
  export type ListOptions = GlobOptions;
3
4
  export type InferListReturnType<TOptions extends GlobOptions> = TOptions["withFileTypes"] extends true ? Path[] : string[];
@@ -7,39 +8,39 @@ export type InferListReturnType<TOptions extends GlobOptions> = TOptions["withFi
7
8
  * @param filesGlob - A glob pattern to match files
8
9
  * @returns A list of file paths
9
10
  */
10
- export declare function list<TOptions extends ListOptions>(filesGlob: string, options?: TOptions): Promise<InferListReturnType<TOptions>>;
11
+ export declare function list<TOptions extends ListOptions>(filesGlob: string | AssetGlob, options?: TOptions): Promise<InferListReturnType<TOptions>>;
11
12
  /**
12
13
  * A synchronous files and directories listing helper function
13
14
  *
14
15
  * @param filesGlob - A glob pattern to match files
15
16
  * @returns A list of file paths
16
17
  */
17
- export declare function listSync<TOptions extends ListOptions>(filesGlob: string, options?: TOptions): InferListReturnType<TOptions>;
18
+ export declare function listSync<TOptions extends ListOptions>(filesGlob: string | AssetGlob, options?: TOptions): InferListReturnType<TOptions>;
18
19
  /**
19
20
  * A file listing helper function
20
21
  *
21
22
  * @param filesGlob - A glob pattern to match files
22
23
  * @returns A list of file paths
23
24
  */
24
- export declare function listFiles<TOptions extends ListOptions>(filesGlob: string, options?: TOptions): Promise<InferListReturnType<TOptions>>;
25
+ export declare function listFiles<TOptions extends ListOptions>(filesGlob: string | AssetGlob, options?: TOptions): Promise<InferListReturnType<TOptions>>;
25
26
  /**
26
27
  * A synchronous file listing helper function
27
28
  *
28
29
  * @param filesGlob - A glob pattern to match files
29
30
  * @returns A list of file paths
30
31
  */
31
- export declare function listFilesSync<TOptions extends ListOptions>(filesGlob: string, options?: TOptions): InferListReturnType<TOptions>;
32
+ export declare function listFilesSync<TOptions extends ListOptions>(filesGlob: string | AssetGlob, options?: TOptions): InferListReturnType<TOptions>;
32
33
  /**
33
34
  * A directories listing helper function
34
35
  *
35
36
  * @param filesGlob - A glob pattern to match files
36
37
  * @returns A list of file paths
37
38
  */
38
- export declare function listDirectories<TOptions extends ListOptions>(filesGlob: string, options?: TOptions): Promise<InferListReturnType<TOptions>>;
39
+ export declare function listDirectories<TOptions extends ListOptions>(filesGlob: string | AssetGlob, options?: TOptions): Promise<InferListReturnType<TOptions>>;
39
40
  /**
40
41
  * A synchronous directories listing helper function
41
42
  *
42
43
  * @param filesGlob - A glob pattern to match files
43
44
  * @returns A list of file paths
44
45
  */
45
- export declare function listDirectoriesSync<TOptions extends ListOptions>(filesGlob: string, options?: TOptions): InferListReturnType<TOptions>;
46
+ export declare function listDirectoriesSync<TOptions extends ListOptions>(filesGlob: string | AssetGlob, options?: TOptions): InferListReturnType<TOptions>;
@@ -1 +1 @@
1
- import n from"defu";import{glob as r}from"glob";const p={dot:!0};export async function list(i,t){return r(i,n(t??{},p))}export function listSync(i,t){return r.sync(i,n(t??{},p))}export async function listFiles(i,t){const s=(await list(i,n({withFileTypes:!0},t??{}))).filter(e=>e.isFile());return t?.withFileTypes?s:s.map(e=>e.fullpath())}export function listFilesSync(i,t){const s=listSync(i,n({withFileTypes:!0},t??{})).filter(e=>e.isFile());return t?.withFileTypes?s:s.map(e=>e.fullpath())}export async function listDirectories(i,t){const s=(await list(i,n({withFileTypes:!0},t??{}))).filter(e=>e.isDirectory());return t?.withFileTypes?s:s.map(e=>e.fullpath())}export function listDirectoriesSync(i,t){const s=listSync(i,n({withFileTypes:!0},t??{})).filter(e=>e.isDirectory());return t?.withFileTypes?s:s.map(e=>e.fullpath())}
1
+ import{joinPaths as p}from"@stryke/path";import{isString as r}from"@stryke/type-checks";import n from"defu";import{glob as o}from"glob";const T={dot:!0};export async function list(t,e){return o(r(t)?t:t.input?p(t.input,t.glob):t.glob,n(r(t)?{}:{dot:t.dot,ignore:t.ignore},e??{},T))}export function listSync(t,e){return o.sync(r(t)?t:t.input?p(t.input,t.glob):t.glob,n(r(t)?{}:{dot:t.dot,ignore:t.ignore},e??{},T))}export async function listFiles(t,e){const s=(await list(t,n({withFileTypes:!0},e??{}))).filter(i=>i.isFile());return e?.withFileTypes?s:s.map(i=>i.fullpath())}export function listFilesSync(t,e){const s=listSync(t,n({withFileTypes:!0},e??{})).filter(i=>i.isFile());return e?.withFileTypes?s:s.map(i=>i.fullpath())}export async function listDirectories(t,e){const s=(await list(t,n({withFileTypes:!0},e??{}))).filter(i=>i.isDirectory());return e?.withFileTypes?s:s.map(i=>i.fullpath())}export function listDirectoriesSync(t,e){const s=listSync(t,n({withFileTypes:!0},e??{})).filter(i=>i.isDirectory());return e?.withFileTypes?s:s.map(i=>i.fullpath())}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/fs",
3
- "version": "0.30.5",
3
+ "version": "0.31.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": {
@@ -16,7 +16,7 @@
16
16
  "@ltd/j-toml": "^1.38.0",
17
17
  "@storm-software/config-tools": "latest",
18
18
  "@stryke/convert": "^0.6.0",
19
- "@stryke/path": "^0.15.4",
19
+ "@stryke/path": "^0.15.5",
20
20
  "@stryke/string-format": "^0.12.0",
21
21
  "chalk": "^5.4.1",
22
22
  "defu": "^6.1.4",
@@ -27,7 +27,7 @@
27
27
  "yaml": "^2.8.1",
28
28
  "@stryke/json": "^0.9.3",
29
29
  "@stryke/type-checks": "^0.3.10",
30
- "@stryke/types": "^0.9.2"
30
+ "@stryke/types": "^0.10.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^22.14.0",
@@ -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": "4976c8286d83b88808404d6c218f3e4b32a11603"
398
+ "gitHead": "6a9aee3710da08beb510066d00f66d7863102cd2"
399
399
  }