@content-collections/core 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +115 -0
  2. package/dist/index.js +9 -3
  3. package/package.json +5 -1
  4. package/.turbo/turbo-build.log +0 -14
  5. package/.turbo/turbo-test.log +0 -47
  6. package/.turbo/turbo-typecheck.log +0 -4
  7. package/coverage/.tmp/coverage-0.json +0 -1
  8. package/coverage/.tmp/coverage-1.json +0 -1
  9. package/coverage/.tmp/coverage-2.json +0 -1
  10. package/coverage/.tmp/coverage-3.json +0 -1
  11. package/coverage/.tmp/coverage-4.json +0 -1
  12. package/coverage/.tmp/coverage-5.json +0 -1
  13. package/coverage/.tmp/coverage-6.json +0 -1
  14. package/coverage/.tmp/coverage-7.json +0 -1
  15. package/coverage/.tmp/coverage-8.json +0 -1
  16. package/coverage/.tmp/coverage-9.json +0 -1
  17. package/coverage/base.css +0 -224
  18. package/coverage/block-navigation.js +0 -87
  19. package/coverage/builder.ts.html +0 -424
  20. package/coverage/clover.xml +0 -960
  21. package/coverage/collector.ts.html +0 -427
  22. package/coverage/config.ts.html +0 -403
  23. package/coverage/configurationReader.ts.html +0 -409
  24. package/coverage/coverage-final.json +0 -11
  25. package/coverage/events.ts.html +0 -310
  26. package/coverage/favicon.png +0 -0
  27. package/coverage/index.html +0 -251
  28. package/coverage/index.ts.html +0 -106
  29. package/coverage/prettify.css +0 -1
  30. package/coverage/prettify.js +0 -2
  31. package/coverage/sort-arrow-sprite.png +0 -0
  32. package/coverage/sorter.js +0 -196
  33. package/coverage/synchronizer.ts.html +0 -394
  34. package/coverage/transformer.ts.html +0 -607
  35. package/coverage/utils.ts.html +0 -118
  36. package/coverage/writer.ts.html +0 -424
  37. package/src/__tests__/.content-collections/cache/config.001.ts.js +0 -19
  38. package/src/__tests__/.content-collections/cache/config.002.mjs +0 -16
  39. package/src/__tests__/.content-collections/cache/config.002.ts.js +0 -16
  40. package/src/__tests__/.content-collections/cache/config.003.ts.js +0 -24
  41. package/src/__tests__/.content-collections/cache/config.004.mjs +0 -47
  42. package/src/__tests__/.content-collections/different-cache-dir/different.config.js +0 -19
  43. package/src/__tests__/.content-collections/generated-config.002/allPosts.json +0 -13
  44. package/src/__tests__/.content-collections/generated-config.002/index.d.ts +0 -7
  45. package/src/__tests__/.content-collections/generated-config.002/index.js +0 -5
  46. package/src/__tests__/.content-collections/generated-config.004/allAuthors.json +0 -13
  47. package/src/__tests__/.content-collections/generated-config.004/allPosts.json +0 -13
  48. package/src/__tests__/.content-collections/generated-config.004/index.d.ts +0 -10
  49. package/src/__tests__/.content-collections/generated-config.004/index.js +0 -6
  50. package/src/__tests__/collections/posts.ts +0 -15
  51. package/src/__tests__/config.001.ts +0 -19
  52. package/src/__tests__/config.002.ts +0 -14
  53. package/src/__tests__/config.003.ts +0 -6
  54. package/src/__tests__/config.004.ts +0 -47
  55. package/src/__tests__/invalid +0 -1
  56. package/src/__tests__/sources/authors/trillian.md +0 -8
  57. package/src/__tests__/sources/posts/first.md +0 -6
  58. package/src/__tests__/sources/test/001.md +0 -5
  59. package/src/__tests__/sources/test/002.md +0 -5
  60. package/src/__tests__/sources/test/broken-frontmatter +0 -6
  61. package/src/builder.test.ts +0 -180
  62. package/src/builder.ts +0 -113
  63. package/src/collector.test.ts +0 -157
  64. package/src/collector.ts +0 -114
  65. package/src/config.ts +0 -106
  66. package/src/configurationReader.test.ts +0 -104
  67. package/src/configurationReader.ts +0 -108
  68. package/src/events.test.ts +0 -84
  69. package/src/events.ts +0 -75
  70. package/src/index.ts +0 -7
  71. package/src/synchronizer.test.ts +0 -192
  72. package/src/synchronizer.ts +0 -103
  73. package/src/transformer.test.ts +0 -431
  74. package/src/transformer.ts +0 -174
  75. package/src/types.test.ts +0 -137
  76. package/src/types.ts +0 -33
  77. package/src/utils.test.ts +0 -48
  78. package/src/utils.ts +0 -11
  79. package/src/watcher.test.ts +0 -200
  80. package/src/watcher.ts +0 -56
  81. package/src/writer.test.ts +0 -135
  82. package/src/writer.ts +0 -113
  83. package/tsconfig.json +0 -27
  84. package/vite.config.ts +0 -24
package/src/writer.ts DELETED
@@ -1,113 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import pluralize from "pluralize";
4
- import { TransformedCollection } from "./transformer";
5
- import { InternalConfiguration } from "./configurationReader";
6
-
7
- function createArrayConstName(name: string) {
8
- let suffix = name.charAt(0).toUpperCase() + name.slice(1);
9
- return "all" + pluralize(suffix);
10
- }
11
-
12
- type DataFileCollection = Pick<TransformedCollection, "name" | "documents">;
13
-
14
- async function createDataFile(
15
- directory: string,
16
- collection: DataFileCollection
17
- ) {
18
- const dataPath = path.join(
19
- directory,
20
- `${createArrayConstName(collection.name)}.json`
21
- );
22
-
23
- await fs.writeFile(
24
- dataPath,
25
- JSON.stringify(
26
- collection.documents.map((doc) => doc.document),
27
- null,
28
- 2
29
- )
30
- );
31
- }
32
-
33
- function createDataFiles(
34
- directory: string,
35
- collections: Array<DataFileCollection>
36
- ) {
37
- return Promise.all(
38
- collections.map((collection) => createDataFile(directory, collection))
39
- );
40
- }
41
-
42
- type JavaScriptFileConfiguration = {
43
- collections: Array<Pick<TransformedCollection, "name">>;
44
- };
45
-
46
- async function createJavaScriptFile(
47
- directory: string,
48
- configuration: JavaScriptFileConfiguration
49
- ) {
50
- const collections = configuration.collections.map(({ name }) =>
51
- createArrayConstName(name)
52
- );
53
-
54
- let content = `// generated by content-collections at ${new Date()}\n\n`;
55
- for (const name of collections) {
56
- content += `import ${name} from "./${name}.json";\n`;
57
- }
58
- content += "\n";
59
- content += "export { " + collections.join(", ") + " };\n";
60
-
61
- await fs.writeFile(path.join(directory, "index.js"), content, "utf-8");
62
- }
63
-
64
- type TypeDefinitionFileConfiguration = Pick<
65
- InternalConfiguration,
66
- "path" | "generateTypes"
67
- > & {
68
- collections: Array<Pick<TransformedCollection, "name" | "typeName">>;
69
- };
70
-
71
- async function createTypeDefinitionFile(
72
- directory: string,
73
- configuration: TypeDefinitionFileConfiguration
74
- ) {
75
- if (!configuration.generateTypes) {
76
- return;
77
- }
78
-
79
- const importPath = path.relative(directory, configuration.path);
80
- let content = `import configuration from "${importPath}";
81
- import { GetTypeByName } from "@content-collections/core";
82
- `;
83
-
84
- const collections = configuration.collections;
85
- for (const collection of collections) {
86
- content += `\n`;
87
- content += `export type ${collection.typeName} = GetTypeByName<typeof configuration, "${collection.name}">;\n`;
88
- content += `export declare const ${createArrayConstName(
89
- collection.name
90
- )}: Array<${collection.typeName}>;\n`;
91
- }
92
-
93
- content += "\n";
94
- // https://github.com/microsoft/TypeScript/issues/38592
95
- content += "export {};\n";
96
-
97
- await fs.writeFile(path.join(directory, "index.d.ts"), content, "utf-8");
98
- }
99
-
100
- export async function createWriter(directory: string) {
101
- await fs.mkdir(directory, { recursive: true });
102
- return {
103
- createJavaScriptFile: (configuration: JavaScriptFileConfiguration) =>
104
- createJavaScriptFile(directory, configuration),
105
- createTypeDefinitionFile: (
106
- configuration: TypeDefinitionFileConfiguration
107
- ) => createTypeDefinitionFile(directory, configuration),
108
- createDataFiles: (collections: Array<DataFileCollection>) =>
109
- createDataFiles(directory, collections),
110
- };
111
- }
112
-
113
- export type Writer = Awaited<ReturnType<typeof createWriter>>;
package/tsconfig.json DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- /* Base Options: */
4
- "esModuleInterop": true,
5
- "skipLibCheck": true,
6
- "target": "es2022",
7
- "allowJs": true,
8
- "resolveJsonModule": true,
9
- "moduleDetection": "force",
10
- "isolatedModules": true,
11
- /* Strictness */
12
- "strict": true,
13
- "noUncheckedIndexedAccess": true,
14
- /* If NOT transpiling with TypeScript: */
15
- "moduleResolution": "Bundler",
16
- "module": "ESNext",
17
- "noEmit": true,
18
- /* If your code doesn't run in the DOM: */
19
- "lib": ["es2022"],
20
-
21
- "baseUrl": ".",
22
- "paths": {
23
- "@content-collections/core": ["./src"]
24
- },
25
- },
26
- "include": ["src/**/*"]
27
- }
package/vite.config.ts DELETED
@@ -1,24 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
-
3
- const excludes = [
4
- "**/node_modules/**",
5
- "**/tmp/**",
6
- "**/.content-collections/**",
7
- "**/__tests__/**",
8
- "**/types.ts",
9
- ];
10
-
11
- if (process.env.ENABLE_WATCHER_TESTS !== "true") {
12
- excludes.push("**/watcher.ts");
13
- }
14
-
15
- export default defineConfig({
16
- test: {
17
- coverage: {
18
- exclude: excludes
19
- },
20
- poolMatchGlobs: [
21
- ["**/watcher.test.ts", "forks"],
22
- ],
23
- },
24
- });