forked from CrowdStrike/faltest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: regenerate readme options on release
- Loading branch information
1 parent
929134c
commit a8d236c
Showing
4 changed files
with
70 additions
and
3 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,16 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const { promisify } = require('util'); | ||
const readFile = promisify(fs.readFile); | ||
const writeFile = promisify(fs.writeFile); | ||
|
||
async function replaceFile(path, callback) { | ||
let contents = await readFile(path, 'utf8'); | ||
contents = await callback(contents); | ||
await writeFile(path, contents); | ||
} | ||
|
||
module.exports = { | ||
replaceFile, | ||
}; |
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,51 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const execa = require('execa'); | ||
const path = require('path'); | ||
const { replaceFile } = require('../helpers/fs'); | ||
|
||
const rootDirectory = path.resolve(__dirname, '..'); | ||
|
||
async function replace({ replacementRegex, replacementText, filePath }) { | ||
replacementText = `$1 | ||
\`\`\` | ||
${replacementText} | ||
\`\`\` | ||
$2`; | ||
|
||
await replaceFile(filePath, (contents) => { | ||
if (!replacementRegex.test(contents)) { | ||
throw new Error(`${filePath} is malformed`); | ||
} | ||
|
||
return contents.replace(replacementRegex, replacementText); | ||
}); | ||
} | ||
|
||
async function syncCliOptions() { | ||
let helpText = ( | ||
await execa('yarn', ['--silent', 'start', '--help'], { | ||
cwd: rootDirectory, | ||
env: { | ||
FALTEST_PRINT_VERSION: 'false', | ||
}, | ||
}) | ||
).stdout; | ||
|
||
let replacementRegex = /(<!-- CODEGEN_CLI_HELP_START -->).+(<!-- CODEGEN_CLI_HELP_END -->)/s; | ||
|
||
let readmePath = path.join(rootDirectory, 'README.md'); | ||
|
||
await replace({ | ||
replacementRegex, | ||
replacementText: helpText, | ||
filePath: readmePath, | ||
}); | ||
} | ||
|
||
(async () => { | ||
await syncCliOptions(); | ||
})(); | ||
|
||
require('../packages/cli/src/utils/throw-up'); |