1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-02-01 19:15:01 +02:00

Generator: Merge ignore files when updating plugin

This commit is contained in:
Laurent Cozic 2021-01-05 18:18:40 +00:00
parent 6e69343bb6
commit fa749d6d2a
2 changed files with 27 additions and 0 deletions

View File

@ -35,6 +35,14 @@ function mergePackageKey(parentKey, source, dest) {
return output;
}
function mergeIgnoreFile(source, dest) {
const output = source.split('\n').concat(dest.split('\n'));
return output.filter(function(item, pos) {
if (!item) return true; // Leave blank lines
return output.indexOf(item) === pos;
});
}
function packageNameFromPluginName(pluginName) {
// Package name is limited to 214 characters
return `joplin-plugin-${slugify(pluginName, {
@ -182,6 +190,17 @@ module.exports = class extends Generator {
},
}
);
} else if (this.options.update && (destFile === '.gitignore' || destFile === '.npmignore') && this.fs.exists(destFilePath)) {
const destContent = this.fs.read(destFilePath);
this.fs.copy(
this.templatePath(file),
destFilePath, {
process: (sourceBuffer) => {
return mergeIgnoreFile(sourceBuffer.toString(), destContent);
},
}
);
} else {
this.fs.copyTpl(
this.templatePath(file),

View File

@ -1,3 +1,11 @@
// -----------------------------------------------------------------------------
// This file is used to build the plugin file (.jpl) and plugin info (.json). It
// is recommended not to edit this file as it would be overwritten when updating
// the plugin framework. If you do make some changes, consider using an external
// JS file and requiring it here to minimize the changes. That way when you
// update, you can easily restore the functionality you've added.
// -----------------------------------------------------------------------------
const path = require('path');
const crypto = require('crypto');
const fs = require('fs-extra');