-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add get linked-repos command
This command renders a list of all linked remote project sources and modules.
- Loading branch information
Showing
4 changed files
with
161 additions
and
0 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,53 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import chalk from "chalk" | ||
import { sortBy } from "lodash" | ||
import { Command, CommandParams, CommandResult } from "../base" | ||
import { LinkedSource } from "../../config-store" | ||
import { printHeader } from "../../logger/util" | ||
import { getLinkedSources } from "../../util/ext-source-util" | ||
import { renderTable } from "../../util/string" | ||
|
||
const getLinkedReposArguments = {} | ||
|
||
type Args = typeof getLinkedReposArguments | ||
|
||
export class GetLinkedReposCommand extends Command { | ||
name = "linked-repos" | ||
help = "Outputs a list of all linked remote sources and modules for this project." | ||
|
||
async action({ garden, log, headerLog }: CommandParams<Args>): Promise<CommandResult<LinkedSource[]>> { | ||
printHeader(headerLog, "List linked modules and sources", "open_book") | ||
|
||
const linkedProjectSources = sortBy(await getLinkedSources(garden, "project"), (s) => s.name) | ||
const linkedModuleSources = sortBy(await getLinkedSources(garden, "module"), (s) => s.name) | ||
|
||
const linkedSources = [...linkedProjectSources, ...linkedModuleSources] | ||
|
||
log.info("") | ||
|
||
if (linkedSources.length === 0) { | ||
log.info(chalk.white("No linked sources or modules found for this project.")) | ||
} else { | ||
const linkedSourcesWithType = [ | ||
...linkedProjectSources.map((s) => ({ ...s, type: "source" })), | ||
...linkedModuleSources.map((s) => ({ ...s, type: "module" })), | ||
] | ||
|
||
const rows = [ | ||
[chalk.bold("Name:"), chalk.bold("Type:"), chalk.bold("Path:")], | ||
...linkedSourcesWithType.map((s) => [chalk.cyan.bold(s.name), chalk.cyan.bold(s.type), s.path.trim()]), | ||
] | ||
|
||
log.info(renderTable(rows)) | ||
} | ||
|
||
return { result: linkedSources } | ||
} | ||
} |
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
97 changes: 97 additions & 0 deletions
97
garden-service/test/unit/src/commands/get/get-linked-repos.ts
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,97 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { expect } from "chai" | ||
import { join } from "path" | ||
import { | ||
resetLocalConfig, | ||
getDataDir, | ||
withDefaultGlobalOpts, | ||
makeExtModuleSourcesGarden, | ||
makeExtProjectSourcesGarden, | ||
TestGarden, | ||
} from "../../../../helpers" | ||
import { LinkSourceCommand } from "../../../../../src/commands/link/source" | ||
import { LinkModuleCommand } from "../../../../../src/commands/link/module" | ||
import { GetLinkedReposCommand } from "../../../../../src/commands/get/get-linked-repos" | ||
|
||
describe("GetLinkedReposCommand", () => { | ||
let garden: TestGarden | ||
|
||
afterEach(async () => { | ||
await resetLocalConfig(garden.gardenDirPath) | ||
}) | ||
|
||
it("should list all linked project sources in the project", async () => { | ||
garden = await makeExtProjectSourcesGarden() | ||
const log = garden.log | ||
const sourcesDir = getDataDir("test-project-local-module-sources") | ||
const linkSourceCmd = new LinkSourceCommand() | ||
const sourceNames = ["source-a", "source-b", "source-c"] | ||
for (const sourceName of sourceNames) { | ||
await linkSourceCmd.action({ | ||
garden, | ||
log, | ||
headerLog: log, | ||
footerLog: log, | ||
args: { source: sourceName, path: join(sourcesDir, sourceName) }, | ||
opts: withDefaultGlobalOpts({}), | ||
}) | ||
} | ||
|
||
const getLinkedReposCommand = new GetLinkedReposCommand() | ||
const results = await getLinkedReposCommand.action({ | ||
garden, | ||
log, | ||
headerLog: log, | ||
footerLog: log, | ||
args: {}, | ||
opts: withDefaultGlobalOpts({}), | ||
}) | ||
|
||
const expected = sourceNames.map((name) => { | ||
return { name, path: join(sourcesDir, name) } | ||
}) | ||
|
||
expect(results.result).to.eql(expected) | ||
}) | ||
|
||
it("should list all linked modules in the project", async () => { | ||
garden = await makeExtModuleSourcesGarden() | ||
const log = garden.log | ||
const sourcesDir = getDataDir("test-project-local-project-sources") | ||
const linkModuleCmd = new LinkModuleCommand() | ||
const sourceNames = ["module-a", "module-b", "module-c"] | ||
for (const moduleName of sourceNames) { | ||
await linkModuleCmd.action({ | ||
garden, | ||
log, | ||
headerLog: log, | ||
footerLog: log, | ||
args: { module: moduleName, path: join(sourcesDir, moduleName) }, | ||
opts: withDefaultGlobalOpts({}), | ||
}) | ||
} | ||
|
||
const getLinkedReposCommand = new GetLinkedReposCommand() | ||
const results = await getLinkedReposCommand.action({ | ||
garden, | ||
log, | ||
headerLog: log, | ||
footerLog: log, | ||
args: {}, | ||
opts: withDefaultGlobalOpts({}), | ||
}) | ||
|
||
const expected = sourceNames.map((name) => { | ||
return { name, path: join(sourcesDir, name) } | ||
}) | ||
|
||
expect(results.result).to.eql(expected) | ||
}) | ||
}) |