Skip to content

Commit

Permalink
feat: --linter flag (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelGoberling authored Feb 22, 2024
1 parent cb59ac5 commit ede5eb8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/commands/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }

Expand All @@ -347,7 +347,8 @@ class InitCommand extends TemplatesCommand {
options: {
'skip-prompt': skipPrompt,
'project-name': projectName,
force: true
force: true,
linter
}
})
await env.runGenerator(appGen)
Expand Down Expand Up @@ -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'
})
}

Expand Down
44 changes: 44 additions & 0 deletions test/commands/app/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ describe('--no-login', () => {
})

test('--standalone-app', async () => {
command.runCodeGenerators = jest.fn()
const installOptions = {
useDefaultValues: false,
installNpm: true,
Expand All @@ -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()
})
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit ede5eb8

Please sign in to comment.