@homedev/files 1.0.1 → 1.0.3

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.
@@ -0,0 +1,56 @@
1
+ export declare const exists: (fileName: string) => Promise<boolean>;
2
+
3
+ declare interface FilePatternOptions {
4
+ cwd: string;
5
+ filter?: (fileName: string, index: number, array: string[]) => boolean;
6
+ map: (fileName: string, index: number, array: string[]) => Promise<any>;
7
+ }
8
+
9
+ export declare const globMap: <T>(pattern: string | string[], options: FilePatternOptions) => Promise<T[] | T>;
10
+
11
+ /**
12
+ * @public
13
+ * @param fileName
14
+ * @param options
15
+ * @returns
16
+ */
17
+ export declare const loadFormat: <T = any>(fileName: string, options?: LoadOptions) => Promise<LoadResult<T>>;
18
+
19
+ /**
20
+ * @public
21
+ */
22
+ export declare interface LoadOptions {
23
+ dirs?: string[];
24
+ parsers?: Record<string, (data: string) => any>;
25
+ }
26
+
27
+ export declare interface LoadResult<T> {
28
+ fullPath: string;
29
+ folderPath: string;
30
+ content: T;
31
+ }
32
+
33
+ export declare const locate: (fileName: string, dirs?: string[]) => Promise<string>;
34
+
35
+ export declare interface Output {
36
+ name: string;
37
+ type?: 'json' | 'yaml' | 'text';
38
+ value: any;
39
+ }
40
+
41
+ export declare const writeFormat: (filePath: string, content: any, format?: "yaml" | "json" | "text") => Promise<void>;
42
+
43
+ export declare const writeOutput: (o: Output, options?: WriteOutputOption) => Promise<void>;
44
+
45
+ export declare interface WriteOutputOption {
46
+ targetDirectory?: string;
47
+ writing?: (output: Output) => boolean | undefined | void;
48
+ }
49
+
50
+ export declare const writeOutputs: (outputs: Output[], options?: WriteOutputsOption) => Promise<void>;
51
+
52
+ export declare interface WriteOutputsOption extends WriteOutputOption {
53
+ removeFirst?: boolean;
54
+ }
55
+
56
+ export { }
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var K=Object.create;var{getPrototypeOf:M,defineProperty:m,getOwnPropertyNames:F,getOwnPropertyDescriptor:R}=Object,j=Object.prototype.hasOwnProperty;var c=(r,e,n)=>{n=r!=null?K(M(r)):{};let t=e||!r||!r.__esModule?m(n,"default",{value:r,enumerable:!0}):n;for(let i of F(r))if(!j.call(t,i))m(t,i,{get:()=>r[i],enumerable:!0});return t},o=new WeakMap,_=(r)=>{var e=o.get(r),n;if(e)return e;if(e=m({},"__esModule",{value:!0}),r&&typeof r==="object"||typeof r==="function")F(r).map((t)=>!j.call(e,t)&&m(e,t,{get:()=>r[t],enumerable:!(n=R(r,t))||n.enumerable}));return o.set(r,e),e};var $=(r,e)=>{for(var n in e)m(r,n,{get:e[n],enumerable:!0,configurable:!0,set:(t)=>e[n]=()=>t})};var C={};$(C,{writeOutputs:()=>B,writeOutput:()=>v,writeFormat:()=>a,locate:()=>y,loadFormat:()=>q,globMap:()=>z,exists:()=>w});module.exports=_(C);var x=c(require("fs/promises")),w=async(r)=>{try{return await x.default.access(r,x.default.constants.R_OK),!0}catch{return!1}};var s=c(require("path"));var y=async(r,e)=>{let n=!s.default.isAbsolute(r)&&e?["",...e]:[""];for(let t of n){let i=s.default.join(t,r);if(await w(i))return s.default.resolve(i)}throw new Error(`File not found: "${r}"`)};var A=c(require("fs/promises")),O=c(require("path")),T=c(require("yaml"));var q=async(r,e)=>{let n=await y(r,e?.dirs),t=await A.default.readFile(n),i=O.default.dirname(n),E={"[.](yml|yaml)$":T.default.parse,"[.]json$":JSON.parse,...e?.parsers},d=Object.entries(E).find((J)=>n.match(J[0]));if(!d)throw new Error(`Unhandled file type: ${r}`);return{content:d[1](t.toString()),fullPath:n,folderPath:i}};var g=c(require("fs/promises")),l=c(require("yaml")),a=async(r,e,n="text")=>{switch(n){case"yaml":await g.default.writeFile(r,l.default.stringify(e));break;case"json":await g.default.writeFile(r,JSON.stringify(e));break;case"text":default:await g.default.writeFile(r,e.toString())}};var S=c(require("fs/promises")),z=async(r,e)=>{if(typeof r==="string"&&!r.includes("*"))return await e.map(r,0,[]);let n=await Array.fromAsync(S.default.glob(r,{cwd:e.cwd})),t=e.filter?n.filter(e.filter):n;return await Promise.all(t.map(e.map))};var b=c(require("fs/promises")),f=c(require("path"));var B=async(r,e)=>{if(e?.targetDirectory&&e?.removeFirst)try{await b.default.rm(e?.targetDirectory,{recursive:!0,force:!0})}catch(n){throw new Error(`Failed to clean the output directory: ${n.message}`)}for(let n of r)await v(n,e)},v=async(r,e)=>{let n=f.default.join(e?.targetDirectory??".",r.name),t=f.default.dirname(n);if(e?.writing?.(r)===!1)return;try{await b.default.mkdir(t,{recursive:!0})}catch(i){throw new Error(`Failed to create target directory "${t}" for output "${n}": ${i.message}`)}try{await a(n,r.value,r.type??"text")}catch(i){throw new Error(`Failed to write output "${n}": ${i.message}`)}};
1
+ var K=Object.create;var{getPrototypeOf:M,defineProperty:m,getOwnPropertyNames:F,getOwnPropertyDescriptor:R}=Object,j=Object.prototype.hasOwnProperty;var c=(r,e,n)=>{n=r!=null?K(M(r)):{};let t=e||!r||!r.__esModule?m(n,"default",{value:r,enumerable:!0}):n;for(let i of F(r))if(!j.call(t,i))m(t,i,{get:()=>r[i],enumerable:!0});return t},o=new WeakMap,_=(r)=>{var e=o.get(r),n;if(e)return e;if(e=m({},"__esModule",{value:!0}),r&&typeof r==="object"||typeof r==="function")F(r).map((t)=>!j.call(e,t)&&m(e,t,{get:()=>r[t],enumerable:!(n=R(r,t))||n.enumerable}));return o.set(r,e),e};var $=(r,e)=>{for(var n in e)m(r,n,{get:e[n],enumerable:!0,configurable:!0,set:(t)=>e[n]=()=>t})};var C={};$(C,{writeOutputs:()=>B,writeOutput:()=>v,writeFormat:()=>a,locate:()=>y,loadFormat:()=>q,globMap:()=>z,exists:()=>w});module.exports=_(C);var x=c(require("fs/promises")),w=async(r)=>{try{return await x.default.access(r,x.default.constants.R_OK),!0}catch{return!1}};var s=c(require("path"));var y=async(r,e)=>{let n=!s.default.isAbsolute(r)&&e?["",...e]:[""];for(let t of n){let i=s.default.join(t,r);if(await w(i))return s.default.resolve(i)}throw Error(`File not found: "${r}"`)};var A=c(require("fs/promises")),O=c(require("path")),T=c(require("yaml"));var q=async(r,e)=>{let n=await y(r,e?.dirs),t=await A.default.readFile(n),i=O.default.dirname(n),E={"[.](yml|yaml)$":T.default.parse,"[.]json$":JSON.parse,...e?.parsers},d=Object.entries(E).find((J)=>n.match(J[0]));if(!d)throw Error(`Unhandled file type: ${r}`);return{content:d[1](t.toString()),fullPath:n,folderPath:i}};var g=c(require("fs/promises")),l=c(require("yaml")),a=async(r,e,n="text")=>{switch(n){case"yaml":await g.default.writeFile(r,l.default.stringify(e));break;case"json":await g.default.writeFile(r,JSON.stringify(e));break;case"text":default:await g.default.writeFile(r,e.toString())}};var S=c(require("fs/promises")),z=async(r,e)=>{if(typeof r==="string"&&!r.includes("*"))return await e.map(r,0,[]);let n=await Array.fromAsync(S.default.glob(r,{cwd:e.cwd})),t=e.filter?n.filter(e.filter):n;return await Promise.all(t.map(e.map))};var b=c(require("fs/promises")),f=c(require("path"));var B=async(r,e)=>{if(e?.targetDirectory&&e?.removeFirst)try{await b.default.rm(e?.targetDirectory,{recursive:!0,force:!0})}catch(n){throw Error(`Failed to clean the output directory: ${n.message}`)}for(let n of r)await v(n,e)},v=async(r,e)=>{let n=f.default.join(e?.targetDirectory??".",r.name),t=f.default.dirname(n);if(e?.writing?.(r)===!1)return;try{await b.default.mkdir(t,{recursive:!0})}catch(i){throw Error(`Failed to create target directory "${t}" for output "${n}": ${i.message}`)}try{await a(n,r.value,r.type??"text")}catch(i){throw Error(`Failed to write output "${n}": ${i.message}`)}};
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@homedev/files",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "files utilities",
5
5
  "author": "julzor",
6
6
  "license": "ISC",
7
7
  "main": "dist/index.js",
8
8
  "type": "module",
9
- "typings": "dist/index.d.ts",
10
- "peerDependencies": {
11
- "yaml": "^2.8.0"
12
- }
9
+ "dependencies": {
10
+ "yaml": "^2.8.1"
11
+ },
12
+ "typings": "dist/index.d.ts"
13
13
  }