diff --git a/src/cli/commands/default.ts b/src/cli/commands/default.ts index a87ac9c..651aaf5 100644 --- a/src/cli/commands/default.ts +++ b/src/cli/commands/default.ts @@ -6,22 +6,47 @@ import { GlobalOptions } from "../types.ts"; import { outputErrors } from "../../plugin/errors.ts"; import { context } from "../../plugin/mod.ts"; import { ensureFile } from "../../../deps.ts"; +import { errorCodes } from "../errors.ts"; +import { config } from "../../config/mod.ts"; type DefaultOptions = GlobalOptions; +const WARN_NOTHING_DETECTED = ` +Check the available stacks at the project README: +https://github.com/pipelinit/pipelinit-cli#support-overview + +If your project has one of the available stacks and it +wasn't detected by pipelinit, this is probably a bug. Please +run pipelinit again with the --debug flag and open an issue here: +https://github.com/pipelinit/pipelinit-cli/issues/new + +If you didn't see your stack there and wish it to be included, +start a discussion proposing the new stack here: +https://github.com/pipelinit/pipelinit-cli/discussions/new +`; + export default async function (opts: DefaultOptions): Promise { await prelude(opts); const logger = context.getLogger("main"); const detected = await introspect(); - const platform = "github"; - const files = await platformWriters[platform]( - context, - renderTemplates(platform, detected), - ); - for (const { path, content } of files) { - logger.info(`Writing ${path}`); - await ensureFile(path); - await Deno.writeTextFile(path, content); + + if (Object.keys(detected).length === 0) { + logger.error(WARN_NOTHING_DETECTED); + Deno.exit(errorCodes.NO_STACK_DETECTED); } + + const platforms = config.platforms!; + for (const platform of platforms) { + const files = await platformWriters[platform]( + context, + renderTemplates(platform, detected), + ); + for (const { path, content } of files) { + logger.info(`Writing ${path}`); + await ensureFile(path); + await Deno.writeTextFile(path, content); + } + } + outputErrors(); } diff --git a/src/cli/errors.ts b/src/cli/errors.ts new file mode 100644 index 0000000..10a8497 --- /dev/null +++ b/src/cli/errors.ts @@ -0,0 +1,3 @@ +export const errorCodes = { + NO_STACK_DETECTED: 2, +}; diff --git a/src/cli/prelude/config.ts b/src/cli/prelude/config.ts index 3176075..f1dfa12 100644 --- a/src/cli/prelude/config.ts +++ b/src/cli/prelude/config.ts @@ -2,6 +2,20 @@ import { Checkbox, log } from "../../../deps.ts"; import { config } from "../../config/mod.ts"; import { isPlatform } from "../../platform/mod.ts"; +// TODO +// The handling of some specific key presses on Windows doesn't +// work correclty in Deno. As a workaround, the checkbox prompt +// uses "u" and "d" to navigate across options. This hint informs +// that to the user. We should remove this hint when the expected +// behavior (up and down arrow keys) are available. +// +// Keep an eye on those issues: +// https://github.com/c4spar/deno-cliffy/issues/272 +// https://github.com/denoland/deno/issues/5945 +const NAV_HINT = Deno.build.os === "windows" + ? "Press to select, use 'u' and 'd' keys to navigate" + : "Press to select, use arrow keys to navigate"; + export async function configure() { const logger = log.getLogger("main"); // Load the project config if it exists @@ -15,9 +29,12 @@ export async function configure() { logger.info("Configure this project"); const ciPlatforms = (await Checkbox.prompt({ message: "Which platforms does this project use?", + minOptions: 1, // The user must select at least one + hint: NAV_HINT, options: [ { name: "GitHub Actions", value: "github", checked: true }, { name: "GitLab CI (coming soon)", value: "gitlab", disabled: true }, + { name: "Travis CI (coming soon)", value: "travis", disabled: true }, ], })).filter(isPlatform); diff --git a/src/stack/introspection.ts b/src/stack/introspection.ts index 3acb409..268dbc3 100644 --- a/src/stack/introspection.ts +++ b/src/stack/introspection.ts @@ -40,7 +40,11 @@ export async function introspect() { logger.info("Detecting stack..."); const stack = await detected(); const stackNames = stack.map((t) => t.name).sort().join(", "); - logger.info(`Detected stack: ${stackNames}`); + if (stackNames.length === 0) { + logger.warning("No stack detected!"); + } else { + logger.info(`Detected stack: ${stackNames}`); + } const introspected = (await Promise.all( stack.map>>((introspector) =>