Skip to content

Commit

Permalink
added some scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Oct 25, 2023
1 parent 4c085b2 commit eda4c06
Show file tree
Hide file tree
Showing 7 changed files with 1,358 additions and 248 deletions.
6 changes: 5 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"format:write": "prettier --write \"**/*.{css,js,json,jsx,ts,tsx}\"",
"format": "prettier \"**/*.{css,js,json,jsx,ts,tsx}\"",
"lint": "next lint",
"start": "next start"
"start": "next start",
"script": "tsx ./scripts/run.ts"
},
"dependencies": {
"@boxyhq/saml-jackson": "^1.14.2",
Expand Down Expand Up @@ -86,6 +87,7 @@
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
"@types/dotenv-flow": "^3.3.2",
"@types/html-escaper": "^3.0.0",
"@types/ms": "^0.7.31",
"@types/node": "18.11.9",
Expand All @@ -95,11 +97,13 @@
"@types/topojson-client": "^3.1.1",
"array-to-ndjson": "^1.0.1",
"autoprefixer": "^10.4.16",
"dotenv-flow": "^4.0.0",
"postcss": "^8.4.31",
"postcss-import": "^15.1.0",
"prettier": "^2.8.0",
"prettier-plugin-tailwindcss": "^0.1.13",
"tailwindcss": "^3.3.3",
"tsx": "^3.14.0",
"turbo": "^1.10.14",
"typescript": "^5.1.6"
},
Expand Down
41 changes: 41 additions & 0 deletions apps/web/scripts/get-active-projects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import "dotenv-flow/config";
import prisma from "@/lib/prisma";

async function main() {
const projects = await prisma.project.findMany({
select: {
slug: true,
plan: true,
usage: true,
domains: {
select: {
slug: true,
},
},
_count: {
select: {
links: true,
domains: true,
},
},
},
orderBy: {
usage: "desc",
},
take: 100,
});
console.table(
projects.map((project) => ({
...project,
domains: `${
project.domains
.slice(0, 2)
.map((domain) => domain.slug)
.join(", ") +
(project.domains.length > 2 ? `... ${project._count.domains - 2}+` : "")
}`,
})),
);
}

main();
15 changes: 15 additions & 0 deletions apps/web/scripts/get-api-users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import "dotenv-flow/config";
import prisma from "@/lib/prisma";

async function main() {
const users = await prisma.user.findMany({
where: {
tokens: {
some: {},
},
},
});
console.log(users.map((user) => user.email).join(", "));
}

main();
44 changes: 44 additions & 0 deletions apps/web/scripts/get-inactive-users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import "dotenv-flow/config";
import prisma from "@/lib/prisma";

async function main() {
const [users, count] = await Promise.all([
prisma.user.findMany({
where: {
projects: {
none: {},
},
links: {
none: {},
},
},
select: {
email: true,
createdAt: true,
_count: {
select: {
projects: true,
links: true,
},
},
},
orderBy: { createdAt: "asc" },
take: 100,
}),
prisma.user.count({
where: {
projects: {
none: {},
},
links: {
none: {},
},
},
}),
]);
// log in table format
console.table(users);
console.log(`Total: ${count}`);
}

main();
20 changes: 20 additions & 0 deletions apps/web/scripts/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// runner.ts
import { exec } from "child_process";

const command: string = process.argv[2];

if (!command) {
console.error("Please provide a command name.");
process.exit(1);
}

const scriptPath = `./scripts/${command}.ts`;

exec(`tsx ${scriptPath}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing script: ${error.message}`);
return;
}
console.log(stdout);
console.error(stderr);
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"publish-tw": "turbo build --filter='@dub/tailwind-config' && cd packages/tailwind-config && npm publish && cd ../../",
"publish-ui": "turbo build --filter='@dub/ui' && cd packages/ui && npm publish && cd ../../",
"publish-utils": "turbo build --filter='@dub/utils' && cd packages/utils && npm publish && cd ../../"
"publish-utils": "turbo build --filter='@dub/utils' && cd packages/utils && npm publish && cd ../../",
"script": "echo 'Run this script in apps/web'"
},
"devDependencies": {
"@dub/tailwind-config": "workspace:*",
Expand Down
Loading

0 comments on commit eda4c06

Please sign in to comment.