You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

34 lines
1.3 KiB

import { readFileSync, writeFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { resolve } from 'node:path'
const root = fileURLToPath(new URL('../', import.meta.url))
const [name, productName, appId] = process.argv.slice(2)
if (
!name ||
!productName ||
!appId ||
!/^[a-z][a-z0-9-]{1,63}$/.test(name) ||
!/^[a-z][a-z0-9]*(\.[a-z][a-z0-9]*){2,}$/.test(appId) ||
productName.length > 80 ||
/[<>:"/\\|?*\x00-\x1f]/.test(productName)
) {
console.error('Usage: pnpm rename <package-name> "Product Name" <com.company.app>')
process.exitCode = 1
} else {
const configFile = resolve(root, 'app.config.json')
const packageFile = resolve(root, 'package.json')
const brand = JSON.parse(readFileSync(configFile, 'utf8'))
const pkg = JSON.parse(readFileSync(packageFile, 'utf8'))
Object.assign(brand, { name, productName, appId })
pkg.name = name
writeFileSync(configFile, `${JSON.stringify(brand, null, 2)}\n`)
writeFileSync(packageFile, `${JSON.stringify(pkg, null, 2)}\n`)
const htmlFile = resolve(root, 'src/renderer/index.html')
const html = readFileSync(htmlFile, 'utf8').replace(
/<title>.*?<\/title>/,
`<title>${productName.replaceAll('&', '&amp;')}</title>`
)
writeFileSync(htmlFile, html)
console.log(`Renamed to ${productName} (${appId}). Run pnpm install to update the lockfile.`)
}