refactor(linter): format files

This commit is contained in:
Mauricio Siu
2024-09-19 22:25:25 -06:00
parent 4845c1ad5d
commit 9a828d4966
15 changed files with 128 additions and 47 deletions

View File

@@ -1,6 +1,8 @@
import fs from "node:fs/promises"; import fs from "node:fs/promises";
import path from "node:path"; import path from "node:path";
import { paths } from "@/server/constants"; import { paths } from "@/server/constants";
const { APPLICATIONS_PATH } = paths();
import type { ApplicationNested } from "@/server/utils/builders";
import { unzipDrop } from "@/server/utils/builders/drop"; import { unzipDrop } from "@/server/utils/builders/drop";
import AdmZip from "adm-zip"; import AdmZip from "adm-zip";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"; import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
@@ -10,12 +12,85 @@ if (typeof window === "undefined") {
globalThis.File = undici.File as any; globalThis.File = undici.File as any;
globalThis.FileList = undici.FileList as any; globalThis.FileList = undici.FileList as any;
} }
const { APPLICATIONS_PATH } = paths();
const baseApp: ApplicationNested = {
applicationId: "",
applicationStatus: "done",
appName: "",
autoDeploy: true,
serverId: "",
branch: null,
dockerBuildStage: "",
buildArgs: null,
buildPath: "/",
gitlabPathNamespace: "",
buildType: "nixpacks",
bitbucketBranch: "",
bitbucketBuildPath: "",
bitbucketId: "",
bitbucketRepository: "",
bitbucketOwner: "",
githubId: "",
gitlabProjectId: 0,
gitlabBranch: "",
gitlabBuildPath: "",
gitlabId: "",
gitlabRepository: "",
gitlabOwner: "",
command: null,
cpuLimit: null,
cpuReservation: null,
createdAt: "",
customGitBranch: "",
customGitBuildPath: "",
customGitSSHKeyId: null,
customGitUrl: "",
description: "",
dockerfile: null,
dockerImage: null,
dropBuildPath: null,
enabled: null,
env: null,
healthCheckSwarm: null,
labelsSwarm: null,
memoryLimit: null,
memoryReservation: null,
modeSwarm: null,
mounts: [],
name: "",
networkSwarm: null,
owner: null,
password: null,
placementSwarm: null,
ports: [],
projectId: "",
publishDirectory: null,
redirects: [],
refreshToken: "",
registry: null,
registryId: null,
replicas: 1,
repository: null,
restartPolicySwarm: null,
rollbackConfigSwarm: null,
security: [],
sourceType: "git",
subtitle: null,
title: null,
updateConfigSwarm: null,
username: null,
dockerContextPath: null,
};
//
vi.mock("@/server/constants", () => ({ vi.mock("@/server/constants", () => ({
APPLICATIONS_PATH: "./__test__/drop/zips/output", paths: () => ({
APPLICATIONS_PATH: "./__test__/drop/zips/output",
}),
// APPLICATIONS_PATH: "./__test__/drop/zips/output",
})); }));
describe("unzipDrop using real zip files", () => { describe("unzipDrop using real zip files", () => {
// const { APPLICATIONS_PATH } = paths();
beforeAll(async () => { beforeAll(async () => {
await fs.rm(APPLICATIONS_PATH, { recursive: true, force: true }); await fs.rm(APPLICATIONS_PATH, { recursive: true, force: true });
}); });
@@ -25,39 +100,42 @@ describe("unzipDrop using real zip files", () => {
}); });
it("should correctly extract a zip with a single root folder", async () => { it("should correctly extract a zip with a single root folder", async () => {
const appName = "single-file"; baseApp.appName = "single-file";
const outputPath = path.join(APPLICATIONS_PATH, appName, "code"); // const appName = "single-file";
const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code");
const zip = new AdmZip("./__test__/drop/zips/single-file.zip"); const zip = new AdmZip("./__test__/drop/zips/single-file.zip");
const zipBuffer = zip.toBuffer(); const zipBuffer = zip.toBuffer();
const file = new File([zipBuffer], "single.zip"); const file = new File([zipBuffer], "single.zip");
await unzipDrop(file, appName); await unzipDrop(file, baseApp);
const files = await fs.readdir(outputPath, { withFileTypes: true }); const files = await fs.readdir(outputPath, { withFileTypes: true });
expect(files.some((f) => f.name === "test.txt")).toBe(true); expect(files.some((f) => f.name === "test.txt")).toBe(true);
}); });
it("should correctly extract a zip with a single root folder and a subfolder", async () => { it("should correctly extract a zip with a single root folder and a subfolder", async () => {
const appName = "folderwithfile"; baseApp.appName = "folderwithfile";
const outputPath = path.join(APPLICATIONS_PATH, appName, "code"); // const appName = "folderwithfile";
const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code");
const zip = new AdmZip("./__test__/drop/zips/folder-with-file.zip"); const zip = new AdmZip("./__test__/drop/zips/folder-with-file.zip");
const zipBuffer = zip.toBuffer(); const zipBuffer = zip.toBuffer();
const file = new File([zipBuffer], "single.zip"); const file = new File([zipBuffer], "single.zip");
await unzipDrop(file, appName); await unzipDrop(file, baseApp);
const files = await fs.readdir(outputPath, { withFileTypes: true }); const files = await fs.readdir(outputPath, { withFileTypes: true });
expect(files.some((f) => f.name === "folder1.txt")).toBe(true); expect(files.some((f) => f.name === "folder1.txt")).toBe(true);
}); });
it("should correctly extract a zip with multiple root folders", async () => { it("should correctly extract a zip with multiple root folders", async () => {
const appName = "two-folders"; baseApp.appName = "two-folders";
const outputPath = path.join(APPLICATIONS_PATH, appName, "code"); // const appName = "two-folders";
const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code");
const zip = new AdmZip("./__test__/drop/zips/two-folders.zip"); const zip = new AdmZip("./__test__/drop/zips/two-folders.zip");
const zipBuffer = zip.toBuffer(); const zipBuffer = zip.toBuffer();
const file = new File([zipBuffer], "single.zip"); const file = new File([zipBuffer], "single.zip");
await unzipDrop(file, appName); await unzipDrop(file, baseApp);
const files = await fs.readdir(outputPath, { withFileTypes: true }); const files = await fs.readdir(outputPath, { withFileTypes: true });
@@ -66,13 +144,14 @@ describe("unzipDrop using real zip files", () => {
}); });
it("should correctly extract a zip with a single root with a file", async () => { it("should correctly extract a zip with a single root with a file", async () => {
const appName = "nested"; baseApp.appName = "nested";
const outputPath = path.join(APPLICATIONS_PATH, appName, "code"); // const appName = "nested";
const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code");
const zip = new AdmZip("./__test__/drop/zips/nested.zip"); const zip = new AdmZip("./__test__/drop/zips/nested.zip");
const zipBuffer = zip.toBuffer(); const zipBuffer = zip.toBuffer();
const file = new File([zipBuffer], "single.zip"); const file = new File([zipBuffer], "single.zip");
await unzipDrop(file, appName); await unzipDrop(file, baseApp);
const files = await fs.readdir(outputPath, { withFileTypes: true }); const files = await fs.readdir(outputPath, { withFileTypes: true });
@@ -82,13 +161,14 @@ describe("unzipDrop using real zip files", () => {
}); });
it("should correctly extract a zip with a single root with a folder", async () => { it("should correctly extract a zip with a single root with a folder", async () => {
const appName = "folder-with-sibling-file"; baseApp.appName = "folder-with-sibling-file";
const outputPath = path.join(APPLICATIONS_PATH, appName, "code"); // const appName = "folder-with-sibling-file";
const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code");
const zip = new AdmZip("./__test__/drop/zips/folder-with-sibling-file.zip"); const zip = new AdmZip("./__test__/drop/zips/folder-with-sibling-file.zip");
const zipBuffer = zip.toBuffer(); const zipBuffer = zip.toBuffer();
const file = new File([zipBuffer], "single.zip"); const file = new File([zipBuffer], "single.zip");
await unzipDrop(file, appName); await unzipDrop(file, baseApp);
const files = await fs.readdir(outputPath, { withFileTypes: true }); const files = await fs.readdir(outputPath, { withFileTypes: true });

View File

@@ -9,6 +9,7 @@ const baseApp: ApplicationNested = {
applicationStatus: "done", applicationStatus: "done",
appName: "", appName: "",
autoDeploy: true, autoDeploy: true,
serverId: "",
branch: null, branch: null,
dockerBuildStage: "", dockerBuildStage: "",
buildArgs: null, buildArgs: null,

View File

@@ -1,5 +1,6 @@
import { ShowBuildChooseForm } from "@/components/dashboard/application/build/show"; import { ShowBuildChooseForm } from "@/components/dashboard/application/build/show";
import { ShowProviderForm } from "@/components/dashboard/application/general/generic/show"; import { ShowProviderForm } from "@/components/dashboard/application/general/generic/show";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Toggle } from "@/components/ui/toggle"; import { Toggle } from "@/components/ui/toggle";
@@ -13,7 +14,6 @@ import { StartApplication } from "../start-application";
import { StopApplication } from "../stop-application"; import { StopApplication } from "../stop-application";
import { DeployApplication } from "./deploy-application"; import { DeployApplication } from "./deploy-application";
import { ResetApplication } from "./reset-application"; import { ResetApplication } from "./reset-application";
import { Badge } from "@/components/ui/badge";
interface Props { interface Props {
applicationId: string; applicationId: string;
} }

View File

@@ -19,6 +19,22 @@ import {
CommandInput, CommandInput,
CommandItem, CommandItem,
} from "@/components/ui/command"; } from "@/components/ui/command";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { import {
Select, Select,
SelectContent, SelectContent,
@@ -34,21 +50,6 @@ import {
TooltipProvider, TooltipProvider,
TooltipTrigger, TooltipTrigger,
} from "@/components/ui/tooltip"; } from "@/components/ui/tooltip";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { Input } from "@/components/ui/input";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { api } from "@/utils/api"; import { api } from "@/utils/api";
import { ScrollArea } from "@radix-ui/react-scroll-area"; import { ScrollArea } from "@radix-ui/react-scroll-area";
@@ -65,7 +66,6 @@ import {
import Link from "next/link"; import Link from "next/link";
import { useState } from "react"; import { useState } from "react";
import { toast } from "sonner"; import { toast } from "sonner";
import { Label } from "@/components/ui/label";
interface Props { interface Props {
projectId: string; projectId: string;
} }

View File

@@ -48,9 +48,9 @@ import { removeDeploymentsByComposeId } from "../services/deployment";
import { createDomain, findDomainsByComposeId } from "../services/domain"; import { createDomain, findDomainsByComposeId } from "../services/domain";
import { createMount } from "../services/mount"; import { createMount } from "../services/mount";
import { findProjectById } from "../services/project"; import { findProjectById } from "../services/project";
import { findServerById } from "../services/server";
import { addNewService, checkServiceAccess } from "../services/user"; import { addNewService, checkServiceAccess } from "../services/user";
import { createTRPCRouter, protectedProcedure } from "../trpc"; import { createTRPCRouter, protectedProcedure } from "../trpc";
import { findServerById } from "../services/server";
export const composeRouter = createTRPCRouter({ export const composeRouter = createTRPCRouter({
create: protectedProcedure create: protectedProcedure

View File

@@ -10,6 +10,7 @@ import {
apiRemoveDestination, apiRemoveDestination,
apiUpdateDestination, apiUpdateDestination,
} from "@/server/db/schema"; } from "@/server/db/schema";
import { execAsync } from "@/server/utils/process/execAsync";
import { TRPCError } from "@trpc/server"; import { TRPCError } from "@trpc/server";
import { findAdmin } from "../services/admin"; import { findAdmin } from "../services/admin";
import { import {
@@ -18,7 +19,6 @@ import {
removeDestinationById, removeDestinationById,
updateDestinationById, updateDestinationById,
} from "../services/destination"; } from "../services/destination";
import { execAsync } from "@/server/utils/process/execAsync";
export const destinationRouter = createTRPCRouter({ export const destinationRouter = createTRPCRouter({
create: adminProcedure create: adminProcedure

View File

@@ -1,3 +1,4 @@
import { paths } from "@/server/constants";
import { import {
apiAssignDomain, apiAssignDomain,
apiEnableDashboard, apiEnableDashboard,
@@ -53,7 +54,6 @@ import {
} from "../services/settings"; } from "../services/settings";
import { canAccessToTraefikFiles } from "../services/user"; import { canAccessToTraefikFiles } from "../services/user";
import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc"; import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc";
import { paths } from "@/server/constants";
export const settingsRouter = createTRPCRouter({ export const settingsRouter = createTRPCRouter({
reloadServer: adminProcedure.mutation(async () => { reloadServer: adminProcedure.mutation(async () => {

View File

@@ -1,6 +1,6 @@
import type { CreateServiceOptions } from "dockerode"; import type { CreateServiceOptions } from "dockerode";
import { generateRandomPassword } from "../auth/random-password"; import { generateRandomPassword } from "../auth/random-password";
import { paths, docker } from "../constants"; import { docker, paths } from "../constants";
import { pullImage } from "../utils/docker/utils"; import { pullImage } from "../utils/docker/utils";
import { execAsync } from "../utils/process/execAsync"; import { execAsync } from "../utils/process/execAsync";

View File

@@ -2,9 +2,9 @@ import type { BackupSchedule } from "@/server/api/services/backup";
import type { Destination } from "@/server/api/services/destination"; import type { Destination } from "@/server/api/services/destination";
import { scheduleJob, scheduledJobs } from "node-schedule"; import { scheduleJob, scheduledJobs } from "node-schedule";
import { runMariadbBackup } from "./mariadb"; import { runMariadbBackup } from "./mariadb";
import { runMongoBackup } from "./mongo";
import { runMySqlBackup } from "./mysql"; import { runMySqlBackup } from "./mysql";
import { runPostgresBackup } from "./postgres"; import { runPostgresBackup } from "./postgres";
import { runMongoBackup } from "./mongo";
export const scheduleBackup = (backup: BackupSchedule) => { export const scheduleBackup = (backup: BackupSchedule) => {
const { schedule, backupId, databaseType, postgres, mysql, mongo, mariadb } = const { schedule, backupId, databaseType, postgres, mysql, mongo, mariadb } =

View File

@@ -1,3 +1,4 @@
import type { InferResultType } from "@/server/types/with";
import type { CreateServiceOptions } from "dockerode"; import type { CreateServiceOptions } from "dockerode";
import { import {
calculateResources, calculateResources,
@@ -7,7 +8,6 @@ import {
prepareEnvironmentVariables, prepareEnvironmentVariables,
} from "../docker/utils"; } from "../docker/utils";
import { getRemoteDocker } from "../servers/remote-docker"; import { getRemoteDocker } from "../servers/remote-docker";
import type { InferResultType } from "@/server/types/with";
export type MariadbNested = InferResultType<"mariadb", { mounts: true }>; export type MariadbNested = InferResultType<"mariadb", { mounts: true }>;
export const buildMariadb = async (mariadb: MariadbNested) => { export const buildMariadb = async (mariadb: MariadbNested) => {

View File

@@ -1,3 +1,4 @@
import type { InferResultType } from "@/server/types/with";
import type { CreateServiceOptions } from "dockerode"; import type { CreateServiceOptions } from "dockerode";
import { import {
calculateResources, calculateResources,
@@ -7,7 +8,6 @@ import {
prepareEnvironmentVariables, prepareEnvironmentVariables,
} from "../docker/utils"; } from "../docker/utils";
import { getRemoteDocker } from "../servers/remote-docker"; import { getRemoteDocker } from "../servers/remote-docker";
import type { InferResultType } from "@/server/types/with";
export type MongoNested = InferResultType<"mongo", { mounts: true }>; export type MongoNested = InferResultType<"mongo", { mounts: true }>;

View File

@@ -1,3 +1,4 @@
import type { InferResultType } from "@/server/types/with";
import type { CreateServiceOptions } from "dockerode"; import type { CreateServiceOptions } from "dockerode";
import { import {
calculateResources, calculateResources,
@@ -7,7 +8,6 @@ import {
prepareEnvironmentVariables, prepareEnvironmentVariables,
} from "../docker/utils"; } from "../docker/utils";
import { getRemoteDocker } from "../servers/remote-docker"; import { getRemoteDocker } from "../servers/remote-docker";
import type { InferResultType } from "@/server/types/with";
export type MysqlNested = InferResultType<"mysql", { mounts: true }>; export type MysqlNested = InferResultType<"mysql", { mounts: true }>;

View File

@@ -1,3 +1,4 @@
import type { InferResultType } from "@/server/types/with";
import type { CreateServiceOptions } from "dockerode"; import type { CreateServiceOptions } from "dockerode";
import { import {
calculateResources, calculateResources,
@@ -7,7 +8,6 @@ import {
prepareEnvironmentVariables, prepareEnvironmentVariables,
} from "../docker/utils"; } from "../docker/utils";
import { getRemoteDocker } from "../servers/remote-docker"; import { getRemoteDocker } from "../servers/remote-docker";
import type { InferResultType } from "@/server/types/with";
export type PostgresNested = InferResultType<"postgres", { mounts: true }>; export type PostgresNested = InferResultType<"postgres", { mounts: true }>;
export const buildPostgres = async (postgres: PostgresNested) => { export const buildPostgres = async (postgres: PostgresNested) => {

View File

@@ -1,3 +1,4 @@
import type { InferResultType } from "@/server/types/with";
import type { CreateServiceOptions } from "dockerode"; import type { CreateServiceOptions } from "dockerode";
import { import {
calculateResources, calculateResources,
@@ -7,7 +8,6 @@ import {
prepareEnvironmentVariables, prepareEnvironmentVariables,
} from "../docker/utils"; } from "../docker/utils";
import { getRemoteDocker } from "../servers/remote-docker"; import { getRemoteDocker } from "../servers/remote-docker";
import type { InferResultType } from "@/server/types/with";
export type RedisNested = InferResultType<"redis", { mounts: true }>; export type RedisNested = InferResultType<"redis", { mounts: true }>;
export const buildRedis = async (redis: RedisNested) => { export const buildRedis = async (redis: RedisNested) => {

View File

@@ -5,13 +5,13 @@ import { docker, paths } from "@/server/constants";
import type { ContainerInfo, ResourceRequirements } from "dockerode"; import type { ContainerInfo, ResourceRequirements } from "dockerode";
import { parse } from "dotenv"; import { parse } from "dotenv";
import type { ApplicationNested } from "../builders"; import type { ApplicationNested } from "../builders";
import { execAsync, execAsyncRemote } from "../process/execAsync";
import { getRemoteDocker } from "../servers/remote-docker";
import type { MongoNested } from "../databases/mongo";
import type { MariadbNested } from "../databases/mariadb"; import type { MariadbNested } from "../databases/mariadb";
import type { MongoNested } from "../databases/mongo";
import type { MysqlNested } from "../databases/mysql"; import type { MysqlNested } from "../databases/mysql";
import type { PostgresNested } from "../databases/postgres"; import type { PostgresNested } from "../databases/postgres";
import type { RedisNested } from "../databases/redis"; import type { RedisNested } from "../databases/redis";
import { execAsync, execAsyncRemote } from "../process/execAsync";
import { getRemoteDocker } from "../servers/remote-docker";
interface RegistryAuth { interface RegistryAuth {
username: string; username: string;