diff --git a/packages/default-plugins/buildDefaultPlugins.ts b/packages/default-plugins/buildDefaultPlugins.ts index 44c21f384..06f935ff3 100644 --- a/packages/default-plugins/buildDefaultPlugins.ts +++ b/packages/default-plugins/buildDefaultPlugins.ts @@ -12,9 +12,12 @@ import waitForCliInput from './utils/waitForCliInput'; import getPathToPatchFileFor from './utils/getPathToPatchFileFor'; import getCurrentCommitHash from './utils/getCurrentCommitHash'; -type BeforeEachInstallCallback = (buildDir: string, pluginName: string)=> Promise; +interface Options { + beforeInstall: (buildDir: string, pluginName: string)=> Promise; + beforePatch: ()=> Promise; +} -const buildDefaultPlugins = async (outputParentDir: string|null, beforeInstall: BeforeEachInstallCallback) => { +const buildDefaultPlugins = async (outputParentDir: string|null, options: Options) => { const pluginSourcesDir = resolve(join(__dirname, 'plugin-sources')); const pluginRepositoryData = await readRepositoryJson(join(__dirname, 'pluginRepositories.json')); @@ -71,11 +74,8 @@ const buildDefaultPlugins = async (outputParentDir: string|null, beforeInstall: logStatus('Initializing repository.'); await execCommand('git init . -b main'); - logStatus('Creating initial commit.'); - 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']); + logStatus('Running before-patch hook.'); + await options.beforePatch(); const patchFile = getPathToPatchFileFor(pluginId); if (await exists(patchFile)) { @@ -83,7 +83,7 @@ const buildDefaultPlugins = async (outputParentDir: string|null, beforeInstall: await execCommand(['git', 'apply', patchFile]); } - await beforeInstall(buildDir, pluginId); + await options.beforeInstall(buildDir, pluginId); logStatus('Installing dependencies.'); await execCommand('npm install'); diff --git a/packages/default-plugins/commands/buildAll.ts b/packages/default-plugins/commands/buildAll.ts index 8d02b26a9..9d4ec2281 100644 --- a/packages/default-plugins/commands/buildAll.ts +++ b/packages/default-plugins/commands/buildAll.ts @@ -1,7 +1,10 @@ import buildDefaultPlugins from '../buildDefaultPlugins'; const buildAll = (outputDirectory: string) => { - return buildDefaultPlugins(outputDirectory, async () => { }); + return buildDefaultPlugins(outputDirectory, { + beforeInstall: async () => { }, + beforePatch: async () => { }, + }); }; export default buildAll; diff --git a/packages/default-plugins/commands/editPatch.ts b/packages/default-plugins/commands/editPatch.ts index 3294d744e..bb79f06ac 100644 --- a/packages/default-plugins/commands/editPatch.ts +++ b/packages/default-plugins/commands/editPatch.ts @@ -8,19 +8,29 @@ import getPathToPatchFileFor from '../utils/getPathToPatchFileFor'; const editPatch = async (targetPluginId: string, outputParentDir: string|null) => { let patchedPlugin = false; - await buildDefaultPlugins(outputParentDir, async (buildDir, pluginId) => { - if (pluginId !== targetPluginId) { - return; - } + 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; + } - // 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']); + // 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']); - await copy(join(buildDir, './diff.diff'), getPathToPatchFileFor(pluginId)); + await copy(join(buildDir, './diff.diff'), getPathToPatchFileFor(pluginId)); - patchedPlugin = true; + patchedPlugin = true; + }, }); if (!patchedPlugin) {