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

Initial release #1

Merged
merged 3 commits into from
Oct 28, 2022
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
5 changes: 5 additions & 0 deletions .changeset/ninety-bags-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@branchlint/cli": patch
---

initial release
5 changes: 5 additions & 0 deletions .changeset/strange-buttons-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@branchlint/cli": patch
---

initial release
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ node_modules
*.tgz
logs
coverage
.turbo
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
19
1 change: 1 addition & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./packages/config/prettierrc.base.cjs')
7 changes: 0 additions & 7 deletions .prettierrc.js

This file was deleted.

30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# branchlint

## Description

A CLI tool to enforce version control branch naming format and structure. Currently uses a format of name/type/subject
transformed to kebab-case. The ability to create and consume different configurations is planned for the future.

### Example

john-doe/feat/add-branchlint

### Installation

#### pnpm

```bash
pnpm install @branchlint/cli -D
```

#### yarn

```bash
yarn add @branchlint/cli -D
```

#### npm

```bash
npm install @branchlint/cli --save-dev
```
File renamed without changes.
3 changes: 0 additions & 3 deletions jest.setup.js

This file was deleted.

110 changes: 50 additions & 60 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,60 +1,50 @@
{
"license": "ISC",
"private": false,
"publishConfig": {
"access": "public"
},
"author": "Omri Levy",
"repository": {
"type": "git",
"url": "https://github.com/Omri-Levy/starter"
},
"description": "",
"keywords": [],
"name": "starter",
"version": "0.0.0",
"main": "dist/index.js",
"scripts": {
"test": "echo \"will add tests soon\"",
"changeset": "changeset",
"version-packages": "changeset version",
"release": "pnpm build && changeset publish",
"format": "prettier --write './src/**/*.{js,ts}'",
"lint": "eslint './src/**/*.{js,ts}' --fix",
"start": "node dist/index.js",
"dev": "NODE_ENV=development nodemon dist/index.js",
"start:dev": "concurrently -k \"pnpm watch\" \"pnpm dev\"",
"clean": "rimraf dist",
"build": "pnpm clean && tsc",
"watch": "tsc -w",
"prepare": "husky install",
"commit": "git add . && git-cz",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@changesets/changelog-git": "^0.1.12",
"@changesets/cli": "^2.22.0",
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"commitizen": "^4.2.5",
"concurrently": "^7.3.0",
"cz-conventional-changelog": "^3.3.0",
"editorconfig": "^0.15.3",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard-with-typescript": "^22.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"husky": "^8.0.1",
"nodemon": "^2.0.19",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.7.4"
},
"dependencies": {
"dotenv": "^16.0.1",
"zod": "^3.18.0"
}
}
{
"license": "ISC",
"private": true,
"name": "branchlint",
"version": "0.0.0",
"scripts": {
"test": "turbo test",
"format": "turbo format",
"lint": "turbo lint",
"start": "turbo start",
"dev": "turbo dev",
"cli:test": "turbo test --filter=cli",
"cli:format": "turbo format --filter=cli",
"cli:lint": "turbo lint --filter=cli",
"cli:build": "turbo build --filter=cli",
"cli:start": "turbo start --filter=cli",
"cli:dev": "turbo dev --filter=cli",
"clean": "turbo clean",
"build": "turbo build",
"prepare": "husky install",
"commit": "git add . && git-cz",
"typecheck": "turbo typecheck",
"changeset": "changeset",
"version-packages": "changeset version",
"release": "pnpm build && changeset publish"
},
"devDependencies": {
"@changesets/changelog-git": "^0.1.12",
"@changesets/cli": "^2.22.0",
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"commitizen": "^4.2.5",
"concurrently": "^7.3.0",
"cz-conventional-changelog": "^3.3.0",
"editorconfig": "^0.15.3",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard-with-typescript": "^22.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"husky": "^8.0.1",
"nodemon": "^2.0.19",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"turbo": "^1.6.2",
"typescript": "^4.7.4"
}
}
9 changes: 9 additions & 0 deletions packages/cli/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const {parserOptions, ...config} = require('../config/eslintrc.cli.cjs');

module.exports = {
...config,
parserOptions: {
...parserOptions,
project: `./tsconfig.json`,
}
}
1 change: 1 addition & 0 deletions packages/cli/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require(`../config/prettierrc.cli.cjs`);
16 changes: 16 additions & 0 deletions packages/cli/.turbo/turbo-build.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

> @branchlint/cli@0.0.0 build /home/o/projects/branchlint/packages/cli
> pnpm clean && pnpm build:cjs && pnpm build:esm


> @branchlint/cli@0.0.0 clean /home/o/projects/branchlint/packages/cli
> rimraf dist


> @branchlint/cli@0.0.0 build:cjs /home/o/projects/branchlint/packages/cli
> tsc --project tsconfig.cjs.json


> @branchlint/cli@0.0.0 build:esm /home/o/projects/branchlint/packages/cli
> tsc --project tsconfig.json

Empty file.
6 changes: 6 additions & 0 deletions packages/cli/.turbo/turbo-start.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

> @branchlint/cli@0.0.0 start /home/o/projects/branchlint/packages/cli
> node dist/cjs/index.js

22
👋 What is your name? 
Empty file.
30 changes: 30 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# branchlint

## Description

A CLI tool to enforce version control branch naming format and structure. Currently uses a format of name/type/subject
transformed to kebab-case. The ability to create and consume different configurations is planned for the future.

### Example

john-doe/feat/add-branchlint

### Installation

#### pnpm

```bash
pnpm install @branchlint/cli -D
```

#### yarn

```bash
yarn add @branchlint/cli -D
```

#### npm

```bash
npm install @branchlint/cli --save-dev
```
4 changes: 4 additions & 0 deletions packages/cli/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
...require('../config/jest.cli.cjs'),
rootDir: '.',
}
57 changes: 57 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"license": "ISC",
"private": false,
"sideEffects": false,
"publishConfig": {
"access": "public"
},
"author": "Omri Levy",
"repository": {
"type": "git",
"url": "https://github.com/Omri-Levy/branchlint"
},
"types": "./dist/cjs/index.d.ts",
"description": "Enforce version control branch naming conventions using a CLI",
"keywords": [
"cli",
"inquirer",
"git",
"version control",
"branch",
"branch naming conventions",
"lint",
"commitlint",
"conventional commits",
"oss",
"open-source",
"enforce",
"code guidelines"
],
"name": "@branchlint/cli",
"version": "0.0.0",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"scripts": {
"test": "echo \"will add tests soon\"",
"format": "prettier --write './src/**/*.{js,ts}'",
"lint": "eslint './src/**/*.{js,ts}' --fix",
"prestart": "pnpm build",
"start": "node dist/cjs/index.js",
"dev": "NODE_ENV=development nodemon dist/cjs/index.js",
"clean": "rimraf dist",
"build:cjs": "tsc --project tsconfig.cjs.json",
"build:esm": "tsc --project tsconfig.json",
"build": "pnpm clean && pnpm build:cjs && pnpm build:esm",
"watch": "tsc -w",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"inquirer": "8.0.1",
"lodash": "^4.17.21",
"zod": "^3.19.1"
},
"devDependencies": {
"@types/inquirer": "^9.0.2",
"@types/lodash": "^4.14.186"
}
}
77 changes: 77 additions & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import inquirer from 'inquirer';
import { kebabCase } from 'lodash';
import { exec } from 'child_process';
import { isTtyError } from './utils';
import { nameValidate, subjectValidate } from './validation';

void (async () => {
try {
const name = {
type: `input`,
name: `name`,
message: `What is your name?`,
prefix: `👋`,
validate: nameValidate,
};
const typeOfChange = {
type: `list`,
name: `typeOfChange`,
message: `Select the type of change that you're committing:`,
prefix: `🚧`,
choices: [
`feat`,
`fix`,
`docs`,
`style`,
`refactor`,
`perf`,
`test`,
`build`,
`ci`,
`chore`,
`revert`,
],
};
const branchSubject = {
type: `input`,
name: `branchSubject`,
message: `What is the branch's main subject? (i.e feature's name)`,
prefix: `🏷️`,
validate: subjectValidate,
};
const shouldCheckout = {
type: `confirm`,
name: `checkout`,
message: `Checkout to new branch?`,
default: true,
prefix: `🍻`,
};
const { checkout, ...answers } = await inquirer.prompt([
name,
typeOfChange,
branchSubject,
shouldCheckout,
]);
const branchName = Object.values(answers as Record<PropertyKey, string>)
?.map(kebabCase)
?.join(`/`);
const command = (checkout as boolean)
? `git checkout -b ${branchName}`
: `git branch ${branchName}`;

exec(command);
console.log(`🎉 Created a branch named ${branchName}`);
} catch (error) {
if (!isTtyError(error)) {
console.error(`💥 Failed to create a branch...`);

process.exit(1);
}

if (error.isTtyError) {
console.error(
`Prompt couldn't be rendered in the current environment`,
);
}
}
})();
1 change: 1 addition & 0 deletions packages/cli/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { isTtyError } from './is-tty-error';
2 changes: 2 additions & 0 deletions packages/cli/src/utils/is-tty-error/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { ITtyError } from './interfaces';
export { isTtyError } from './is-tty-error';
3 changes: 3 additions & 0 deletions packages/cli/src/utils/is-tty-error/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface ITtyError extends Error {
isTtyError: boolean;
}
Loading