2023-12-11 15:58:45 +02:00
|
|
|
import { execCommand } from '@joplin/utils';
|
|
|
|
import waitForCliInput from '../utils/waitForCliInput';
|
|
|
|
import { copy } from 'fs-extra';
|
|
|
|
import { join } from 'path';
|
|
|
|
import buildDefaultPlugins from '../buildDefaultPlugins';
|
|
|
|
import getPathToPatchFileFor from '../utils/getPathToPatchFileFor';
|
|
|
|
|
|
|
|
const editPatch = async (targetPluginId: string, outputParentDir: string|null) => {
|
|
|
|
let patchedPlugin = false;
|
|
|
|
|
2024-04-15 19:14:47 +02:00
|
|
|
await buildDefaultPlugins(outputParentDir, {
|
|
|
|
beforePatch: async () => {
|
|
|
|
// To make updating just the patch possible, a commit is created just before applying
|
|
|
|
// the patch.
|
|
|
|
await execCommand('git add .');
|
|
|
|
await execCommand(['git', 'config', 'user.name', 'Build script']);
|
|
|
|
await execCommand(['git', 'config', 'user.email', '']);
|
|
|
|
await execCommand(['git', 'commit', '-m', 'Initial commit']);
|
|
|
|
},
|
|
|
|
beforeInstall: async (buildDir, pluginId) => {
|
|
|
|
if (pluginId !== targetPluginId) {
|
|
|
|
return;
|
|
|
|
}
|
2023-12-11 15:58:45 +02:00
|
|
|
|
2024-04-15 19:14:47 +02:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log('Make changes to', buildDir, 'to create a patch.');
|
|
|
|
await waitForCliInput();
|
|
|
|
await execCommand(['sh', '-c', 'git diff -p > diff.diff']);
|
2023-12-11 15:58:45 +02:00
|
|
|
|
2024-04-15 19:14:47 +02:00
|
|
|
await copy(join(buildDir, './diff.diff'), getPathToPatchFileFor(pluginId));
|
2023-12-11 15:58:45 +02:00
|
|
|
|
2024-04-15 19:14:47 +02:00
|
|
|
patchedPlugin = true;
|
|
|
|
},
|
2023-12-11 15:58:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!patchedPlugin) {
|
|
|
|
throw new Error(`No default plugin with ID ${targetPluginId} found!`);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default editPatch;
|