From ede5eb8aa8a1795c4839b1aa51cdeb9a4461a947 Mon Sep 17 00:00:00 2001 From: Michael Goberling Date: Wed, 21 Feb 2024 22:00:43 -0500 Subject: [PATCH] feat: --linter flag (#770) --- src/commands/app/init.js | 14 +++++++---- test/commands/app/init.test.js | 44 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/commands/app/init.js b/src/commands/app/init.js index 9c1bebc5..7f5aa918 100644 --- a/src/commands/app/init.js +++ b/src/commands/app/init.js @@ -115,7 +115,7 @@ class InitCommand extends TemplatesCommand { // 3. run base code generators const projectName = (consoleConfig && consoleConfig.project.name) || path.basename(process.cwd()) - await this.runCodeGenerators(this.getInitialGenerators(flags), flags.yes, projectName) + await this.runCodeGenerators(this.getInitialGenerators(flags), flags.yes, projectName, flags.linter) // 4. install templates await this.installTemplates({ @@ -163,7 +163,7 @@ class InitCommand extends TemplatesCommand { // 7. run base code generators if (!flags.repo) { - await this.runCodeGenerators(this.getInitialGenerators(flags), flags.yes, consoleConfig.project.name) + await this.runCodeGenerators(this.getInitialGenerators(flags), flags.yes, consoleConfig.project.name, flags.linter) } // 8. import config @@ -337,7 +337,7 @@ class InitCommand extends TemplatesCommand { return workspace } - async runCodeGenerators (generatorNames, skipPrompt, projectName) { + async runCodeGenerators (generatorNames, skipPrompt, projectName, linter) { const env = yeoman.createEnv() env.options = { skipInstall: true } @@ -347,7 +347,8 @@ class InitCommand extends TemplatesCommand { options: { 'skip-prompt': skipPrompt, 'project-name': projectName, - force: true + force: true, + linter } }) await env.runGenerator(appGen) @@ -484,6 +485,11 @@ InitCommand.flags = { 'github-pat': Flags.string({ description: 'github personal access token to use for downloading private quickstart repos', dependsOn: ['repo'] + }), + linter: Flags.string({ + description: 'Specify the linter to use for the project', + options: ['none', 'basic', 'adobe-recommended'], + default: 'basic' }) } diff --git a/test/commands/app/init.test.js b/test/commands/app/init.test.js index 09e85fa8..1de0e0f6 100644 --- a/test/commands/app/init.test.js +++ b/test/commands/app/init.test.js @@ -302,6 +302,7 @@ describe('--no-login', () => { }) test('--standalone-app', async () => { + command.runCodeGenerators = jest.fn() const installOptions = { useDefaultValues: false, installNpm: true, @@ -313,6 +314,7 @@ describe('--no-login', () => { await command.run() expect(command.installTemplates).toHaveBeenCalledWith(installOptions) + expect(command.runCodeGenerators).toHaveBeenCalledWith(['base-app', 'add-ci', 'application'], false, 'cwd', 'basic') expect(LibConsoleCLI.init).not.toHaveBeenCalled() expect(importHelperLib.importConfigJson).not.toHaveBeenCalled() }) @@ -448,6 +450,48 @@ describe('--no-login', () => { expect(LibConsoleCLI.init).not.toHaveBeenCalled() expect(importHelperLib.importConfigJson).not.toHaveBeenCalled() }) + + test('--yes --no-login --linter=none', async () => { + command.runCodeGenerators = jest.fn() + const installOptions = { + useDefaultValues: true, + installNpm: true, + installConfig: false, + templates: [] + } + + command.argv = ['--yes', '--no-login', '--linter=none'] + await command.run() + + expect(command.installTemplates).toHaveBeenCalledWith(installOptions) + expect(command.runCodeGenerators).toHaveBeenCalledWith(['base-app', 'add-ci', 'application'], true, 'cwd', 'none') + expect(LibConsoleCLI.init).not.toHaveBeenCalled() + expect(importHelperLib.importConfigJson).not.toHaveBeenCalled() + }) + + test('--yes --no-login --linter=adobe-recommended', async () => { + command.runCodeGenerators = jest.fn() + const installOptions = { + useDefaultValues: true, + installNpm: true, + installConfig: false, + templates: [] + } + + command.argv = ['--yes', '--no-login', '--linter=adobe-recommended'] + await command.run() + + expect(command.installTemplates).toHaveBeenCalledWith(installOptions) + expect(command.runCodeGenerators).toHaveBeenCalledWith(['base-app', 'add-ci', 'application'], true, 'cwd', 'adobe-recommended') + expect(LibConsoleCLI.init).not.toHaveBeenCalled() + expect(importHelperLib.importConfigJson).not.toHaveBeenCalled() + }) + + test('--yes --no-login --linter=invalid', async () => { + command.runCodeGenerators = jest.fn() + command.argv = ['--yes', '--no-login', '--linter=invalid'] + await expect(command.run()).rejects.toThrow('Expected --linter=invalid to be one of: none, basic, adobe-recommended\nSee more help with --help') + }) }) describe('--login', () => {