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

Use snippet prompt for initial details #42

Merged
merged 1 commit into from
Jun 11, 2020
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
4 changes: 3 additions & 1 deletion .changeset/neat-lobsters-suffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
'skuba': minor
---

Add template for private npm packages
**template/private-npm-package:** Add new template

The `private-npm-package` template replaces `smt init`.

This change also defaults TypeScript's `moduleResolution` to `node`.
This shouldn't break any existing consumers as it is the default resolution strategy for CommonJS.
5 changes: 5 additions & 0 deletions .changeset/pretty-dolls-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

**init:** Redesign first prompt
18 changes: 9 additions & 9 deletions src/cli/init/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import {

import { downloadGitHubTemplate } from './git';
import {
BASE_CHOICES,
BaseFields,
BASE_PROMPT,
GIT_PATH_PROMPT,
SHOULD_CONTINUE_PROMPT,
TEMPLATE_PROMPT,
Expand Down Expand Up @@ -133,13 +132,14 @@ export const getTemplateConfig = (dir: string): TemplateConfig => {
};

export const configureFromPrompt = async (): Promise<InitConfig> => {
const baseAnswers = await runForm<BaseFields>({
choices: BASE_CHOICES,
message: 'For starters:',
name: 'baseAnswers',
});

Object.values(baseAnswers).forEach((value) => log.plain(chalk.cyan(value)));
const { values: baseAnswers } = await BASE_PROMPT.run();
log.plain(
chalk.cyan(baseAnswers.repoName),
'by',
chalk.cyan(baseAnswers.teamName),
'in',
chalk.cyan(baseAnswers.orgName),
);

const destinationDir = baseAnswers.repoName;

Expand Down
33 changes: 23 additions & 10 deletions src/cli/init/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
import { Input, Select } from 'enquirer';
import { Input, Select, Snippet } from 'enquirer';
import fs from 'fs-extra';

export type BaseFields = Record<typeof BASE_CHOICES[number]['name'], string>;
type BaseFields = Record<typeof BASE_CHOICES[number]['name'], string>;

export const BASE_CHOICES = [
const BASE_CHOICES = [
{
name: 'repoName',
message: 'Repository',
initial: 'prefix-my-project',
validate: async (value: string) => {
message: 'repo',
validate: async (value: unknown) => {
if (typeof value !== 'string') {
return 'required';
}

const exists = await fs.pathExists(value);

return !exists || `'${value}' is an existing directory`;
},
},
{
name: 'orgName',
message: 'Github org name',
initial: 'my-org',
message: 'org',
initial: 'SEEK-Jobs',
},
{
name: 'teamName',
message: 'GitHub team',
initial: 'my-team',
message: 'team',
},
] as const;

export const BASE_PROMPT = new Snippet<BaseFields>({
fields: BASE_CHOICES,
message: 'For starters:',
name: 'baseAnswers',
required: true,
template: [
'https://github.com/${orgName}/${repoName}',
'https://github.com/orgs/${orgName}/teams/${teamName}',
].join('\n'),
});

export const SHOULD_CONTINUE_PROMPT = new Select({
choices: ['yes', 'no'] as const,
message: 'Fill this in now?',
Expand Down
9 changes: 7 additions & 2 deletions src/enquirer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ declare module 'enquirer' {
constructor(opts: {
name: string;
message: string;
fields: Array<{
fields: ReadonlyArray<{
name: string;
message?: string;
initial?: string;
validate?: (
values: Record<string, string>,
) => boolean | string | Promise<boolean | string>;
}>;
required?: boolean;
template: string;
});

run(): Promise<T>;
run(): Promise<{ result: string; values: T }>;
}
}