From 3186cff725cd458607abb168d3615b051608eda6 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Wed, 16 Oct 2024 10:49:07 +0200 Subject: [PATCH] chore: simplify link-dependencies task Use `yarn link` without additional scripts for diagram-js and bpmn-js. --- tasks/link-dependencies.js | 59 +++++++++++++++----------------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/tasks/link-dependencies.js b/tasks/link-dependencies.js index 386223964..a95a8acd7 100644 --- a/tasks/link-dependencies.js +++ b/tasks/link-dependencies.js @@ -13,9 +13,9 @@ const { shellSync: exec } = require('execa'); const path = require('path'); const customLinkersMap = { - 'bpmn-io/bpmn-js': linkBpmnJs, + 'bpmn-io/bpmn-js': linkWithYarn, 'bpmn-io/dmn-js': linkDmnJs, - 'bpmn-io/diagram-js': linkDiagramJs, + 'bpmn-io/diagram-js': linkWithYarn, 'bpmn-io/form-js': linkFormJs }; @@ -136,50 +136,27 @@ function linkDmnJs({ repo, ref }) { * * @param {Dependency} dependency */ -function linkBpmnJs({ repo, ref }) { - gitClone(repo); +function linkWithYarn({ repo, ref }) { + const targetDir = toDirName(repo); + + gitClone(repo, targetDir); console.log(`Cloned ${repo}.`); - const rootDir = path.join(dependenciesDir, 'bpmn-js'); + const rootDir = path.join(dependenciesDir, targetDir); exec(`git checkout ${ref}`, { cwd: rootDir }); console.log(`Checked out ${ref}.`); exec('npm ci', { cwd: rootDir }); console.log('Installed dependencies.'); - try { - exec('yarn link diagram-js', { cwd: rootDir }); - console.log('Linked diagram-js.'); - } catch (error) { - console.log('Unable to link diagram-js.'); - } - - exec('npm run distro', { cwd: rootDir }); - console.log('Built distro.'); - exec('yarn link', { cwd: rootDir }); - exec('yarn link bpmn-js', { cwd: clientDir }); -} + const packageJson = path.join(rootDir, 'package.json'); + const packageName = getPackageName(packageJson); -/** - * - * @param {Dependency} dependency - */ -function linkDiagramJs({ repo, ref }) { - gitClone(repo); - console.log(`Cloned ${repo}.`); - - const rootDir = path.join(dependenciesDir, 'diagram-js'); - exec(`git checkout ${ref}`, { cwd: rootDir }); - console.log(`Checked out ${ref}.`); - - exec('npm ci', { cwd: rootDir }); - console.log('Installed dependencies.'); + exec(`yarn link ${packageName}`, { cwd: clientDir }); - exec('yarn link', { cwd: rootDir }); - - exec('yarn link diagram-js', { cwd: clientDir }); + console.log(`Linked ${packageName}.`); } /** @@ -213,16 +190,26 @@ function linkFormJs({ repo, ref }) { exec('yarn link @bpmn-io/form-js', { cwd: clientDir }); } -function gitClone(repo) { +function gitClone(repo, target = toDirName(repo)) { const repoUrl = getRepoUrl(repo); - exec(`git clone ${repoUrl}`, { cwd: dependenciesDir }); + exec(`git clone ${repoUrl} ${target}`, { cwd: dependenciesDir }); } function getRepoUrl(repo) { return `https://github.com/${repo}.git`; } +function toDirName(repo) { + return repo.replaceAll('/', '-'); +} + +function getPackageName(jsonPath) { + const packageJson = JSON.parse(fs.readFileSync(jsonPath, { encoding: 'utf8' })); + + return packageJson.name; +} + async function del(path) { const delModule = await import('del');