Skip to content

Commit

Permalink
Merge pull request #40 from collective/perrepooutputoverride
Browse files Browse the repository at this point in the history
Support for override output directory per repository
  • Loading branch information
sneridagh authored Mar 11, 2024
2 parents 40c8c66 + b0da47a commit cbff71a
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 8 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down Expand Up @@ -154,6 +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.

## Usage with (non-TypeScript) React

Expand Down
15 changes: 9 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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 = [];
Expand Down
6 changes: 6 additions & 0 deletions test/developTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
7 changes: 6 additions & 1 deletion test/getRepoDirTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
4 changes: 4 additions & 0 deletions test/mrs.developer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@
},
"local1": {
"local": "some/path"
},
"repo5": {
"output": "packages",
"url": "./test/fake-remote/repo1"
}
}
2 changes: 1 addition & 1 deletion test/test-clean.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

rm -rf test/src/develop test/fake-remote
rm -rf test/src/develop test/fake-remote test/packages
3 changes: 3 additions & 0 deletions test/tsconfig-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
],
"local1": [
"src/some/path"
],
"repo5": [
"src/develop/repo5"
]
},
"baseUrl": "./"
Expand Down
3 changes: 3 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
],
"local1": [
"some/path"
],
"repo5": [
"develop/repo5"
]
},
"baseUrl": "src"
Expand Down

0 comments on commit cbff71a

Please sign in to comment.