Skip to content

Commit 6912f20

Browse files
maneikeactions-user
authored andcommitted
Prettified Code!
1 parent b3a9600 commit 6912f20

20 files changed

+209
-270
lines changed

packages/cli/index.ts

+18-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
2-
import { Command } from "commander";
3-
import inquirer from "inquirer";
4-
import chalk from "chalk";
5-
import { createProject } from "@create-stapler-app/core";
2+
import { Command } from 'commander';
3+
import inquirer from 'inquirer';
4+
import chalk from 'chalk';
5+
import { createProject } from '@create-stapler-app/core';
66

77
const asciiArt = `
88
.&&&% &&&&
@@ -17,32 +17,32 @@ const asciiArt = `
1717
`;
1818

1919
function displayHeader() {
20-
console.log(chalk.hex("#3100F5").bold(asciiArt));
21-
console.log(chalk.bold("\n🍸 Welcome to Stapler!\n"));
20+
console.log(chalk.hex('#3100F5').bold(asciiArt));
21+
console.log(chalk.bold('\n🍸 Welcome to Stapler!\n'));
2222
}
2323

2424
const program = new Command();
2525

2626
program
27-
.name("create-stapler-app")
28-
.description("CLI to bootstrap a new tonik-infused app")
29-
.version("0.1.0")
30-
.hook("preAction", () => {
27+
.name('create-stapler-app')
28+
.description('CLI to bootstrap a new tonik-infused app')
29+
.version('0.1.0')
30+
.hook('preAction', () => {
3131
displayHeader();
3232
});
3333

3434
const createAction = async () => {
3535
const answers = await inquirer.prompt([
3636
{
37-
type: "input",
38-
name: "name",
39-
message: "What is your project named?",
40-
default: "my-stapled-app",
37+
type: 'input',
38+
name: 'name',
39+
message: 'What is your project named?',
40+
default: 'my-stapled-app',
4141
},
4242
{
43-
type: "confirm",
44-
name: "usePayload",
45-
message: "Would you like to add Payload to your app?",
43+
type: 'confirm',
44+
name: 'usePayload',
45+
message: 'Would you like to add Payload to your app?',
4646
default: true,
4747
},
4848
// we dont support Inngest yet
@@ -57,10 +57,7 @@ const createAction = async () => {
5757
await createProject(answers);
5858
};
5959

60-
program
61-
.command("create")
62-
.description("Create a new tonik-infused app")
63-
.action(createAction);
60+
program.command('create').description('Create a new tonik-infused app').action(createAction);
6461

6562
// Set "create" as the default command
6663
program.action(createAction);

packages/core/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { execSync } from "child_process";
2-
import { createEnvFile } from "./utils/env/createEnvFile";
3-
import { preparePayload } from "./utils/payload/install";
4-
import { installSupabase } from "./utils/supabase/install";
5-
import { prettify } from "./utils/prettier/prettify";
6-
import { prepareDrink } from "./utils/bar/prepareDrink";
1+
import { execSync } from 'child_process';
2+
import { createEnvFile } from './utils/env/createEnvFile';
3+
import { preparePayload } from './utils/payload/install';
4+
import { installSupabase } from './utils/supabase/install';
5+
import { prettify } from './utils/prettier/prettify';
6+
import { prepareDrink } from './utils/bar/prepareDrink';
77

88
interface ProjectOptions {
99
name: string;
@@ -16,7 +16,7 @@ export async function createProject(options: ProjectOptions) {
1616

1717
console.log(`🍸 Stapling ${name}...`);
1818
execSync(`npx create-turbo@latest ${name} -m pnpm`, {
19-
stdio: "inherit",
19+
stdio: 'inherit',
2020
});
2121

2222
process.chdir(name);
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import { createBrowserClient } from "@supabase/ssr";
1+
import { createBrowserClient } from '@supabase/ssr';
22

3-
import type { Database } from "./types";
3+
import type { Database } from './types';
44

55
interface CreateClientOptions {
66
supabaseUrl: string;
77
supabaseAnonKey: string;
88
}
99

10-
export const createClient = ({
11-
supabaseUrl,
12-
supabaseAnonKey,
13-
}: CreateClientOptions) =>
10+
export const createClient = ({ supabaseUrl, supabaseAnonKey }: CreateClientOptions) =>
1411
createBrowserClient<Database>(supabaseUrl, supabaseAnonKey);

packages/core/templates/supabase/files/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type * as supabase from "@supabase/supabase-js";
1+
import type * as supabase from '@supabase/supabase-js';
22

3-
import type { Database } from "./types";
3+
import type { Database } from './types';
44

5-
export type { CookieStore } from "./types";
5+
export type { CookieStore } from './types';
66
export type Session = supabase.Session;
77
export type SupabaseClient = supabase.SupabaseClient<Database>;
88
export type User = supabase.User;

packages/core/templates/supabase/files/middleware.ts

+37-44
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,55 @@
1-
import type { CookieOptions } from "@supabase/ssr";
2-
import type { NextRequest } from "next/server";
3-
import { createServerClient } from "@supabase/ssr";
1+
import type { CookieOptions } from '@supabase/ssr';
2+
import type { NextRequest } from 'next/server';
3+
import { createServerClient } from '@supabase/ssr';
44

5-
import type { Database } from "./types";
5+
import type { Database } from './types';
66

77
interface CreateMiddlewareOptions {
88
supabaseUrl: string;
99
supabaseAnonKey: string;
1010
}
1111

12-
export const createMiddleware = ({
13-
supabaseAnonKey,
14-
supabaseUrl,
15-
}: CreateMiddlewareOptions) =>
12+
export const createMiddleware = ({ supabaseAnonKey, supabaseUrl }: CreateMiddlewareOptions) =>
1613
async function middleware(request: NextRequest) {
1714
const cookiesToSet: {
1815
name: string;
1916
value: string;
2017
}[] = [];
2118

22-
const supabase = createServerClient<Database>(
23-
supabaseUrl,
24-
supabaseAnonKey,
25-
{
26-
cookies: {
27-
get(name: string) {
28-
const cookieValue = request.cookies.get(name)?.value;
29-
return cookieValue;
30-
},
31-
set(name: string, value: string, options: CookieOptions) {
32-
request.cookies.set({
33-
name,
34-
value,
35-
...options,
36-
});
37-
38-
cookiesToSet.push({
39-
name,
40-
value,
41-
...options,
42-
});
43-
},
44-
remove(name: string, options: CookieOptions) {
45-
request.cookies.set({
46-
name,
47-
value: "",
48-
...options,
49-
});
50-
51-
cookiesToSet.push({
52-
name,
53-
value: "",
54-
...options,
55-
});
56-
},
19+
const supabase = createServerClient<Database>(supabaseUrl, supabaseAnonKey, {
20+
cookies: {
21+
get(name: string) {
22+
const cookieValue = request.cookies.get(name)?.value;
23+
return cookieValue;
24+
},
25+
set(name: string, value: string, options: CookieOptions) {
26+
request.cookies.set({
27+
name,
28+
value,
29+
...options,
30+
});
31+
32+
cookiesToSet.push({
33+
name,
34+
value,
35+
...options,
36+
});
37+
},
38+
remove(name: string, options: CookieOptions) {
39+
request.cookies.set({
40+
name,
41+
value: '',
42+
...options,
43+
});
44+
45+
cookiesToSet.push({
46+
name,
47+
value: '',
48+
...options,
49+
});
5750
},
5851
},
59-
);
52+
});
6053

6154
const { data } = await supabase.auth.getUser();
6255

packages/core/templates/supabase/files/next_api_endpoint.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import type { NextApiRequest, NextApiResponse } from "next";
2-
import { supabase } from "../../lib/supabase";
1+
import type { NextApiRequest, NextApiResponse } from 'next';
2+
import { supabase } from '../../lib/supabase';
33

4-
export default async function handler(
5-
req: NextApiRequest,
6-
res: NextApiResponse,
7-
) {
8-
const { data, error } = await supabase.from("your_table").select("*");
4+
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
5+
const { data, error } = await supabase.from('your_table').select('*');
96

107
if (error) {
118
return res.status(500).json({ error: error.message });
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { CookieOptions } from "@supabase/ssr";
2-
import { createServerClient } from "@supabase/ssr";
1+
import type { CookieOptions } from '@supabase/ssr';
2+
import { createServerClient } from '@supabase/ssr';
33

4-
import type { CookieStore, Database } from "./types";
4+
import type { CookieStore, Database } from './types';
55

66
interface BaseOptions {
77
supabaseApiUrl: string;
@@ -14,34 +14,30 @@ interface BaseOptions {
1414
}
1515

1616
export function createClient(configOptions: BaseOptions) {
17-
return createServerClient<Database>(
18-
configOptions.supabaseApiUrl,
19-
configOptions.supabaseKey,
20-
{
21-
cookies: {
22-
get(name: string) {
23-
return configOptions.cookieStore?.get(name)?.value;
24-
},
25-
set(name: string, value: string, options: CookieOptions) {
26-
try {
27-
configOptions.cookieStore?.set({ name, value, ...options });
28-
} catch (error) {
29-
// The `set` method was called from a Server Component.
30-
// This can be ignored if you have middleware refreshing
31-
// user sessions.
32-
}
33-
},
34-
remove(name: string, options: CookieOptions) {
35-
try {
36-
configOptions.cookieStore?.set({ name, value: "", ...options });
37-
} catch (error) {
38-
// The `set` method was called from a Server Component.
39-
// The `delete` method was called from a Server Component.
40-
// This can be ignored if you have middleware refreshing
41-
// user sessions.
42-
}
43-
},
17+
return createServerClient<Database>(configOptions.supabaseApiUrl, configOptions.supabaseKey, {
18+
cookies: {
19+
get(name: string) {
20+
return configOptions.cookieStore?.get(name)?.value;
21+
},
22+
set(name: string, value: string, options: CookieOptions) {
23+
try {
24+
configOptions.cookieStore?.set({ name, value, ...options });
25+
} catch (error) {
26+
// The `set` method was called from a Server Component.
27+
// This can be ignored if you have middleware refreshing
28+
// user sessions.
29+
}
30+
},
31+
remove(name: string, options: CookieOptions) {
32+
try {
33+
configOptions.cookieStore?.set({ name, value: '', ...options });
34+
} catch (error) {
35+
// The `set` method was called from a Server Component.
36+
// The `delete` method was called from a Server Component.
37+
// This can be ignored if you have middleware refreshing
38+
// user sessions.
39+
}
4440
},
4541
},
46-
);
42+
});
4743
}

packages/core/templates/supabase/files/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type * from "./types.gen";
1+
export type * from './types.gen';
22
export interface CookieStore {
33
get(name: string): { value: string } | undefined;
44
set(options: { name: string; value: string }): void;

packages/core/templates/supabase/installConfig.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
export const supabaseFiles = [
22
{
3-
path: "supabase/src/",
4-
files: ["client.ts", "index.ts", "middleware.ts", "server.ts", "types.ts"],
3+
path: 'supabase/src/',
4+
files: ['client.ts', 'index.ts', 'middleware.ts', 'server.ts', 'types.ts'],
55
},
66
{
7-
path: "supabase/",
8-
files: ["package"],
7+
path: 'supabase/',
8+
files: ['package'],
99
rename: [
1010
{
11-
from: "package",
12-
to: "package.json",
11+
from: 'package',
12+
to: 'package.json',
1313
},
1414
],
1515
},

packages/core/tsconfig.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
"declaration": true, // Ensure TypeScript generates declaration files
1111
"emitDeclarationOnly": true // Only emit declaration files without compiling the code
1212
},
13-
"include": [
14-
"index.ts",
15-
"utils/**/*.ts",
16-
"templates/supabase/installConfig.ts"
17-
],
13+
"include": ["index.ts", "utils/**/*.ts", "templates/supabase/installConfig.ts"],
1814
"exclude": ["node_modules", "dist", "templates/supabase/files/**/*"]
1915
}

packages/core/utils/bar/prepareDrink.ts

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
const getName = (name: string) => {
22
if (!name) {
3-
return ".";
3+
return '.';
44
}
55

66
return name;
77
};
88

99
export const prepareDrink = (name: string) => {
1010
setTimeout(() => {
11-
console.log("🍸 Filling a high ball glass with ice...");
11+
console.log('🍸 Filling a high ball glass with ice...');
1212
setTimeout(() => {
13-
console.log("🍸 Adding gin and lime juice...");
13+
console.log('🍸 Adding gin and lime juice...');
1414
setTimeout(() => {
15-
console.log("🍸 Topping with", "\x1b[34mTonik\x1b[0m...");
15+
console.log('🍸 Topping with', '\x1b[34mTonik\x1b[0m...');
1616
setTimeout(() => {
17-
console.log("🍸 Garnishing with lime wedge...");
17+
console.log('🍸 Garnishing with lime wedge...');
1818
setTimeout(() => {
19-
console.log(
20-
`\x1b[32m%s\x1b[0m`,
21-
`🍸 Your Stapled ${getName(name)} is ready!`,
22-
`\x1b[0m`,
23-
);
19+
console.log(`\x1b[32m%s\x1b[0m`, `🍸 Your Stapled ${getName(name)} is ready!`, `\x1b[0m`);
2420
// I'm too lazy to mess with modules building to allow coloring library to be installed lol
25-
console.log(
26-
`🍸 You can now run:`,
27-
`\x1b[36mcd ${name} && pnpm dev\x1b[0m`,
28-
);
21+
console.log(`🍸 You can now run:`, `\x1b[36mcd ${name} && pnpm dev\x1b[0m`);
2922
}, 1000);
3023
}, 1000);
3124
}, 1000);

0 commit comments

Comments
 (0)