-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmanifest-util.ts
64 lines (54 loc) · 1.69 KB
/
manifest-util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { invariant } from '@epic-web/invariant'
import { getCompanionAppUrl } from '@zodiac/env'
import chalk from 'chalk'
import { config } from 'dotenv'
import fs from 'fs'
import { parseArgs } from 'node:util'
config()
// this script is used to update the release value
// in the manifest.json when released through github
// actions. Meant to be used as a cli script:
//
// node manifest-util.js ./public/manifest.json
const updateManifest = (templateFileName, outFileName, version) => {
try {
console.log(chalk.white.bold('Manifest template file:'))
console.log(new URL(templateFileName, import.meta.url).pathname)
const data = fs
.readFileSync(templateFileName)
.toString()
.replaceAll('<COMPANION_APP_URL>', getCompanionAppUrl())
const manifest = JSON.parse(data)
manifest['version'] = version.replace('v', '')
console.log(chalk.white.bold('\nWriting manifest to:'))
console.log(new URL(outFileName, import.meta.url).pathname)
fs.writeFileSync(outFileName, JSON.stringify(manifest, undefined, 2))
} catch (error) {
console.log(error)
}
}
const {
values: { template, outFile, version },
} = parseArgs({
options: {
template: {
type: 'string',
short: 't',
description: 'Path to the template file',
},
outFile: {
type: 'string',
short: 'o',
description: 'Path to the output file',
},
version: {
type: 'string',
short: 'v',
description: 'Version to update the manifest to',
default: 'v0.0.0',
},
},
})
invariant(template != null, 'Path to template file missing')
invariant(outFile != null, 'Path to output file missing')
updateManifest(template, outFile, version)