Skip to content

Commit

Permalink
chore: reformat entire codebase with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
sdorra committed Sep 13, 2024
1 parent af32a44 commit b48974e
Show file tree
Hide file tree
Showing 202 changed files with 1,100 additions and 1,045 deletions.
3 changes: 3 additions & 0 deletions docs/adapter/next.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const nextConfig = {

export default withContentCollections(nextConfig);
```

</Tab>
<Tab value="next.config.js">

Expand All @@ -69,6 +70,7 @@ const nextConfig = {

module.exports = withContentCollections(nextConfig);
```

</Tab>
<Tab value="next.config.ts">

Expand All @@ -82,6 +84,7 @@ const nextConfig: NextConfig = {

export default withContentCollections(nextConfig);
```

</Tab>
</Tabs>

Expand Down
2 changes: 1 addition & 1 deletion docs/adapter/remix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ The package exports a single function as the default export. The function takes

### `configPath` (optional)

Specifies the path to the Content Collections configuration file. Defaults to `content-collections.ts`.
Specifies the path to the Content Collections configuration file. Defaults to `content-collections.ts`.
3 changes: 3 additions & 0 deletions docs/quickstart/next.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const nextConfig = {
// withContentCollections must be the outermost plugin
export default withContentCollections(nextConfig);
```

</Tab>
<Tab value="next.config.js">

Expand All @@ -72,6 +73,7 @@ const nextConfig = {
// withContentCollections must be the outermost plugin
module.exports = withContentCollections(nextConfig);
```

</Tab>
<Tab value="next.config.ts">

Expand All @@ -86,6 +88,7 @@ const nextConfig: NextConfig = {
// withContentCollections must be the outermost plugin
export default withContentCollections(nextConfig);
```

</Tab>
</Tabs>

Expand Down
2 changes: 1 addition & 1 deletion docs/quickstart/qwik.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ The `allPosts` collection will contain all posts that are valid.
The `post` object will contain the `title`, `summary` and `content` fields as well as some meta information in the `_meta` field.

</div>
</div>
</div>
22 changes: 11 additions & 11 deletions docs/serialization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ title: Serialization

The resulting document of a collection is serialized before being written to the file system. This process ensures the document can be stored in a file and later read back into memory. To serialize the document, the resulting object must be serializable, meaning it can only consist of the following types:

* String
* Number
* Boolean
* Null
* Undefined
* Date
* Map
* Set
* BigInt
* Array of serializable types
* Object with serializable values
- String
- Number
- Boolean
- Null
- Undefined
- Date
- Map
- Set
- BigInt
- Array of serializable types
- Object with serializable values
4 changes: 2 additions & 2 deletions docs/sorting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ However, you can easily sort the collections in your own code. For example, you
import { allPosts } from "content-collections";

export const postsSortedByDate = allPosts.toSorted(
(a, b) => b.date.getTime() - a.date.getTime()
(a, b) => b.date.getTime() - a.date.getTime(),
);
```

Expand All @@ -28,4 +28,4 @@ This approach allows you to sort your collections in any way you prefer.

For more information, refer to [Issue #169](https://github.com/sdorra/content-collections/issues/169).

</Callout>
</Callout>
11 changes: 7 additions & 4 deletions docs/transform.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ Example:
```ts
const posts = defineCollection({
// ...
transform: async (doc, {collection}) => {
transform: async (doc, { collection }) => {
const docs = await collection.documents();
const idx = docs.findIndex(d => doc._meta.filePath === d._meta.filePath);
const idx = docs.findIndex((d) => doc._meta.filePath === d._meta.filePath);
return {
...doc,
prev: idx > 0 ? docs[idx - 1] : null,
Expand Down Expand Up @@ -88,7 +88,10 @@ const posts = defineCollection({
For a complete example have a look at the [Join collections](#join-collections) example.
<Callout type="warn">
It is not possible to access documents of the same collection with the `documents` function. Use the `collection.documents` function instead. Please refer to [Access sibling documents](#access-sibling-documents) for more information.
It is not possible to access documents of the same collection with the
`documents` function. Use the `collection.documents` function instead. Please
refer to [Access sibling documents](#access-sibling-documents) for more
information.
</Callout>
## Examples
Expand Down Expand Up @@ -116,7 +119,7 @@ transform: async (author, { cache }) => {
const response = await fetch(url);
const user = await response.json();
return user.bio;
}
},
);

return {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node
import { Clerc, helpPlugin, versionPlugin, completionsPlugin } from "clerc";
import { Clerc, completionsPlugin, helpPlugin, versionPlugin } from "clerc";
import packageJson from "../package.json" assert { type: "json" };
import build from "./commands/build.js";
import watch from "./commands/watch.js";
import packageJson from "../package.json" assert { type: "json" };

const name = "content-collections";
if (!packageJson.bin[name]) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
/* If your code doesn't run in the DOM: */
"lib": ["es2022"],

"baseUrl": ".",
"baseUrl": "."
}
}
}
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/collections/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ const collection = defineCollection({
include: "**/*.md(x)?",
});

export default collection;
export default collection;
4 changes: 2 additions & 2 deletions packages/core/src/__tests__/config.004.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const posts = defineCollection({
fs.writeFileSync(
"tmp/posts.length",
JSON.stringify(documents.length),
"utf-8"
"utf-8",
);
},
});
Expand All @@ -37,7 +37,7 @@ const authors = defineCollection({
fs.writeFileSync(
"tmp/authors.length",
JSON.stringify(documents.length),
"utf-8"
"utf-8",
);
},
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/__tests__/config.005.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const posts = defineCollection({
schema: (z) => ({
title: z.string(),
}),
transform: async (doc, {collection}) => {
transform: async (doc, { collection }) => {
const docs = await collection.documents();
const idx = docs.findIndex(d => doc._meta.filePath === d._meta.filePath);
const idx = docs.findIndex((d) => doc._meta.filePath === d._meta.filePath);
return {
...doc,
prev: idx > 0 ? docs[idx - 1] : null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default async () => {
const simple = await import("@alias");
return simple.default;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"baseUrl": ".",
"paths": {
"@alias": ["../simple"]
},
}
}
}
4 changes: 2 additions & 2 deletions packages/core/src/__tests__/esbuild/dynamicImport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default async () => {
const simple = await import("./simple");
return simple.default
};
return simple.default;
};
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/esbuild/external.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import camelcase from "camelcase";

export default camelcase("hello world");
export default camelcase("hello world");
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/esbuild/internal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import simple from "./simple";

export default simple;
export default simple;
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/esbuild/simple.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default "hello world";
export default "hello world";
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/esbuild/tsconfigPaths/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import alias from "@alias";

export default alias;
export default alias;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"baseUrl": ".",
"paths": {
"@alias": ["../simple"]
},
},
}
}
}
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/sources/authors/trillian.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ displayName: Tricia Marie McMillan

Tricia Marie McMillan, also known as Trillian Astra, is a fictional character from Douglas Adams' series The Hitchhiker's Guide to the Galaxy. She is most commonly referred to simply as "Trillian", a modification of her birth name, which she adopted because it sounded more "space-like". According to the movie version, her middle name is Marie. Physically, she is described as "a slim, darkish humanoid, with long waves of black hair, a full mouth, an odd little knob of a nose and ridiculously brown eyes," looking "vaguely Arabic."

Source: https://en.wikipedia.org/wiki/Trillian_(character)
Source: https://en.wikipedia.org/wiki/Trillian_(character)
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/sources/posts/first.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ title: First post
author: trillian
---

# First post
# First post
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/sources/test/001.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
name: One
---

# One
# One
8 changes: 4 additions & 4 deletions packages/core/src/__tests__/tmpdir.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { test } from "vitest";
import os from "node:os";
import fs from "node:fs/promises";
import path, { resolve } from "node:path";
import os from "node:os";
import path from "node:path";
import { test } from "vitest";

interface TmpDirFixture {
tmpdir: string;
};
}

export const tmpdirTest = test.extend<TmpDirFixture>({
tmpdir: async ({}, use) => {
Expand Down
27 changes: 12 additions & 15 deletions packages/core/src/build.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { describe, it, expect, beforeEach } from "vitest";
import { createEmitter, Emitter, Events } from "./events";
import path from "node:path";
import fs from "node:fs/promises";
import { existsSync } from "node:fs";
import { InternalConfiguration } from "./configurationReader";
import { build, createBuildContext } from "./build";
import { tmpdirTest } from "./__tests__/tmpdir";
import fs from "node:fs/promises";
import path from "node:path";
import { beforeEach, describe, expect, it } from "vitest";
import z from "zod";
import { tmpdirTest } from "./__tests__/tmpdir";
import { build, createBuildContext } from "./build";
import { AnyCollection } from "./config";
import { InternalConfiguration } from "./configurationReader";
import { createEmitter, Emitter, Events } from "./events";

describe("createBuildContext", () => {
it("should create a build context", async () => {
Expand Down Expand Up @@ -113,7 +113,7 @@ describe("build", () => {
await fs.writeFile(
path.join(tmpdir, filename),
JSON.stringify(documents.length),
"utf-8"
"utf-8",
);
};
}
Expand Down Expand Up @@ -145,14 +145,14 @@ describe("build", () => {
expect(allPosts.length).toBe(1);
const postsLength = await fs.readFile(
path.join(tmpdir, "posts.length"),
"utf-8"
"utf-8",
);
expect(postsLength).toBe("1");

expect(allAuthors.length).toBe(1);
const authorsLength = await fs.readFile(
path.join(tmpdir, "authors.length"),
"utf-8"
"utf-8",
);
expect(authorsLength).toBe("1");
});
Expand Down Expand Up @@ -194,15 +194,15 @@ describe("build", () => {
expect(event.stats).toBeDefined();
expect(event.stats.collections).toBe(2);
expect(event.stats.documents).toBe(2);
}
},
);

tmpdirTest("should create type definition file", async ({ tmpdir }) => {
await doBuild(tmpdir, posts);

const typeDefinition = await fs.readFile(
path.join(tmpdir, "index.d.ts"),
"utf-8"
"utf-8",
);

expect(typeDefinition).toContain("export type Post ");
Expand All @@ -212,7 +212,6 @@ describe("build", () => {
const configuration = createConfiguration(tmpdir, posts);
configuration.generateTypes = false;


const context = await createBuildContext({
emitter,
configuration,
Expand All @@ -237,7 +236,6 @@ describe("build", () => {
tmpdirTest("should create data files", async ({ tmpdir }) => {
await doBuild(tmpdir, posts, authors);


const allPosts = existsSync(path.join(tmpdir, "allPosts.js"));
expect(allPosts).toBe(true);

Expand All @@ -252,5 +250,4 @@ describe("build", () => {
const exists = existsSync(path.join(output, "index.js"));
expect(exists).toBe(true);
});

});
Loading

0 comments on commit b48974e

Please sign in to comment.