fix(usage-to-readme): fix multiple .USAGE.md changes
This commit is contained in:
parent
3892efcca2
commit
a624330818
@ -10,32 +10,38 @@ const { execFile } = require('node:child_process')
|
||||
const generateReadme = readFile(join(__dirname, 'README.md.tpl'), 'utf8').then(compile)
|
||||
|
||||
async function usageToReadme(...args) {
|
||||
console.error(process.argv, args)
|
||||
|
||||
const gitAdd = args[0] === '--git-add'
|
||||
if (gitAdd) {
|
||||
args.shift()
|
||||
}
|
||||
|
||||
const usagePath = args[0]
|
||||
const dir = dirname(usagePath)
|
||||
for (const usagePath of args) {
|
||||
console.error(usagePath)
|
||||
const dir = dirname(usagePath)
|
||||
|
||||
const [usage, pkg] = await Promise.all([
|
||||
readFile(usagePath, 'utf8'),
|
||||
readFile(join(dir, 'package.json')).then(JSON.parse),
|
||||
])
|
||||
const [usage, pkg] = await Promise.all([
|
||||
readFile(usagePath, 'utf8'),
|
||||
readFile(join(dir, 'package.json')).then(JSON.parse),
|
||||
])
|
||||
|
||||
const readmePath = join(dir, 'README.md')
|
||||
await writeFile(readmePath, (await generateReadme)({ pkg, usage: usage.trim() }))
|
||||
const readmePath = join(dir, 'README.md')
|
||||
await writeFile(readmePath, (await generateReadme)({ pkg, usage: usage.trim() }))
|
||||
|
||||
if (gitAdd) {
|
||||
await new Promise((resolve, reject) => {
|
||||
execFile('git', ['add', '--', readmePath])
|
||||
.on('error', reject)
|
||||
.on('exit', code => {
|
||||
if (code !== 0) {
|
||||
reject(new Error('command exited with non-zero status code: ' + code))
|
||||
}
|
||||
})
|
||||
})
|
||||
if (gitAdd) {
|
||||
await new Promise((resolve, reject) => {
|
||||
execFile('git', ['add', '--', readmePath])
|
||||
.on('error', reject)
|
||||
.on('exit', code => {
|
||||
if (code !== 0) {
|
||||
reject(new Error('command exited with non-zero status code: ' + code))
|
||||
} else {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user