-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-assets.ts
66 lines (60 loc) · 1.59 KB
/
generate-assets.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
65
66
import fs from 'fs'
import path from 'path'
import {
findFirmwareFilesInManifest,
Manifest,
} from './findFirmwareFilesInManifest.js'
const hasJsonExtension = (filename: string): boolean =>
path.parse(filename).ext.endsWith('.json')
const applications: Manifest[] = []
const applicationFolders = fs.readdirSync(
path.join(process.cwd(), 'applications'),
)
for (const folder of applicationFolders) {
const entries = fs.readdirSync(
path.join(process.cwd(), 'applications', folder),
)
const manifest = entries.find(hasJsonExtension)
if (manifest === undefined) {
throw new Error(`no JSON file found in folder ${folder}`)
}
const application = JSON.parse(
fs.readFileSync(
path.join(process.cwd(), 'applications', folder, manifest),
'utf-8',
),
)
applications.push(application)
const files = findFirmwareFilesInManifest(application)
for (const file of files) {
fs.copyFileSync(
path.join(process.cwd(), 'applications', folder, file),
path.join(process.cwd(), 'assets', file),
)
}
}
const manifest = path.join(process.cwd(), 'assets', 'manifest.json')
console.log(manifest)
fs.writeFileSync(
manifest,
JSON.stringify(
{
$schema:
'https://nordicsemiconductor.github.io/nrfprogrammer-firmware-images/manifest.schema.json',
version: 1,
applications,
},
null,
2,
),
'utf-8',
)
// Copy JSON schemas
fs.copyFileSync(
path.join(process.cwd(), 'manifest.schema.json'),
path.join(process.cwd(), 'assets', 'manifest.schema.json'),
)
fs.copyFileSync(
path.join(process.cwd(), 'application.schema.json'),
path.join(process.cwd(), 'assets', 'application.schema.json'),
)