chore: isolate shared dsh plugins into independent monorepo
This commit is contained in:
49
scripts/patch-cordis.mjs
Normal file
49
scripts/patch-cordis.mjs
Normal file
@@ -0,0 +1,49 @@
|
||||
import fs from 'node:fs'
|
||||
|
||||
/**
|
||||
* Idempotently append an `- insert:` patch block to a DSH cordis.patch.yml
|
||||
* file unless a row with the same full package name already exists.
|
||||
*
|
||||
* Usage: node patch-cordis.mjs --file <path> --name <full pkg name> [--id <id>]
|
||||
*/
|
||||
function parseArg(key) {
|
||||
const i = process.argv.indexOf(key)
|
||||
return i >= 0 ? process.argv[i + 1] : undefined
|
||||
}
|
||||
|
||||
const file = parseArg('--file')
|
||||
const name = parseArg('--name')
|
||||
const id = parseArg('--id') || (name ? name.split('/').pop() : undefined)
|
||||
|
||||
if (!file || !name || !id) {
|
||||
console.error('usage: node patch-cordis.mjs --file <path> --name <full-pkg-name> [--id <id>]')
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
let text
|
||||
try {
|
||||
text = fs.readFileSync(file, 'utf8')
|
||||
} catch (err) {
|
||||
console.error(`cannot read ${file}: ${err.message}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// Idempotency: if a row with this name already exists, nothing to do.
|
||||
if (text.includes(`name: '${name}'`) || text.includes(`name: "${name}"`)) {
|
||||
console.log(`already present: ${name} — no change`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const block = [
|
||||
'',
|
||||
'- insert:',
|
||||
' - id: ' + id,
|
||||
` name: '${name}'`,
|
||||
' config: {}',
|
||||
'',
|
||||
].join('\n')
|
||||
|
||||
// Append preserving a single trailing newline.
|
||||
const trimmed = text.endsWith('\n') ? text.slice(0, -1) : text
|
||||
fs.writeFileSync(file, trimmed + '\n' + block + '\n')
|
||||
console.log(`appended insert for ${name} (id=${id}) to ${file}`)
|
||||
Reference in New Issue
Block a user