-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathmake-manifest.js
73 lines (61 loc) · 1.78 KB
/
make-manifest.js
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
67
68
69
70
71
72
73
/**
* Script to create manifest for an extension, based on the files in the extension folder.
* The manifest.json file will be put inside the extension folder, replacing any existing
* manifest file there.
*
* It's used by eg roomos.cisco.com to install extensions easily.
*
* Usage:
* node make_manifest <extension_folder>
*
*/
const { readFileSync, readdirSync, fstat, writeFileSync } = require('fs');
const { join, basename } = require('path');
const template = require('./manifest-template.json');
function endsWith(ext, file) {
if (Array.isArray(ext)) {
return ext.some(e => file.toLowerCase().endsWith(e.toLowerCase()));
}
return file.toLowerCase().endsWith(ext.toLowerCase());
}
function findFiles(dir, extension) {
return readdirSync(dir, { withFileTypes: true })
.filter(item => item.isFile() && endsWith(extension, item.name))
.map(item => item.name);
}
function go(dir) {
// console.log('make manifest', dir);
const macros = findFiles(dir, '.js');
const macroList = macros.map(file => {
const id = basename(file, '.js');
return {
payload: file,
id,
type: 'url'
}
});
const roomcontrol = findFiles(dir, '.xml');
const roomcontrolList = roomcontrol.map(file => {
const id = basename(file, '.xml');
return {
payload: file,
id,
type: 'url'
}
});
template.profile.macro.items = macroList;
template.profile.roomcontrol.items = roomcontrolList;
template.profile.userParams = [];
const file = join(dir, 'manifest.json');
writeFileSync(file, JSON.stringify(template, null, 2));
console.log('wrote', file);
}
function main() {
const dir = process.argv[2];
if (!dir) {
console.log(`\nUsage: node ${process.argv[1]} <extension_dir>\n`);
process.exit(1);
}
go(dir);
}
main();