1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-06 09:19:22 +02:00

Plugins: Add support for the JPL plugin format

This commit is contained in:
Laurent Cozic
2020-11-18 10:17:27 +00:00
parent 73571f1c48
commit 8e2daef144
134 changed files with 1101 additions and 323 deletions

View File

@@ -5,9 +5,45 @@ const chalk = require('chalk');
const yosay = require('yosay');
module.exports = class extends Generator {
prompting() {
constructor(args, opts) {
super(args, opts);
this.option('silent');
this.option('update');
if (this.options.update) {
// When updating, overwrite files without prompting
this.conflicter.force = true;
}
}
async prompting() {
this.log(yosay(`Welcome to the fine ${chalk.red('generator-joplin')} generator!`));
if (this.options.update && !this.options.silent) {
const answers = await this.prompt([
{
type: 'confirm',
name: 'proceed',
message: [
'Updating will overwrite all the generator files **except for the',
'src/ directory**. So if you have made any changes outside of src/',
'make sure your code is under version control so that you can inspect',
'the diff and re-apply your changes if needed. Do you want to proceed?',
].join('\n'),
},
]);
if (!answers.proceed) {
this.log('');
this.log('Operation was cancelled and no changes was made');
process.exit(0);
}
}
const prompts = [
{
type: 'input',
@@ -36,9 +72,17 @@ module.exports = class extends Generator {
},
];
return this.prompt(prompts).then(props => {
if (this.options.update) {
const props = {};
for (const prompt of prompts) {
props[prompt.name] = '';
}
this.props = props;
});
} else {
return this.prompt(prompts).then(props => {
this.props = props;
});
}
}
writing() {
@@ -53,12 +97,20 @@ module.exports = class extends Generator {
'README.md',
'tsconfig.json',
'webpack.config.js',
];
const noUpdateFiles = [
'src/index.ts',
'src/manifest.json',
];
for (const file of files) {
const allFiles = files.concat(noUpdateFiles);
for (const file of allFiles) {
if (this.options.update && noUpdateFiles.includes(file)) continue;
const destFile = file.replace(/_TEMPLATE/, '');
this.fs.copyTpl(
this.templatePath(file),
this.destinationPath(destFile),

View File

@@ -1,3 +1,3 @@
dist/*
node_modules/
*.jpl
*.jpl

View File

@@ -7,8 +7,18 @@ The main two files you will want to look at are:
- `/src/index.ts`, which contains the entry point for the plugin source code.
- `/src/manifest.json`, which is the plugin manifest. It contains information such as the plugin a name, version, etc.
The plugin is built using webpack, which create the compiled code in `/dist`. The project is setup to use TypeScript, although you can change the configuration to use plain JavaScript.
## Building the plugin
The plugin is built using Webpack, which creates the compiled code in `/dist`. A JPL archive will also be created at the root, which can use to distribute the plugin.
To build the plugin, simply run `npm run dist`.
The project is setup to use TypeScript, although you can change the configuration to use plain JavaScript.
## Updating the plugin framework
To update the plugin framework, run `yo joplin --update`
Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes.
For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file.

View File

@@ -1,5 +1,5 @@
{
"name": "<%= pluginId %>",
"name": "joplin_plugin",
"version": "1.0.0",
"description": "",
"scripts": {
@@ -7,7 +7,6 @@
"postinstall": "npm run dist"
},
"keywords": [],
"author": "<%= pluginAuthor %>",
"license": "MIT",
"devDependencies": {
"@types/node": "^14.0.14",