Skip to content

Commit

Permalink
change print width and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
claytercek committed Nov 7, 2024
1 parent 5e5ae32 commit fbbdf20
Show file tree
Hide file tree
Showing 52 changed files with 1,044 additions and 429 deletions.
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"formatter": {
"enabled": true,
"indentStyle": "tab",
"lineWidth": 160
"lineWidth": 100
},
"organizeImports": {
"enabled": true
Expand Down
31 changes: 20 additions & 11 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,24 @@ yargs(hideBin(process.argv))
.option("env", { alias: "e", describe: "Path(s) to your .env file(s)", type: "array" })
.option("env-cascade", {
alias: "E",
describe: "cascade env variables from `.env`, `.env.<arg>`, `.env.local`, `.env.<arg>.local` in launchpad root dir",
describe:
"cascade env variables from `.env`, `.env.<arg>`, `.env.local`, `.env.<arg>.local` in launchpad root dir",
type: "string",
})
.command("start", "Starts launchpad by updating content and starting apps.", async ({ argv }) => {
const resolvedArgv = await argv;
const { start } = await import("./commands/start.js");
await start(resolvedArgv);
})
.command("stop", "Stops launchpad by stopping apps and killing any existing PM2 instance.", async ({ argv }) => {
const resolvedArgv = await argv;
const { stop } = await import("./commands/stop.js");
await stop(resolvedArgv);
})
.command(
"stop",
"Stops launchpad by stopping apps and killing any existing PM2 instance.",
async ({ argv }) => {
const resolvedArgv = await argv;
const { stop } = await import("./commands/stop.js");
await stop(resolvedArgv);
},
)
.command("content", "Only download content.", async ({ argv }) => {
const resolvedArgv = await argv;
const { content } = await import("./commands/content.js");
Expand All @@ -42,10 +47,14 @@ yargs(hideBin(process.argv))
const { monitor } = await import("./commands/monitor.js");
await monitor(resolvedArgv);
})
.command("scaffold", "Configures the current PC for exhibit environments (with admin prompt).", async ({ argv }) => {
const resolvedArgv = await argv;
const { scaffold } = await import("./commands/scaffold.js");
await scaffold(resolvedArgv);
})
.command(
"scaffold",
"Configures the current PC for exhibit environments (with admin prompt).",
async ({ argv }) => {
const resolvedArgv = await argv;
const { scaffold } = await import("./commands/scaffold.js");
await scaffold(resolvedArgv);
},
)
.help()
.parse();
5 changes: 4 additions & 1 deletion packages/cli/src/commands/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export function content(argv: LaunchpadArgv) {
export function importLaunchpadContent() {
return ResultAsync.fromPromise(
import("@bluecadet/launchpad-content"),
() => new ImportError('Could not find module "@bluecadet/launchpad-content". Make sure you have installed it.'),
() =>
new ImportError(
'Could not find module "@bluecadet/launchpad-content". Make sure you have installed it.',
),
);
}
15 changes: 12 additions & 3 deletions packages/cli/src/commands/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ export function monitor(argv: LaunchpadArgv) {
return ok(monitorInstance);
})
.andThrough((monitorInstance) => {
return ResultAsync.fromPromise(monitorInstance.connect(), () => new MonitorError("Failed to connect to monitor"));
return ResultAsync.fromPromise(
monitorInstance.connect(),
() => new MonitorError("Failed to connect to monitor"),
);
})
.andThrough((monitorInstance) => {
return ResultAsync.fromPromise(monitorInstance.start(), () => new MonitorError("Failed to start monitor"));
return ResultAsync.fromPromise(
monitorInstance.start(),
() => new MonitorError("Failed to start monitor"),
);
})
.orElse((error) => handleFatalError(error, rootLogger));
});
Expand All @@ -29,6 +35,9 @@ export function monitor(argv: LaunchpadArgv) {
export function importLaunchpadMonitor() {
return ResultAsync.fromPromise(
import("@bluecadet/launchpad-monitor"),
() => new ImportError('Could not find module "@bluecadet/launchpad-monitor". Make sure you have installed it.'),
() =>
new ImportError(
'Could not find module "@bluecadet/launchpad-monitor". Make sure you have installed it.',
),
);
}
10 changes: 8 additions & 2 deletions packages/cli/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ export async function start(argv: LaunchpadArgv) {
return ok(monitorInstance);
})
.andThrough((monitorInstance) => {
return ResultAsync.fromPromise(monitorInstance.connect(), () => new MonitorError("Failed to connect to monitor"));
return ResultAsync.fromPromise(
monitorInstance.connect(),
() => new MonitorError("Failed to connect to monitor"),
);
})
.andThrough((monitorInstance) => {
return ResultAsync.fromPromise(monitorInstance.start(), () => new MonitorError("Failed to start monitor"));
return ResultAsync.fromPromise(
monitorInstance.start(),
() => new MonitorError("Failed to start monitor"),
);
})
.orElse((error) => handleFatalError(error, rootLogger));
});
Expand Down
19 changes: 13 additions & 6 deletions packages/cli/src/utils/command-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { type ResolvedLaunchpadOptions, resolveLaunchpadConfig } from "../launch
import { findConfig, loadConfigFromFile } from "./config.js";
import { resolveEnv } from "./env.js";

export function loadConfigAndEnv(argv: LaunchpadArgv): ResultAsync<ResolvedLaunchpadOptions, ConfigError> {
export function loadConfigAndEnv(
argv: LaunchpadArgv,
): ResultAsync<ResolvedLaunchpadOptions, ConfigError> {
const configPath = argv.config ?? findConfig();

if (!configPath) {
Expand Down Expand Up @@ -36,9 +38,10 @@ export function loadConfigAndEnv(argv: LaunchpadArgv): ResultAsync<ResolvedLaunc
resolveEnv([path.resolve(configDir, ".env"), path.resolve(configDir, ".env.local")]);
}

return ResultAsync.fromPromise(loadConfigFromFile(configPath), (e) => new ConfigError(`Failed to load config file at path: ${chalk.white(configPath)}`)).map(
(config) => resolveLaunchpadConfig(config),
);
return ResultAsync.fromPromise(
loadConfigFromFile(configPath),
(e) => new ConfigError(`Failed to load config file at path: ${chalk.white(configPath)}`),
).map((config) => resolveLaunchpadConfig(config));
}

export function initializeLogger(config: ResolvedLaunchpadOptions) {
Expand All @@ -56,7 +59,9 @@ export function handleFatalError(error: Error, rootLogger: Logger): never {
export function logFullErrorChain(logger: Logger, error: Error) {
let currentError: Error | undefined = error;
while (currentError) {
logger.error(`${chalk.red("┌─")} ${chalk.red.bold(currentError.name)}: ${chalk.red(currentError.message)}`);
logger.error(
`${chalk.red("┌─")} ${chalk.red.bold(currentError.name)}: ${chalk.red(currentError.message)}`,
);
const callstack = currentError.stack;
// logger.error(`${chalk.red(callstack ? '│' : '└')} `);
if (callstack) {
Expand All @@ -65,7 +70,9 @@ export function logFullErrorChain(logger: Logger, error: Error) {
let loggedLines = 0;
for (const line of lines) {
const isLastLine = loggedLines === lines.length - 1 || loggedLines > 2;
logger.error(`${chalk.red("│")} ${chalk.red.dim(isLastLine && lines.length > 3 ? "..." : line.trim())}`);
logger.error(
`${chalk.red("│")} ${chalk.red.dim(isLastLine && lines.length > 3 ? "..." : line.trim())}`,
);
if (isLastLine) {
logger.error(`${chalk.red("└──────────────────")}`);
}
Expand Down
12 changes: 10 additions & 2 deletions packages/cli/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import path from "node:path";
import url from "node:url";
import chalk from "chalk";

const DEFAULT_CONFIG_PATHS = ["launchpad.config.js", "launchpad.config.mjs", "launchpad.json", "config.json"];
const DEFAULT_CONFIG_PATHS = [
"launchpad.config.js",
"launchpad.config.mjs",
"launchpad.json",
"config.json",
];

function getProcessDirname(importMeta?: ImportMeta) {
return importMeta ? path.dirname(url.fileURLToPath(importMeta.url)) : "";
Expand All @@ -17,7 +22,10 @@ function getProcessDirname(importMeta?: ImportMeta) {
* @param importMeta The import.meta property of the file at your base directory.
* @returns The parsed config object or null if none can be found
*/
export async function importJsConfig<T>(paths: string[], importMeta?: ImportMeta): Promise<Partial<T> | null> {
export async function importJsConfig<T>(
paths: string[],
importMeta?: ImportMeta,
): Promise<Partial<T> | null> {
const __dirname = getProcessDirname(importMeta);
for (const configPath of paths) {
const fileUrl = url.pathToFileURL(path.join(__dirname, configPath));
Expand Down
73 changes: 39 additions & 34 deletions packages/content/src/__tests__/content-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,40 +85,43 @@ describe("Content Integration", () => {
describe("Sanity Source with HTML Conversion", () => {
it("should fetch Sanity content and convert blocks to HTML", async () => {
server.use(
http.get("https://test-project.apicdn.sanity.io/v2021-10-21/data/query/production", ({ request }) => {
const url = new URL(request.url);
const query = url.searchParams.get("query");

if (query?.includes("[100..")) {
return HttpResponse.json({
result: [],
ms: 15,
});
}

if (query?.includes("article")) {
return HttpResponse.json({
result: [
{
_type: "article",
title: "Test Article",
content: {
_type: "block",
children: [
{
_type: "span",
text: "Hello from Sanity",
},
],
http.get(
"https://test-project.apicdn.sanity.io/v2021-10-21/data/query/production",
({ request }) => {
const url = new URL(request.url);
const query = url.searchParams.get("query");

if (query?.includes("[100..")) {
return HttpResponse.json({
result: [],
ms: 15,
});
}

if (query?.includes("article")) {
return HttpResponse.json({
result: [
{
_type: "article",
title: "Test Article",
content: {
_type: "block",
children: [
{
_type: "span",
text: "Hello from Sanity",
},
],
},
},
},
],
ms: 15,
});
}

return HttpResponse.json({ result: [] });
}),
],
ms: 15,
});
}

return HttpResponse.json({ result: [] });
},
),
);

const content = new LaunchpadContent(
Expand Down Expand Up @@ -255,7 +258,9 @@ describe("Content Integration", () => {

// Check if existing content was preserved
expect(vol.existsSync("/downloads/test/existing.json")).toBe(true);
const preserved = JSON.parse(vol.readFileSync("/downloads/test/existing.json", "utf8").toString());
const preserved = JSON.parse(
vol.readFileSync("/downloads/test/existing.json", "utf8").toString(),
);
expect(preserved.data).toBe("existing");
});

Expand Down
9 changes: 7 additions & 2 deletions packages/content/src/__tests__/content-plugin-driver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { createMockLogger } from "@bluecadet/launchpad-testing/test-utils.ts";
import { PluginDriver } from "@bluecadet/launchpad-utils";
import { describe, expect, it, vi } from "vitest";
import { resolveContentConfig } from "../content-config.js";
import { ContentError, ContentPluginDriver, defineContentPlugin } from "../content-plugin-driver.js";
import {
ContentError,
ContentPluginDriver,
defineContentPlugin,
} from "../content-plugin-driver.js";
import { DataStore } from "../utils/data-store.js";

describe("ContentPluginDriver", () => {
Expand All @@ -16,7 +20,8 @@ describe("ContentPluginDriver", () => {

const paths = {
getDownloadPath: (source?: string) => (source ? `/downloads/${source}` : "/downloads"),
getTempPath: (source?: string, plugin?: string) => (source ? `/temp/${plugin}/${source}` : `/temp/${plugin}`),
getTempPath: (source?: string, plugin?: string) =>
source ? `/temp/${plugin}/${source}` : `/temp/${plugin}`,

getBackupPath: (source?: string) => (source ? `/backups/${source}` : "/backups"),
};
Expand Down
5 changes: 4 additions & 1 deletion packages/content/src/__tests__/launchpad-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ describe("LaunchpadContent", () => {
},
};

const content = new LaunchpadContent(createBasicConfig([plugin1, plugin2]), createMockLogger());
const content = new LaunchpadContent(
createBasicConfig([plugin1, plugin2]),
createMockLogger(),
);
await content.download();

expect(order).toEqual(["plugin1:setup", "plugin2:setup", "plugin1:done", "plugin2:done"]);
Expand Down
21 changes: 17 additions & 4 deletions packages/content/src/content-plugin-driver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { type BaseHookContext, HookContextProvider, type Plugin, type PluginDriver } from "@bluecadet/launchpad-utils";
import {
type BaseHookContext,
HookContextProvider,
type Plugin,
type PluginDriver,
} from "@bluecadet/launchpad-utils";
import type { ResolvedContentConfig } from "./content-config.js";
import type { DataStore } from "./utils/data-store.js";

Expand All @@ -25,12 +30,20 @@ export type ContentHooks = {
onSetupError: (ctx: CombinedContentHookContext, error: ContentError) => void | PromiseLike<void>;
onContentFetchSetup: (ctx: CombinedContentHookContext) => void | PromiseLike<void>;
onContentFetchDone: (ctx: CombinedContentHookContext) => void | PromiseLike<void>;
onContentFetchError: (ctx: CombinedContentHookContext, error: ContentError) => void | PromiseLike<void>;
onContentFetchError: (
ctx: CombinedContentHookContext,
error: ContentError,
) => void | PromiseLike<void>;
};

export type ContentPlugin<T extends Partial<ContentHooks> = Partial<ContentHooks>> = Plugin<ContentHooks, T>;
export type ContentPlugin<T extends Partial<ContentHooks> = Partial<ContentHooks>> = Plugin<
ContentHooks,
T
>;

export function defineContentPlugin<T extends Partial<ContentHooks>>(plugin: ContentPlugin<T>): ContentPlugin<T> {
export function defineContentPlugin<T extends Partial<ContentHooks>>(
plugin: ContentPlugin<T>,
): ContentPlugin<T> {
return plugin;
}

Expand Down
Loading

0 comments on commit fbbdf20

Please sign in to comment.