mirror of https://github.com/keeweb/keeweb.git
watch plugins
This commit is contained in:
parent
11dc8bef67
commit
a65f89e1a9
|
@ -22,6 +22,9 @@ switch (op) {
|
|||
case 'sign':
|
||||
signPlugin();
|
||||
break;
|
||||
case 'watch':
|
||||
watchSignPlugin();
|
||||
break;
|
||||
default:
|
||||
showHelp();
|
||||
}
|
||||
|
@ -33,17 +36,14 @@ function showBanner() {
|
|||
function showHelp() {
|
||||
console.log('Usage:');
|
||||
console.log(' - node keeweb-plugin sign <plugin_name>');
|
||||
console.log(' sign plugin and exit');
|
||||
console.log(' - node keeweb-plugin watch <plugin_name>');
|
||||
console.log(' watch plugin directory and sign on changes');
|
||||
}
|
||||
|
||||
function signPlugin() {
|
||||
const packageName = args.shift();
|
||||
function signPlugin(packageName) {
|
||||
if (!packageName) {
|
||||
showHelp();
|
||||
return;
|
||||
}
|
||||
if (!fs.existsSync(packageName)) {
|
||||
console.error('Package folder does not exist');
|
||||
return process.exit(1);
|
||||
packageName = getPackageArg();
|
||||
}
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(packageName, 'manifest.json')));
|
||||
const privateKey = fs.readFileSync(path.join(packageName, 'private_key.pem'), 'binary');
|
||||
|
@ -70,3 +70,42 @@ function signPlugin() {
|
|||
fs.writeFileSync(path.join(packageName, 'manifest.json'), JSON.stringify(manifest, null, 2));
|
||||
console.log('Done, package manifest updated');
|
||||
}
|
||||
|
||||
function watchSignPlugin() {
|
||||
const packageName = getPackageArg();
|
||||
let changed = {};
|
||||
let updateTimer;
|
||||
fs.watch(packageName, { persistent: true }, (eventType, fileName) => {
|
||||
if (fileName.lastIndexOf('manifest.json', 0) === 0) {
|
||||
return;
|
||||
}
|
||||
changed[fileName] = true;
|
||||
if (updateTimer) {
|
||||
clearTimeout(updateTimer);
|
||||
}
|
||||
updateTimer = setTimeout(() => {
|
||||
console.log('Changed:', Object.keys(changed).join(', '));
|
||||
signPlugin(packageName);
|
||||
updateTimer = null;
|
||||
changed = {};
|
||||
}, 1000);
|
||||
});
|
||||
console.log('Waiting for changes...');
|
||||
}
|
||||
|
||||
function getPackageArg() {
|
||||
const packageName = args.shift();
|
||||
if (!packageName) {
|
||||
showHelp();
|
||||
return process.exit(1);
|
||||
}
|
||||
if (!fs.existsSync(packageName)) {
|
||||
console.error('Package folder does not exist');
|
||||
return process.exit(1);
|
||||
}
|
||||
if (!fs.existsSync(path.join(packageName, 'manifest.json'))) {
|
||||
console.error('Package manifest.json does not exist');
|
||||
return process.exit(1);
|
||||
}
|
||||
return packageName;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "keeweb-plugin",
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"description": "KeeWeb plugin utils",
|
||||
"main": "keeweb-plugin.js",
|
||||
"scripts": {
|
||||
|
|
Loading…
Reference in New Issue