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

Support for override output directory per repository #40

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
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
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
Loading