diff --git a/CHANGELOG.md b/CHANGELOG.md index 4be1cb4..79fff69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.19 + +- Cleanup + ## 2.0.18 - Cleanup diff --git a/Target/Class/Files.d.ts b/Target/Class/Files.d.ts deleted file mode 100644 index 943cff4..0000000 --- a/Target/Class/Files.d.ts +++ /dev/null @@ -1,37 +0,0 @@ -import type { Type as Action } from "../Interface/Action.js"; -import type { Type as Option } from "../Interface/Option.js"; -import type { Type as Path } from "../Interface/Path.js"; -import type { Type as Plan } from "../Interface/Plan.js"; -import type { Pattern } from "fast-glob"; -export default class Files { - /** - * The function `Pipe` is a TypeScript async function that takes an optional `Action` - * parameter and returns the result of calling `Pipe` with `this.Plan` and `Action`. - * @param {Action} Action - The Action parameter is an optional parameter that - * specifies the execution strategy to be used in the Pipe function. It has a default value of - * Default.Pipe, which means that if no Action parameter is provided when calling the Pipe - * function, it will use the default execution strategy. - */ - Pipe: (Action: Action) => Promise; - /** - * The function `Not` takes a `File` parameter and excludes it from the `Plan.Results` array. - * @param File - The parameter "File" is of type "Option['Exclude']". - * @returns the current object (`this`) after performing some operations. - */ - Not: (File: Option["Exclude"]) => Promise; - /** - * The function `By` takes a file pattern or an array of file patterns and returns a promise that - * resolves to the results of executing the patterns on the specified paths. - * @param {Pattern | Pattern[]} [File=**/ By: (File?: Pattern | Pattern[]) => Promise; - /** - * The function `In` takes a path and updates the `Plan.Paths` property with the input and output - * paths. - * @param {Path} [Path=./] - The `Path` parameter is a string that represents the path to a file or - * directory. It has a default value of "./", which means it will use the current directory if no path - * is provided. - * @returns the value of `this`, which refers to the current object. - */ - In: (Path?: Path) => Promise; - Plan: Plan; - constructor(Cache?: Option["Cache"], Logger?: Option["Logger"]); -} diff --git a/Target/Class/Files.js b/Target/Class/Files.js index aa76dba..13cb907 100644 --- a/Target/Class/Files.js +++ b/Target/Class/Files.js @@ -1 +1,153 @@ -import o from"../Fn/By.js";import r from"../Fn/In.js";import i from"../Fn/Merge.js";import p from"../Fn/Not.js";import P from"../Fn/Pipe.js";import e from"../Object/Option.js";class h{Pipe=async t=>await P(this.Plan,i(e.Action,t));Not=async t=>(this.Plan.Results=await p(t,this.Plan.Results),this);By=async(t="**/*")=>(this.Plan.Results=await o(t,this.Plan.Paths,this.Plan.Results),this);In=async(t="./")=>{const a=await r(t,this.Plan.Paths);if(a instanceof Map)for(const[n,s]of a)this.Plan.Paths.set(n,s);return this};Plan={Cache:e.Cache,Files:0,Logger:e.Logger,Info:{},Paths:new Map,Results:new Map,On:{Buffer:"",After:0,Before:0,Input:"",Output:""}};constructor(t,a){this.Plan.Cache=t??this.Plan.Cache,this.Plan.Logger=a??this.Plan.Logger}}export{h as default}; +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var By_js_1 = require("../Fn/By.js"); +var In_js_1 = require("../Fn/In.js"); +var Merge_js_1 = require("../Fn/Merge.js"); +var Not_js_1 = require("../Fn/Not.js"); +var Pipe_js_1 = require("../Fn/Pipe.js"); +var Option_js_1 = require("../Object/Option.js"); +var Files = /** @class */ (function () { + function Files(Cache, Logger) { + var _this = this; + /** + * The function `Pipe` is a TypeScript async function that takes an optional `Action` + * parameter and returns the result of calling `Pipe` with `this.Plan` and `Action`. + * @param {Action} Action - The Action parameter is an optional parameter that + * specifies the execution strategy to be used in the Pipe function. It has a default value of + * Default.Pipe, which means that if no Action parameter is provided when calling the Pipe + * function, it will use the default execution strategy. + */ + this.Pipe = function (Action) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, (0, Pipe_js_1.default)(this.Plan, (0, Merge_js_1.default)(Option_js_1.default.Action, Action))]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); }); }; + /** + * The function `Not` takes a `File` parameter and excludes it from the `Plan.Results` array. + * @param File - The parameter "File" is of type "Option['Exclude']". + * @returns the current object (`this`) after performing some operations. + */ + this.Not = function (File) { return __awaiter(_this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = this.Plan; + return [4 /*yield*/, (0, Not_js_1.default)(File, this.Plan.Results)]; + case 1: + _a.Results = _b.sent(); + return [2 /*return*/, this]; + } + }); + }); }; + /** + * The function `By` takes a file pattern or an array of file patterns and returns a promise that + * resolves to the results of executing the patterns on the specified paths. + * @param {Pattern | Pattern[]} [File=**/ /*] - The `File` parameter is of type `Pattern` or + * `Pattern[]`. It represents the file or files that you want to search for. The `Pattern` type is a + * string pattern that can include wildcards to match multiple files. The default value for `File` is + * `"**/ /*" + * @returns the current object (`this`) after the `By` function has been executed. + */ + this.By = function (File) { + if (File === void 0) { File = "**/*"; } + return __awaiter(_this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = this.Plan; + return [4 /*yield*/, (0, By_js_1.default)(File, this.Plan.Paths, this.Plan.Results)]; + case 1: + _a.Results = _b.sent(); + return [2 /*return*/, this]; + } + }); + }); + }; + /** + * The function `In` takes a path and updates the `Plan.Paths` property with the input and output + * paths. + * @param {Path} [Path=./] - The `Path` parameter is a string that represents the path to a file or + * directory. It has a default value of "./", which means it will use the current directory if no path + * is provided. + * @returns the value of `this`, which refers to the current object. + */ + this.In = function (Path) { + if (Path === void 0) { Path = "./"; } + return __awaiter(_this, void 0, void 0, function () { + var Paths, _i, Paths_1, _a, Input, Output; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: return [4 /*yield*/, (0, In_js_1.default)(Path, this.Plan.Paths)]; + case 1: + Paths = _b.sent(); + if (Paths instanceof Map) { + for (_i = 0, Paths_1 = Paths; _i < Paths_1.length; _i++) { + _a = Paths_1[_i], Input = _a[0], Output = _a[1]; + this.Plan.Paths.set(Input, Output); + } + } + return [2 /*return*/, this]; + } + }); + }); + }; + this.Plan = { + Cache: Option_js_1.default.Cache, + Files: 0, + Logger: Option_js_1.default.Logger, + Info: {}, + Paths: new Map(), + Results: new Map(), + On: { + Buffer: "", + After: 0, + Before: 0, + Input: "", + Output: "", + }, + }; + this.Plan.Cache = Cache !== null && Cache !== void 0 ? Cache : this.Plan.Cache; + this.Plan.Logger = Logger !== null && Logger !== void 0 ? Logger : this.Plan.Logger; + } + return Files; +}()); +exports.default = Files; diff --git a/Target/Export.d.ts b/Target/Export.d.ts deleted file mode 100644 index 4b21bce..0000000 --- a/Target/Export.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -export type { Type as Action } from "./Interface/Action.js"; -export type { Type as Buffer } from "./Interface/Buffer.js"; -export type { Type as Dir } from "./Interface/Dir.js"; -export type { Type as Exclude } from "./Interface/Exclude.js"; -export type { Type as File } from "./Interface/File.js"; -export type { Type as Logger } from "./Interface/Logger.js"; -export type { Type as Option } from "./Interface/Option.js"; -export type { Type as Path } from "./Interface/Path.js"; -export { default as Files } from "./Class/Files.js"; -export { default as Apply } from "./Fn/Apply.js"; -export { default as By } from "./Fn/By.js"; -export { default as Bytes } from "./Fn/Bytes.js"; -export { default as In } from "./Fn/In.js"; -export { default as Merge } from "./Fn/Merge.js"; -export { default as Not } from "./Fn/Not.js"; -export { default as Pipe } from "./Fn/Pipe.js"; -export { default as Default } from "./Object/Option.js"; diff --git a/Target/Export.js b/Target/Export.js index 1932d06..1940380 100644 --- a/Target/Export.js +++ b/Target/Export.js @@ -1 +1,21 @@ -import{default as r}from"./Class/Files.js";import{default as f}from"./Fn/Apply.js";import{default as a}from"./Fn/By.js";import{default as x}from"./Fn/Bytes.js";import{default as m}from"./Fn/In.js";import{default as u}from"./Fn/Merge.js";import{default as c}from"./Fn/Not.js";import{default as i}from"./Fn/Pipe.js";import{default as j}from"./Object/Option.js";export{f as Apply,a as By,x as Bytes,j as Default,r as Files,m as In,u as Merge,c as Not,i as Pipe}; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Default = exports.Pipe = exports.Not = exports.Merge = exports.In = exports.Bytes = exports.By = exports.Apply = exports.Files = void 0; +var Files_js_1 = require("./Class/Files.js"); +Object.defineProperty(exports, "Files", { enumerable: true, get: function () { return Files_js_1.default; } }); +var Apply_js_1 = require("./Fn/Apply.js"); +Object.defineProperty(exports, "Apply", { enumerable: true, get: function () { return Apply_js_1.default; } }); +var By_js_1 = require("./Fn/By.js"); +Object.defineProperty(exports, "By", { enumerable: true, get: function () { return By_js_1.default; } }); +var Bytes_js_1 = require("./Fn/Bytes.js"); +Object.defineProperty(exports, "Bytes", { enumerable: true, get: function () { return Bytes_js_1.default; } }); +var In_js_1 = require("./Fn/In.js"); +Object.defineProperty(exports, "In", { enumerable: true, get: function () { return In_js_1.default; } }); +var Merge_js_1 = require("./Fn/Merge.js"); +Object.defineProperty(exports, "Merge", { enumerable: true, get: function () { return Merge_js_1.default; } }); +var Not_js_1 = require("./Fn/Not.js"); +Object.defineProperty(exports, "Not", { enumerable: true, get: function () { return Not_js_1.default; } }); +var Pipe_js_1 = require("./Fn/Pipe.js"); +Object.defineProperty(exports, "Pipe", { enumerable: true, get: function () { return Pipe_js_1.default; } }); +var Option_js_1 = require("./Object/Option.js"); +Object.defineProperty(exports, "Default", { enumerable: true, get: function () { return Option_js_1.default; } }); diff --git a/Target/Fn/Apply.d.ts b/Target/Fn/Apply.d.ts deleted file mode 100644 index 44faa4d..0000000 --- a/Target/Fn/Apply.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * The function `Apply` takes a function `Fn` and a test value `Test`, and applies `Fn` to `Test` based - * on its type (Map, Set, Array, or other) and returns the result. - * @param {unknown} Fn - Fn is a parameter that represents a function. It can be any type of function. - * @param {unknown} Test - The `Test` parameter can be any value that you want to apply the function - * `Fn` to. It can be a single value, an array of values, a set of values, or a map of key-value pairs. - * @returns The function `Apply` returns the result of applying the function `Fn` to the input `Test`. - * The specific return value depends on the type of `Test`: - */ -declare const _default: (Fn: unknown, Test: unknown) => Promise; -export default _default; diff --git a/Target/Fn/Apply.js b/Target/Fn/Apply.js index 355b7e9..1ae9496 100644 --- a/Target/Fn/Apply.js +++ b/Target/Fn/Apply.js @@ -1 +1,112 @@ -var r=async(t,a)=>{if(t instanceof Function){if(a instanceof Map){const n=new Map;for(const[o,e]of a)n.set(await t(o),await t(e));return n}if(a instanceof Set){const n=new Set;for(const o of a)n.add(await t(o));return n}if(a instanceof Array){const n=new Array;for(const o of a)n.push(await t(o));return n}return await t(a)}};export{r as default}; +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * The function `Apply` takes a function `Fn` and a test value `Test`, and applies `Fn` to `Test` based + * on its type (Map, Set, Array, or other) and returns the result. + * @param {unknown} Fn - Fn is a parameter that represents a function. It can be any type of function. + * @param {unknown} Test - The `Test` parameter can be any value that you want to apply the function + * `Fn` to. It can be a single value, an array of values, a set of values, or a map of key-value pairs. + * @returns The function `Apply` returns the result of applying the function `Fn` to the input `Test`. + * The specific return value depends on the type of `Test`: + */ +exports.default = (function (Fn, Test) { return __awaiter(void 0, void 0, void 0, function () { + var Tests, _i, Test_1, _a, Key, Value, _b, _c, _d, Tests, _e, Test_2, El, _f, _g, Tests, _h, Test_3, Index, _j, _k; + return __generator(this, function (_l) { + switch (_l.label) { + case 0: + if (!(Fn instanceof Function)) return [3 /*break*/, 18]; + if (!(Test instanceof Map)) return [3 /*break*/, 6]; + Tests = new Map(); + _i = 0, Test_1 = Test; + _l.label = 1; + case 1: + if (!(_i < Test_1.length)) return [3 /*break*/, 5]; + _a = Test_1[_i], Key = _a[0], Value = _a[1]; + _c = (_b = Tests).set; + return [4 /*yield*/, Fn(Key)]; + case 2: + _d = [_l.sent()]; + return [4 /*yield*/, Fn(Value)]; + case 3: + _c.apply(_b, _d.concat([_l.sent()])); + _l.label = 4; + case 4: + _i++; + return [3 /*break*/, 1]; + case 5: return [2 /*return*/, Tests]; + case 6: + if (!(Test instanceof Set)) return [3 /*break*/, 11]; + Tests = new Set(); + _e = 0, Test_2 = Test; + _l.label = 7; + case 7: + if (!(_e < Test_2.length)) return [3 /*break*/, 10]; + El = Test_2[_e]; + _g = (_f = Tests).add; + return [4 /*yield*/, Fn(El)]; + case 8: + _g.apply(_f, [_l.sent()]); + _l.label = 9; + case 9: + _e++; + return [3 /*break*/, 7]; + case 10: return [2 /*return*/, Tests]; + case 11: + if (!(Test instanceof Array)) return [3 /*break*/, 16]; + Tests = new Array(); + _h = 0, Test_3 = Test; + _l.label = 12; + case 12: + if (!(_h < Test_3.length)) return [3 /*break*/, 15]; + Index = Test_3[_h]; + _k = (_j = Tests).push; + return [4 /*yield*/, Fn(Index)]; + case 13: + _k.apply(_j, [_l.sent()]); + _l.label = 14; + case 14: + _h++; + return [3 /*break*/, 12]; + case 15: return [2 /*return*/, Tests]; + case 16: return [4 /*yield*/, Fn(Test)]; + case 17: return [2 /*return*/, _l.sent()]; + case 18: return [2 /*return*/]; + } + }); +}); }); diff --git a/Target/Fn/By.d.ts b/Target/Fn/By.d.ts deleted file mode 100644 index 1d87eb1..0000000 --- a/Target/Fn/By.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { Type as Plan } from "../Interface/Plan.ts"; -import type { Pattern } from "fast-glob"; -/** - * The function `By` takes in a file pattern or an array of file patterns, a set of - * input and output paths, and a map of results, and returns the updated map of results - * after matching the file patterns with the input paths. - * @param {Pattern | Pattern[]} File - The `File` parameter is either a single file - * pattern or an array of file patterns. These patterns are used to match files in the - * input directory (`Input`) that will be processed. - * @param Paths - Paths is an array of tuples that represent the input and output paths. - * Each tuple contains two elements: the input path and the output path. - * @param Results - The `Results` parameter is a Map object that stores the mapping - * between the output file paths and their corresponding input file paths. It is used to - * keep track of the files that have been processed and their respective destinations. - * @returns the `Results` object. - */ -declare const _default: (File: Pattern | Pattern[], Paths: Plan["Paths"], Results: Plan["Results"]) => Promise>; -export default _default; diff --git a/Target/Fn/By.js b/Target/Fn/By.js index ae76408..8549461 100644 --- a/Target/Fn/By.js +++ b/Target/Fn/By.js @@ -1 +1,86 @@ -import f from"fast-glob";var p=async(a,e,t)=>{for(const[o,n]of e)for(const r of await f(a,{cwd:o,onlyFiles:!0}))t.set(`${n}${r}`,`${o}${r}`);return t};export{p as default}; +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var fast_glob_1 = require("fast-glob"); +/** + * The function `By` takes in a file pattern or an array of file patterns, a set of + * input and output paths, and a map of results, and returns the updated map of results + * after matching the file patterns with the input paths. + * @param {Pattern | Pattern[]} File - The `File` parameter is either a single file + * pattern or an array of file patterns. These patterns are used to match files in the + * input directory (`Input`) that will be processed. + * @param Paths - Paths is an array of tuples that represent the input and output paths. + * Each tuple contains two elements: the input path and the output path. + * @param Results - The `Results` parameter is a Map object that stores the mapping + * between the output file paths and their corresponding input file paths. It is used to + * keep track of the files that have been processed and their respective destinations. + * @returns the `Results` object. + */ +exports.default = (function (File, Paths, Results) { return __awaiter(void 0, void 0, void 0, function () { + var _i, Paths_1, _a, Input, Output, _b, _c, _File; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: + _i = 0, Paths_1 = Paths; + _d.label = 1; + case 1: + if (!(_i < Paths_1.length)) return [3 /*break*/, 6]; + _a = Paths_1[_i], Input = _a[0], Output = _a[1]; + _b = 0; + return [4 /*yield*/, (0, fast_glob_1.default)(File, { + cwd: Input, + onlyFiles: true, + })]; + case 2: + _c = _d.sent(); + _d.label = 3; + case 3: + if (!(_b < _c.length)) return [3 /*break*/, 5]; + _File = _c[_b]; + Results.set("".concat(Output).concat(_File), "".concat(Input).concat(_File)); + _d.label = 4; + case 4: + _b++; + return [3 /*break*/, 3]; + case 5: + _i++; + return [3 /*break*/, 1]; + case 6: return [2 /*return*/, Results]; + } + }); +}); }); diff --git a/Target/Fn/Bytes.d.ts b/Target/Fn/Bytes.d.ts deleted file mode 100644 index dca70b7..0000000 --- a/Target/Fn/Bytes.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * The function converts a given number of bytes into a human-readable format with appropriate units - * (e.g., KB, MB, GB). - * @param {number} Bytes - The `Bytes` parameter is the number of bytes that you want to convert to a - * human-readable format. - * @param [Decimals=2.0] - The `Decimals` parameter is an optional parameter that specifies the number - * of decimal places to round the result to. If not provided, it defaults to 2. - * @returns a string that represents the given number of bytes in a human-readable format. The format - * includes the converted value in the appropriate unit (Bytes, KB, MB, GB, etc.) based on the size of - * the input. - */ -declare const _default: (Bytes: number, Decimals?: number) => Promise; -export default _default; diff --git a/Target/Fn/Bytes.js b/Target/Fn/Bytes.js index f76d1e1..c4b8066 100644 --- a/Target/Fn/Bytes.js +++ b/Target/Fn/Bytes.js @@ -1 +1,63 @@ -var a=async(t,o=2)=>{if(t===0)return"0 Bytes";const r=1024,B=Math.floor(Math.log(t)/Math.log(r));return`${parseFloat((t/r**B).toFixed(o<0?0:o))} ${["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][B]}`};export{a as default}; +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * The function converts a given number of bytes into a human-readable format with appropriate units + * (e.g., KB, MB, GB). + * @param {number} Bytes - The `Bytes` parameter is the number of bytes that you want to convert to a + * human-readable format. + * @param [Decimals=2.0] - The `Decimals` parameter is an optional parameter that specifies the number + * of decimal places to round the result to. If not provided, it defaults to 2. + * @returns a string that represents the given number of bytes in a human-readable format. The format + * includes the converted value in the appropriate unit (Bytes, KB, MB, GB, etc.) based on the size of + * the input. + */ +exports.default = (function (Bytes, Decimals) { + if (Decimals === void 0) { Decimals = 2.0; } + return __awaiter(void 0, void 0, void 0, function () { + var K, I; + return __generator(this, function (_a) { + if (Bytes === 0) { + return [2 /*return*/, "0 Bytes"]; + } + K = 1024; + I = Math.floor(Math.log(Bytes) / Math.log(K)); + return [2 /*return*/, "".concat(parseFloat((Bytes / Math.pow(K, I)).toFixed(Decimals < 0 ? 0 : Decimals)), " ").concat(["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][I])]; + }); + }); +}); diff --git a/Target/Fn/In.d.ts b/Target/Fn/In.d.ts deleted file mode 100644 index 3ddb835..0000000 --- a/Target/Fn/In.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { Type as Path } from "../Interface/Path.js"; -import type { Type as Plan } from "../Interface/Plan.js"; -/** - * The function `In` takes a `Path` and a `Paths` object, and adds the `Path` to the `Paths` object. - * @param {Path} Path - The `Path` parameter is a string or URL that represents the path to a file or - * directory. - * @param Paths - Paths is a variable of type Plan["Paths"]. It is likely an object or a map that - * stores key-value pairs. - * @returns The function `In` returns the `Paths` object. - */ -declare const _default: (Path: Path, Paths: Plan["Paths"]) => Promise>; -export default _default; diff --git a/Target/Fn/In.js b/Target/Fn/In.js index 7cfdbb1..d7ffa3f 100644 --- a/Target/Fn/In.js +++ b/Target/Fn/In.js @@ -1 +1,72 @@ -import n from"./Apply.js";import{fileURLToPath as s}from"url";var i=async(o,e)=>{const a=await n(t=>t.endsWith("/")?t:`${t}/`,await n(t=>t instanceof URL?s(t):t,o));if(a instanceof Map)for(const[t,r]of a)e.set(t,r);else e.set(a,a);return e};export{i as default}; +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var Apply_js_1 = require("./Apply.js"); +var url_1 = require("url"); +/** + * The function `In` takes a `Path` and a `Paths` object, and adds the `Path` to the `Paths` object. + * @param {Path} Path - The `Path` parameter is a string or URL that represents the path to a file or + * directory. + * @param Paths - Paths is a variable of type Plan["Paths"]. It is likely an object or a map that + * stores key-value pairs. + * @returns The function `In` returns the `Paths` object. + */ +exports.default = (function (Path, Paths) { return __awaiter(void 0, void 0, void 0, function () { + var _Path, _a, _b, _i, _Path_1, _c, Input, Output; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: + _a = Apply_js_1.default; + _b = [function (Path) { return (Path.endsWith("/") ? Path : "".concat(Path, "/")); }]; + return [4 /*yield*/, (0, Apply_js_1.default)(function (_URL) { return (_URL instanceof URL ? (0, url_1.fileURLToPath)(_URL) : _URL); }, Path)]; + case 1: return [4 /*yield*/, _a.apply(void 0, _b.concat([_d.sent()]))]; + case 2: + _Path = _d.sent(); + if (_Path instanceof Map) { + for (_i = 0, _Path_1 = _Path; _i < _Path_1.length; _i++) { + _c = _Path_1[_i], Input = _c[0], Output = _c[1]; + Paths.set(Input, Output); + } + } + else { + Paths.set(_Path, _Path); + } + return [2 /*return*/, Paths]; + } + }); +}); }); diff --git a/Target/Fn/Merge.d.ts b/Target/Fn/Merge.d.ts deleted file mode 100644 index 5fef9e2..0000000 --- a/Target/Fn/Merge.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -declare const _default: (...objects: Ts) => import("deepmerge-ts").DeepMergeHKT, Readonly<{ - key: PropertyKey; - parents: readonly Readonly>[]; -}>>; -export default _default; diff --git a/Target/Fn/Merge.js b/Target/Fn/Merge.js index 0e7af4e..184b687 100644 --- a/Target/Fn/Merge.js +++ b/Target/Fn/Merge.js @@ -1 +1,6 @@ -import{deepmergeCustom as e}from"deepmerge-ts";var m=e({mergeArrays:!1});export{m as default}; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var deepmerge_ts_1 = require("deepmerge-ts"); +exports.default = (0, deepmerge_ts_1.deepmergeCustom)({ + mergeArrays: false, +}); diff --git a/Target/Fn/Not.d.ts b/Target/Fn/Not.d.ts deleted file mode 100644 index d9c788e..0000000 --- a/Target/Fn/Not.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { Type as Option } from "../Interface/Option.js"; -import type { Type as Plan } from "../Interface/Plan.js"; -/** - * The function `Not` filters out files from the `Files` array based on the provided `Pattern` - * parameter. - * @param Pattern - The `Pattern` parameter is of type `Option["Exclude"]`. It represents the patterns - * or filters that will be used to exclude certain files from the `Files` array. - * @param Files - The `Files` parameter is expected to be an array of results from a plan. Each element - * in the array should be an array itself, with two elements. The first element represents the file - * name, and the second element represents the file content. - * @returns the modified `Files` set after applying the filters. - */ -declare const _default: (Pattern: Option["Exclude"], Files: Plan["Results"]) => Promise>; -export default _default; diff --git a/Target/Fn/Not.js b/Target/Fn/Not.js index ba50723..8fc03be 100644 --- a/Target/Fn/Not.js +++ b/Target/Fn/Not.js @@ -1 +1,87 @@ -var f=async(n,o)=>{const s=new Set;if(typeof n<"u")if(n instanceof Array||n instanceof Set)for(const e of n)s.add(e);else s.add(n);for(const e of s)for(const t of o)switch(!0){case typeof e=="string":{(t[0].match(e)||t[1].match(e))&&o.delete(t[0]);break}case typeof e=="function":(e(t[0])||e(t[1]))&&o.delete(t[0])}return o};export{f as default}; +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * The function `Not` filters out files from the `Files` array based on the provided `Pattern` + * parameter. + * @param Pattern - The `Pattern` parameter is of type `Option["Exclude"]`. It represents the patterns + * or filters that will be used to exclude certain files from the `Files` array. + * @param Files - The `Files` parameter is expected to be an array of results from a plan. Each element + * in the array should be an array itself, with two elements. The first element represents the file + * name, and the second element represents the file content. + * @returns the modified `Files` set after applying the filters. + */ +exports.default = (function (Pattern, Files) { return __awaiter(void 0, void 0, void 0, function () { + var Filters, _i, Pattern_1, Patterns, _a, Filters_1, Filter, _b, Files_1, File_1; + return __generator(this, function (_c) { + Filters = new Set(); + if (typeof Pattern !== "undefined") { + if (Pattern instanceof Array || Pattern instanceof Set) { + for (_i = 0, Pattern_1 = Pattern; _i < Pattern_1.length; _i++) { + Patterns = Pattern_1[_i]; + Filters.add(Patterns); + } + } + else { + Filters.add(Pattern); + } + } + for (_a = 0, Filters_1 = Filters; _a < Filters_1.length; _a++) { + Filter = Filters_1[_a]; + for (_b = 0, Files_1 = Files; _b < Files_1.length; _b++) { + File_1 = Files_1[_b]; + switch (true) { + case typeof Filter === "string": { + if (File_1[0].match(Filter) || + File_1[1].match(Filter)) { + Files.delete(File_1[0]); + } + break; + } + case typeof Filter === "function": { + if (Filter(File_1[0]) || + Filter(File_1[1])) { + Files.delete(File_1[0]); + } + } + } + } + } + return [2 /*return*/, Files]; + }); +}); }); diff --git a/Target/Fn/Pipe.d.ts b/Target/Fn/Pipe.d.ts deleted file mode 100644 index 928fff0..0000000 --- a/Target/Fn/Pipe.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { Type as Action } from "../Interface/Action.ts"; -import type { Type as Plan } from "../Interface/Plan.ts"; -/** - * The function `Pipe` takes a `Plan` and an `Action` object as input, and performs a series of - * operations based on the plan, handling various callbacks and error handling along the way. - * @param {Plan} Plan - The `Plan` parameter is an object that represents the execution plan. It - * contains information about the tasks to be executed and their corresponding inputs and outputs. - * @param {Action} - - `Plan`: The plan object that contains the tasks to be executed. - * @returns The function `Pipe` returns the modified `Plan` object. - */ -declare const _default: (Plan: Plan, { Fulfilled, Failed, Accomplished, Changed, Passed, Read, Wrote }: Action) => Promise; -export default _default; diff --git a/Target/Fn/Pipe.js b/Target/Fn/Pipe.js index 479fef6..588e3bb 100644 --- a/Target/Fn/Pipe.js +++ b/Target/Fn/Pipe.js @@ -1 +1,168 @@ -import{constants as w}from"fs";import{access as m,writeFile as y,mkdir as B,stat as O}from"fs/promises";import{dirname as p}from"path";var M=async(l,{Fulfilled:o,Failed:i,Accomplished:s,Changed:f,Passed:r,Read:u,Wrote:c})=>{let t=l;for(const[n,g]of t.Results)try{if(t.On.Input=g,t.On.Output=n,t.On.Before=(await O(t.On.Input)).size,u&&c){t.On.Buffer=await u(t.On);const a=await c(t.On);if(!a)continue;if(t.On.Buffer=a,r&&await r(t.On)){try{await m(p(t.On.Output),w.W_OK)}catch{await B(p(t.On.Output),{recursive:!0})}if(await y(t.On.Output,t.On.Buffer,"utf-8"),t.On.After=(await O(t.On.Output)).size,t.Logger>0&&(t.Files++,f&&(t=await f(t))),t.Logger>1&&typeof s=="function"){const e=await s(t.On);e&&e.length>0&&console.log(e)}}}}catch(a){if(t.Results.delete(n),typeof i=="function"){const e=await i(t.On,a);e&&e.length>0&&console.log(e)}else t.Logger>1&&console.log(a)}if(t.Logger>0&&t.Results.size>0&&typeof o=="function"){const n=await o(t);n&&n.length>0&&console.log(n)}return t};export{M as default}; +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var fs_1 = require("fs"); +var promises_1 = require("fs/promises"); +var path_1 = require("path"); +/** + * The function `Pipe` takes a `Plan` and an `Action` object as input, and performs a series of + * operations based on the plan, handling various callbacks and error handling along the way. + * @param {Plan} Plan - The `Plan` parameter is an object that represents the execution plan. It + * contains information about the tasks to be executed and their corresponding inputs and outputs. + * @param {Action} - - `Plan`: The plan object that contains the tasks to be executed. + * @returns The function `Pipe` returns the modified `Plan` object. + */ +exports.default = (function (Plan, _a) { + var Fulfilled = _a.Fulfilled, Failed = _a.Failed, Accomplished = _a.Accomplished, Changed = _a.Changed, Passed = _a.Passed, Read = _a.Read, Wrote = _a.Wrote; + return __awaiter(void 0, void 0, void 0, function () { + var _Plan, _i, _b, _c, Output, Input, _d, _e, Buffer_1, _f, _Error_1, _g, Message, _Error_2, Message, Message; + return __generator(this, function (_h) { + switch (_h.label) { + case 0: + _Plan = Plan; + _i = 0, _b = _Plan.Results; + _h.label = 1; + case 1: + if (!(_i < _b.length)) return [3 /*break*/, 24]; + _c = _b[_i], Output = _c[0], Input = _c[1]; + _h.label = 2; + case 2: + _h.trys.push([2, 19, , 23]); + _Plan.On.Input = Input; + _Plan.On.Output = Output; + _d = _Plan.On; + return [4 /*yield*/, (0, promises_1.stat)(_Plan.On.Input)]; + case 3: + _d.Before = (_h.sent()).size; + if (!(Read && Wrote)) return [3 /*break*/, 18]; + // @TODO: Before Read check cache, only on read file write is always necessary + _e = _Plan.On; + return [4 /*yield*/, Read(_Plan.On)]; + case 4: + // @TODO: Before Read check cache, only on read file write is always necessary + _e.Buffer = _h.sent(); + return [4 /*yield*/, Wrote(_Plan.On)]; + case 5: + Buffer_1 = _h.sent(); + if (!Buffer_1) { + return [3 /*break*/, 23]; + } + _Plan.On.Buffer = Buffer_1; + _f = Passed; + if (!_f) return [3 /*break*/, 7]; + return [4 /*yield*/, Passed(_Plan.On)]; + case 6: + _f = (_h.sent()); + _h.label = 7; + case 7: + if (!_f) return [3 /*break*/, 18]; + _h.label = 8; + case 8: + _h.trys.push([8, 10, , 12]); + return [4 /*yield*/, (0, promises_1.access)((0, path_1.dirname)(_Plan.On.Output), fs_1.constants.W_OK)]; + case 9: + _h.sent(); + return [3 /*break*/, 12]; + case 10: + _Error_1 = _h.sent(); + return [4 /*yield*/, (0, promises_1.mkdir)((0, path_1.dirname)(_Plan.On.Output), { + recursive: true, + })]; + case 11: + _h.sent(); + return [3 /*break*/, 12]; + case 12: return [4 /*yield*/, (0, promises_1.writeFile)(_Plan.On.Output, _Plan.On.Buffer, "utf-8")]; + case 13: + _h.sent(); + _g = _Plan.On; + return [4 /*yield*/, (0, promises_1.stat)(_Plan.On.Output)]; + case 14: + _g.After = (_h.sent()).size; + if (!(_Plan.Logger > 0)) return [3 /*break*/, 16]; + _Plan.Files++; + if (!Changed) return [3 /*break*/, 16]; + return [4 /*yield*/, Changed(_Plan)]; + case 15: + _Plan = _h.sent(); + _h.label = 16; + case 16: + if (!(_Plan.Logger > 1)) return [3 /*break*/, 18]; + if (!(typeof Accomplished === "function")) return [3 /*break*/, 18]; + return [4 /*yield*/, Accomplished(_Plan.On)]; + case 17: + Message = _h.sent(); + if (Message && Message.length > 0) { + console.log(Message); + } + _h.label = 18; + case 18: return [3 /*break*/, 23]; + case 19: + _Error_2 = _h.sent(); + _Plan.Results.delete(Output); + if (!(typeof Failed === "function")) return [3 /*break*/, 21]; + return [4 /*yield*/, Failed(_Plan.On, _Error_2)]; + case 20: + Message = _h.sent(); + if (Message && Message.length > 0) { + console.log(Message); + } + return [3 /*break*/, 22]; + case 21: + if (_Plan.Logger > 1) { + console.log(_Error_2); + } + _h.label = 22; + case 22: return [3 /*break*/, 23]; + case 23: + _i++; + return [3 /*break*/, 1]; + case 24: + if (!(_Plan.Logger > 0 && _Plan.Results.size > 0)) return [3 /*break*/, 26]; + if (!(typeof Fulfilled === "function")) return [3 /*break*/, 26]; + return [4 /*yield*/, Fulfilled(_Plan)]; + case 25: + Message = _h.sent(); + if (Message && Message.length > 0) { + console.log(Message); + } + _h.label = 26; + case 26: return [2 /*return*/, _Plan]; + } + }); + }); +}); diff --git a/Target/Interface/Action.d.ts b/Target/Interface/Action.d.ts deleted file mode 100644 index 978ff9e..0000000 --- a/Target/Interface/Action.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -import type { Type as Buffer } from "./Buffer.js"; -import type { Type as Cache } from "./Cache.js"; -import type { Type as File } from "./File.js"; -import type { Type as Plan } from "./Plan.js"; -/** - * Represents the execution configuration for specific actions on files. - */ -export interface Type { - /** - * Attaches a callback for the fulfillment of the Action. - * @param Plan The execution plan to be fulfilled. - * @returns A Promise that resolves to either a string or false. - */ - Fulfilled?: boolean | ((Plan: Plan) => Promise); - /** - * Attaches a callback for handling failures in the Action. - * @param Input The input file being processed. - * @param _Error The error encountered during execution. - * @returns A Promise that resolves to either a string or false. - */ - Failed?: boolean | ((Input: File, _Error: unknown) => Promise); - /** - * Attaches a callback for actions that are accomplished. - * @param On The file on which an action was accomplished. - * @returns A Promise that resolves to either a string or false. - */ - Accomplished?: boolean | ((On: File) => Promise); - /** - * Attaches a callback for actions that result in changes to the plan. - * @param Plan The execution plan to be changed. - * @returns A Promise that resolves to the modified execution plan. - */ - Changed?: (Plan: Plan) => Promise; - /** - * Attaches a callback for actions that check if a file can pass through the pipe. - * @param On The file on which the action is being checked. - * @returns A Promise that resolves to a boolean value indicating if the file has passed the checks. - */ - Passed?: (On: File) => Promise; - /** - * Attaches a callback for reading from a file. - * @param On The file to be read. - * @returns A Promise that resolves to the buffer read from the file. - */ - Read?: (On: File) => Promise; - /** - * Attaches a callback for writing to a file. - * @param On The file to be written to. - * @returns A Promise that resolves to the buffer written to the file. - */ - Wrote?: (On: File, Cache: Cache) => Promise; -} diff --git a/Target/Interface/Action.js b/Target/Interface/Action.js index e69de29..c8ad2e5 100644 --- a/Target/Interface/Action.js +++ b/Target/Interface/Action.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/Target/Interface/Buffer.d.ts b/Target/Interface/Buffer.d.ts deleted file mode 100644 index 773077c..0000000 --- a/Target/Interface/Buffer.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -/// -/// -import type { Stream } from "stream"; -/** - * Represents various types that can be used as buffer data. - */ -export type Type = string | NodeJS.ArrayBufferView | Iterable | AsyncIterable | Stream; diff --git a/Target/Interface/Buffer.js b/Target/Interface/Buffer.js index e69de29..c8ad2e5 100644 --- a/Target/Interface/Buffer.js +++ b/Target/Interface/Buffer.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/Target/Interface/Cache.d.ts b/Target/Interface/Cache.d.ts deleted file mode 100644 index bb71063..0000000 --- a/Target/Interface/Cache.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -/// -/** - * Represents the cache path configuration. - */ -export type Type = string | URL | false; diff --git a/Target/Interface/Cache.js b/Target/Interface/Cache.js index e69de29..c8ad2e5 100644 --- a/Target/Interface/Cache.js +++ b/Target/Interface/Cache.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/Target/Interface/Dir.d.ts b/Target/Interface/Dir.d.ts deleted file mode 100644 index 1be7b5c..0000000 --- a/Target/Interface/Dir.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Represents a directory specification. - */ -export interface Type { - /** - * The input directory. - */ - Input: string; - /** - * The output directory. - */ - Output: string; -} diff --git a/Target/Interface/Dir.js b/Target/Interface/Dir.js index e69de29..c8ad2e5 100644 --- a/Target/Interface/Dir.js +++ b/Target/Interface/Dir.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/Target/Interface/Exclude.d.ts b/Target/Interface/Exclude.d.ts deleted file mode 100644 index 4d4d677..0000000 --- a/Target/Interface/Exclude.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Represents criteria for excluding files. - */ -export type Type = string | RegExp | ((File: string) => boolean); diff --git a/Target/Interface/Exclude.js b/Target/Interface/Exclude.js index e69de29..c8ad2e5 100644 --- a/Target/Interface/Exclude.js +++ b/Target/Interface/Exclude.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/Target/Interface/File.d.ts b/Target/Interface/File.d.ts deleted file mode 100644 index 79550ac..0000000 --- a/Target/Interface/File.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { Type as Buffer } from "./Buffer.js"; -/** - * Represents a file specification. - */ -export interface Type { - /** - * The input file. - */ - Input: string; - /** - * The output file. - */ - Output: string; - /** - * The size after the action. - */ - After: number; - /** - * The size before the action. - */ - Before: number; - /** - * The buffer data. - */ - Buffer: Buffer; -} diff --git a/Target/Interface/File.js b/Target/Interface/File.js index e69de29..c8ad2e5 100644 --- a/Target/Interface/File.js +++ b/Target/Interface/File.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/Target/Interface/Logger.d.ts b/Target/Interface/Logger.d.ts deleted file mode 100644 index 65899d8..0000000 --- a/Target/Interface/Logger.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Represents the possible debugging levels. - */ -export type Type = 0 | 1 | 2; diff --git a/Target/Interface/Logger.js b/Target/Interface/Logger.js index e69de29..c8ad2e5 100644 --- a/Target/Interface/Logger.js +++ b/Target/Interface/Logger.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/Target/Interface/Option.d.ts b/Target/Interface/Option.d.ts deleted file mode 100644 index d323505..0000000 --- a/Target/Interface/Option.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -import type { Type as Action } from "./Action.js"; -import type { Type as Cache } from "./Cache.js"; -import type { Type as Exclude } from "./Exclude.js"; -import type { Type as Logger } from "./Logger.js"; -import type { Type as Path } from "./Path.js"; -import type { Pattern } from "fast-glob"; -/** - * Represents options for configuring the behavior of the program. - */ -export interface Type { - [key: string]: any; - /** - * Configuration for the target cache. - * - * @default "./Cache" - */ - Cache?: Cache; - /** - * Configuration for the target path(s). - * - * @default "./Target" - */ - Path?: Path | Path[] | Set; - /** - * Criteria for excluding files. - */ - Exclude?: Exclude | Exclude[] | Set; - /** - * File patterns to be matched. - */ - Files?: Pattern | Pattern[]; - /** - * Action pipe configuration. - */ - Action?: Action; - /** - * Debugging level. - * - * @default 2 - */ - Logger?: Logger; -} diff --git a/Target/Interface/Option.js b/Target/Interface/Option.js index e69de29..c8ad2e5 100644 --- a/Target/Interface/Option.js +++ b/Target/Interface/Option.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/Target/Interface/Path.d.ts b/Target/Interface/Path.d.ts deleted file mode 100644 index 2789fef..0000000 --- a/Target/Interface/Path.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -/// -/** - * Represents a path specification. - */ -export type Type = string | URL | Map | false; diff --git a/Target/Interface/Path.js b/Target/Interface/Path.js index e69de29..c8ad2e5 100644 --- a/Target/Interface/Path.js +++ b/Target/Interface/Path.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/Target/Interface/Plan.d.ts b/Target/Interface/Plan.d.ts deleted file mode 100644 index af12124..0000000 --- a/Target/Interface/Plan.d.ts +++ /dev/null @@ -1,37 +0,0 @@ -import type { Type as Cache } from "./Cache.js"; -import type { Type as Dir } from "./Dir.js"; -import type { Type as File } from "./File.js"; -import type { Type as Logger } from "./Logger.js"; -/** - * Represents the execution's plan. - */ -export interface Type { - /** - * The folder of the plan cache. - */ - Cache: Cache; - /** - * The debugging level for the execution plan. - */ - Logger: Logger; - /** - * The number of files in the execution plan. - */ - Files: number; - /** - * Additional information associated with the execution plan. - */ - Info: any; - /** - * Mapping of input paths to output paths. - */ - Paths: Map; - /** - * Mapping of result paths to corresponding input paths. - */ - Results: Map<`${Dir["Output"]}${File["Output"]}`, `${Dir["Input"]}${File["Input"]}`>; - /** - * The file currently being operated on. - */ - On: File; -} diff --git a/Target/Interface/Plan.js b/Target/Interface/Plan.js index e69de29..c8ad2e5 100644 --- a/Target/Interface/Plan.js +++ b/Target/Interface/Plan.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/Target/Object/Option.d.ts b/Target/Object/Option.d.ts deleted file mode 100644 index 09718de..0000000 --- a/Target/Object/Option.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Default configuration object. - */ -declare const _default: { - Cache: string; - Path: string; - Logger: 2; - Action: { - Read: (On: import("../Export.ts").File) => Promise; - Wrote: (On: import("../Export.ts").File) => Promise; - Passed: (On: import("../Export.ts").File) => Promise; - Failed: (On: import("../Export.ts").File) => Promise; - Accomplished: (On: import("../Export.ts").File) => Promise; - Fulfilled: (Plan: import("../Interface/Plan.ts").Type) => Promise; - Changed: (Plan: import("../Interface/Plan.ts").Type) => Promise; - }; -}; -export default _default; diff --git a/Target/Object/Option.js b/Target/Object/Option.js index e12e460..4302de2 100644 --- a/Target/Object/Option.js +++ b/Target/Object/Option.js @@ -1 +1,77 @@ -import{readFile as s}from"fs/promises";var t={Cache:"./Cache",Path:"./Target",Logger:2,Action:{Read:async e=>await s(e.Input,"utf-8"),Wrote:async e=>e.Buffer,Passed:async e=>e&&!0,Failed:async e=>`Error: Cannot process file ${e.Input}!`,Accomplished:async e=>`Processed ${e.Input} in ${e.Output}.`,Fulfilled:async e=>e.Files>0?`Successfully processed a total of ${e.Files} ${e.Files===1?"file":"files"}.`:!1,Changed:async e=>e}};export{t as default}; +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var promises_1 = require("fs/promises"); +/** + * Default configuration object. + */ +exports.default = { + Cache: "./Cache", + Path: "./Target", + Logger: 2, + Action: { + Read: function (On) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, (0, promises_1.readFile)(On.Input, "utf-8")]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); }); }, + Wrote: function (On) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { + return [2 /*return*/, On.Buffer]; + }); }); }, + Passed: function (On) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { + return [2 /*return*/, On && true]; + }); }); }, + Failed: function (On) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { + return [2 /*return*/, "Error: Cannot process file ".concat(On.Input, "!")]; + }); }); }, + Accomplished: function (On) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { + return [2 /*return*/, "Processed ".concat(On.Input, " in ").concat(On.Output, ".")]; + }); }); }, + Fulfilled: function (Plan) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, Plan.Files > 0 + ? "Successfully processed a total of ".concat(Plan.Files, " ").concat(Plan.Files === 1 ? "file" : "files", ".") + : false]; + }); + }); }, + Changed: function (Plan) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { + return [2 /*return*/, Plan]; + }); }); }, + }, +}; diff --git a/package.json b/package.json index dee2052..43bdd9d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "files-pipe", - "version": "2.0.18", + "version": "2.0.19", "private": false, "description": "🧪 Files processing with JavaScript.", "homepage": "https://github.com/NikolaRHristov/FilesPipe#readme", @@ -24,12 +24,12 @@ "prepublishOnly": "TypeScriptESBuild 'Source/**/*.ts'" }, "dependencies": { - "@types/node": "20.6.0", + "@types/node": "20.6.2", "deepmerge-ts": "5.1.0", "fast-glob": "3.3.1" }, "devDependencies": { - "typescript-esbuild": "0.1.15" + "typescript-esbuild": "0.1.16" }, "publishConfig": { "access": "public"