-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d9bea2
commit 4c712bb
Showing
8 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import type { PlopTypes } from "@turbo/gen"; | ||
|
||
import { component, init, story } from "./generators"; | ||
import { component, init, nextAction, story } from "./generators"; | ||
|
||
export default function generator(plop: PlopTypes.NodePlopAPI): void { | ||
plop.setGenerator("init", init); | ||
plop.setGenerator("component", component); | ||
plop.setGenerator("next-action", nextAction); | ||
plop.setGenerator("story", story); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { PlopTypes } from "@turbo/gen"; | ||
|
||
export const nextAction = { | ||
description: "Nextjs Server Action", | ||
prompts: [ | ||
{ | ||
type: "input", | ||
name: "app", | ||
message: "📁 Which app do you want to add to?", | ||
default: "nextjs", | ||
validate: (value) => !!value || `App name is required`, | ||
}, | ||
{ | ||
type: "input", | ||
name: "name", | ||
message: "🐫 Action Name:", | ||
default: "create action", | ||
validate: (value) => !!value || `Action name is required`, | ||
}, | ||
], | ||
actions: [ | ||
{ | ||
type: "add", | ||
path: "apps/{{app}}/actions/index.ts", | ||
skipIfExists: true, | ||
}, | ||
{ | ||
type: "add", | ||
path: "apps/{{app}}/actions/{{dashCase name}}.ts", | ||
templateFile: "templates/action/index.ts.hbs", | ||
abortOnFail: true, | ||
}, | ||
{ | ||
type: "append", | ||
path: "apps/{{app}}/actions/index.ts", | ||
template: 'export * from "./{{dashCase name}}"', | ||
}, | ||
{ | ||
type: "add", | ||
path: "packages/validators/src/actions/{{dashCase name}}.ts", | ||
templateFile: "templates/action/schema.ts.hbs", | ||
abortOnFail: true, | ||
}, | ||
{ | ||
type: "append", | ||
path: "packages/validators/src/actions/index.ts", | ||
template: 'export * from "./{{dashCase name}}"', | ||
}, | ||
], | ||
} satisfies PlopTypes.PlopGeneratorConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./action"; | ||
export * from "./component"; | ||
export * from "./init"; | ||
export * from "./story"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use server" | ||
|
||
import { worxpace } from "@acme/prisma"; | ||
import { type ActionHandler, createSafeAction } from "@acme/ui/lib"; | ||
import { {{pascalCase name}}, type {{pascalCase name}}Input } from "@acme/validators"; | ||
|
||
import { UnauthorizedError, fetchClient } from "~/lib"; | ||
|
||
const handler: ActionHandler<{{pascalCase name}}Input, any> = async (data) => { | ||
let result; | ||
const {} = data; | ||
|
||
try { | ||
const { clientId } = fetchClient(); | ||
} catch (error) { | ||
if (error instanceof UnauthorizedError) | ||
return { error: "Unauthorized" }; | ||
console.log(`ERROR`, error); | ||
return { error: "Failed to {{lowerCase name}}." }; | ||
} | ||
|
||
return { data: result }; | ||
}; | ||
|
||
export const {{camelCase name}} = createSafeAction({{pascalCase name}}, handler); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { z } from "zod"; | ||
|
||
export const {{pascalCase name}} = z.object({}); | ||
|
||
export type {{pascalCase name}}Input = z.infer<typeof {{pascalCase name}}>; |