diff --git a/docs/en/create-hermione-app.md b/docs/en/create-hermione-app.md index 2af6a5f..ccf1f75 100644 --- a/docs/en/create-hermione-app.md +++ b/docs/en/create-hermione-app.md @@ -14,19 +14,21 @@ Without specifying the path, project will be created in the current directory. If you already have a project at given path, the tool will try to guess used package manager. -### No questions mode +### Extra questions mode -You can add `-y` or `--yes` argument to launch a tool in *no-questions* mode: +By default, project will be created with zero questions. + +You can add `-v` or `--verbose` argument to launch a tool in *extra-questions* mode, to pick custom package manager or pick extra plugins: ```bash -npm init hermione-app my-app -- -y +npm init hermione-app my-app -- -v ``` In this mode you won't be asked questions about desired plugins and packet manager. -Default packet manager, used with `--yes` argument: `npm` +Default packet manager, used without `--verbose` argument: `npm` -Default plugins, installed with `--yes` argument: +Default plugins, installed without `--verbose` argument: - [html-reporter](https://github.com/gemini-testing/html-reporter) ### Lang @@ -86,14 +88,14 @@ createHermioneApp.run({ **Required parameter** -Default tool's CLI handles given path and `--yes` argument. In this callback you need to at least specify `path` and `noQuestions` values: +Default tool's CLI handles given path and `--verbose` argument. In this callback you need to at least specify `path` and `extraQuestions` values: ```ts import type { DefaultOpts } from "create-hermione-app"; const argvOpts = { path: ".", - noQuestions: true + extraQuestions: false }; const createOpts = (defaultOpts: DefaultOpts) => { @@ -160,7 +162,7 @@ const generalPromptsHandler: HandleGeneralPromptsCallback = (hermioneConfig, ans }; ``` -If `GeneralPrompt` does not have `default` value, the question will be asked even with `noQuestions: true` +If `GeneralPrompt` does not have `default` value, the question will be asked with `extraQuestions: false` #### createPluginsConfig @@ -245,7 +247,7 @@ const createOpts = (defaultOpts: DefaultOpts) => { return { ...defaultOpts, path: ".", - noQuestions: false + extraQuestions: false }; }; ``` diff --git a/docs/ru/create-hermione-app.md b/docs/ru/create-hermione-app.md index 8ee6396..3408e43 100644 --- a/docs/ru/create-hermione-app.md +++ b/docs/ru/create-hermione-app.md @@ -14,15 +14,21 @@ npm init hermione-app my-app Если по указанному пути уже имеется проект, инструмент попробует определить используемый пакетный менеджер, и будет использовать его для установки пакетов. -### Режим «без вопросов» +### Режим продвинутой установки -Вы можете добавить аргумент `-y` или `--yes` чтобы запустить инструмент в режиме «без вопросов». +По умолчанию, проект будет настроен без всяких вопросов. + +Для запуска инструмента в режиме продвинутой установки, Вы можете добавить аргумент `-v` или `--verbose`. Это позволит выбрать пакетный менеджер или сразу установить дополнительные плагины. + +```bash +npm init hermione-app my-app -- -v +``` В этом режиме у вас не будут спрашивать о желаемых плагинах и пакетном менеджере, будут использоваться настройки по умолчанию. -Пакетный менеджер по умолчанию, используемый с аргументом `--yes`: `npm` +Пакетный менеджер по умолчанию, используемый без аргумента `--verbose`: `npm` -Плагины по умолчанию, устанавливаемые с аргументом `--yes`: +Плагины по умолчанию, устанавливаемые без аргумента `--verbose`: - [html-reporter](https://github.com/gemini-testing/html-reporter) ### Язык @@ -82,15 +88,15 @@ createHermioneApp.run({ **Обязательный параметр.** -Консольный интерфейс по умолчанию обрабатывает данный путь и аргумент `--yes`. -В этом коллбэке вам необходимо указать как минимум значения `path` и `noQuestions`: +Консольный интерфейс по умолчанию обрабатывает данный путь и аргумент `--verbose`. +В этом коллбэке вам необходимо указать, как минимум, значения `path` и `extraQuestions`: ```ts import type { DefaultOpts } from "create-hermione-app"; const argvOpts = { path: ".", - noQuestions: true + extraQuestions: false }; const createOpts = (defaultOpts: DefaultOpts) => { @@ -156,7 +162,7 @@ const generalPromptsHandler: HandleGeneralPromptsCallback = (hermioneConfig, ans }; ``` -Если у `GeneralPrompt` не указать значение по умолчанию, вопрос будет задан даже при `noQuestions: true` +Если у `GeneralPrompt` не указать значение по умолчанию, вопрос будет задан даже при `extraQuestions: false` #### createPluginsConfig @@ -241,7 +247,7 @@ const createOpts = (defaultOpts: DefaultOpts) => { return { ...defaultOpts, path: ".", - noQuestions: false + extraQuestions: false }; }; ``` diff --git a/src/bin/create-hermione-app.ts b/src/bin/create-hermione-app.ts index ed6e56d..8111d09 100644 --- a/src/bin/create-hermione-app.ts +++ b/src/bin/create-hermione-app.ts @@ -17,11 +17,11 @@ const argv = yargs(hideBin(process.argv)) description: "Language, which will be used to write hermione tests", choices: ["ts", "js"], }) - .option("yes", { - alias: "y", + .option("verbose", { + alias: "v", type: "boolean", default: false, - description: "Auto configuration with 0 questions", + description: "Advanced configuration with extra questions", }) .parse(); diff --git a/src/configBuilder.test.ts b/src/configBuilder.test.ts index 122a6fd..0a41804 100644 --- a/src/configBuilder.test.ts +++ b/src/configBuilder.test.ts @@ -47,7 +47,7 @@ describe("configBuilder", () => { describe("should do nothing if", () => { it("prompts are empty", () => { - configBuilder.handleGeneralQuestions([], [jest.fn()], { path: "/", noQuestions: false }); + configBuilder.handleGeneralQuestions([], [jest.fn()], { path: "/", extraQuestions: true }); expectConfig(defaultHermioneConfig); }); @@ -55,14 +55,14 @@ describe("configBuilder", () => { it("handlers are empty", () => { configBuilder.handleGeneralQuestions([{ message: "foo", type: "input", name: "bar" }], [], { path: "/", - noQuestions: false, + extraQuestions: true, }); expectConfig(defaultHermioneConfig); }); }); - it("should not ask extra questions in 'noQuestions' mode", () => { + it("should not ask extra questions if 'extraQuestions' is not set", () => { configBuilder.handleGeneralQuestions( [ { message: "first silent question", type: "input", name: "1", default: "42" }, @@ -70,7 +70,7 @@ describe("configBuilder", () => { { message: "second silent question", type: "input", name: "3", default: "42" }, ], [jest.fn()], - { path: "/", noQuestions: true }, + { path: "/", extraQuestions: false }, ); expect(inquirer.prompt).toBeCalledWith([{ message: "loud question", type: "input", name: "2" }]); @@ -93,7 +93,7 @@ describe("configBuilder", () => { configBuilder.handleGeneralQuestions(questions, [firstHandler, secondHandler], { path: "/", - noQuestions: false, + extraQuestions: true, }); }); }); diff --git a/src/configBuilder.ts b/src/configBuilder.ts index 1c7fe6f..dc06774 100644 --- a/src/configBuilder.ts +++ b/src/configBuilder.ts @@ -35,7 +35,7 @@ export class ConfigBuilder { async handleGeneralQuestions( promts: GeneralPrompt[], handlers: HandleGeneralPromptsCallback[], - { path, noQuestions }: { path: string; noQuestions: boolean }, + { path, extraQuestions }: { path: string; extraQuestions: boolean }, ): Promise { const answers: Answers = { _path: path, @@ -54,7 +54,7 @@ export class ConfigBuilder { return acc; }, {}); - const promptsToAsk = noQuestions ? promts.filter(prompt => _.isUndefined(prompt.default)) : promts; + const promptsToAsk = extraQuestions ? promts : promts.filter(prompt => _.isUndefined(prompt.default)); const inquirerAnswers = await inquirer.prompt(promptsToAsk); Object.assign(answers, defaults, inquirerAnswers, answers); diff --git a/src/index.ts b/src/index.ts index b5fd78e..1c7e7d9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,7 +59,7 @@ export const run = async ({ const opts = createOpts(defaultToolOpts); const configBuilder = ConfigBuilder.create(createBaseConfig, { language: opts.language }); - const packageManager = await initApp(opts.path, opts.noQuestions); + const packageManager = await initApp(opts.path, opts.extraQuestions); const generalPromptsHandlers = generalPromptsHandler ? [baseGeneralPromptsHandler, generalPromptsHandler] diff --git a/src/package.ts b/src/package.ts index 9a647a2..69ab7b0 100644 --- a/src/package.ts +++ b/src/package.ts @@ -14,7 +14,7 @@ import { Colors } from "./utils/colors"; import { askQuestion, packageNameFromPlugin } from "./utils"; import type { PackageManager } from "./constants/packageManagement"; -const getPackageManager = async (dirPath: string, noQuestions: boolean): Promise => { +const getPackageManager = async (dirPath: string, extraQuestions: boolean): Promise => { let packageManager: PackageManager | undefined; const packageManagers = Object.keys(PMS) as PackageManager[]; await Promise.all( @@ -30,7 +30,7 @@ const getPackageManager = async (dirPath: string, noQuestions: boolean): Promise return packageManager; } - if (noQuestions) { + if (!extraQuestions) { return DEFAULT_PM; } @@ -54,7 +54,7 @@ const initNodeProject = (dirPath: string, packageManager: PackageManager): Promi ); }); -export const initApp = async (dirPath: string, noQuestions: boolean): Promise => { +export const initApp = async (dirPath: string, extraQuestions: boolean): Promise => { await fsUtils.ensureDirectory(dirPath); const isHermioneJsConfigExist = await fsUtils.exists(path.resolve(dirPath, HERMIONE_JS_CONFIG_NAME)); @@ -73,7 +73,7 @@ export const initApp = async (dirPath: string, noQuestions: boolean): Promise => { - return opts.noQuestions ? getDefaultPluginNames(opts) : await askPluginNames(opts); + return opts.extraQuestions ? await askPluginNames(opts) : getDefaultPluginNames(opts); }; diff --git a/src/types/toolArgv.ts b/src/types/toolArgv.ts index a1c44ec..2d854dc 100644 --- a/src/types/toolArgv.ts +++ b/src/types/toolArgv.ts @@ -3,6 +3,6 @@ import { Language } from "./hermioneConfig"; export interface ToolArgv { $0: string; _: string[]; - yes?: boolean; + verbose?: boolean; lang?: Language; } diff --git a/src/types/toolOpts.ts b/src/types/toolOpts.ts index f3c25b7..b8329d9 100644 --- a/src/types/toolOpts.ts +++ b/src/types/toolOpts.ts @@ -33,7 +33,7 @@ export type HandleGeneralPromptsCallback = ( export interface ArgvOpts { path: string; language: Language; - noQuestions: boolean; + extraQuestions: boolean; } export interface DefaultOpts { diff --git a/src/utils/index.test.ts b/src/utils/index.test.ts index 1384016..f7003d7 100644 --- a/src/utils/index.test.ts +++ b/src/utils/index.test.ts @@ -49,17 +49,17 @@ describe("utils", () => { expect(result.path).toBe("/cwd/some folder"); }); - describe("should return noQuestions", () => { + describe("should return extraQuestions", () => { [true, false, undefined].forEach(state => { - it(`if "yes" is "${state}"`, () => { + it(`if "verbose" is "${state}"`, () => { const result = utils.optsFromArgv({ _: ["some folder"], $0: "", lang: "ts", - yes: state, + verbose: state, }); - expect(result.noQuestions).toBe(Boolean(state)); + expect(result.extraQuestions).toBe(Boolean(state)); }); }); }); diff --git a/src/utils/index.ts b/src/utils/index.ts index 07d8df2..2081477 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -20,7 +20,7 @@ export const optsFromArgv = (argv: ToolArgv): ArgvOpts => { return { path: path.resolve(process.cwd(), argv["_"][0]), language: argv.lang === "js" ? "js" : "ts", - noQuestions: Boolean(argv.yes), + extraQuestions: Boolean(argv.verbose), }; };