-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kent C. Dodds
committed
Sep 19, 2017
1 parent
3cb5f39
commit 208cce6
Showing
6 changed files
with
237 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const lintStagedConfig = require('kcd-scripts/config').lintStaged | ||
|
||
module.exports = Object.assign(lintStagedConfig.linters, { | ||
'**/__snapshots__/**': 'node other/snap-to-readme.js', | ||
}) |
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,41 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
|
||
const readmePath = path.join(__dirname, '../README.md') | ||
const readme = fs.readFileSync(readmePath, 'utf8') | ||
const snaps = require('../src/__tests__/__snapshots__/macro.js.snap') | ||
|
||
const snapNumberRegex = /^README:(\d+)/ | ||
const snapTitleRegex = /^README:\d+(.*) \d+$/ | ||
const readmeSnapRegex = /<!-- SNAP_TO_README:START -->[\s\S]*?<!-- SNAP_TO_README:END -->/ | ||
const snapsToUse = Object.keys(snaps) | ||
.filter(name => name.startsWith('README')) | ||
.sort( | ||
(nameA, nameB) => | ||
Number(nameA.match(snapNumberRegex)[1]) > | ||
Number(nameB.match(snapNumberRegex)[1]) | ||
? 1 | ||
: 0, | ||
) | ||
.reduce((acc, key) => { | ||
const title = key.match(snapTitleRegex)[1].trim() | ||
const contents = snaps[key].trim() | ||
return [acc, `**${title}**`, `~~~javascript\n${contents}\n~~~`] | ||
.join('\n\n') | ||
.replace(/~/g, '`') | ||
}, []) | ||
|
||
const newReadme = readme.replace( | ||
readmeSnapRegex, | ||
` | ||
<!-- SNAP_TO_README:START --> | ||
<!-- This section is generated by the other/snap-to-readme.js script. --> | ||
<!-- Do not edit directly. --> | ||
${snapsToUse.trim()} | ||
<!-- SNAP_TO_README:END --> | ||
`.trim(), | ||
) | ||
|
||
fs.writeFileSync(readmePath, newReadme) |
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
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