Skip to content

Commit

Permalink
feat: add scan command to output info about modules in project
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald authored and eysi09 committed May 14, 2018
1 parent 7ba24b7 commit 075e6c2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { safeDump } from "js-yaml"
import * as sywac from "sywac"
import chalk from "chalk"
import { RunCommand } from "./commands/run"
import { ScanCommand } from "./commands/scan"
import { DeepPrimitiveMap } from "./types/common"
import { enumToArray, shutdown } from "./util"
import { merge, intersection, reduce } from "lodash"
Expand Down Expand Up @@ -247,6 +248,7 @@ export class GardenCli {
new LogsCommand(),
new PushCommand(),
new RunCommand(),
new ScanCommand(),
new StatusCommand(),
new TestCommand(),
new ValidateCommand(),
Expand Down
43 changes: 43 additions & 0 deletions src/commands/scan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2018 Garden Technologies, Inc. <info@garden.io>
*
* 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 { safeDump } from "js-yaml"
import { PluginContext } from "../plugin-context"
import { highlightYaml } from "../util"
import { Command } from "./base"
import Bluebird = require("bluebird")
import {
mapValues,
omit,
} from "lodash"

export class ScanCommand extends Command {
name = "scan"
help = "Scans your project and outputs an overview of all modules"

async action(ctx: PluginContext) {
const modules = await ctx.getModules()

const output = await Bluebird.props(mapValues(modules, async (m) => {
return {
name: m.name,
type: m.type,
path: m.path,
description: m.config.description,
version: await m.getVersion(),
config: m.config,
}
}))

const shortOutput = mapValues(output, m => omit(m, ["config"]))

ctx.log.info(highlightYaml(safeDump(shortOutput, { noRefs: true, skipInvalid: true })))

return output
}
}

0 comments on commit 075e6c2

Please sign in to comment.