@xylabs/readme-gen 5.0.79 → 5.0.81

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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @xylabs/set
1
+ # @xylabs/readme-gen
2
2
 
3
3
  [![logo][]](https://xylabs.com)
4
4
 
@@ -17,107 +17,29 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
17
17
 
18
18
  ## Reference
19
19
 
20
- **@xylabs/set**
20
+ **@xylabs/readme-gen**
21
21
 
22
22
  ***
23
23
 
24
24
  ## Functions
25
25
 
26
- - [difference](#functions/difference)
27
- - [intersection](#functions/intersection)
28
- - [union](#functions/union)
26
+ - [generateReadmeFiles](#functions/generateReadmeFiles)
29
27
 
30
28
  ### functions
31
29
 
32
- ### <a id="difference"></a>difference
30
+ ### <a id="generateReadmeFiles"></a>generateReadmeFiles
33
31
 
34
- [**@xylabs/set**](#../README)
32
+ [**@xylabs/readme-gen**](#../README)
35
33
 
36
34
  ***
37
35
 
38
36
  ```ts
39
- function difference<TKey>(a, b): Set<TKey>;
37
+ function generateReadmeFiles(): Promise<void>;
40
38
  ```
41
39
 
42
- ## Type Parameters
43
-
44
- ### TKey
45
-
46
- `TKey`
47
-
48
- ## Parameters
49
-
50
- ### a
51
-
52
- `Set`\<`TKey`\>
53
-
54
- ### b
55
-
56
- `Set`\<`TKey`\>
57
-
58
- ## Returns
59
-
60
- `Set`\<`TKey`\>
61
-
62
- ### <a id="intersection"></a>intersection
63
-
64
- [**@xylabs/set**](#../README)
65
-
66
- ***
67
-
68
- ```ts
69
- function intersection<TKey>(a, b): Set<TKey>;
70
- ```
71
-
72
- ## Type Parameters
73
-
74
- ### TKey
75
-
76
- `TKey`
77
-
78
- ## Parameters
79
-
80
- ### a
81
-
82
- `Set`\<`TKey`\>
83
-
84
- ### b
85
-
86
- `Set`\<`TKey`\>
87
-
88
- ## Returns
89
-
90
- `Set`\<`TKey`\>
91
-
92
- ### <a id="union"></a>union
93
-
94
- [**@xylabs/set**](#../README)
95
-
96
- ***
97
-
98
- ```ts
99
- function union<TKey>(a, b): Set<TKey>;
100
- ```
101
-
102
- ## Type Parameters
103
-
104
- ### TKey
105
-
106
- `TKey`
107
-
108
- ## Parameters
109
-
110
- ### a
111
-
112
- `Set`\<`TKey`\>
113
-
114
- ### b
115
-
116
- `Set`\<`TKey`\>
117
-
118
40
  ## Returns
119
41
 
120
- `Set`\<`TKey`\>
42
+ `Promise`\<`void`\>
121
43
 
122
44
 
123
45
  Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
@@ -141,8 +63,8 @@ Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
141
63
 
142
64
  [main-build]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml/badge.svg
143
65
  [main-build-link]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml
144
- [npm-badge]: https://img.shields.io/npm/v/@xylabs/set.svg
145
- [npm-link]: https://www.npmjs.com/package/@xylabs/set
66
+ [npm-badge]: https://img.shields.io/npm/v/@xylabs/readme-gen.svg
67
+ [npm-link]: https://www.npmjs.com/package/@xylabs/readme-gen
146
68
  [codacy-badge]: https://app.codacy.com/project/badge/Grade/c8e15e14f37741c18cfb47ac7245c698
147
69
  [codacy-link]: https://www.codacy.com/gh/xylabs/sdk-js/dashboard?utm_source=github.com&utm_medium=referral&utm_content=xylabs/sdk-js&utm_campaign=Badge_Grade
148
70
  [codeclimate-badge]: https://api.codeclimate.com/v1/badges/c5eb068f806f0b047ea7/maintainability
@@ -150,11 +72,11 @@ Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
150
72
  [snyk-badge]: https://snyk.io/test/github/xylabs/sdk-js/badge.svg?targetFile=package.json
151
73
  [snyk-link]: https://snyk.io/test/github/xylabs/sdk-js?targetFile=package.json
152
74
 
153
- [npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/set
154
- [npm-license-badge]: https://img.shields.io/npm/l/@xylabs/set
75
+ [npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/readme-gen
76
+ [npm-license-badge]: https://img.shields.io/npm/l/@xylabs/readme-gen
155
77
 
156
- [jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xylabs/set/badge
157
- [jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xylabs/set
78
+ [jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xylabs/readme-gen/badge
79
+ [jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xylabs/readme-gen
158
80
 
159
- [socket-badge]: https://socket.dev/api/badge/npm/package/@xylabs/set
160
- [socket-link]: https://socket.dev/npm/package/@xylabs/set
81
+ [socket-badge]: https://socket.dev/api/badge/npm/package/@xylabs/readme-gen
82
+ [socket-link]: https://socket.dev/npm/package/@xylabs/readme-gen
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/readme-gen",
3
- "version": "5.0.79",
3
+ "version": "5.0.81",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "readme",
@@ -31,28 +31,25 @@
31
31
  "exports": {
32
32
  ".": {
33
33
  "types": "./dist/node/index.d.ts",
34
- "source": "./src/index.ts",
35
34
  "default": "./dist/node/index.mjs"
36
35
  },
37
36
  "./package.json": "./package.json"
38
37
  },
39
38
  "module": "./dist/node/index.mjs",
40
- "source": "./src/index.ts",
41
39
  "types": "./dist/node/index.d.ts",
42
40
  "files": [
43
41
  "dist",
44
- "src",
45
42
  "!**/*.bench.*",
46
43
  "!**/*.spec.*",
47
44
  "!**/*.test.*"
48
45
  ],
49
46
  "dependencies": {
50
- "@xylabs/ts-scripts-yarn3": "~7.3.2"
47
+ "@xylabs/ts-scripts-yarn3": "~7.4.11"
51
48
  },
52
49
  "devDependencies": {
53
- "@xylabs/tsconfig": "~7.3.2",
50
+ "@xylabs/tsconfig": "~7.4.11",
54
51
  "typescript": "~5.9.3",
55
- "vitest": "~4.0.18"
52
+ "vitest": "^4.0.18"
56
53
  },
57
54
  "engines": {
58
55
  "node": ">=18"
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env node
2
- /* eslint-disable no-console */
3
-
4
- // generate-readmes.mjs
5
- import { readFile, writeFile } from 'node:fs/promises'
6
- import path from 'node:path'
7
- import { fileURLToPath } from 'node:url'
8
-
9
- import { yarnWorkspaces } from '@xylabs/ts-scripts-yarn3'
10
-
11
- import { generateTypeDoc } from './generateTypeDoc.ts'
12
-
13
- const dirName = () => path.dirname(fileURLToPath(import.meta.url))
14
- const templatePath = () => path.join(dirName(), 'README.template.md')
15
-
16
- function fillTemplate(template: string, data: { [key: string]: string }) {
17
- const additionalData: { [key: string]: string } = { ...data, safeName: data.name.replaceAll('/', '__').replaceAll('@', '') }
18
- return template.replaceAll(/{{(.*?)}}/g, (_, key) => additionalData[(key as string).trim()] ?? '')
19
- }
20
-
21
- async function tryLoadReadmeBody(location: string) {
22
- try {
23
- return await readFile(path.join(location, 'README.body.md'), 'utf8')
24
- } catch {
25
- return
26
- }
27
- }
28
-
29
- async function tryLoadReadmeReference(location: string) {
30
- try {
31
- return await readFile(path.join(location, 'README.reference.md'), 'utf8')
32
- } catch {
33
- return
34
- }
35
- }
36
-
37
- export async function generateReadmeFiles() {
38
- const template = await readFile(templatePath(), 'utf8')
39
- const pkgs = yarnWorkspaces()
40
-
41
- for (const { location } of pkgs) {
42
- try {
43
- if (location.includes('wallet-chrome')) {
44
- continue
45
- }
46
- const pkgJsonPath = path.join(location, 'package.json')
47
- const pkg = JSON.parse(await readFile(pkgJsonPath, 'utf8'))
48
- const body = await tryLoadReadmeBody(location) ?? ''
49
- const reference = await tryLoadReadmeReference(location) ?? await generateTypeDoc(location, ['src/index*.ts'])
50
- const readmeContent = fillTemplate(template, {
51
- ...pkg, body, reference,
52
- })
53
- await writeFile(path.join(location, 'README.md'), readmeContent)
54
- console.log(`✅ Created README.md for ${pkg.name}`)
55
- } catch (ex) {
56
- const error = ex as Error
57
- console.warn(`⚠️ Skipped ${location}:`, error.message)
58
- }
59
- }
60
- }
@@ -1,174 +0,0 @@
1
- /* eslint-disable no-console */
2
- import { execSync } from 'node:child_process'
3
- import {
4
- existsSync, mkdirSync, readdirSync,
5
- readFileSync,
6
- } from 'node:fs'
7
- import { rm, writeFile } from 'node:fs/promises'
8
- import path from 'node:path'
9
- import { fileURLToPath } from 'node:url'
10
-
11
- /**
12
- * Generates inline TypeDoc markdown documentation
13
- * @param {string} packageLocation - The package location path
14
- * @param {string} sourceGlob - The glob pattern for source files
15
- * @returns {Promise<string>} A markdown string containing Reference
16
- */
17
- export async function generateTypeDoc(packageLocation: string, entryPoints: string[]) {
18
- const __dirname = path.dirname(fileURLToPath(import.meta.url))
19
- const tempDir = path.join(__dirname, '.temp-typedoc')
20
-
21
- console.log(`Generating TypeDoc for package at: ${packageLocation}`)
22
- for (const ep of entryPoints) {
23
- console.log(` - Entry point: ${path.resolve(packageLocation, ep)}`)
24
- }
25
-
26
- try {
27
- // Create temp directory if it doesn't exist
28
- if (!existsSync(tempDir)) {
29
- mkdirSync(tempDir, { recursive: true })
30
- }
31
-
32
- // Create a minimal TypeDoc config for markdown generation
33
- const typedocConfig = {
34
- entryPoints: entryPoints.map(ep => path.resolve(packageLocation, ep)),
35
- entryPointStrategy: 'expand',
36
- out: tempDir,
37
- plugin: ['typedoc-plugin-markdown'],
38
- readme: 'none',
39
- theme: 'markdown',
40
- useCodeBlocks: true,
41
- hidePageTitle: true,
42
- githubPages: false,
43
- hideGenerator: true,
44
- hideBreadcrumbs: true,
45
- disableSources: true,
46
- skipErrorChecking: true,
47
- excludeExternals: true,
48
- excludeInternal: true,
49
- excludePrivate: true,
50
- sort: ['source-order'],
51
- }
52
-
53
- // Create temporary typedoc.json file
54
- const typedocJsonPath = path.join(tempDir, 'typedoc.json')
55
- await writeFile(typedocJsonPath, JSON.stringify(typedocConfig, null, 2))
56
-
57
- // Run TypeDoc with the config
58
- try {
59
- console.log(`Generating docs for: ${packageLocation}`)
60
- execSync(`npx typedoc --options ${typedocJsonPath}`, {
61
- cwd: process.cwd(),
62
- stdio: ['ignore', 'pipe', 'pipe'],
63
- })
64
- } catch (ex) {
65
- const error = ex as Error
66
- console.error(`TypeDoc error: ${error.message}`)
67
- return '## Reference\n\nReference generation failed.'
68
- }
69
-
70
- // Combine all markdown files into a single document
71
- return consolidateMarkdown(tempDir)
72
- } catch (ex) {
73
- const error = ex as Error
74
- console.warn(`⚠️ Error generating TypeDoc for ${packageLocation}:`, error.message)
75
- return '## Reference\n\nReference generation failed.'
76
- } finally {
77
- // Clean up the temp directory
78
- try {
79
- await rm(tempDir, { recursive: true, force: true })
80
- } catch (ex) {
81
- const error = ex as Error
82
- console.warn('⚠️ Failed to clean up temp directory:', error.message)
83
- }
84
- }
85
- }
86
-
87
- /**
88
- * Consolidates all markdown files in the TypeDoc output directory into a single markdown string
89
- * @param {string} tempDir - The temporary directory containing TypeDoc output
90
- * @returns {string} - Consolidated markdown content
91
- */
92
- function consolidateMarkdown(tempDir: string) {
93
- // Start with the main README content
94
- let consolidated = '## Reference\n\n'
95
-
96
- // Read main README.md first (if it exists)
97
- const mainReadmePath = path.join(tempDir, 'README.md')
98
- if (existsSync(mainReadmePath)) {
99
- const mainContent = readFileSync(mainReadmePath, 'utf8')
100
- .replace(/^---(.|\n)*?---\n/, '') // Remove front matter
101
- .replace(/^# .+\n/, '') // Remove top-level header
102
- .replaceAll(/\]\((.+?)\.md\)/g, '](#$1)') // Fix internal links to use anchors
103
-
104
- consolidated += mainContent + '\n\n'
105
- }
106
-
107
- // Function to process a directory recursively
108
- function processDirectory(dir: string, level = 0): string {
109
- const indent = ' '.repeat(level)
110
- let content = ''
111
-
112
- try {
113
- const items = readdirSync(dir, { withFileTypes: true })
114
-
115
- // Process files first
116
- for (const item of items) {
117
- const itemPath = path.join(dir, item.name)
118
-
119
- // Skip directories for now (process them later)
120
- if (item.isDirectory()) continue
121
-
122
- // Skip README.md (already processed) and files that aren't markdown
123
- if (item.name === 'README.md' || !item.name.endsWith('.md')) continue
124
-
125
- // Read file content
126
- const fileContent = readFileSync(itemPath, 'utf8')
127
- .replace(/^---(.|\n)*?---\n/, '') // Remove front matter
128
-
129
- // Get the module name from filename (without extension)
130
- const moduleName = item.name.replace('.md', '')
131
-
132
- // Create a header with anchor
133
- content += `\n\n${indent}### <a id="${moduleName}"></a>${moduleName}\n\n`
134
-
135
- // Add file content with fixed links
136
- content += fileContent
137
- .replace(/^# .+\n/, '') // Remove top-level header
138
- .replaceAll(/\]\((.+?)\.md\)/g, '](#$1)') // Fix internal links to use anchors
139
- }
140
-
141
- // Process subdirectories
142
- for (const item of items) {
143
- if (item.isDirectory()) {
144
- const subDirPath = path.join(dir, item.name)
145
- // Skip spec directories
146
- if (item.name === 'spec' || item.name.includes('.spec')) continue
147
-
148
- // Create a header for the directory
149
- content += `\n\n${indent}### ${item.name}\n`
150
-
151
- // Process the subdirectory
152
- content += processDirectory(subDirPath, level + 1)
153
- }
154
- }
155
- } catch (ex) {
156
- const error = ex as Error
157
- console.warn(`⚠️ Error processing directory ${dir}:`, error.message)
158
- }
159
-
160
- return content
161
- }
162
-
163
- // Process all files in the tempDir
164
- consolidated += processDirectory(tempDir)
165
-
166
- // Clean up the markdown (fix duplicate headers, etc.)
167
- consolidated = consolidated
168
- .replaceAll(/\n\n\n+/g, '\n\n') // Remove excess newlines
169
- .replaceAll(/^#### /gm, '### ') // Adjust heading levels
170
- .replaceAll(/^##### /gm, '#### ') // Adjust heading levels
171
- .replaceAll(/^###### /gm, '##### ') // Adjust heading levels
172
-
173
- return consolidated
174
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './generateReadmeFiles.ts'