Skip to content

Commit

Permalink
add script and template to make manifests for extensions
Browse files Browse the repository at this point in the history
usage: node make-manifest.js <my-extensions-folder>
  • Loading branch information
tbjolset committed Jun 8, 2021
1 parent ab3d394 commit 02556ec
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
73 changes: 73 additions & 0 deletions make-manifest.js
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();
34 changes: 34 additions & 0 deletions manifest-template.json
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
}
]
}
}

0 comments on commit 02556ec

Please sign in to comment.