database seed and coloredConsole
This commit is contained in:
@@ -3,6 +3,7 @@ import { ReactElement, ReactNode } from "react";
|
||||
import type { AppProps } from "next/app";
|
||||
import { NextPage } from "next";
|
||||
import { SessionProvider } from "next-auth/react";
|
||||
export { coloredConsole } from "@documenso/lib";
|
||||
|
||||
export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
|
||||
getLayout?: (page: ReactElement) => ReactNode;
|
||||
|
||||
4518
package-lock.json
generated
4518
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -4,10 +4,14 @@
|
||||
"scripts": {
|
||||
"dev": "cd apps&&cd web&&next dev",
|
||||
"build": "cd apps&&cd web&&next build",
|
||||
"start": "cd apps&&cd web&&next start"
|
||||
"start": "cd apps&&cd web&&next start",
|
||||
"db-seed": "prisma db seed"
|
||||
},
|
||||
"workspaces": [
|
||||
"apps/*",
|
||||
"packages/*"
|
||||
]
|
||||
],
|
||||
"prisma": {
|
||||
"seed": "ts-node --transpile-only ./packages/prisma/seed.ts"
|
||||
}
|
||||
}
|
||||
|
||||
40
packages/lib/coloredConsole.ts
Normal file
40
packages/lib/coloredConsole.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
// https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color
|
||||
|
||||
export default class coloredConsole {
|
||||
public static setupColoredConsole(): void {
|
||||
let infoLog = console.info;
|
||||
let logLog = console.log;
|
||||
let errorLog = console.error;
|
||||
let warnLog = console.warn;
|
||||
|
||||
let colors = {
|
||||
Reset: "\x1b[0m",
|
||||
Red: "\x1b[31m",
|
||||
Green: "\x1b[32m",
|
||||
Yellow: "\x1b[33m",
|
||||
};
|
||||
|
||||
console.info = function (args: any) {
|
||||
let copyArgs = Array.prototype.slice.call(arguments);
|
||||
copyArgs.unshift(colors.Green);
|
||||
copyArgs.push(colors.Reset);
|
||||
infoLog.apply(null, copyArgs);
|
||||
};
|
||||
|
||||
console.warn = function (args: any) {
|
||||
let copyArgs = Array.prototype.slice.call(arguments);
|
||||
copyArgs.unshift(colors.Yellow);
|
||||
copyArgs.push(colors.Reset);
|
||||
warnLog.apply(null, copyArgs);
|
||||
};
|
||||
|
||||
console.error = function (args: any) {
|
||||
let copyArgs = Array.prototype.slice.call(arguments);
|
||||
copyArgs.unshift(colors.Red);
|
||||
copyArgs.push(colors.Reset);
|
||||
errorLog.apply(null, copyArgs);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
coloredConsole.setupColoredConsole();
|
||||
@@ -1 +1 @@
|
||||
export {};
|
||||
export { coloredConsole } from "./coloredConsole";
|
||||
|
||||
@@ -4,9 +4,18 @@
|
||||
"private": true,
|
||||
"main": "index.ts",
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.18",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "4.8.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"prisma": "^4.8.0",
|
||||
"@prisma/client": "^4.8.0"
|
||||
"@prisma/client": "^4.8.0",
|
||||
"prisma": "^4.8.0"
|
||||
},
|
||||
"scripts": {
|
||||
"db-seed": "prisma db seed"
|
||||
},
|
||||
"prisma": {
|
||||
"seed": "ts-node --transpile-only ./seed.ts"
|
||||
}
|
||||
}
|
||||
|
||||
40
packages/prisma/seed.ts
Normal file
40
packages/prisma/seed.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import prisma from "@documenso/prisma";
|
||||
import { hashPassword } from "@documenso/lib/auth";
|
||||
import { IdentityProvider } from "@prisma/client";
|
||||
import { coloredConsole } from "@documenso/lib";
|
||||
|
||||
async function createUser(userData: { email: string; password: string }) {
|
||||
try {
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
email: userData.email,
|
||||
password: userData.password,
|
||||
identityProvider: IdentityProvider.DOCUMENSO,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.info(
|
||||
`WARN: Could not create user "${userData.email}". Maybe the email is already taken?`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await createUser({
|
||||
email: "example@documenso.com",
|
||||
password: await hashPassword("123456789"),
|
||||
});
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => {
|
||||
coloredConsole.setupColoredConsole();
|
||||
console.log("Finished seeding 🌱");
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user