diff --git a/apps/dokploy/.prettierignore b/apps/dokploy/.prettierignore new file mode 100644 index 00000000..8c51966d --- /dev/null +++ b/apps/dokploy/.prettierignore @@ -0,0 +1,9 @@ +node_modules +.next +.docker +coverage +.prettierignore +.stylelintignore +.eslintignore +*.log +docs diff --git a/apps/dokploy/.prettierrc b/apps/dokploy/.prettierrc new file mode 100644 index 00000000..30b344cc --- /dev/null +++ b/apps/dokploy/.prettierrc @@ -0,0 +1,5 @@ +{ + "plugins": ["prettier-plugin-tailwindcss"], + "useTabs": true, + "printWidth": 80 +} diff --git a/apps/dokploy/components/dashboard/application/build/show.tsx b/apps/dokploy/components/dashboard/application/build/show.tsx index 5c6e044c..d01b313f 100644 --- a/apps/dokploy/components/dashboard/application/build/show.tsx +++ b/apps/dokploy/components/dashboard/application/build/show.tsx @@ -20,7 +20,7 @@ import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; -enum BuildType { +export enum BuildType { dockerfile = "dockerfile", heroku_buildpacks = "heroku_buildpacks", paketo_buildpacks = "paketo_buildpacks", @@ -29,9 +29,18 @@ enum BuildType { railpack = "railpack", } +const buildTypeDisplayMap: Record = { + [BuildType.dockerfile]: "Dockerfile", + [BuildType.railpack]: "Railpack", + [BuildType.nixpacks]: "Nixpacks", + [BuildType.heroku_buildpacks]: "Heroku Buildpacks", + [BuildType.paketo_buildpacks]: "Paketo Buildpacks", + [BuildType.static]: "Static", +}; + const mySchema = z.discriminatedUnion("buildType", [ z.object({ - buildType: z.literal("dockerfile"), + buildType: z.literal(BuildType.dockerfile), dockerfile: z .string({ required_error: "Dockerfile path is required", @@ -42,18 +51,18 @@ const mySchema = z.discriminatedUnion("buildType", [ dockerBuildStage: z.string().nullable().default(""), }), z.object({ - buildType: z.literal("heroku_buildpacks"), + buildType: z.literal(BuildType.heroku_buildpacks), herokuVersion: z.string().nullable().default(""), }), z.object({ - buildType: z.literal("paketo_buildpacks"), + buildType: z.literal(BuildType.paketo_buildpacks), }), z.object({ - buildType: z.literal("nixpacks"), + buildType: z.literal(BuildType.nixpacks), publishDirectory: z.string().optional(), }), z.object({ - buildType: z.literal("static"), + buildType: z.literal(BuildType.static), }), z.object({ buildType: z.literal("railpack"), @@ -61,20 +70,39 @@ const mySchema = z.discriminatedUnion("buildType", [ ]); type AddTemplate = z.infer; + interface Props { applicationId: string; } +const resetData = (data: any): AddTemplate => { + switch (data.buildType) { + case BuildType.dockerfile: + return { + buildType: BuildType.dockerfile, + dockerfile: data.dockerfile || "", + dockerContextPath: data.dockerContextPath || "", + dockerBuildStage: data.dockerBuildStage || "", + }; + case BuildType.heroku_buildpacks: + return { + buildType: BuildType.heroku_buildpacks, + herokuVersion: data.herokuVersion || "", + }; + default: + return { + buildType: data.buildType, + publishDirectory: data.publishDirectory || undefined, + }; + } +}; + export const ShowBuildChooseForm = ({ applicationId }: Props) => { const { mutateAsync, isLoading } = api.application.saveBuildType.useMutation(); const { data, refetch } = api.application.one.useQuery( - { - applicationId, - }, - { - enabled: !!applicationId, - }, + { applicationId }, + { enabled: !!applicationId }, ); const form = useForm({ @@ -85,46 +113,29 @@ export const ShowBuildChooseForm = ({ applicationId }: Props) => { }); const buildType = form.watch("buildType"); + useEffect(() => { if (data) { - if (data.buildType === "dockerfile") { - form.reset({ - buildType: data.buildType, - ...(data.buildType && { - dockerfile: data.dockerfile || "", - dockerContextPath: data.dockerContextPath || "", - dockerBuildStage: data.dockerBuildStage || "", - }), - }); - } else if (data.buildType === "heroku_buildpacks") { - form.reset({ - buildType: data.buildType, - ...(data.buildType && { - herokuVersion: data.herokuVersion || "", - }), - }); - } else { - form.reset({ - buildType: data.buildType, - publishDirectory: data.publishDirectory || undefined, - }); - } + form.reset(resetData(data)); } - }, [form.formState.isSubmitSuccessful, form.reset, data, form]); + }, [data, form]); const onSubmit = async (data: AddTemplate) => { await mutateAsync({ applicationId, buildType: data.buildType, publishDirectory: - data.buildType === "nixpacks" ? data.publishDirectory : null, - dockerfile: data.buildType === "dockerfile" ? data.dockerfile : null, + data.buildType === BuildType.nixpacks ? data.publishDirectory : null, + dockerfile: + data.buildType === BuildType.dockerfile ? data.dockerfile : null, dockerContextPath: - data.buildType === "dockerfile" ? data.dockerContextPath : null, + data.buildType === BuildType.dockerfile ? data.dockerContextPath : null, dockerBuildStage: - data.buildType === "dockerfile" ? data.dockerBuildStage : null, + data.buildType === BuildType.dockerfile ? data.dockerBuildStage : null, herokuVersion: - data.buildType === "heroku_buildpacks" ? data.herokuVersion : null, + data.buildType === BuildType.heroku_buildpacks + ? data.herokuVersion + : null, }) .then(async () => { toast.success("Build type saved"); @@ -160,193 +171,143 @@ export const ShowBuildChooseForm = ({ applicationId }: Props) => { control={form.control} name="buildType" defaultValue={form.control._defaultValues.buildType} - render={({ field }) => { - return ( - - Build Type - - - - - - - - Dockerfile - - - - - - - - Railpack{" "} - New - - - - - - - - Nixpacks - - - - - - - - Heroku Buildpacks - - - - - - - - Paketo Buildpacks - - - - - - - Static - - - - - - ); - }} + render={({ field }) => ( + + Build Type + + + {Object.entries(buildTypeDisplayMap).map( + ([value, label]) => ( + + + + + + {label} + {value === BuildType.railpack && ( + New + )} + + + ), + )} + + + + + )} /> - {buildType === "heroku_buildpacks" && ( + {buildType === BuildType.heroku_buildpacks && ( { - return ( - - Heroku Version (Optional) - - - - - - - ); - }} + render={({ field }) => ( + + Heroku Version (Optional) + + + + + + )} /> )} - {buildType === "dockerfile" && ( + {buildType === BuildType.dockerfile && ( <> { - return ( - - Docker File - - - - - - - ); - }} - /> - - { - return ( - - Docker Context Path - - - - - - - ); - }} - /> - - { - return ( - -
- Docker Build Stage - - Allows you to target a specific stage in a - Multi-stage Dockerfile. If empty, Docker defaults to - build the last defined stage. - -
- - - -
- ); - }} - /> - - )} - - {buildType === "nixpacks" && ( - { - return ( + render={({ field }) => ( -
- Publish Directory - - Allows you to serve a single directory via NGINX after - the build phase. Useful if the final build assets - should be served as a static site. - -
+ Docker File -
- ); - }} + )} + /> + ( + + Docker Context Path + + + + + + )} + /> + ( + +
+ Docker Build Stage + + Allows you to target a specific stage in a Multi-stage + Dockerfile. If empty, Docker defaults to build the + last defined stage. + +
+ + + +
+ )} + /> + + )} + {buildType === BuildType.nixpacks && ( + ( + +
+ Publish Directory + + Allows you to serve a single directory via NGINX after + the build phase. Useful if the final build assets should + be served as a static site. + +
+ + + + +
+ )} /> )}
diff --git a/apps/dokploy/package.json b/apps/dokploy/package.json index 22649f92..c0e5ed97 100644 --- a/apps/dokploy/package.json +++ b/apps/dokploy/package.json @@ -176,6 +176,8 @@ "esbuild": "0.20.2", "lint-staged": "^15.2.7", "memfs": "^4.11.0", + "prettier": "^3.5.3", + "prettier-plugin-tailwindcss": "^0.6.11", "tailwindcss": "^3.4.1", "tsx": "^4.7.0", "typescript": "^5.4.2", @@ -196,6 +198,8 @@ ] }, "commitlint": { - "extends": ["@commitlint/config-conventional"] + "extends": [ + "@commitlint/config-conventional" + ] } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ddbc702..735b2184 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -512,6 +512,12 @@ importers: memfs: specifier: ^4.11.0 version: 4.11.0 + prettier: + specifier: ^3.5.3 + version: 3.5.3 + prettier-plugin-tailwindcss: + specifier: ^0.6.11 + version: 0.6.11(prettier@3.5.3) tailwindcss: specifier: ^3.4.1 version: 3.4.7(ts-node@10.9.2(@types/node@18.19.42)(typescript@5.5.3)) @@ -6386,6 +6392,66 @@ packages: engines: {node: '>=10'} hasBin: true + prettier-plugin-tailwindcss@0.6.11: + resolution: {integrity: sha512-YxaYSIvZPAqhrrEpRtonnrXdghZg1irNg4qrjboCXrpybLWVs55cW2N3juhspVJiO0JBvYJT8SYsJpc8OQSnsA==} + engines: {node: '>=14.21.3'} + peerDependencies: + '@ianvs/prettier-plugin-sort-imports': '*' + '@prettier/plugin-pug': '*' + '@shopify/prettier-plugin-liquid': '*' + '@trivago/prettier-plugin-sort-imports': '*' + '@zackad/prettier-plugin-twig': '*' + prettier: ^3.0 + prettier-plugin-astro: '*' + prettier-plugin-css-order: '*' + prettier-plugin-import-sort: '*' + prettier-plugin-jsdoc: '*' + prettier-plugin-marko: '*' + prettier-plugin-multiline-arrays: '*' + prettier-plugin-organize-attributes: '*' + prettier-plugin-organize-imports: '*' + prettier-plugin-sort-imports: '*' + prettier-plugin-style-order: '*' + prettier-plugin-svelte: '*' + peerDependenciesMeta: + '@ianvs/prettier-plugin-sort-imports': + optional: true + '@prettier/plugin-pug': + optional: true + '@shopify/prettier-plugin-liquid': + optional: true + '@trivago/prettier-plugin-sort-imports': + optional: true + '@zackad/prettier-plugin-twig': + optional: true + prettier-plugin-astro: + optional: true + prettier-plugin-css-order: + optional: true + prettier-plugin-import-sort: + optional: true + prettier-plugin-jsdoc: + optional: true + prettier-plugin-marko: + optional: true + prettier-plugin-multiline-arrays: + optional: true + prettier-plugin-organize-attributes: + optional: true + prettier-plugin-organize-imports: + optional: true + prettier-plugin-sort-imports: + optional: true + prettier-plugin-style-order: + optional: true + prettier-plugin-svelte: + optional: true + + prettier@3.5.3: + resolution: {integrity: sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==} + engines: {node: '>=14'} + hasBin: true + pretty-format@29.7.0: resolution: {integrity: sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -13505,6 +13571,12 @@ snapshots: tunnel-agent: 0.6.0 optional: true + prettier-plugin-tailwindcss@0.6.11(prettier@3.5.3): + dependencies: + prettier: 3.5.3 + + prettier@3.5.3: {} + pretty-format@29.7.0: dependencies: '@jest/schemas': 29.6.3