@homedev/files 1.0.6 → 1.0.7
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 +7 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export declare const loadFormat: <T = any>(fileName: string, options?: LoadOptio
|
|
|
43
43
|
export declare interface LoadOptions {
|
|
44
44
|
dirs?: string[];
|
|
45
45
|
parsers?: Record<string, (data: string) => any>;
|
|
46
|
+
format?: string;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
export declare interface LoadResult<T> {
|
|
@@ -60,7 +61,12 @@ export declare interface Output {
|
|
|
60
61
|
class?: string;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
export declare const writeFormat: (filePath: string, content: any,
|
|
64
|
+
export declare const writeFormat: (filePath: string, content: any, options?: WriteFormatOptions) => Promise<void>;
|
|
65
|
+
|
|
66
|
+
export declare interface WriteFormatOptions {
|
|
67
|
+
format: string;
|
|
68
|
+
encoders?: Record<string, (data: string) => Promise<string> | string>;
|
|
69
|
+
}
|
|
64
70
|
|
|
65
71
|
export declare const writeOutput: (o: Output, options?: WriteOutputOption) => Promise<void>;
|
|
66
72
|
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import g from"fs/promises";var l=async(e)=>{try{return await g.access(e,g.constants.R_OK),!0}catch{return!1}};import f from"path";var d=async(e,r)=>{let t=!f.isAbsolute(e)&&r?["",...r]:[""];for(let n of t){let o=f.join(n,e);if(await l(o))return f.resolve(o)}throw Error(`File not found: "${e}"`)};import F from"fs/promises";import y from"path";var G=async(e,r)=>{let t=await d(e,r?.dirs),n=await F.readFile(t,"utf-8"),o=y.dirname(t),i={text:(O)=>O,json:JSON.parse,...r?.parsers}[r?.format??y.extname(e).slice(1)];if(!i)throw Error(`Unhandled file type: ${e}`);return{content:i(n),fullPath:t,folderPath:o}};import A from"fs/promises";var u=async(e,r,t)=>{let n={text:(i)=>i,json:JSON.stringify,...t?.encoders},o=t?.format??"text",s=n[o];if(!s)throw Error(`Unsupported format: ${o}`);await A.writeFile(e,await s(r))};import v from"fs/promises";var U=async(e,r)=>{if(typeof e==="string"&&!e.includes("*"))return await r.map(e,0,[]);let t=await Array.fromAsync(v.glob(e,{cwd:r.cwd})),n=r.filter?t.filter(r.filter):t;return await Promise.all(n.map(r.map))};import w from"fs/promises";import x from"path";var H=async(e,r)=>{if(r?.targetDirectory&&r?.removeFirst)try{await w.rm(r?.targetDirectory,{recursive:!0,force:!0})}catch(t){throw Error(`Failed to clean the output directory: ${t.message}`)}for(let t of e)await E(t,r)},E=async(e,r)=>{let t=x.join(r?.targetDirectory??".",e.name),n=x.dirname(t);if(r?.classes){if(e.class!==void 0&&!r.classes.includes(e.class))return;if(r.classRequired&&e.class===void 0)throw Error(`Output "${e.name}" is missing class field`)}if(r?.writing?.(e)===!1)return;try{await w.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${t}": ${o.message}`)}try{await u(t,e.value,{format:e.type??"text"})}catch(o){throw Error(`Failed to write output "${t}": ${o.message}`)}};import $ from"fs/promises";import c from"path";import b from"path";var a=(e)=>e?b.isAbsolute(e)?e:b.join(process.cwd(),e):process.cwd();var j=async(e,r)=>{let t=[];for(let n of e)try{let o=!c.isAbsolute(n)?c.join(a(r?.cwd),n):n;if(r?.filter?.(o)===!1)continue;let s=await import(o);if(r?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let i=r?.resolveDefault?s.default??s:s,m=r?.map?await r.map(i,n):i;if(m!==void 0)t.push(m)}catch(o){if(r?.fail?.(n,o)===!1)continue;throw Error(`Failed to import module ${n}: ${o.message??o}`)}return t},p=async(e,r)=>{let t=[];for(let n of e){let o=(await Array.fromAsync($.glob(n,{cwd:a(r?.cwd)}))).map((s)=>c.join(a(r?.cwd),s));t.push(...await j(o,r))}return t};export{H as writeOutputs,E as writeOutput,u as writeFormat,d as locate,G as loadFormat,j as importList,p as importGlob,U as globMap,l as exists};
|