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

Feature/ask for foundation name #232

Merged
merged 3 commits into from
Sep 18, 2023
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
87 changes: 48 additions & 39 deletions src/commands/foundation/new.command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as colors from "std/fmt/colors";
import { prompt, Select } from "x/cliffy/prompt";
import { Input, prompt, Select } from "x/cliffy/prompt";
import { Logger } from "../../cli/Logger.ts";
import {
Dir,
Expand All @@ -21,45 +21,54 @@ import { CollieConfig } from "../../model/CollieConfig.ts";

export function registerNewCmd(program: TopLevelCommand) {
program
.command("new <foundation:foundation>")
.command("new [foundation:foundation]")
.description("generate a new cloud foundation")
.action(async (opts: GlobalCommandOptions, foundation: string) => {
const repo = await CollieRepository.load();
const logger = new Logger(repo, opts);

const foundationPath = repo.resolvePath("foundations", foundation);

const factory = new CliApiFacadeFactory(repo, logger);

const platformEntries = await promptPlatformEntries(foundation, factory);

const dir = new DirectoryGenerator(WriteMode.skip, logger);
const d: Dir = {
name: foundationPath,
entries: [
{ name: "README.md", content: generateReadmeMd(foundation) },
{
name: "platforms",
entries: [
{
name: "README.md",
content: generatePlatformsReadmeMd(foundation),
},
...platformEntries,
],
},
],
};

await dir.write(d, "");

logger.progress(
"generated new foundation at " + repo.relativePath(foundationPath),
);

const config = new CollieConfig(repo, logger);
config.setProperty("foundation", foundation);
});
.action(
async (opts: GlobalCommandOptions, foundationArg: string | undefined) => {
const foundation: string = foundationArg ||
await Input.prompt(
`Choose a name for your new foundation`,
);
const repo = await CollieRepository.load();
const logger = new Logger(repo, opts);

const foundationPath = repo.resolvePath("foundations", foundation);

const factory = new CliApiFacadeFactory(repo, logger);

const platformEntries = await promptPlatformEntries(
foundation,
factory,
);

const dir = new DirectoryGenerator(WriteMode.skip, logger);
const d: Dir = {
name: foundationPath,
entries: [
{ name: "README.md", content: generateReadmeMd(foundation) },
{
name: "platforms",
entries: [
{
name: "README.md",
content: generatePlatformsReadmeMd(foundation),
},
...platformEntries,
],
},
],
};

await dir.write(d, "");

logger.progress(
"generated new foundation at " + repo.relativePath(foundationPath),
);

const config = new CollieConfig(repo, logger);
config.setProperty("foundation", foundation);
},
);
}

function generateReadmeMd(foundationName: string) {
Expand Down
4 changes: 4 additions & 0 deletions src/model/CollieConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as path from "std/path";
import * as fs from "std/fs";
import { Logger } from "../cli/Logger.ts";
import { CollieRepository } from "./CollieRepository.ts";

Expand Down Expand Up @@ -58,6 +60,8 @@ export class CollieConfig {
}

private async saveToDisk() {
await fs.ensureDir(path.dirname(this.configFilePath));

await Deno.writeTextFile(
this.configFilePath,
JSON.stringify(this.properties),
Expand Down