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

feat: --linter flag #770

Merged
merged 3 commits into from
Feb 22, 2024
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
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
Loading