Skip to content

Commit

Permalink
add subrepo subdirectory functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
rpmccarter committed May 9, 2024
1 parent 47cb893 commit a0c4672
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ the target branch
A stringified yaml array containing objects representing the
mintlify docs repositories to be aggregated. These objects
have the following properties:
- `owner`: **(required)** the owner/org of the repo
- `repo`: **(required)** the name of the repo
- `ref`: the branch/ref at which to check out the repository
- `owner`: **(required)** the owner/org of the subrepo
- `repo`: **(required)** the name of the subrepo
- `ref`: the branch/ref at which to check out the subrepo
- `subdirectory`: path to the directory containing the subrepo's `mint.json`

### target-branch (required)

Expand Down
12 changes: 10 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,22 @@ try {
await checkoutBranch(targetBranch);
const mainConfig = JSON.parse(await readFile('mint.json', 'utf-8'));
resetToken = await setToken(token);
for (const { owner, repo, ref } of repos) {
for (const { owner, repo, ref, subdirectory: subrepoSubdirectory } of repos) {
await io.rmRF(repo);
const args = ['clone', '--depth=1'];
if (ref)
args.push('--branch', ref);
args.push(`https://github.com/${owner}/${repo}`);
await execOrThrow('git', args);
await io.rmRF(`${repo}/.git`);
if (subrepoSubdirectory) {
const tempDirName = 'temporary-docs-dir';
await io.mv(path.join(repo, subrepoSubdirectory), tempDirName);
await io.rmRF(repo);
await io.mv(tempDirName, repo);
}
else {
await io.rmRF(`${repo}/.git`);
}
const subConfig = JSON.parse(await readFile(path.join(repo, 'mint.json'), 'utf-8'));
mainConfig.navigation = mergeNavigation(mainConfig.navigation, subConfig.navigation, repo);
}
Expand Down
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Repo = {
owner: string;
repo: string;
ref?: string;
subdirectory?: string;
}

const execOrThrow: (...args: Parameters<typeof exec.exec>) => Promise<void> = async (...args) => {
Expand Down Expand Up @@ -72,15 +73,23 @@ try {
const mainConfig = JSON.parse(await readFile('mint.json', 'utf-8')) as MintConfig;

resetToken = await setToken(token);
for (const { owner, repo, ref } of repos) {
for (const { owner, repo, ref, subdirectory: subrepoSubdirectory } of repos) {
await io.rmRF(repo);

const args = ['clone', '--depth=1'];
if (ref) args.push('--branch', ref);
args.push(`https://github.com/${owner}/${repo}`);

await execOrThrow('git', args);
await io.rmRF(`${repo}/.git`);

if (subrepoSubdirectory) {
const tempDirName = 'temporary-docs-dir';
await io.mv(path.join(repo, subrepoSubdirectory), tempDirName);
await io.rmRF(repo);
await io.mv(tempDirName, repo);
} else {
await io.rmRF(`${repo}/.git`);
}

const subConfig = JSON.parse(await readFile(path.join(repo, 'mint.json'), 'utf-8')) as MintConfig;
mainConfig.navigation = mergeNavigation(mainConfig.navigation, subConfig.navigation, repo);
Expand Down

0 comments on commit a0c4672

Please sign in to comment.