From ec7395591f3a79e03080e368025c3048a4c69530 Mon Sep 17 00:00:00 2001 From: Nikola Hristov Date: Fri, 22 Sep 2023 04:31:15 +0300 Subject: [PATCH] squash! --- Script/Configuration/ESBuild.ts | 5 +++-- Script/Source/Command/Cloudflare.ts | 14 +++++++------ Script/Source/Command/Dependabot.ts | 12 ++++++----- Script/Source/Command/NPM.ts | 20 +++++++++++++------ Script/Source/Command/Node.ts | 14 +++++++------ Script/Source/Command/Rust.ts | 16 ++++++++------- .../{Option/Index.ts => Interface/Files.ts} | 2 +- Script/Source/Library/Directory.ts | 11 ++++++++++ Script/Source/Library/Package.ts | 8 +++++--- Script/Source/Library/Request.ts | 6 ++++-- Script/Source/Library/Type.ts | 6 +++--- Script/Source/Option/Cloudflare.ts | 5 +++-- Script/Source/Option/Command.ts | 6 ++++-- Script/Source/Option/Dependabot.ts | 6 +++--- Script/Source/Option/NPM.ts | 5 +++-- Script/Source/Option/Node.ts | 5 +++-- Script/Source/Option/Rust.ts | 5 +++-- 17 files changed, 92 insertions(+), 54 deletions(-) rename Script/Source/{Option/Index.ts => Interface/Files.ts} (72%) diff --git a/Script/Configuration/ESBuild.ts b/Script/Configuration/ESBuild.ts index 0f46beb..80f7625 100644 --- a/Script/Configuration/ESBuild.ts +++ b/Script/Configuration/ESBuild.ts @@ -1,4 +1,5 @@ -import type { PluginBuild as Build, BuildOptions as Option } from "esbuild"; +import type { PluginBuild as Build, BuildOptions as Type } from "esbuild"; + import { copy as Copy } from "esbuild-plugin-copy"; import { access as Access, @@ -49,4 +50,4 @@ export default { ], }), ], -} satisfies Option; +} satisfies Type as Type; diff --git a/Script/Source/Command/Cloudflare.ts b/Script/Source/Command/Cloudflare.ts index 491a08c..d429ee4 100644 --- a/Script/Source/Command/Cloudflare.ts +++ b/Script/Source/Command/Cloudflare.ts @@ -1,11 +1,13 @@ -import { constants as Constant } from "fs"; -import { access, mkdir, rm, writeFile } from "fs/promises"; -import { dirname as Dir } from "path"; -import gitDirectories from "../Library/Directory.js"; +import type { Type as Files } from "../Interface/Files.js"; + +import Directory from "../Library/Directory.js"; import Package from "../Library/Package.js"; import Type from "../Library/Type.js"; import Cloudflare from "../Option/Cloudflare.js"; -import type { Files } from "../Option/Index.js"; + +import { constants as Constant } from "fs"; +import { access, mkdir, rm, writeFile } from "fs/promises"; +import { dirname as Dir } from "path"; /** * The function `Workflow` iterates through a list of files, checks if a specific file exists, and @@ -15,7 +17,7 @@ import type { Files } from "../Option/Index.js"; */ const Workflow = async (files: Files) => { for (const { Path, Name, File } of files) { - for (const [directory, packageFiles] of await gitDirectories( + for (const [directory, packageFiles] of await Directory( await Package("Cloudflare") )) { const githubDir = `${directory}/.github`; diff --git a/Script/Source/Command/Dependabot.ts b/Script/Source/Command/Dependabot.ts index f39ed63..557ff61 100644 --- a/Script/Source/Command/Dependabot.ts +++ b/Script/Source/Command/Dependabot.ts @@ -1,3 +1,10 @@ +import type { Type as Files } from "../Interface/Files.js"; + +import DirsGit from "../Library/Directory.js"; +import Packages from "../Library/Package.js"; +import Types from "../Library/Type.js"; +import Dependabot from "../Option/Dependabot.js"; + import { constants as Constant } from "fs"; import { access as Access, @@ -6,11 +13,6 @@ import { writeFile as _File, } from "fs/promises"; import { dirname as Dir } from "path"; -import DirsGit from "../Library/Directory.js"; -import Packages from "../Library/Package.js"; -import Types from "../Library/Type.js"; -import Dependabot from "../Option/Dependabot.js"; -import type { Files } from "../Option/Index.js"; /** * It creates a `dependabot.yml` file in each `.github` directory of each repository in the current diff --git a/Script/Source/Command/NPM.ts b/Script/Source/Command/NPM.ts index e2a7082..e05c9cf 100644 --- a/Script/Source/Command/NPM.ts +++ b/Script/Source/Command/NPM.ts @@ -1,12 +1,20 @@ -import { constants as Constant } from "fs"; -import { access as Access, mkdir as Dir, rm as Remove, readFile as _File, writeFile as __File } from "fs/promises"; -import { dirname } from "path"; -import gitDirectories from "../Library/Directory.js"; +import type { Type as Files } from "../Interface/Files.js"; + +import Directory from "../Library/Directory.js"; import Package from "../Library/Package.js"; import Type from "../Library/Type.js"; -import type { Files } from "../Option/Index.js"; import NPM from "../Option/NPM.js"; +import { constants as Constant } from "fs"; +import { + access as Access, + mkdir as Dir, + rm as Remove, + readFile as _File, + writeFile as __File, +} from "fs/promises"; +import { dirname } from "path"; + /** * This function writes workflows for npm packages based on their package.json files. * @param {Files} Files - The `files` parameter is an array of objects containing information @@ -14,7 +22,7 @@ import NPM from "../Option/NPM.js"; */ const Workflow = async (Files: Files) => { for (const { Path, Name, File } of Files) { - for (const [directory, packageFiles] of await gitDirectories( + for (const [directory, packageFiles] of await Directory( await Package("NPM") )) { const githubDir = `${directory}/.github`; diff --git a/Script/Source/Command/Node.ts b/Script/Source/Command/Node.ts index 9ed8517..ee83021 100644 --- a/Script/Source/Command/Node.ts +++ b/Script/Source/Command/Node.ts @@ -1,11 +1,13 @@ -import { constants as Constant } from "fs"; -import { access, mkdir, readFile, rm, writeFile } from "fs/promises"; -import { dirname as Dir } from "path"; -import gitDirectories from "../Library/Directory.js"; +import type { Type as Files } from "../Interface/Files.js"; + +import Directory from "../Library/Directory.js"; import Package from "../Library/Package.js"; import Type from "../Library/Type.js"; import Node from "../Option/Node.js"; -import type { Files } from "../Option/Index.js"; + +import { constants as Constant } from "fs"; +import { access, mkdir, readFile, rm, writeFile } from "fs/promises"; +import { dirname as Dir } from "path"; /** * It takes a list of files, and for each file, it checks if the file is a workflow file, and if it is, @@ -16,7 +18,7 @@ import type { Files } from "../Option/Index.js"; */ const Workflow = async (files: Files) => { for (const { Path, Name, File } of files) { - for (const [directory, packageFiles] of await gitDirectories( + for (const [directory, packageFiles] of await Directory( await Package("NPM") )) { const githubDir = `${directory}/.github`; diff --git a/Script/Source/Command/Rust.ts b/Script/Source/Command/Rust.ts index 38f2edc..b1a5e04 100644 --- a/Script/Source/Command/Rust.ts +++ b/Script/Source/Command/Rust.ts @@ -1,16 +1,18 @@ +import type { Type as Files } from "../Interface/Files.js"; + +import Directory from "../Library/Directory.js"; +import Packages from "../Library/Package.js"; +import Types from "../Library/Type.js"; +import Rust from "../Option/Rust.js"; + import { constants as Constant } from "fs"; import { access as Access, - writeFile as _File, mkdir as Dir, rm as Remove, + writeFile as _File, } from "fs/promises"; import { basename, dirname } from "path"; -import gitDirectories from "../Library/Directory.js"; -import Packages from "../Library/Package.js"; -import Types from "../Library/Type.js"; -import Rust from "../Option/Rust.js"; -import type { Files } from "../Option/Index.js"; /** * It takes a list of files, and for each file, it checks if the file is a workflow file, and if it is, @@ -21,7 +23,7 @@ import type { Files } from "../Option/Index.js"; */ const Workflow = async (Files: Files) => { for (const { Path, Name, File } of Files) { - for (const [directory, packageFiles] of await gitDirectories( + for (const [directory, packageFiles] of await Directory( await Packages("Cargo") )) { const githubDir = `${directory}/.github`; diff --git a/Script/Source/Option/Index.ts b/Script/Source/Interface/Files.ts similarity index 72% rename from Script/Source/Option/Index.ts rename to Script/Source/Interface/Files.ts index a02cdde..b5f9d61 100644 --- a/Script/Source/Option/Index.ts +++ b/Script/Source/Interface/Files.ts @@ -1,4 +1,4 @@ -export type Files = Set<{ +export type Type = Set<{ Path: string; Name: string; File: () => Promise>; diff --git a/Script/Source/Library/Directory.ts b/Script/Source/Library/Directory.ts index 2e75912..59c4a80 100644 --- a/Script/Source/Library/Directory.ts +++ b/Script/Source/Library/Directory.ts @@ -1,5 +1,16 @@ import WalkUntilGit from "./WalkUntilGit.js"; +/** + * The function `Directory` takes a set of file globs, walks through the directories + * until it finds a Git repository, and returns a map where the keys are the directories + * and the values are sets of globs associated with each directory. + * @param Globs - Globs is a Set of strings representing file globs. A file glob is a + * pattern used to match file paths. For example, "*.js" would match all JavaScript + * files in a directory. The Globs parameter is a set of these file globs that will be + * used to search for files in + * @returns The function `Directory` returns a `Map` object where the keys are directory + * paths and the values are sets of glob patterns associated with each directory. + */ export default async (Globs: Set) => { const Results = new Map(); diff --git a/Script/Source/Library/Package.ts b/Script/Source/Library/Package.ts index 4f06c77..bc85378 100644 --- a/Script/Source/Library/Package.ts +++ b/Script/Source/Library/Package.ts @@ -1,9 +1,11 @@ -import Glob from "fast-glob"; +import type { Type } from "./Type.js"; + import Environment from "./Environment.js"; import Types from "./Type.js"; -import type { Filter } from "./Type.js"; -export default async (Filter: Filter = false) => +import Glob from "fast-glob"; + +export default async (Filter: Type = false) => new Set( [ ...(await Glob( diff --git a/Script/Source/Library/Request.ts b/Script/Source/Library/Request.ts index 17e9735..31151cb 100644 --- a/Script/Source/Library/Request.ts +++ b/Script/Source/Library/Request.ts @@ -1,8 +1,10 @@ -import { Octokit } from "@octokit/core"; import type { OctokitResponse } from "@octokit/types"; + +import Environment from "../Library/Environment.js"; + +import { Octokit } from "@octokit/core"; import { deepmerge as Merge } from "deepmerge-ts"; import Tag from "etag"; -import Environment from "../Library/Environment.js"; const OCTOKIT = new Octokit({ auth: Environment.Token, diff --git a/Script/Source/Library/Type.ts b/Script/Source/Library/Type.ts index 0cf14ec..9b4f74a 100644 --- a/Script/Source/Library/Type.ts +++ b/Script/Source/Library/Type.ts @@ -1,4 +1,4 @@ -export type Filter = +export type Type = | "NPM" | "Cargo" | "Composer" @@ -6,8 +6,8 @@ export type Filter = | "Cloudflare" | false; -export default async (Filter: Filter = false) => { - const Result = new Map(); +export default async (Filter: Type = false) => { + const Result = new Map(); Result.set("package.json", "NPM"); Result.set("Cargo.toml", "Cargo"); diff --git a/Script/Source/Option/Cloudflare.ts b/Script/Source/Option/Cloudflare.ts index d41f892..dff65c9 100644 --- a/Script/Source/Option/Cloudflare.ts +++ b/Script/Source/Option/Cloudflare.ts @@ -1,7 +1,8 @@ +import type { Type as Files } from "../Interface/Files.js"; + import { readFile as File } from "fs/promises"; import { dirname as Dir, resolve as Resolve } from "path"; import { fileURLToPath as Path } from "url"; -import type { Files } from "./Index.js"; export default new Set([ { @@ -21,4 +22,4 @@ export default new Set([ ).toString(), ]), }, -]) satisfies Files; +]) satisfies Files as Files; diff --git a/Script/Source/Option/Command.ts b/Script/Source/Option/Command.ts index 59a9bec..c57a373 100644 --- a/Script/Source/Option/Command.ts +++ b/Script/Source/Option/Command.ts @@ -1,8 +1,10 @@ -import type { CommandOptions as Options } from "commander"; +import type { CommandOptions as Type } from "commander"; +/* The `Commands` variable is a set of objects representing different commands that can be executed in +a program. Each object in the set has the following properties: */ const Commands: Set<{ Name: string; - Opts?: Options; + Opts?: Type; Type?: "Workflow"; Description?: string; Arguments?: Set<{ diff --git a/Script/Source/Option/Dependabot.ts b/Script/Source/Option/Dependabot.ts index f6cce51..24947ec 100644 --- a/Script/Source/Option/Dependabot.ts +++ b/Script/Source/Option/Dependabot.ts @@ -1,8 +1,8 @@ +import type { Type as Files } from "../Interface/Files.js"; + import { readFile as File } from "fs/promises"; import { dirname as Dir, resolve as Resolve } from "path"; - import { fileURLToPath as Path } from "url"; -import type { Files } from "./Index.js"; export default new Set([ { @@ -39,4 +39,4 @@ export default new Set([ ).toString(), ]), }, -]) satisfies Files; +]) satisfies Files as Files; diff --git a/Script/Source/Option/NPM.ts b/Script/Source/Option/NPM.ts index d5595cf..04bcffc 100644 --- a/Script/Source/Option/NPM.ts +++ b/Script/Source/Option/NPM.ts @@ -1,7 +1,8 @@ +import type { Type as Files } from "../Interface/Files.js"; + import { readFile as File } from "fs/promises"; import { dirname as Dir, resolve as Resolve } from "path"; import { fileURLToPath as Path } from "url"; -import type { Files } from "./Index.js"; export default new Set([ { @@ -21,4 +22,4 @@ export default new Set([ ).toString(), ]), }, -]) satisfies Files; +]) satisfies Files as Files; diff --git a/Script/Source/Option/Node.ts b/Script/Source/Option/Node.ts index 219552e..886ad42 100644 --- a/Script/Source/Option/Node.ts +++ b/Script/Source/Option/Node.ts @@ -1,7 +1,8 @@ +import type { Type as Files } from "../Interface/Files.js"; + import { readFile as File } from "fs/promises"; import { dirname as Dir, resolve as Resolve } from "path"; import { fileURLToPath as Path } from "url"; -import type { Files } from "./Index.js"; export default new Set([ { @@ -21,4 +22,4 @@ export default new Set([ ).toString(), ]), }, -]) satisfies Files; +]) satisfies Files as Files; diff --git a/Script/Source/Option/Rust.ts b/Script/Source/Option/Rust.ts index bfd0fdc..cb1b75c 100644 --- a/Script/Source/Option/Rust.ts +++ b/Script/Source/Option/Rust.ts @@ -1,7 +1,8 @@ +import type { Type as Files } from "../Interface/Files.js"; + import { readFile as File } from "fs/promises"; import { dirname as Dir, resolve as Resolve } from "path"; import { fileURLToPath as Path } from "url"; -import type { Files } from "./Index.js"; export default new Set([ { @@ -21,4 +22,4 @@ export default new Set([ ).toString(), ]), }, -]) satisfies Files; +]) satisfies Files as Files;