From 60ea354473dd74fa44646aeab40b62ffbeccefa6 Mon Sep 17 00:00:00 2001 From: Victor Fernandez de Alba Date: Sat, 9 Mar 2024 00:21:26 +0100 Subject: [PATCH 1/3] Support for override output directory per repository --- src/index.js | 15 +++++++++------ test/developTest.js | 6 ++++++ test/getRepoDirTest.js | 7 ++++++- test/mrs.developer.json | 4 ++++ test/test-clean.sh | 2 +- test/tsconfig-1.json | 3 +++ test/tsconfig.json | 3 +++ 7 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index 775165e..65b4e88 100644 --- a/src/index.js +++ b/src/index.js @@ -18,9 +18,13 @@ function getRemotePath(url) { } } -function getRepoDir(root, output) { +function getRepoDir({ root, output }, { output: pkgOutput } = {}) { // Check for download directory; create if needed. - const repoDir = path.join(root || '.', 'src', output || DEVELOP_DIRECTORY); + const repoDir = path.join( + root || '.', + pkgOutput ? '' : 'src', + pkgOutput || output || DEVELOP_DIRECTORY, + ); if (!fs.existsSync(repoDir)) { console.log(`\nCreating repoDir ${repoDir}`); fs.mkdirSync(repoDir); @@ -236,9 +240,10 @@ function checkoutRepository(name, root, settings, options) { }); } -async function developPackage(pkg, name, options, repoDir) { +async function developPackage(pkg, name, options) { let gitTag; const paths = {}; + const repoDir = getRepoDir(options, pkg); if (!pkg.local) { gitTag = await checkoutRepository(name, repoDir, pkg, options); @@ -262,14 +267,12 @@ async function developPackage(pkg, name, options, repoDir) { } async function developPackages(pkgs, options) { - const repoDir = getRepoDir(options.root, options.output); const developedPackages = Object.keys(pkgs).filter( (name) => pkgs[name].develop ?? true, ); const paths = {}; const tasks = developedPackages.map( - (name) => async () => - await developPackage(pkgs[name], name, options, repoDir), + (name) => async () => await developPackage(pkgs[name], name, options), ); let results = []; diff --git a/test/developTest.js b/test/developTest.js index d90ef58..9385e7f 100644 --- a/test/developTest.js +++ b/test/developTest.js @@ -23,6 +23,12 @@ describe('develop', () => { const repo3 = await developer.openRepository('repo3', './test/src/develop/repo3'); commits = await repo3.log(); expect(commits.latest.message).to.be.equal('Add file 2'); + const repo5 = await developer.openRepository( + 'repo5', + './test/packages/repo5', + ); + commits = await repo5.log(); + expect(commits.latest.message).to.be.equal('Add file 2'); }); it('updates tsconfig.json with proper paths', async () => { diff --git a/test/getRepoDirTest.js b/test/getRepoDirTest.js index 8259b94..b041bbf 100644 --- a/test/getRepoDirTest.js +++ b/test/getRepoDirTest.js @@ -8,10 +8,15 @@ const exec = require('child_process').execSync; describe('getRepoDir', () => { it('creates the ./src/develop folder if it does not exist', () => { - developer.getRepoDir('./test'); + developer.getRepoDir({ root: './test' }); expect(fs.existsSync('./test/src/develop')).to.be.true; }); + it('creates a folder with no src if it does not exist', () => { + developer.getRepoDir({ root: './test' }, { output: 'packages' }); + expect(fs.existsSync('./test/packages')).to.be.true; + }); + afterEach(async () => { await exec('./test/test-clean.sh'); }); diff --git a/test/mrs.developer.json b/test/mrs.developer.json index d945292..355dd61 100644 --- a/test/mrs.developer.json +++ b/test/mrs.developer.json @@ -23,5 +23,9 @@ }, "local1": { "local": "some/path" + }, + "repo5": { + "output": "packages", + "url": "./test/fake-remote/repo1" } } diff --git a/test/test-clean.sh b/test/test-clean.sh index 072d5ef..a037f69 100755 --- a/test/test-clean.sh +++ b/test/test-clean.sh @@ -1,3 +1,3 @@ #!/bin/bash -rm -rf test/src/develop test/fake-remote \ No newline at end of file +rm -rf test/src/develop test/fake-remote test/packages diff --git a/test/tsconfig-1.json b/test/tsconfig-1.json index 2523cc7..843ef4e 100644 --- a/test/tsconfig-1.json +++ b/test/tsconfig-1.json @@ -25,6 +25,9 @@ ], "local1": [ "src/some/path" + ], + "repo5": [ + "src/develop/repo5" ] }, "baseUrl": "./" diff --git a/test/tsconfig.json b/test/tsconfig.json index 7995ce0..f56cf7a 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -22,6 +22,9 @@ ], "local1": [ "some/path" + ], + "repo5": [ + "develop/repo5" ] }, "baseUrl": "src" From 44b6d7278bc27956865b43398553c7c3d55e3f56 Mon Sep 17 00:00:00 2001 From: Victor Fernandez de Alba Date: Sat, 9 Mar 2024 00:24:28 +0100 Subject: [PATCH 2/3] Docs --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 87166c5..861f628 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,7 @@ Properties: - `branch`: Optional. Branch name, defaults to the remote's default branch. Ignored if `tag` is defined. - `tag`: Optional. Tag name. - `develop`: Optional. Boolean, can be toggled on/off to activate/deactivate a package. If activated, then deactivated afterwards, the package gets removed from `jsconfig` maintaining the synchronization with `mrs.developer.json`. Default is `true`. +- `output`: Optional. Output directory override per repository. It also removes the `src/` prefix. If you still want it, you have to pass it along with the new output. ## Usage with (non-TypeScript) React From b0da47aea1cd9cb95c980130a8acdaf861f7d45d Mon Sep 17 00:00:00 2001 From: Victor Fernandez de Alba Date: Mon, 11 Mar 2024 09:38:07 +0100 Subject: [PATCH 3/3] Improve docs --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 861f628..128dbc6 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,21 @@ It is possible to keep a package in mrs-developer.json, but don't process it, by } ``` +You can override the default `output` provided via command line per repository in `mrs.developer.json`. + +```json +{ + "volto-light-theme": { + "output": "addons", + "package": "@kitconcept/volto-light-theme", + "url": "git@github.com:kitconcept/volto-light-theme.git", + "https": "https://github.com/kitconcept/volto-light-theme.git" + } +} +``` + +This repository will be checked out in the `addons` directory, instead of the one provided via command line. It won't prepend the `src` prefix to it, if you still want it, you should provide it in the `output` key. This might be useful in combination with monorepos where you want to checkout packages into workspaces folders. + ## Usage ``` @@ -154,7 +169,7 @@ Properties: - `branch`: Optional. Branch name, defaults to the remote's default branch. Ignored if `tag` is defined. - `tag`: Optional. Tag name. - `develop`: Optional. Boolean, can be toggled on/off to activate/deactivate a package. If activated, then deactivated afterwards, the package gets removed from `jsconfig` maintaining the synchronization with `mrs.developer.json`. Default is `true`. -- `output`: Optional. Output directory override per repository. It also removes the `src/` prefix. If you still want it, you have to pass it along with the new output. +- `output`: Optional. Output directory override per repository. ## Usage with (non-TypeScript) React