Skip to content

Commit

Permalink
chore: upgrade to atmina/linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mvarendorff committed Dec 9, 2023
1 parent 3dcba4a commit eb5bc77
Show file tree
Hide file tree
Showing 192 changed files with 1,957 additions and 2,030 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: ./.github/actions/yarn-action
name: "Install and check formatting"
with:
command: format:check
command: prettier:check

test:
name: "Test"
Expand Down Expand Up @@ -51,3 +51,13 @@ jobs:
name: "Install and tsc server"
with:
command: workspace @yestheory.family/server tsc --noEmit

tsc-cms:
name: "TSC CMS"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/yarn-action
name: "Install and tsc cms"
with:
command: workspace @yestheory.family/cms tsc --noEmit
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"scripts": {
"e2e:open": "yarn workspace @yestheory.family/web e2e:open",
"e2e:run": "yarn workspace @yestheory.family/web e2e:run",
"eslint:check": "yarn workspaces foreach --all run lint",
"eslint:write": "yarn workspaces foreach --all run lint --fix",
"format:check": "prettier --check packages",
"format:write": "prettier --write packages",
"eslint:check": "yarn workspaces foreach --all run eslint:check",
"eslint:fix": "yarn workspaces foreach --all run eslint:fix",
"prettier:check": "yarn workspaces foreach --all run prettier:check",
"prettier:fix": "yarn workspaces foreach --all run prettier:fix",
"server:dev": "yarn workspace @yestheory.family/server start",
"server:generate": "yarn workspace @yestheory.family/server generate",
"storybook": "yarn workspace @yestheory.family/web storybook",
Expand All @@ -18,9 +18,6 @@
"workspaces": [
"packages/*"
],
"devDependencies": {
"prettier": "3.1.0"
},
"resolutions": {
"react-test-renderer": "18.2.0"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/cms/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @type {import('eslint').Linter.FlatConfig[]}
*/
module.exports = [
...require('@atmina/linting/eslint/recommended'),
require('@atmina/linting/eslint/react'),
];
14 changes: 12 additions & 2 deletions packages/cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/",
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
"generate:graphQLSchema": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema"
"generate:graphQLSchema": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema",
"lint": "yarn run lint:fix && yarn run prettier:fix",
"eslint:check": "eslint . --report-unused-disable-directives --max-warnings 0",
"eslint:fix": "eslint . --fix --report-unused-disable-directives --max-warnings 0",
"prettier:check": "prettier . --check",
"prettier:fix": "prettier . --write"
},
"dependencies": {
"@payloadcms/bundler-vite": "^0.1.5",
Expand All @@ -26,13 +31,18 @@
"typesense": "^1.7.2"
},
"devDependencies": {
"@atmina/linting": "^2.0.1",
"@types/eslint": "^8.44.8",
"@types/express": "^4.17.21",
"@types/node-cron": "^3.0.11",
"@types/pg": "^8.10.9",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"eslint": "^8.55.0",
"prettier": "^3.1.0",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"typescript": "^5.3.2"
}
},
"prettier": "@atmina/linting/prettier"
}
58 changes: 29 additions & 29 deletions packages/cms/src/collections/groupchats.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import { type CollectionConfig } from "payload/types";
import { typesenseClient } from "../lib/typesense";
import {type CollectionConfig} from 'payload/types';
import {typesenseClient} from '../lib/typesense';

export const Groupchats: CollectionConfig = {
slug: "groupchats",
slug: 'groupchats',
access: {
read: () => true,
},
admin: {
useAsTitle: "name",
defaultColumns: ["name", "url", "platform"],
useAsTitle: 'name',
defaultColumns: ['name', 'url', 'platform'],
},
fields: [
{
name: "name",
type: "text",
name: 'name',
type: 'text',
unique: true,
required: true,
},
{
name: "platform",
type: "select",
name: 'platform',
type: 'select',
required: true,
options: [
{ label: "Discord", value: "discord" },
{ label: "Facebook", value: "facebook" },
{ label: "Signal", value: "signal" },
{ label: "Telegram", value: "telegram" },
{ label: "WhatsApp", value: "whatsapp" },
{label: 'Discord', value: 'discord'},
{label: 'Facebook', value: 'facebook'},
{label: 'Signal', value: 'signal'},
{label: 'Telegram', value: 'telegram'},
{label: 'WhatsApp', value: 'whatsapp'},
],
},
{ name: "description", type: "text" },
{name: 'description', type: 'text'},
{
name: "url",
type: "text",
name: 'url',
type: 'text',
required: true,
hooks: {
beforeValidate: [
({ value }) => {
({value}) => {
if (value && !value.match(/^https?:\/\//i)) {
return `https://${value}`;
}
Expand All @@ -47,44 +47,44 @@ export const Groupchats: CollectionConfig = {
},
},
{
name: "keywords",
type: "array",
name: 'keywords',
type: 'array',
required: true,
fields: [{ name: "value", type: "text", required: true }],
fields: [{name: 'value', type: 'text', required: true}],
},
{
name: "promoted",
type: "number",
name: 'promoted',
type: 'number',
min: 0,
max: 100,
required: true,
defaultValue: 0,
admin: {
description:
"This value may be used to push results. A value of 0 means no promotion. Any value between 1 and 100 may be used to order promoted groupchats.",
'This value may be used to push results. A value of 0 means no promotion. Any value between 1 and 100 may be used to order promoted groupchats.',
},
},
],
hooks: {
afterChange: [
async ({ doc, context }) => {
if ("dataseeder" in context && context.dataseeder) return;
async ({doc, context}) => {
if ('dataseeder' in context && context.dataseeder) return;

const typesenseDoc = {
...doc,
id: doc.id.toString(),
keywords: doc.keywords.map((k) => k.value),
};
await typesenseClient
.collections("groupchats")
.collections('groupchats')
.documents()
.upsert(typesenseDoc);
},
],
afterDelete: [
async ({ id }) => {
async ({id}) => {
await typesenseClient
.collections("groupchats")
.collections('groupchats')
.documents()
.delete(id.toString());
},
Expand Down
6 changes: 3 additions & 3 deletions packages/cms/src/collections/users.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CollectionConfig } from "payload/types";
import {type CollectionConfig} from 'payload/types';

export const Users: CollectionConfig = {
slug: "users",
slug: 'users',
auth: true,
admin: {
useAsTitle: "email",
useAsTitle: 'email',
},
fields: [],
};
54 changes: 27 additions & 27 deletions packages/cms/src/cron-jobs/groupchat-sync.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import payload from "payload";
import { schedule } from "node-cron";
import { typesenseClient } from "../lib/typesense";
import { CollectionCreateSchema } from "typesense/lib/Typesense/Collections";
import {schedule} from 'node-cron';
import payload from 'payload';
import {type CollectionCreateSchema} from 'typesense/lib/Typesense/Collections';
import {typesenseClient} from '../lib/typesense';

// TODO see if we can remove this alltogether thanks to the hook
export const setupGroupchatSync = async () => {
console.info("Setting up groupchats!");
console.info('Setting up groupchats!');
await ensureTypesenseCollectionExists();

const everyHour = "0 * * * *";
schedule(everyHour, syncGroupchatsToTypesense, { runOnInit: true });
const everyHour = '0 * * * *';
schedule(everyHour, syncGroupchatsToTypesense, {runOnInit: true});
};

const collectionName = "groupchats";
const collectionName = 'groupchats';
const schema: CollectionCreateSchema = {
name: collectionName,
fields: [
{
name: "name",
type: "string",
name: 'name',
type: 'string',
},
{
name: "keywords",
type: "string[]",
name: 'keywords',
type: 'string[]',
optional: true,
},
{
name: "url",
type: "string",
name: 'url',
type: 'string',
},
{
name: "description",
type: "string",
name: 'description',
type: 'string',
optional: true,
},
{
name: "platform",
type: "string",
name: 'platform',
type: 'string',
facet: true,
},
{
name: "promoted",
type: "int32",
name: 'promoted',
type: 'int32',
},
],
};
Expand All @@ -59,35 +59,35 @@ const ensureTypesenseCollectionExists = async () => {
}

await typesenseClient.collections().create(schema);
console.info("Schema is up to date in Typesense");
console.info('Schema is up to date in Typesense');
};

const syncGroupchatsToTypesense = async () => {
console.info("Syncing groupchats to Typesense");
console.info('Syncing groupchats to Typesense');

try {
const { docs: groupchats } = await payload.find({
const {docs: groupchats} = await payload.find({
collection: collectionName,
pagination: false,
});

const typesenseChats = groupchats.map(
({ id, createdAt, updatedAt, keywords, ...rest }) => ({
({id, createdAt, updatedAt, keywords, ...rest}) => ({
...rest,
id: id.toString(),
keywords: keywords?.map(({ value }) => value) ?? [],
keywords: keywords?.map(({value}) => value) ?? [],
}),
);

if (typesenseChats.length === 0) {
console.info("No groupchats available, skipping import");
console.info('No groupchats available, skipping import');
return;
}

await typesenseClient
.collections(collectionName)
.documents()
.import(typesenseChats, { action: "upsert" });
.import(typesenseChats, {action: 'upsert'});

console.info(`Synced ${groupchats.length} groupchats to Typesense`);
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cms/src/cron-jobs/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setupGroupchatSync } from "./groupchat-sync";
import {setupGroupchatSync} from './groupchat-sync';

export const setupCronJobs = async () => {
await Promise.all([setupGroupchatSync()]);
Expand Down
14 changes: 7 additions & 7 deletions packages/cms/src/dataseeder/main.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import path from "node:path";
import path from 'node:path';

import { initPayload } from "../init-payload";
import { seedUsers } from "./seed-users";
import { seedGroupchats } from "./seed-groupchats";
import { seedTypesenseKey } from "./seed-typesense-key";
import { typesenseReady } from "../lib/typesense";
import {initPayload} from '../init-payload';
import {typesenseReady} from '../lib/typesense';
import {seedGroupchats} from './seed-groupchats';
import {seedTypesenseKey} from './seed-typesense-key';
import {seedUsers} from './seed-users';

export const main = async () => {
process.env.PAYLOAD_CONFIG_PATH = path.resolve(
__dirname,
`../payload.config${path.extname(__filename)}`,
);

await initPayload({ local: true });
await initPayload({local: true});

await seedUsers();
await seedGroupchats();
Expand Down
Loading

0 comments on commit eb5bc77

Please sign in to comment.