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

Fix/handle no prefix #1

Merged
merged 5 commits into from
Nov 6, 2023
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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ npm init adonisjs -- --pkg="yarn"
### Other options

| Option | Description |
| ----------------- | --------------------------------- |
| `--skip-install` | Skip installing dependencies. |
| `--skip-git-init` | Skip initializing git repository. |
|-------------------|-----------------------------------|
| `--install` | Install dependencies. |
| `--git-init` | Initialize git repository. |
| `--no-install` | Don't install dependencies. |
| `--no-git-init` | Don't initialize git repository. |

## Contributing

Expand Down
30 changes: 17 additions & 13 deletions commands/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ export class CreateNewApp extends BaseCommand {
/**
* Skip packages installation
*/
@flags.boolean({ description: 'Skip packages installation' })
declare skipInstall: boolean
@flags.boolean({ description: 'Packages installation' })
declare install?: boolean

/**
* Skip git initialization
*/
@flags.boolean({ description: 'Skip git initialization' })
declare skipGitInit: boolean
@flags.boolean({ description: 'Git initialization' })
declare gitInit?: boolean

/**
* Package manager to use
Expand Down Expand Up @@ -127,14 +127,16 @@ export class CreateNewApp extends BaseCommand {
* Install dependencies with the detected package manager
*/
async #installDependencies() {
if (this.skipInstall) {
if (this.install === false) {
return
}

this.#shouldInstallDependencies = await this.prompt.confirm(
'Do you want to install dependencies?',
{ hint: this.packageManager + ' will be used', default: true }
)
this.#shouldInstallDependencies =
this.install ||
(await this.prompt.confirm('Do you want to install dependencies?', {
hint: this.packageManager + ' will be used',
default: true,
}))

if (!this.#shouldInstallDependencies) {
return
Expand All @@ -158,13 +160,15 @@ export class CreateNewApp extends BaseCommand {
* Init git repository inside the destination directory
*/
async #initGitRepo() {
if (this.skipGitInit) {
if (this.gitInit === false) {
return
}

const shouldInit = await this.prompt.confirm('Do you want to initialize a git repository?', {
default: true,
})
const shouldInit =
this.gitInit ||
(await this.prompt.confirm('Do you want to initialize a git repository?', {
default: true,
}))

if (!shouldInit) {
return
Expand Down
63 changes: 49 additions & 14 deletions tests/install_adonis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ test.group('Create new app', (group) => {
test('clone template to destination', async ({ assert, fs }) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--skip-install',
'--skip-git-init',
'--no-install',
'--no-git-init',
'--kit="github:samuelmarina/is-even"',
])

Expand All @@ -38,8 +38,8 @@ test.group('Create new app', (group) => {

test('prompt for destination when not provided', async ({ assert }) => {
const command = await kernel.create(CreateNewApp, [
'--skip-install',
'--skip-git-init',
'--no-install',
'--no-git-init',
'--kit="github:samuelmarina/is-even"',
])

Expand All @@ -55,8 +55,8 @@ test.group('Create new app', (group) => {

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

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

const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--skip-git-init',
'--no-git-init',
'--kit="github:samuelmarina/is-even"',
])
command.prompt.trap('Do you want to install dependencies?').replyWith(true)
Expand All @@ -95,8 +95,8 @@ test.group('Create new app', (group) => {
test('do not install dependencies', async ({ assert, fs }) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--skip-install',
'--skip-git-init',
'--no-install',
'--no-git-init',
'--kit="github:samuelmarina/is-even"',
])

Expand All @@ -105,10 +105,10 @@ test.group('Create new app', (group) => {
await assert.fileNotExists(`foo/package-lock.json`)
})

test('initialize git repo', async ({ assert, fs }) => {
test('prompt for initialize git repo', async ({ assert, fs }) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--skip-install',
'--no-install',
'--kit="github:samuelmarina/is-even"',
])

Expand All @@ -122,8 +122,8 @@ test.group('Create new app', (group) => {
test('do not initialize git repo', async ({ assert, fs }) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--skip-install',
'--skip-git-init',
'--no-install',
'--no-git-init',
'--kit="github:samuelmarina/is-even"',
])

Expand All @@ -136,7 +136,7 @@ test.group('Create new app', (group) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--pkg="yarn"',
'--skip-git-init',
'--no-git-init',
'--kit="github:samuelmarina/is-even"',
])

Expand Down Expand Up @@ -207,4 +207,39 @@ test.group('Create new app', (group) => {
await command.exec()
await assert.fileNotExists('foo/README.md')
}).disableTimeout()

test('install dependencies without prompt')
.with([
{ agent: 'npm/7.0.0 node/v15.0.0 darwin x64', lockFile: 'package-lock.json' },
{ agent: 'pnpm/5.0.0 node/v15.0.0 darwin x64', lockFile: 'pnpm-lock.yaml' },
{ agent: 'yarn/1.22.5 npm/? node/v15.0.0 darwin x64', lockFile: 'yarn.lock' },
])
.run(async ({ assert, fs }, { agent, lockFile }) => {
process.env.npm_config_user_agent = agent

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

await command.exec()

await assert.fileExists(`foo/${lockFile}`)
process.env.npm_config_user_agent = undefined
})

test('initialize git repository without prompt', async ({ assert, fs }) => {
const command = await kernel.create(CreateNewApp, [
join(fs.basePath, 'foo'),
'--no-install',
'--git-init',
'--kit="github:samuelmarina/is-even"',
])

await command.exec()

await assert.dirExists(`foo/.git`)
})
})