Skip to content

Commit

Permalink
Bump prettier, use same printWidth as others
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarvelle committed Jan 4, 2024
1 parent b3dfa4d commit 598de90
Show file tree
Hide file tree
Showing 53 changed files with 1,580 additions and 1,951 deletions.
4 changes: 1 addition & 3 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module.exports = {
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
printWidth: 120,
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"start-prod-no-ssr": "cross-env NODE_ENV=production DISABLE_SSR=true node build/server | bunyan",
"start-with-local-graphql": "cross-env LOCAL_GRAPHQL_API=true yarn start",
"lint": "eslint --ext .js,.jsx,.ts,.tsx src",
"format": "node prettier.js write",
"format-check": "node prettier.js lint",
"format": "prettier '{src,scripts}/**/*(*.js|*.jsx|*.ts|*.tsx)' --write",
"format-check": "prettier '{src,scripts}/**/*(*.js|*.jsx|*.ts|*.tsx)' --check",
"check-all": "yarn format-check && yarn lint && yarn test",
"get-and-generate-gql-types": "graphql-codegen --config codegen.yml && prettier --write src/graphqlTypes.ts src/schema.graphql",
"generate-gql-types-local": "graphql-codegen --config local-codegen.yml && prettier --write src/graphqlTypes.ts src/schema.graphql",
Expand Down Expand Up @@ -71,7 +71,7 @@
"postcss-loader": "^7.0.2",
"postcss-preset-env": "^7.8.3",
"postcss-reporter": "^7.0.5",
"prettier": "^1.7.4",
"prettier": "^3.1.1",
"react-refresh": "^0.14.0",
"rimraf": "^2.6.2",
"sass": "^1.32.8",
Expand Down
53 changes: 0 additions & 53 deletions prettier.js

This file was deleted.

46 changes: 17 additions & 29 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@
* LICENSE file in the root directory of this source tree. *
*/

import chalk from 'chalk';
import { rmSync } from 'fs';
import { resolve } from 'path';
import webpack, {
Stats,
StatsCompilation,
Configuration,
StatsError,
} from 'webpack';
import getConfig from '../webpack/getConfig';
import chalk from "chalk";
import { rmSync } from "fs";
import { resolve } from "path";
import webpack, { Stats, StatsCompilation, Configuration, StatsError } from "webpack";
import getConfig from "../webpack/getConfig";

const configs: Configuration[] = getConfig('production');
const configs: Configuration[] = getConfig("production");
const clientConfig = configs[0]!;
const serverConfig = configs[1]!;

Expand All @@ -25,10 +20,7 @@ interface BuildOutput {
warnings: StatsError[];
}

const build = async (
config: Configuration,
type: 'client' | 'server',
): Promise<void> => {
const build = async (config: Configuration, type: "client" | "server"): Promise<void> => {
try {
const build = await new Promise<BuildOutput>((resolve, reject) => {
// eslint-disable-next-line no-console
Expand All @@ -49,26 +41,26 @@ const build = async (
warnings: messages?.warnings ?? [],
});
},
err => reject(err),
(err) => reject(err),
);
});

if (build.warnings.length) {
print(`${type} build compiled with warnings`, build.warnings, 'warning');
print(`${type} build compiled with warnings`, build.warnings, "warning");
} else {
// eslint-disable-next-line no-console
console.log(chalk.green(`Compiled ${type} build successfully.`));
}
} catch (e) {
print('Failed to compile client build', [e as Error].flat(), 'error');
print("Failed to compile client build", [e as Error].flat(), "error");
process.exitCode = 1;
}
};

const main = async () => {
rmSync(resolve('./build'), { recursive: true, force: true });
await build(clientConfig, 'client');
await build(serverConfig, 'server');
rmSync(resolve("./build"), { recursive: true, force: true });
await build(clientConfig, "client");
await build(serverConfig, "server");
};

const compile = (
Expand All @@ -80,18 +72,14 @@ const compile = (
const compiler = webpack(config);
compiler.run((err, stats) => callback(err, stats));
} catch (e) {
print('Failed to compile.', [e as Error], 'error');
print("Failed to compile.", [e as Error], "error");
return internalErrorCallback(e as Error);
}
};

const print = (
summary: string,
errors: string[] | StatsError[] | Error[],
type: 'warning' | 'error',
) => {
const chalkFunc = type === 'warning' ? chalk.yellow : chalk.red;
const logFunc = type === 'warning' ? console.warn : console.error;
const print = (summary: string, errors: string[] | StatsError[] | Error[], type: "warning" | "error") => {
const chalkFunc = type === "warning" ? chalk.yellow : chalk.red;
const logFunc = type === "warning" ? console.warn : console.error;
logFunc(`${chalkFunc(summary)}`);
errors.forEach(logFunc);
};
Expand Down
63 changes: 27 additions & 36 deletions scripts/start-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@
* LICENSE file in the root directory of this source tree. *
*/

import { Configuration, webpack } from 'webpack';
import express from 'express';
import chalk from 'chalk';
import { rmSync } from 'fs';
import { resolve } from 'path';
import devServer from 'webpack-dev-server';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import getConfig from '../webpack/getConfig';
import { Configuration, webpack } from "webpack";
import express from "express";
import chalk from "chalk";
import { rmSync } from "fs";
import { resolve } from "path";
import devServer from "webpack-dev-server";
import webpackDevMiddleware from "webpack-dev-middleware";
import webpackHotMiddleware from "webpack-hot-middleware";
import getConfig from "../webpack/getConfig";

const [clientConfig, serverConfig] = getConfig('development') as [
Configuration,
Configuration,
];
const [clientConfig, serverConfig] = getConfig("development") as [Configuration, Configuration];

const start = async () => {
rmSync(resolve('./build'), { recursive: true, force: true });
rmSync(resolve("./build"), { recursive: true, force: true });
const clientCompiler = compile(clientConfig);
const serverCompiler = compile(serverConfig);
const server = express();
Expand All @@ -35,53 +32,47 @@ const start = async () => {
);
server.use(webpackHotMiddleware(serverCompiler, { heartbeat: 100 }));

const clientDevServer = new devServer(
Object.assign(clientConfig.devServer!, { port: 3001 }),
clientCompiler,
);
const clientDevServer = new devServer(Object.assign(clientConfig.devServer!, { port: 3001 }), clientCompiler);

clientDevServer.startCallback(err => {
clientDevServer.startCallback((err) => {
if (err) {
logMessage(err, 'error');
logMessage(err, "error");
}
});

const serverBuildPromise = new Promise<void>(resolve => {
serverCompiler.hooks.done.tap('server', () => resolve());
const serverBuildPromise = new Promise<void>((resolve) => {
serverCompiler.hooks.done.tap("server", () => resolve());
});

const clientBuildPromise = new Promise<void>(resolve => {
clientCompiler.hooks.done.tap('client', () => resolve());
const clientBuildPromise = new Promise<void>((resolve) => {
clientCompiler.hooks.done.tap("client", () => resolve());
});
await clientBuildPromise;
await serverBuildPromise;
const app = require('../build/server').default;
const app = require("../build/server").default;
server.use((req, res) => app.handle(req, res));
};

const compile = (config: Configuration) => {
try {
return webpack(config);
} catch (e) {
logMessage(e as Error, 'error');
logMessage(e as Error, "error");
process.exit(1);
}
};

type TextType = keyof Pick<Console, 'error' | 'warn' | 'info' | 'log'>;
type Color = 'red' | 'yellow' | 'blue' | 'white';
type TextType = keyof Pick<Console, "error" | "warn" | "info" | "log">;
type Color = "red" | "yellow" | "blue" | "white";

const colorMap: Record<TextType, Color> = {
error: 'red',
warn: 'yellow',
info: 'blue',
log: 'white',
error: "red",
warn: "yellow",
info: "blue",
log: "white",
};

export const logMessage = (
message: string | Error,
level: TextType = 'info',
) => {
export const logMessage = (message: string | Error, level: TextType = "info") => {
//@ts-ignore
// eslint-disable-next-line no-console
console[level](chalk[colorMap[level] ?? colorMap.log!](message));
Expand Down
22 changes: 11 additions & 11 deletions src/__tests__/i18n-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
*
*/

import { getValidLocale, isValidLocale } from '../i18n';
import { getValidLocale, isValidLocale } from "../i18n";

test('i18n getLocaleObject()', () => {
expect(getValidLocale('en')).toBe('en');
expect(getValidLocale('nb')).toBe('nb');
test("i18n getLocaleObject()", () => {
expect(getValidLocale("en")).toBe("en");
expect(getValidLocale("nb")).toBe("nb");
// Defaults to nb if locale not found
expect(getValidLocale('ru')).toBe('nb');
expect(getValidLocale("ru")).toBe("nb");
});

test('i18n isValidLocale()', () => {
expect(isValidLocale('nb')).toBe(true);
expect(isValidLocale('nn')).toBe(true);
expect(isValidLocale('en')).toBe(true);
expect(isValidLocale('aa')).toBe(false);
expect(isValidLocale('ub')).toBe(false);
test("i18n isValidLocale()", () => {
expect(isValidLocale("nb")).toBe(true);
expect(isValidLocale("nn")).toBe(true);
expect(isValidLocale("en")).toBe(true);
expect(isValidLocale("aa")).toBe(false);
expect(isValidLocale("ub")).toBe(false);
});
Loading

0 comments on commit 598de90

Please sign in to comment.