You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-08-13 22:12:50 +02:00
Load commands dynamically
This commit is contained in:
9
CliClient/app/command-version.js
Normal file
9
CliClient/app/command-version.js
Normal file
@@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
usage: 'version',
|
||||
description: 'Displays version information',
|
||||
action: function(args, end) {
|
||||
const packageJson = require('./package.json');
|
||||
this.log(packageJson.name + ' ' + packageJson.version);
|
||||
end();
|
||||
},
|
||||
};
|
@@ -27,7 +27,7 @@ import { importEnex } from 'import-enex';
|
||||
import { vorpalUtils } from 'vorpal-utils.js';
|
||||
import { reg } from 'lib/registry.js';
|
||||
import { FsDriverNode } from './fs-driver-node.js';
|
||||
import { filename, basename } from 'lib/path-utils.js';
|
||||
import { filename, basename, fileExtension } from 'lib/path-utils.js';
|
||||
import { shim } from 'lib/shim.js';
|
||||
import { shimInit } from 'lib/shim-init-node.js';
|
||||
import { _ } from 'lib/locale.js';
|
||||
@@ -62,14 +62,21 @@ let syncLogger = new Logger();
|
||||
let showPromptString = true;
|
||||
let logLevel = Logger.LEVEL_INFO;
|
||||
|
||||
commands.push({
|
||||
usage: 'version',
|
||||
description: 'Displays version information',
|
||||
action: function(args, end) {
|
||||
this.log(packageJson.name + ' ' + packageJson.version);
|
||||
end();
|
||||
},
|
||||
});
|
||||
function commandFiles() {
|
||||
var results = [];
|
||||
const dir = __dirname;
|
||||
|
||||
fs.readdirSync(dir).forEach(function(file) {
|
||||
if (file.indexOf('command-') !== 0) return;
|
||||
const ext = fileExtension(file)
|
||||
if (ext != 'js') return;
|
||||
file = dir+'/'+file;
|
||||
});
|
||||
};
|
||||
|
||||
//commandFiles();
|
||||
|
||||
commands.push(require('./command-version.js'));
|
||||
|
||||
commands.push({
|
||||
usage: 'mkbook <notebook>',
|
||||
|
@@ -21,10 +21,18 @@ function filename(path) {
|
||||
return output.join('.');
|
||||
}
|
||||
|
||||
function fileExtension(path) {
|
||||
if (!path) throw new Error('Path is empty');
|
||||
|
||||
let output = path.split('.');
|
||||
if (output.length <= 1) return '';
|
||||
return output[output.length - 1];
|
||||
}
|
||||
|
||||
function isHidden(path) {
|
||||
let b = basename(path);
|
||||
if (!b.length) throw new Error('Path empty or not a valid path: ' + path);
|
||||
return b[0] === '.';
|
||||
}
|
||||
|
||||
export { basename, dirname, filename, isHidden };
|
||||
export { basename, dirname, filename, isHidden, fileExtension };
|
Reference in New Issue
Block a user