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

Chore: Fixes #10306: Remove unnecessary initial commit in default plugins build (#10308)

This commit is contained in:
Henry Heino 2024-04-15 10:14:47 -07:00 committed by GitHub
parent 035557de9f
commit e3ba605592
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 19 deletions

View File

@ -12,9 +12,12 @@ import waitForCliInput from './utils/waitForCliInput';
import getPathToPatchFileFor from './utils/getPathToPatchFileFor'; import getPathToPatchFileFor from './utils/getPathToPatchFileFor';
import getCurrentCommitHash from './utils/getCurrentCommitHash'; import getCurrentCommitHash from './utils/getCurrentCommitHash';
type BeforeEachInstallCallback = (buildDir: string, pluginName: string)=> Promise<void>; interface Options {
beforeInstall: (buildDir: string, pluginName: string)=> Promise<void>;
beforePatch: ()=> Promise<void>;
}
const buildDefaultPlugins = async (outputParentDir: string|null, beforeInstall: BeforeEachInstallCallback) => { const buildDefaultPlugins = async (outputParentDir: string|null, options: Options) => {
const pluginSourcesDir = resolve(join(__dirname, 'plugin-sources')); const pluginSourcesDir = resolve(join(__dirname, 'plugin-sources'));
const pluginRepositoryData = await readRepositoryJson(join(__dirname, 'pluginRepositories.json')); const pluginRepositoryData = await readRepositoryJson(join(__dirname, 'pluginRepositories.json'));
@ -71,11 +74,8 @@ const buildDefaultPlugins = async (outputParentDir: string|null, beforeInstall:
logStatus('Initializing repository.'); logStatus('Initializing repository.');
await execCommand('git init . -b main'); await execCommand('git init . -b main');
logStatus('Creating initial commit.'); logStatus('Running before-patch hook.');
await execCommand('git add .'); await options.beforePatch();
await execCommand(['git', 'config', 'user.name', 'Build script']);
await execCommand(['git', 'config', 'user.email', '']);
await execCommand(['git', 'commit', '-m', 'Initial commit']);
const patchFile = getPathToPatchFileFor(pluginId); const patchFile = getPathToPatchFileFor(pluginId);
if (await exists(patchFile)) { if (await exists(patchFile)) {
@ -83,7 +83,7 @@ const buildDefaultPlugins = async (outputParentDir: string|null, beforeInstall:
await execCommand(['git', 'apply', patchFile]); await execCommand(['git', 'apply', patchFile]);
} }
await beforeInstall(buildDir, pluginId); await options.beforeInstall(buildDir, pluginId);
logStatus('Installing dependencies.'); logStatus('Installing dependencies.');
await execCommand('npm install'); await execCommand('npm install');

View File

@ -1,7 +1,10 @@
import buildDefaultPlugins from '../buildDefaultPlugins'; import buildDefaultPlugins from '../buildDefaultPlugins';
const buildAll = (outputDirectory: string) => { const buildAll = (outputDirectory: string) => {
return buildDefaultPlugins(outputDirectory, async () => { }); return buildDefaultPlugins(outputDirectory, {
beforeInstall: async () => { },
beforePatch: async () => { },
});
}; };
export default buildAll; export default buildAll;

View File

@ -8,19 +8,29 @@ import getPathToPatchFileFor from '../utils/getPathToPatchFileFor';
const editPatch = async (targetPluginId: string, outputParentDir: string|null) => { const editPatch = async (targetPluginId: string, outputParentDir: string|null) => {
let patchedPlugin = false; let patchedPlugin = false;
await buildDefaultPlugins(outputParentDir, async (buildDir, pluginId) => { await buildDefaultPlugins(outputParentDir, {
if (pluginId !== targetPluginId) { beforePatch: async () => {
return; // 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;
}
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('Make changes to', buildDir, 'to create a patch.'); console.log('Make changes to', buildDir, 'to create a patch.');
await waitForCliInput(); await waitForCliInput();
await execCommand(['sh', '-c', 'git diff -p > diff.diff']); await execCommand(['sh', '-c', 'git diff -p > diff.diff']);
await copy(join(buildDir, './diff.diff'), getPathToPatchFileFor(pluginId)); await copy(join(buildDir, './diff.diff'), getPathToPatchFileFor(pluginId));
patchedPlugin = true; patchedPlugin = true;
},
}); });
if (!patchedPlugin) { if (!patchedPlugin) {