Skip to content

Commit

Permalink
feat: remove prpc & add AuthPC + bump
Browse files Browse the repository at this point in the history
  • Loading branch information
OrJDev committed Oct 30, 2024
1 parent 0cb0d41 commit e722670
Show file tree
Hide file tree
Showing 26 changed files with 149 additions and 130 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-lobsters-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-jd-app": minor
---

feat: remove prpc & add AuthPC + bump
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ pnpm create jd-app@latest
All addons are optional, you may select some, you may select all and you may select none.

- [Prisma](https://github.com/prisma/prisma)
- [pRPC](https://github.com/solidjs-community/mediakit/tree/main/packages/prpc)
- [AuthPC](https://github.com/solidjs-community/mediakit/tree/main/packages/authpc/solid)
- [TailwindCSS](https://github.com/tailwindlabs/tailwindcss)
- [AuthJS](https://github.com/solidjs-community/mediakit/tree/main/packages/auth)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"keywords": [
"JDev",
"pRPC",
"AuthPC",
"TypeScript",
"Tailwind",
"Solid",
Expand Down
71 changes: 50 additions & 21 deletions src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,70 @@ import prettier from "prettier";

export const getAppConfig: IUtil = async (ctx) => {
const usePrisma = ctx.installers.includes("Prisma");
const usePRPC = ctx.installers.includes("pRPC");
const useAuthPC = ctx.installers.includes("AuthPC");
const useAuth = ctx.installers.includes("AuthJS");
if (useAuthPC) {
return await prettier.format(
`import { withAuthPC } from "@solid-mediakit/authpc-plugin";
const config = withAuthPC(
{
ssr: true,${useAuth ? "\n middleware: './src/middleware.ts'," : ""}${
usePrisma
? `\n vite: {
ssr: {
external: ["@prisma/client"],
},
},`
: ""
}${
ctx.vercel
? `\n server: {
preset: 'vercel',
},`
: ""
}
},${
useAuth
? `\n {
auth: "authjs",
authCfg: {
configName: "authOptions",
source: "~/server/auth",
},
}`
: ""
}
);
export default config;
declare module "@solid-mediakit/authpc" {
interface Settings {
config: typeof config;
}
}
`,
{
parser: "typescript",
},
);
}
return await prettier.format(
`import { defineConfig } from "@solidjs/start/config";${
usePRPC ? `\nimport { prpcVite } from "@solid-mediakit/prpc-plugin";` : ""
}${
useAuth ? `\nimport { authVite } from "@solid-mediakit/auth-plugin";` : ""
}
export default defineConfig({
ssr: true,${
usePrisma || usePRPC
usePrisma
? `\n vite: {
${
usePrisma
? `ssr: {
external: ["@prisma/client"],
},`
: ""
}${
usePRPC
? `${usePrisma ? "\n" : ""} plugins: [${
usePRPC ? "prpcVite(), " : ""
}${
useAuth
? `authVite({
authOpts:{
name: "authOptions",
dir: "~/server/auth"
},
redirectTo: "/"
})`
: ""
}],`
: ""
}
},`
: ""
Expand All @@ -61,7 +90,7 @@ export default defineConfig({
export const modifyConfigIfNeeded = async (ctx: ICtx) => {
if (
ctx.vercel ||
ctx.installers.includes("pRPC") ||
ctx.installers.includes("AuthPC") ||
ctx.installers.includes("Prisma")
) {
await fs.writeFile(
Expand Down
9 changes: 4 additions & 5 deletions src/helpers/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ const packages = {
normal: {
// prisma
"@prisma/client": "^5.20.0",
// prpc
// authpc
"@tanstack/solid-query": "^5.59.0",
"@solid-mediakit/prpc": "^1.3.3",
"@solid-mediakit/prpc-plugin": "^1.3.4",
"@solid-mediakit/authpc": "^1.2.1",
"@solid-mediakit/authpc-plugin": "^1.5.2",
// authjs
"@solid-mediakit/auth": "^3.0.0",
"@solid-mediakit/auth-plugin": "^1.1.4",
"@solid-mediakit/auth": "^3.0.1",
"@auth/core": "0.35.0",
"@auth/prisma-adapter": "^2.6.0",
// tailwind
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/utils/getAppLocation.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { ICtx } from "~types";

const getAppLocation = (ctx: ICtx) => {
const usingPRPC = ctx.installers.includes("pRPC");
const usingAuthPC = ctx.installers.includes("AuthPC");
const usingAuth = ctx.installers.includes("AuthJS");

if (usingPRPC && usingAuth)
return `${ctx.templateDir}/app/with-auth-prpc.tsx`;
else if (usingPRPC) return `${ctx.templateDir}/app/with-prpc.tsx`;
if (usingAuthPC && usingAuth)
return `${ctx.templateDir}/app/with-auth-authpc.tsx`;
else if (usingAuthPC) return `${ctx.templateDir}/app/with-authpc.tsx`;
return ``;
};

Expand Down
20 changes: 10 additions & 10 deletions src/helpers/utils/getIndexLocation.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import type { ICtx } from "~types";

const getIndexLocation = (ctx: ICtx) => {
const usingPRPC = ctx.installers.includes("pRPC");
const usingAuthPC = ctx.installers.includes("AuthPC");
const usingTw = ctx.installers.includes("TailwindCSS");
const usingAuth = ctx.installers.includes("AuthJS");
return createFileHelper(usingPRPC, usingTw, usingAuth, ctx);
return createFileHelper(usingAuthPC, usingTw, usingAuth, ctx);
};

export default getIndexLocation;

function createFileHelper(
usingPRPC: boolean,
usingAuthPC: boolean,
usingTw: boolean,
usingAuth: boolean,
ctx: ICtx
ctx: ICtx,
) {
const fileName = usingPRPC ? `prpc` : "";
const fileName = usingAuthPC ? `authpc` : "";
let indexFile = "";
if (usingPRPC && usingTw && usingAuth) {
if (usingAuthPC && usingTw && usingAuth) {
indexFile = `with-auth-${fileName}-tw.tsx`;
} else if (usingPRPC && !usingTw && usingAuth) {
} else if (usingAuthPC && !usingTw && usingAuth) {
indexFile = `with-auth-${fileName}.tsx`;
} else if (usingPRPC && usingTw) {
} else if (usingAuthPC && usingTw) {
indexFile = `with-${fileName}-tw.tsx`;
} else if (usingPRPC && !usingTw) {
} else if (usingAuthPC && !usingTw) {
indexFile = `with-${fileName}.tsx`;
} else if (usingAuth && usingTw) {
indexFile = "with-auth-tw.tsx";
} else if (!usingPRPC && usingTw) {
} else if (!usingAuthPC && usingTw) {
indexFile = "with-tw.tsx";
} else if (usingAuth) {
indexFile = "with-auth.tsx";
Expand Down
2 changes: 1 addition & 1 deletion src/installers/AuthJS/files/app.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function App() {
<MetaProvider>
<Title>Create JD APP</Title>
<Suspense>
<SessionProvider>{props.children} </SessionProvider>
<SessionProvider>{props.children}</SessionProvider>
</Suspense>
</MetaProvider>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/installers/AuthJS/files/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { serverEnv } from "~/env/server";

declare module "@auth/core/types" {
export interface Session {
user?: DefaultSession["user"];
user: DefaultSession["user"];
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/installers/AuthJS/files/middleware.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { authMiddleware } from "@solid-mediakit/auth";
import { createMiddleware } from "@solidjs/start/middleware";
import { authOptions } from "./server/auth";

const pathsToPreload = ["/"];

export default createMiddleware({
onRequest: [authMiddleware(pathsToPreload, authOptions)],
});
4 changes: 2 additions & 2 deletions src/installers/AuthJS/files/prisma-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { serverEnv } from "~/env/server";

declare module "@auth/core/types" {
export interface Session {
user?: {
id?: string;
user: {
id: string;
} & DefaultSession["user"];
}
}
Expand Down
13 changes: 0 additions & 13 deletions src/installers/AuthJS/files/protected.txt

This file was deleted.

12 changes: 6 additions & 6 deletions src/installers/AuthJS/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const config: IInstaller = (ctx) => {
const normal: KeyOrKeyArray<"normal"> = [
"@auth/core",
"@solid-mediakit/auth",
"@solid-mediakit/auth-plugin",
];
if (usePrisma) {
normal.push("@auth/prisma-adapter");
Expand All @@ -25,15 +24,16 @@ const config: IInstaller = (ctx) => {
path: `${__dirname}/files/handler.txt`,
to: `${ctx.userDir}/src/routes/api/auth/[...solidauth].ts`,
},
!ctx.installers.includes("pRPC")
{
path: `${__dirname}/files/middleware.txt`,
to: `${ctx.userDir}/src/middleware.ts`,
},
!ctx.installers.includes("AuthPC")
? {
path: `${__dirname}/files/app.txt`,
to: `${ctx.userDir}/src/app.tsx`,
}
: {
path: `${__dirname}/files/protected.txt`,
to: `${ctx.userDir}/src/routes/protected.tsx`,
},
: undefined,
],
env: [
{
Expand Down
14 changes: 14 additions & 0 deletions src/installers/AuthPC/files/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { z } from "zod";
import { helloCaller } from "../authpc";

export const helloQuery = helloCaller(
z.object({
hello: z.string(),
}),
({ input$, ctx$ }) => {
if (input$.hello === "hello") {
return ctx$.hello;
}
return ctx$.world;
},
);
11 changes: 11 additions & 0 deletions src/installers/AuthPC/files/user.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from "zod";
import { userCaller } from "../authpc";

export const protectedQuery = userCaller(
z.object({
hello: z.string(),
}),
({ input$, ctx$ }) => {
return `this is top secret: ${input$.hello} ${ctx$.user.name}`;
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const config: IInstaller = (ctx) => {
return {
pkgs: withPackages({
normal: [
"@solid-mediakit/prpc",
"@solid-mediakit/prpc-plugin",
"@solid-mediakit/authpc",
"@solid-mediakit/authpc-plugin",
"@tanstack/solid-query",
],
}),
Expand All @@ -18,7 +18,7 @@ const config: IInstaller = (ctx) => {
},
{
path: `${__dirname}/utils/getBuilder`,
to: `${ctx.userDir}/src/server/prpc.ts`,
to: `${ctx.userDir}/src/server/authpc.ts`,
type: "exec",
},
useAuth
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { IUtil } from "~types";
import type { IUtil } from "~types";

const getBuilder: IUtil = (ctx) => {
const useAuth = ctx.installers.includes("AuthJS");
return `import { builder$${
return `import { createCaller${
useAuth ? ", error$" : ""
} } from "@solid-mediakit/prpc";${
} } from "@solid-mediakit/authpc";${
useAuth
? `\nimport { authOptions } from "./auth";\nimport { getSession } from "@solid-mediakit/auth";`
: ""
}
export const helloBuilder = builder$()
.middleware$(() => {
export const helloCaller = createCaller
.use(() => {
return {
hello: 1,
};
})
.middleware$((ctx) => {
.use(({ ctx$ }) => {
return {
...ctx,
...ctx$,
world: 2,
};
});${
useAuth
? `\n\nexport const userBuilder = builder$().middleware$(async ({ event$ }) => {
? `\n\nexport const userCaller = createCaller.use(async ({ event$ }) => {
const session = await getSession(event$.request, authOptions);
if (!session) {
return error$("Unauthorized", {
Expand Down
15 changes: 0 additions & 15 deletions src/installers/pRPC/files/hello.txt

This file was deleted.

12 changes: 0 additions & 12 deletions src/installers/pRPC/files/user.txt

This file was deleted.

Loading

0 comments on commit e722670

Please sign in to comment.