-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add interactive module id selection to "kit import" command
- Loading branch information
1 parent
cf42711
commit d26b738
Showing
4 changed files
with
97 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as fs from "std/fs"; | ||
import { GitCliFacade } from "../../api/git/GitCliFacade.ts"; | ||
import { CollieRepository } from "../../model/CollieRepository.ts"; | ||
|
||
export class KitModuleHub { | ||
constructor( | ||
private readonly git: GitCliFacade, | ||
private readonly repo: CollieRepository, | ||
) {} | ||
private readonly hubCacheDirPath = [".collie", "hub"]; | ||
|
||
// hardcoding this is ok for now | ||
readonly url = | ||
"https://github.com/meshcloud/landing-zone-construction-kit.git"; | ||
|
||
public async import(id: string, moduleDestDir: string, overwrite?: boolean) { | ||
const moduleSrcDir = this.repo.resolvePath( | ||
...this.hubCacheDirPath, | ||
"kit", | ||
id, | ||
); | ||
|
||
await fs.copy(moduleSrcDir, moduleDestDir, { overwrite: overwrite }); | ||
} | ||
|
||
async updateHubClone() { | ||
const hubCacheDir = this.repo.resolvePath(...this.hubCacheDirPath); | ||
|
||
// we do keep a git clone of the repo locally because copying on the local FS is much faster than downloading and | ||
// extracting a huge tarball | ||
await fs.ensureDir(hubCacheDir); | ||
|
||
const hubCacheGitDir = this.repo.resolvePath( | ||
...this.hubCacheDirPath, | ||
".git", | ||
); | ||
const hasAlreadyCloned = await this.git.isRepo(hubCacheGitDir); | ||
|
||
if (hasAlreadyCloned) { | ||
await this.git.pull(hubCacheDir); | ||
} else { | ||
await this.git.clone(hubCacheDir, this.url); | ||
} | ||
|
||
return hubCacheDir; | ||
} | ||
|
||
public async cleanHubClone() { | ||
const hubCacheDir = this.repo.resolvePath(...this.hubCacheDirPath); | ||
await Deno.remove(hubCacheDir, { recursive: true }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters