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

Init :: Initialize git repo and new flag --noGit #192

Merged
merged 4 commits into from
Oct 8, 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
13 changes: 12 additions & 1 deletion src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import { basename, join } from 'node:path'
import { userInfo } from 'os'
import { ENTER, createFolderIfNotExists } from '../utils'
import { PROGRAM_FILE_EXTENSION, TEST_FILE_EXTENSION, WOLLOK_FILE_EXTENSION } from 'wollok-ts'
import { execSync } from 'node:child_process'

export type Options = {
project: string,
name?: string | undefined,
noTest: boolean,
noCI: boolean,
game: boolean,
noGit: boolean
}

export default function (folder: string | undefined, { project: _project, name, noTest = false, noCI = false, game = false }: Options): void {
export default function (folder: string | undefined, { project: _project, name, noTest = false, noCI = false, game = false, noGit = false }: Options): void {
const project = join(_project, folder ?? '')

// Initialization
Expand Down Expand Up @@ -63,6 +65,15 @@ export default function (folder: string | undefined, { project: _project, name,
logger.info('Creating Gitignore')
writeFileSync(join(project, '.gitignore'), gitignore)

if (!noGit) {
logger.info('Initializing Git repository')
try {
execSync('git init', { cwd: project })
} catch {
logger.error(yellow('🚨 Error initializing git repository, please check if git is installed in your system.'))
}
}

// Finish
logger.info(green('✨ Project succesfully created. Happy coding!'))
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ program.command('init')
.option('-g, --game', 'adds a game program to the project', false)
.option('-t, --noTest', 'avoids creating a test file', false)
.option('-c, --noCI', 'avoids creating a file for CI', false)
.option('-ng, --noGit', 'avoids initializing a git repository', false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏅

.allowUnknownOption()
.action(init)

Expand Down
20 changes: 19 additions & 1 deletion test/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const baseOptions: Options = {
noCI: false,
noTest: false,
game: false,
noGit: false,
}

describe('testing init', () => {
Expand All @@ -37,7 +38,7 @@ describe('testing init', () => {
sinon.restore()
})

it('should create files successfully for default values: ci, no game & example name', async () => {
it('should create files successfully for default values: ci, no game, example name & git', async () => {
init(undefined, baseOptions)

expect(join(project, 'example.wlk')).to.pathExists
Expand All @@ -47,6 +48,8 @@ describe('testing init', () => {
expect(join(project, 'README.md')).to.pathExists
expect(join(project, '.gitignore')).to.pathExists
expect(join(project, 'mainExample.wpgm')).to.pathExists
expect(join(project, '.git')).to.pathExists
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bien ahí chequeando el directorio en los tests!

expect(join(project, '.git/HEAD')).to.pathExists
expect(getResourceFolder()).to.be.undefined

await test(undefined, {
Expand Down Expand Up @@ -105,6 +108,21 @@ describe('testing init', () => {
expect(join(customFolderProject, '.gitignore')).to.pathExists
})

it('should skip the initialization of a git repository if notGit flag es enabled', async () => {
init(undefined, { ...baseOptions, noGit: true })

expect(join(project, '.git')).not.to.pathExists
expect(join(project, '.git/HEAD')).not.to.pathExists
Comment on lines +114 to +115
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏🏼 👏🏼 👏🏼

expect(join(project, 'example.wlk')).to.pathExists
expect(join(project, 'testExample.wtest')).to.pathExists
expect(join(project, 'package.json')).to.pathExists
expect(join(project, GITHUB_FOLDER, 'ci.yml')).to.pathExists
expect(join(project, 'README.md')).to.pathExists
expect(join(project, '.gitignore')).to.pathExists
expect(join(project, 'mainExample.wpgm')).to.pathExists
expect(getResourceFolder()).to.be.undefined
})

it('should exit with code 1 if folder already exists', () => {
init(undefined, {
...baseOptions,
Expand Down
Loading