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

refactor: remove any code related to install prompt #4

Merged
merged 3 commits into from
Jun 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
43 changes: 5 additions & 38 deletions commands/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ export class CreateNewApp extends BaseCommand {
})
declare token?: string

/**
* Auto install packages after creating the project. Display prompt
* when flag is not mentioned.
*/
@flags.boolean({
description: 'Force install or skip dependencies installation',
showNegatedVariantInHelp: true,
})
declare install?: boolean

/**
* Init git repository. Do not init when flag is not mentioned.
*/
Expand Down Expand Up @@ -270,20 +260,6 @@ export class CreateNewApp extends BaseCommand {
}
}

/**
* Prompt to check if we should install dependencies?
*/
async #promptForInstallingDeps() {
if (this.install === undefined) {
this.install = await this.prompt.confirm(
`Do you want to install dependencies using "${this.packageManager}"`,
{
default: true,
}
)
}
}

/**
* Replace the package.json name with the destination directory name.
* Errors are ignored.
Expand Down Expand Up @@ -331,10 +307,6 @@ export class CreateNewApp extends BaseCommand {
* Generate a fresh app key. Errors are ignored
*/
async #generateFreshAppKey() {
if (this.install === false) {
return
}

await this.#runBashCommand('node', ['ace', 'generate:key'])
}

Expand Down Expand Up @@ -403,7 +375,7 @@ export class CreateNewApp extends BaseCommand {
'--adapter',
this.adapter!,
this.ssr ? '--ssr' : '--no-ssr',
this.install ? '--install' : '--no-install',
'--install',
]

if (this.verbose) {
Expand Down Expand Up @@ -442,8 +414,6 @@ export class CreateNewApp extends BaseCommand {
await this.#promptForInertiaSsr()
}

await this.#promptForInstallingDeps()

/**
* Create tasks instance for displaying
* actions as tasks
Expand All @@ -456,23 +426,20 @@ export class CreateNewApp extends BaseCommand {
*/
const configureLucid =
[WEB_STARTER_KIT, API_STARTER_KIT, INERTIA_STARTER_KIT].includes(this.kit || '') &&
this.db !== 'skip' &&
this.install !== false
this.db !== 'skip'

/**
* Configure auth when using our own starter kits
* and installing dependencies
*/
const configureAuth =
[WEB_STARTER_KIT, API_STARTER_KIT, INERTIA_STARTER_KIT].includes(this.kit || '') &&
this.authGuard !== 'skip' &&
this.install !== false
this.authGuard !== 'skip'

/**
* Configure inertia when using our inertia starter kit
*/
const configureInertia =
this.kit === INERTIA_STARTER_KIT && this.adapter !== 'skip' && this.install !== false
const configureInertia = this.kit === INERTIA_STARTER_KIT && this.adapter !== 'skip'

tasks
.add('Download starter kit', async (task) => {
Expand All @@ -489,7 +456,7 @@ export class CreateNewApp extends BaseCommand {
await this.#runBashCommand('git', ['init'])
return 'Initialized git repository'
})
.addIf(this.install !== false, 'Install packages', async (task) => {
.add('Install packages', async (task) => {
const spinner = this.logger.await('installing dependencies', {
silent: this.verbose,
})
Expand Down
74 changes: 0 additions & 74 deletions tests/install_adonis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ test.group('Create new app', (group) => {
test('clone template to destination', async ({ assert, fs }) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--no-install',
'--db=sqlite',
'--auth-guard=session',
'--kit="github:samuelmarina/is-even"',
Expand All @@ -47,7 +46,6 @@ test.group('Create new app', (group) => {
test('use github as default provider', async ({ assert, fs }) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--no-install',
'--kit="samuelmarina/is-even"',
])

Expand All @@ -60,7 +58,6 @@ test.group('Create new app', (group) => {

test('prompt for destination when not provided', async ({ assert }) => {
const command = await kernel.create(CreateNewApp, [
'--no-install',
'--db=sqlite',
'--auth-guard=session',
'--kit="github:samuelmarina/is-even"',
Expand All @@ -78,7 +75,6 @@ test.group('Create new app', (group) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--pkg="npm"',
'--install',
// not provide `--db` and `--auth-guard` to test that it will not prompt for slim kit
])

Expand All @@ -102,7 +98,6 @@ test.group('Create new app', (group) => {
'--pkg="npm"',
'-K=web',
'--db=sqlite',
'--install',
])

command.verbose = VERBOSE
Expand All @@ -127,7 +122,6 @@ test.group('Create new app', (group) => {
'--pkg="npm"',
'-K=api',
'--auth-guard=session',
'--install',
])

command.verbose = VERBOSE
Expand All @@ -143,37 +137,13 @@ test.group('Create new app', (group) => {
await assert.fileExists('foo/config/database.ts')
})

test('prompt for install dependencies when --install flag is not used', async ({
assert,
fs,
}) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--pkg="npm"',
'--db=sqlite',
'--auth-guard=session',
'-K=slim',
])

command.verbose = VERBOSE
command.prompt.trap('Do you want to install dependencies using "npm"').replyWith(true)

await command.exec()

const result = await execa('node', ['ace', '--help'], { cwd: join(fs.basePath, 'foo') })

assert.deepEqual(result.exitCode, 0)
assert.deepInclude(result.stdout, 'View list of available commands')
})

test('do not configure lucid when user skip database driver selection', async ({
assert,
fs,
}) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--pkg="npm"',
'--install',
'-K=web',
'--auth-guard=session',
])
Expand All @@ -196,7 +166,6 @@ test.group('Create new app', (group) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--pkg="npm"',
'--install',
'-K=web',
'--db=sqlite',
])
Expand All @@ -220,7 +189,6 @@ test.group('Create new app', (group) => {

const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--no-install',
'--kit="github:samuelmarina/is-even"',
])

Expand All @@ -245,7 +213,6 @@ test.group('Create new app', (group) => {

const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--install',
'--db=sqlite',
'--auth-guard=session',
'--kit="github:samuelmarina/is-even"',
Expand All @@ -259,25 +226,9 @@ test.group('Create new app', (group) => {
process.env.npm_config_user_agent = undefined
})

test('do not install dependencies when --no-install flag is provided', async ({ assert, fs }) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--db=sqlite',
'--auth-guard=session',
'--no-install',
'--kit="github:samuelmarina/is-even"',
])

command.verbose = VERBOSE
await command.exec()

await assert.fileNotExists(`foo/package-lock.json`)
})

test('initialize git repo when --git-init flag is provided', async ({ assert, fs }) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--no-install',
'--git-init',
'--kit="github:samuelmarina/is-even"',
])
Expand All @@ -294,7 +245,6 @@ test.group('Create new app', (group) => {
'--pkg="yarn"',
'--db=sqlite',
'--auth-guard=session',
'--install',
'--kit="github:samuelmarina/is-even"',
])

Expand All @@ -308,7 +258,6 @@ test.group('Create new app', (group) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--pkg="npm"',
'--install',
'--kit="github:adonisjs/slim-starter-kit"',
])

Expand All @@ -325,7 +274,6 @@ test.group('Create new app', (group) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--pkg="npm"',
'--no-install',
'--kit="github:adonisjs/slim-starter-kit"',
])

Expand All @@ -338,7 +286,6 @@ test.group('Create new app', (group) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--pkg="npm"',
'--no-install',
'--kit="github:adonisjs/slim-starter-kit"',
])

Expand All @@ -351,29 +298,13 @@ test.group('Create new app', (group) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo/bar'),
'--pkg="npm"',
'--no-install',
'--kit="github:adonisjs/slim-starter-kit"',
])

command.verbose = VERBOSE
await command.exec()
await assert.fileContains('foo/bar/package.json', `"name": "bar"`)
})

test('remove existing lockfile if starter kit contains one', async ({ assert, fs }) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--pkg="npm"',
'--no-install',
'--kit="github:adonisjs/slim-starter-kit"',
])

command.verbose = VERBOSE
await command.exec()
await assert.fileNotExists('foo/yarn.lock')
await assert.fileNotExists('foo/package-lock.json')
await assert.fileNotExists('foo/pnpm-lock.yaml')
})
})

test.group('Configure | Web starter kit', (group) => {
Expand All @@ -385,7 +316,6 @@ test.group('Configure | Web starter kit', (group) => {
'--pkg="npm"',
'--db=sqlite',
'--auth-guard=session',
'--install',
'-K=web',
])

Expand Down Expand Up @@ -417,7 +347,6 @@ test.group('Configure | Web starter kit', (group) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--pkg="npm"',
'--install',
'-K=web',
'--auth-guard=session',
'--db=postgres',
Expand All @@ -442,7 +371,6 @@ test.group('Configure | API starter kit', (group) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--pkg="npm"',
'--install',
'-K=api',
'--db=sqlite',
'--auth-guard=session',
Expand Down Expand Up @@ -485,7 +413,6 @@ test.group('Configure | API starter kit', (group) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--pkg="npm"',
'--install',
'-K=api',
'--db=sqlite',
'--auth-guard=access_tokens',
Expand Down Expand Up @@ -516,7 +443,6 @@ test.group('Configure | Inertia Starter Kit', (group) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--pkg="npm"',
'--install',
'-K=inertia',
'--db=sqlite',
'--auth-guard=session',
Expand Down
Loading