@homedev/files 1.0.4 → 1.0.5
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.
- package/dist/index.d.ts +21 -0
- package/dist/index.js +2 -1
- package/package.json +1 -4
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,27 @@ declare interface FilePatternOptions {
|
|
|
8
8
|
|
|
9
9
|
export declare const globMap: <T>(pattern: string | string[], options: FilePatternOptions) => Promise<T[] | T>;
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare const importGlob: (patterns: string[], options?: ImportOptions) => Promise<any[]>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export declare const importList: (modules: string[], options?: ImportOptions) => Promise<any[]>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare interface ImportOptions {
|
|
25
|
+
cwd?: string;
|
|
26
|
+
resolveDefault?: boolean | 'only';
|
|
27
|
+
filter?: (name: string) => boolean | undefined;
|
|
28
|
+
fail?: (name: string, error: any) => boolean | undefined;
|
|
29
|
+
map?: (module: any, name: string) => any;
|
|
30
|
+
}
|
|
31
|
+
|
|
11
32
|
/**
|
|
12
33
|
* @public
|
|
13
34
|
* @param fileName
|
package/dist/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
import c from"fs/promises";var l=async(r)=>{try{return await c.access(r,c.constants.R_OK),!0}catch{return!1}};import o from"path";var y=async(r,e)=>{let t=!o.isAbsolute(r)&&e?["",...e]:[""];for(let n of t){let a=o.join(n,r);if(await l(a))return o.resolve(a)}throw Error(`File not found: "${r}"`)};import A from"path";var D=async(r,e)=>{let t=await y(r,e?.dirs),n=await Bun.file(t).text(),a=A.dirname(t),s={"[.]json$":JSON.parse,"[.](yml|yaml)$":Bun.YAML.parse,"[.]toml$":Bun.TOML.parse,...e?.parsers},i=Object.entries(s).find((b)=>t.match(b[0]));if(!i)throw Error(`Unhandled file type: ${r}`);return{content:i[1](n),fullPath:t,folderPath:a}};var u=async(r,e,t="text")=>{switch(t){case"yaml":await Bun.write(r,Bun.YAML.stringify(e));break;case"json":await Bun.write(r,JSON.stringify(e));break;case"text":default:await Bun.write(r,e.toString())}};import O from"fs/promises";var C=async(r,e)=>{if(typeof r==="string"&&!r.includes("*"))return await e.map(r,0,[]);let t=await Array.fromAsync(O.glob(r,{cwd:e.cwd})),n=e.filter?t.filter(e.filter):t;return await Promise.all(n.map(e.map))};import x from"fs/promises";import g from"path";var _=async(r,e)=>{if(e?.targetDirectory&&e?.removeFirst)try{await x.rm(e?.targetDirectory,{recursive:!0,force:!0})}catch(t){throw Error(`Failed to clean the output directory: ${t.message}`)}for(let t of r)await v(t,e)},v=async(r,e)=>{let t=g.join(e?.targetDirectory??".",r.name),n=g.dirname(t);if(e?.classes){if(r.class!==void 0&&!e.classes.includes(r.class))return;if(e.classRequired&&r.class===void 0)throw Error(`Output "${r.name}" is missing class field`)}if(e?.writing?.(r)===!1)return;try{await x.mkdir(n,{recursive:!0})}catch(a){throw Error(`Failed to create target directory "${n}" for output "${t}": ${a.message}`)}try{await u(t,r.value,r.type??"text")}catch(a){throw Error(`Failed to write output "${t}": ${a.message}`)}};import w from"path";import d from"path";var f=(r)=>r?d.isAbsolute(r)?r:d.join(process.cwd(),r):process.cwd();var B=async(r,e)=>{let t=[];for(let n of r)try{let a=!w.isAbsolute(n)?w.join(f(e?.cwd),n):n;if(e?.filter?.(a)===!1)continue;let s=await import(a);if(e?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let i=e?.resolveDefault?s.default??s:s,m=e?.map?await e.map(i,n):i;if(m!==void 0)t.push(m)}catch(a){if(e?.fail?.(n,a)===!1)continue;throw Error(`Failed to import module ${n}: ${a.message??a}`)}return t},V=async(r,e)=>{let t=[];for(let n of r){let a=await Array.fromAsync(new Bun.Glob(n).scan({cwd:f(e?.cwd),absolute:!0}));t.push(...await B(a,e))}return t};export{_ as writeOutputs,v as writeOutput,u as writeFormat,y as locate,D as loadFormat,B as importList,V as importGlob,C as globMap,l as exists};
|
package/package.json
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homedev/files",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "files utilities",
|
|
5
5
|
"author": "julzor",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"type": "module",
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"yaml": "^2.8.2"
|
|
11
|
-
},
|
|
12
9
|
"typings": "dist/index.d.ts"
|
|
13
10
|
}
|