Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from Rome to Biome #182

Merged
merged 3 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ ingestions and queries.

## \[Unreleased\]

### Changed

- Migrate our linting and formatting setup from Rome to Biome

[//]: # (Template:)

[//]: # (Version number)
Expand Down
4 changes: 2 additions & 2 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"*.{ts,js}": [
"rome check",
"rome format --write"
"biome check",
"biome format --write"
]
}
11 changes: 5 additions & 6 deletions rome.json → biome.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"$schema": "./node_modules/rome/configuration_schema.json",
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"organizeImports": {
"enabled": false
"enabled": true
},
"linter": {
"enabled": true,
"ignore": ["node_modules", "src/**/__snapshots__"],
"rules": {
"recommended": true,
"suspicious": {
Expand All @@ -21,15 +20,15 @@
"formatWithErrors": false,
"indentStyle": "space",
"indentSize": 2,
"lineWidth": 80,
"ignore": ["node_modules", "src/**/__snapshots__"]
"lineWidth": 160
},
"javascript": {
"formatter": {
"trailingComma": "es5",
"semicolons": "always",
"quoteProperties": "asNeeded",
"quoteStyle": "single"
"quoteStyle": "single",
"arrowParentheses": "always"
}
}
}
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"typecheck": "tsc",
"build": "rimraf build && tsx esbuild.config.ts",
"build:typecheck": "pnpm typecheck && pnpm build",
"lint": "rome check ./src",
"lint:fix": "rome check --apply ./src",
"lint:fix:unsafe": "rome check --apply-unsafe ./src",
"format:rome": "rome format --write ./src",
"ci": "rome ci ./src",
"format": "pnpm format:rome && prisma format",
"lint": "biome check ./src",
"lint:fix": "biome check --apply ./src",
"lint:fix:unsafe": "biome check --apply-unsafe ./src",
"format:biome": "biome format --write ./src",
"ci": "biome ci ./src",
"format": "pnpm format:biome && prisma format",
"test": "vitest",
"test:silent": "vitest --silent",
"prisma:migrate": "prisma migrate dev",
Expand Down Expand Up @@ -56,6 +56,7 @@
"zod": "^3.21.4"
},
"devDependencies": {
"@biomejs/biome": "^1.0.0",
"@faker-js/faker": "^8.0.2",
"@types/node": "^18.17.4",
"@types/node-fetch": "^2.6.4",
Expand All @@ -68,7 +69,6 @@
"msw": "^1.2.3",
"prisma": "^5.1.1",
"rimraf": "^5.0.1",
"rome": "^12.1.3",
"tsx": "^3.12.7",
"typescript": "^5.1.6",
"vitest": "^0.34.1",
Expand Down
136 changes: 71 additions & 65 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 19 additions & 32 deletions src/autobump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,45 @@ import { ThreadChannel } from 'discord.js';
import { Result } from 'oxide.ts';
import { getDiscordClient } from './clients';
import { listAllThreads } from './commands/autobump-threads/util';
import { getCurrentUnixTime } from './utils/dateUtils';
import { loadEnv } from './utils/loadEnv';
import { logger } from './utils/logger';
import { getCurrentUnixTime } from './utils/dateUtils';

const autobump = async () => {
loadEnv();
logger.info(`AUTOBUMPING THREADS. TIMESTAMP: ${getUnixTime(new Date())}`);

const settings = await Result.safe(listAllThreads());
if (settings.isErr()) {
logger.error(
`Cannot retrieve autobump thread lists. Timestamp: ${getCurrentUnixTime()}`
);
logger.error(`Cannot retrieve autobump thread lists. Timestamp: ${getCurrentUnixTime()}`);
process.exit(1);
}

const data = settings.unwrap();
if (data.length === 0) {
logger.info(
`No autobump threads settings found. Timestamp: ${getCurrentUnixTime()}`
);
logger.info(`No autobump threads settings found. Timestamp: ${getCurrentUnixTime()}`);
process.exit(0);
}

const token = process.env.TOKEN ?? '';
const client = await getDiscordClient({ token });

const jobs = await data.reduce(
async (accumulator, { guildId, autobumpThreads }) => {
const guild = client.guilds.cache.find(
(g) => g.available && g.id === guildId
);
if (!guild) {
return accumulator;
}

const prev = await accumulator;
const bumpPromises = autobumpThreads.map(async (id) => {
const thread = (await guild.channels.fetch(id)) as ThreadChannel;
return thread.setArchived(false);
});
const results = await Promise.all(bumpPromises);
return [...prev, ...results];
},
Promise.resolve([] as unknown[])
);

logger.info(
`Thread autobump complete. Jobs: ${
jobs.length
}. Timestamp: ${getCurrentUnixTime()}`
);
const jobs = await data.reduce(async (accumulator, { guildId, autobumpThreads }) => {
const guild = client.guilds.cache.find((g) => g.available && g.id === guildId);
if (!guild) {
return accumulator;
}

const prev = await accumulator;
const bumpPromises = autobumpThreads.map(async (id) => {
const thread = (await guild.channels.fetch(id)) as ThreadChannel;
return thread.setArchived(false);
});
const results = await Promise.all(bumpPromises);
return [...prev, ...results];
}, Promise.resolve([] as unknown[]));

logger.info(`Thread autobump complete. Jobs: ${jobs.length}. Timestamp: ${getCurrentUnixTime()}`);
process.exit(0);
};

Expand Down
Loading
Loading