-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #9 This is rudimentary. I'll get a better method to update README docs (mainly for npm) at a later date.
- Loading branch information
Showing
4 changed files
with
87 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// THIS WILL BE MOVED INTO A LOCAL PLUGIN | ||
|
||
import devkit from '@nx/devkit'; | ||
import { readFileSync, writeFileSync } from 'node:fs'; | ||
|
||
const { readCachedProjectGraph, readProjectsConfigurationFromProjectGraph } = | ||
devkit; | ||
|
||
const LIB_NAME = 'ngxtension'; | ||
const START_MARKER = '<!-- UTILITIES:START -->\n'; | ||
const END_MARKER = '\n\n<!-- UTILITIES:END -->\n'; | ||
const PATTERN = new RegExp(`${START_MARKER}([\\s\\S]*?)${END_MARKER}`, 'g'); | ||
|
||
(async () => { | ||
const projectGraph = readCachedProjectGraph(); | ||
const projects = readProjectsConfigurationFromProjectGraph(projectGraph); | ||
|
||
const projectConfiguration = projects.projects[LIB_NAME]; | ||
const entryPoints = getEntryPoints(projectConfiguration); | ||
console.log(entryPoints); | ||
|
||
if (!entryPoints.length) return; | ||
|
||
let utilitiesMarkdown = ` | ||
|name|link| | ||
|---|---|`; | ||
|
||
for (const entryPoint of entryPoints) { | ||
utilitiesMarkdown += ` | ||
|\`${entryPoint}\`|[README](./libs/${LIB_NAME}/${entryPoint}/README.md)|`; | ||
} | ||
|
||
const readmeContent = readFileSync('README.md', { encoding: 'utf8' }); | ||
const updatedContent = readmeContent.replace( | ||
PATTERN, | ||
`${START_MARKER}${utilitiesMarkdown}${END_MARKER}` | ||
); | ||
|
||
writeFileSync('README.md', updatedContent); | ||
})(); | ||
|
||
function getEntryPoints(projectConfiguration) { | ||
const lintTarget = projectConfiguration.targets['lint']; | ||
const lintFilePatterns = lintTarget.options.lintFilePatterns; | ||
const entryPoints = new Set(); | ||
|
||
for (const filePattern of lintFilePatterns.slice(3)) { | ||
const entryPoint = filePattern.split('/')[2]; | ||
if (entryPoints.has(entryPoint)) { | ||
continue; | ||
} | ||
entryPoints.add(entryPoint); | ||
} | ||
|
||
return Array.from(entryPoints.values()); | ||
} |