Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simplify link-dependencies task #4611

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 23 additions & 36 deletions tasks/link-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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}.`);
}

/**
Expand Down Expand Up @@ -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');

Expand Down