Skip to content

Commit cbff71a

Browse files
authored
Merge pull request #40 from collective/perrepooutputoverride
Support for override output directory per repository
2 parents 40c8c66 + b0da47a commit cbff71a

File tree

8 files changed

+48
-8
lines changed

8 files changed

+48
-8
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ It is possible to keep a package in mrs-developer.json, but don't process it, by
7272
}
7373
```
7474

75+
You can override the default `output` provided via command line per repository in `mrs.developer.json`.
76+
77+
```json
78+
{
79+
"volto-light-theme": {
80+
"output": "addons",
81+
"package": "@kitconcept/volto-light-theme",
82+
"url": "git@github.com:kitconcept/volto-light-theme.git",
83+
"https": "https://github.com/kitconcept/volto-light-theme.git"
84+
}
85+
}
86+
```
87+
88+
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.
89+
7590
## Usage
7691

7792
```
@@ -154,6 +169,7 @@ Properties:
154169
- `branch`: Optional. Branch name, defaults to the remote's default branch. Ignored if `tag` is defined.
155170
- `tag`: Optional. Tag name.
156171
- `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`.
172+
- `output`: Optional. Output directory override per repository.
157173

158174
## Usage with (non-TypeScript) React
159175

src/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ function getRemotePath(url) {
1818
}
1919
}
2020

21-
function getRepoDir(root, output) {
21+
function getRepoDir({ root, output }, { output: pkgOutput } = {}) {
2222
// Check for download directory; create if needed.
23-
const repoDir = path.join(root || '.', 'src', output || DEVELOP_DIRECTORY);
23+
const repoDir = path.join(
24+
root || '.',
25+
pkgOutput ? '' : 'src',
26+
pkgOutput || output || DEVELOP_DIRECTORY,
27+
);
2428
if (!fs.existsSync(repoDir)) {
2529
console.log(`\nCreating repoDir ${repoDir}`);
2630
fs.mkdirSync(repoDir);
@@ -236,9 +240,10 @@ function checkoutRepository(name, root, settings, options) {
236240
});
237241
}
238242

239-
async function developPackage(pkg, name, options, repoDir) {
243+
async function developPackage(pkg, name, options) {
240244
let gitTag;
241245
const paths = {};
246+
const repoDir = getRepoDir(options, pkg);
242247

243248
if (!pkg.local) {
244249
gitTag = await checkoutRepository(name, repoDir, pkg, options);
@@ -262,14 +267,12 @@ async function developPackage(pkg, name, options, repoDir) {
262267
}
263268

264269
async function developPackages(pkgs, options) {
265-
const repoDir = getRepoDir(options.root, options.output);
266270
const developedPackages = Object.keys(pkgs).filter(
267271
(name) => pkgs[name].develop ?? true,
268272
);
269273
const paths = {};
270274
const tasks = developedPackages.map(
271-
(name) => async () =>
272-
await developPackage(pkgs[name], name, options, repoDir),
275+
(name) => async () => await developPackage(pkgs[name], name, options),
273276
);
274277

275278
let results = [];

test/developTest.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ describe('develop', () => {
2323
const repo3 = await developer.openRepository('repo3', './test/src/develop/repo3');
2424
commits = await repo3.log();
2525
expect(commits.latest.message).to.be.equal('Add file 2');
26+
const repo5 = await developer.openRepository(
27+
'repo5',
28+
'./test/packages/repo5',
29+
);
30+
commits = await repo5.log();
31+
expect(commits.latest.message).to.be.equal('Add file 2');
2632
});
2733

2834
it('updates tsconfig.json with proper paths', async () => {

test/getRepoDirTest.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ const exec = require('child_process').execSync;
88

99
describe('getRepoDir', () => {
1010
it('creates the ./src/develop folder if it does not exist', () => {
11-
developer.getRepoDir('./test');
11+
developer.getRepoDir({ root: './test' });
1212
expect(fs.existsSync('./test/src/develop')).to.be.true;
1313
});
1414

15+
it('creates a folder with no src if it does not exist', () => {
16+
developer.getRepoDir({ root: './test' }, { output: 'packages' });
17+
expect(fs.existsSync('./test/packages')).to.be.true;
18+
});
19+
1520
afterEach(async () => {
1621
await exec('./test/test-clean.sh');
1722
});

test/mrs.developer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@
2323
},
2424
"local1": {
2525
"local": "some/path"
26+
},
27+
"repo5": {
28+
"output": "packages",
29+
"url": "./test/fake-remote/repo1"
2630
}
2731
}

test/test-clean.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
rm -rf test/src/develop test/fake-remote
3+
rm -rf test/src/develop test/fake-remote test/packages

test/tsconfig-1.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
],
2626
"local1": [
2727
"src/some/path"
28+
],
29+
"repo5": [
30+
"src/develop/repo5"
2831
]
2932
},
3033
"baseUrl": "./"

test/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
],
2323
"local1": [
2424
"some/path"
25+
],
26+
"repo5": [
27+
"develop/repo5"
2528
]
2629
},
2730
"baseUrl": "src"

0 commit comments

Comments
 (0)