diff --git a/.changeset/clever-items-fly.md b/.changeset/clever-items-fly.md new file mode 100644 index 0000000..87ad1b3 --- /dev/null +++ b/.changeset/clever-items-fly.md @@ -0,0 +1,5 @@ +--- +"create-jd-app": patch +--- + +fix: prettify all files diff --git a/src/helpers/installer.ts b/src/helpers/installer.ts index da64d79..2824b2e 100644 --- a/src/helpers/installer.ts +++ b/src/helpers/installer.ts @@ -10,7 +10,7 @@ import type { IExpectedPackages } from "./packages"; import type { TInstallers } from "~types"; export default async ( - ctx: ICtx + ctx: ICtx, ): Promise<[Record, IExpectedPackages, IEnv[], string[]]> => { let normalDeps: IExpectedPackages[0] = {}; let devModeDeps: IExpectedPackages[1] = {}; @@ -40,7 +40,7 @@ export default async ( scripts = { ...scripts, ...cfg.scripts }; } if (cfg.files?.length) { - await execFiles(cfg.files, ctx, cfg.ignorePrettier); + await execFiles(cfg.files, ctx); } if (cfg.commands) { if (Array.isArray(cfg.commands)) { @@ -59,9 +59,9 @@ export default async ( (installer: { default: IInstaller }) => typeof installer.default === "function" ? installer.default(ctx) - : installer.default - ) - ) + : installer.default, + ), + ), ); console.log(); @@ -85,7 +85,7 @@ export default async ( export async function getCtxWithInstallers( ctx: IAppCtx, - curr: string[] + curr: string[], ): Promise { let installers: string[] = []; let pkgs: TInstallers[] = []; @@ -103,12 +103,12 @@ export async function getCtxWithInstallers( console.log( `${chalk.green("√")} Using installers: ${validInstallers .map((installer) => chalk.blue(installer)) - .join(", ")}` + .join(", ")}`, ); } if (!skip) { let optInstallers = installers.filter( - (pkg) => !validInstallers.includes(pkg) + (pkg) => !validInstallers.includes(pkg), ); const newPkgs = ( await inquirer.prompt<{ pkgs: TInstallers[] }>({ diff --git a/src/installers/AuthJS/files/protected.txt b/src/installers/AuthJS/files/protected.txt index 518c9a5..633ab58 100644 --- a/src/installers/AuthJS/files/protected.txt +++ b/src/installers/AuthJS/files/protected.txt @@ -1,13 +1,13 @@ -import {protected$} from "@solid-mediakit/auth" -import { protectedQuery } from "~/server/user/user.queries" +import { protected$ } from "@solid-mediakit/auth"; +import { protectedQuery } from "~/server/user/user.queries"; -export default protected$(session$=>{ - const res = protectedQuery(()=> ({hello: 'world'})) - return ( -
-

Protected Page

-

Session: {JSON.stringify(session$)}

-

Response: {JSON.stringify(res.data)}

-
- ) -}) \ No newline at end of file +export default protected$((session$) => { + const res = protectedQuery(() => ({ hello: "world" })); + return ( +
+

Protected Page

+

Session: {JSON.stringify(session$)}

+

Response: {JSON.stringify(res.data)}

+
+ ); +}); diff --git a/src/installers/Prisma/index.ts b/src/installers/Prisma/index.ts index 2aa3b83..0897226 100644 --- a/src/installers/Prisma/index.ts +++ b/src/installers/Prisma/index.ts @@ -7,6 +7,7 @@ const config: IInstaller = (ctx) => ({ path: `${__dirname}/utils/getSchema`, type: "exec", to: `${ctx.userDir}/prisma/schema.prisma`, + ignorePrettier: true, }, { path: `${__dirname}/files/client.txt`, @@ -36,7 +37,6 @@ const config: IInstaller = (ctx) => ({ normal: "@prisma/client", }), commands: `${ctx.pkgManager === "npm" ? "npx" : "pnpm"} prisma db push`, - ignorePrettier: true }); export default config; diff --git a/src/types.ts b/src/types.ts index 3660c0f..c8050f3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -27,7 +27,6 @@ export type IConfig = { scripts?: Record; env?: IEnv[]; commands?: string | string[]; - ignorePrettier?: boolean; }; type IInstallerCB = (ctx: ICtx) => IPromiseOrType; @@ -52,6 +51,9 @@ export type IEnv = { kind: "server" | "client"; }; -export type IUtil = (ctx: ICtx, passed?: T) => string | Promise; +export type IUtil = ( + ctx: ICtx, + passed?: T, +) => string | Promise; export type TInstallers = "AuthJS" | "Prisma" | "TailwindCSS" | "pRPC"; diff --git a/src/utils/files.ts b/src/utils/files.ts index 5a6bbf6..d3e51ae 100644 --- a/src/utils/files.ts +++ b/src/utils/files.ts @@ -2,41 +2,47 @@ import fs from "fs-extra"; import ora from "ora"; import type { ICtx, IFile } from "~types"; import { formatError } from "./helpers"; -import prettier from "prettier" +import prettier from "prettier"; -export async function execFiles(files: (IFile | undefined)[], ctx: ICtx, ignorePrettier?:boolean) { +export async function execFiles(files: (IFile | undefined)[], ctx: ICtx) { const actualFiles = files.filter((f) => f !== undefined) as IFile[]; // `sep` files are parent files, so they should be executed first ro resolve conflicts for (const file of actualFiles.filter((e) => e.sep)) { - await execFile(file, ctx, ignorePrettier); + await execFile(file, ctx); } await Promise.all( actualFiles .filter((e) => !e.sep) .map(async (file) => { - await execFile(file, ctx, ignorePrettier); - }) + await execFile(file, ctx); + }), ); } -async function execFile(file: IFile, ctx: ICtx, ignorePrettier?: boolean) { +async function execFile(file: IFile, ctx: ICtx) { if (file.type && file.type !== "copy") { if (file.type === "exec") { if (!file.path) { return; } const method = await import(file.path); - let code = await method.default(ctx, file.pass) - if(!ignorePrettier && !file.ignorePrettier) { + let code = await method.default(ctx, file.pass); + if (!file.ignorePrettier) { code = await prettier.format(code, { parser: "typescript", }); } - await fs.outputFile(file.to,code); + await fs.outputFile(file.to, code); } else if (file.type === "delete") { await fs.remove(file.to); } else if (file.type === "write") { - await fs.outputFile(file.to, file.content); + let code = file.content!; + if (!file.ignorePrettier) { + code = await prettier.format(code, { + parser: "typescript", + }); + } + await fs.outputFile(file.to, code); } else if (file.type === "append") { await fs.appendFile(file.to, file.content); }