-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script and template to make manifests for extensions
usage: node make-manifest.js <my-extensions-folder>
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"version": "1", | ||
"profile": { | ||
"macro": { | ||
"items": [ | ||
{ | ||
"payload": "mymacro.js", | ||
"id": "mymacro", | ||
"type": "url" | ||
} | ||
] | ||
}, | ||
"roomcontrol": { | ||
"items": [ | ||
{ | ||
"payload": "mypanel.xml", | ||
"id": "mypanel", | ||
"type": "url" | ||
} | ||
] | ||
}, | ||
"userParams": [ | ||
{ | ||
"id": "myVariable", | ||
"name": "My Variable", | ||
"info": "The value the user chooses will be replaced inside the js that has id equal to domain", | ||
"type": "string", | ||
"default": "foobar", | ||
"domain": "mymacro", | ||
"required": true | ||
} | ||
] | ||
} | ||
} |