bounce-in-style
Advanced tools
Comparing version 0.0.2 to 0.0.3
#!/usr/bin/env node | ||
declare const lintStaged: any; | ||
export {}; |
@@ -12,20 +12,65 @@ #!/usr/bin/env node | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const arg_1 = __importDefault(require("arg")); | ||
const child_process_1 = require("child_process"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const lintStaged = require('lint-staged'); | ||
(() => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const success = yield lintStaged({ | ||
const args = arg_1.default({ | ||
// Types | ||
'--react': Boolean, | ||
'--staged': Boolean, | ||
'--help': Boolean, | ||
'--check': Boolean, | ||
// Aliases | ||
'-h': '--help' | ||
}); | ||
if (args['--help']) { | ||
console.log(` | ||
Usage | ||
$ npx bis [flags] | ||
Options | ||
--help Print help message. | ||
--react Use for React & React Native projects. | ||
--staged Only run on staged files. Useful when adding as a git hook. | ||
--check Only check files. Skips running Prettier and doesn't use the --fix flag for ESLint. | ||
This option does not support the --staged flag. | ||
`); | ||
return; | ||
} | ||
const isStagedChanges = args['--staged']; | ||
const isReact = args['--react']; | ||
const isCheck = args['--check']; | ||
if (isStagedChanges && isCheck) { | ||
console.error('Cannot provide the --staged and the --check flag together'); | ||
return; | ||
} | ||
const prettierCommand = 'npx prettier --config ./node_modules/prettier-config-bouncedinc/index.json --write'; | ||
const eslintCommand = `npx eslint -c ./node_modules/eslint-config-bouncedinc${isReact ? '-react' : ''}/index.js ${isCheck ? '' : '--fix'} --cache --ext ts --ext tsx --ext js --ext jsx`; | ||
if (isStagedChanges) { | ||
yield lintStaged({ | ||
config: { | ||
'*.{js,jsx,ts,tsx}': [ | ||
`npx prettier --config ./node_modules/bounce-in-style/prettier-config-bouncedinc --write`, | ||
`npx eslint -c ./node_modules/bounce-in-style/eslint-config-bouncedinc --cache --fix` | ||
] | ||
'*.{js,jsx,ts,tsx}': [prettierCommand, eslintCommand], | ||
'*.{json,css,md,yml,yaml}': [prettierCommand] | ||
} | ||
}); | ||
console.log(success ? 'Format and lint was successful 🏀' : 'Linting failed!'); | ||
} | ||
catch (e) { | ||
// Failed to load configuration | ||
console.error(e); | ||
else { | ||
// append "." for files to format and lint | ||
if (!isCheck) | ||
child_process_1.execSync(prettierCommand + ' .', { stdio: 'inherit' }); | ||
try { | ||
// errors already get printed automatically, we dont need to | ||
// print more | ||
child_process_1.execSync(eslintCommand + ' .', { stdio: 'inherit' }); | ||
} | ||
catch (err) { | ||
return; | ||
} | ||
} | ||
console.log('Formating and linting was successful 🏀'); | ||
}))(); |
{ | ||
"name": "bounce-in-style", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "The Bounce style guide, formatter, and commit validator.", | ||
@@ -11,3 +11,4 @@ "main": "./dist/index.js", | ||
"build": "npx tsc", | ||
"prepack": "rm -rf dist && npx tsc -b" | ||
"prepack": "rm -rf dist && npx tsc -b", | ||
"prepare": "husky install" | ||
}, | ||
@@ -26,11 +27,13 @@ "repository": { | ||
"dependencies": { | ||
"arg": "^5.0.0", | ||
"eslint": "^7.27.0", | ||
"eslint-config-bouncedinc": "^0.0.2", | ||
"eslint-config-bouncedinc-react": "^0.0.2", | ||
"prettier-config-bouncedinc": "^0.0.1", | ||
"eslint": "^7.27.0", | ||
"lint-staged": "^11.0.0", | ||
"prettier": "^2.3.0" | ||
"prettier": "^2.3.0", | ||
"prettier-config-bouncedinc": "^0.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^15.6.1", | ||
"husky": "^6.0.0", | ||
"typescript": "^4.3.2" | ||
@@ -37,0 +40,0 @@ }, |
@@ -7,38 +7,42 @@ # Bounce in Style | ||
- a single source of truth for all linting, formatting, commit message validation, changelog generator, semantic versioning | ||
- minimal config required | ||
- compatible with all Bounce Typescript projects | ||
- separate config for react / react-native | ||
- Single source of truth for all linting, formatting, commit message validation, changelog generator, semantic versioning | ||
- Minimal config | ||
- Compatible with all Bounce Typescript projects (Express, React, React Native) | ||
## Progres and whats next | ||
# Instructions | ||
- test current setup in terms of linting / formatting | ||
- try adding airbnb extends (optional, or later) | ||
- setup cli to run: `bis { --staged | --all } { --react }` | ||
- setup commit validator & changelog generator | ||
- Fresh install of Husky (version 6 has some major changes) | ||
# Instructions | ||
```bash | ||
npm install husky -D | ||
npx husky install | ||
``` | ||
- Install bounce-in-style and husky | ||
- Install bounce-in-style | ||
```bash | ||
# with npm | ||
npm install bounce-in-style husky -D | ||
# with yarn | ||
yarn add bounce-in-style husky -D | ||
npm install bounce-in-style -D | ||
``` | ||
- Add husky to `package.json` | ||
- Add git hook with Husky | ||
```json | ||
{ | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "npx bis" | ||
} | ||
} | ||
} | ||
```bash | ||
# react/react-native projects | ||
npx husky add .husky/pre-commit "npx bis --staged --react" | ||
# all other projects (ie backend) | ||
npx husky add .husky/pre-commit "npx bis --staged" | ||
``` | ||
- Add your own `.eslintignore` and `.prettierignore` files to the root of your project. | ||
- Add your own `.eslintignore` and `.prettierignore` files to the root of your project. | ||
# Extending eslint config | ||
We don't recommend extending the config, instead a PR should be made into this repo to add the change for everyone. | ||
If you need to extend the config, you can extend it like you would any other eslint config. The simplest way to do so can be seen in the `.eslintrc` file at the root of this repo. | ||
## What's next | ||
- try adding airbnb extends | ||
- setup commit validator & changelog generator |
#!/usr/bin/env node | ||
import arg from 'arg'; | ||
import { execSync } from 'child_process'; | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
@@ -6,17 +8,63 @@ const lintStaged = require('lint-staged'); | ||
(async () => { | ||
try { | ||
const success = await lintStaged({ | ||
const args = arg({ | ||
// Types | ||
'--react': Boolean, | ||
'--staged': Boolean, | ||
'--help': Boolean, | ||
'--check': Boolean, | ||
// Aliases | ||
'-h': '--help' | ||
}); | ||
if (args['--help']) { | ||
console.log(` | ||
Usage | ||
$ npx bis [flags] | ||
Options | ||
--help Print help message. | ||
--react Use for React & React Native projects. | ||
--staged Only run on staged files. Useful when adding as a git hook. | ||
--check Only check files. Skips running Prettier and doesn't use the --fix flag for ESLint. | ||
This option does not support the --staged flag. | ||
`); | ||
return; | ||
} | ||
const isStagedChanges = args['--staged']; | ||
const isReact = args['--react']; | ||
const isCheck = args['--check']; | ||
if (isStagedChanges && isCheck) { | ||
console.error('Cannot provide the --staged and the --check flag together'); | ||
return; | ||
} | ||
const prettierCommand = | ||
'npx prettier --config ./node_modules/prettier-config-bouncedinc/index.json --write'; | ||
const eslintCommand = `npx eslint -c ./node_modules/eslint-config-bouncedinc${ | ||
isReact ? '-react' : '' | ||
}/index.js ${isCheck ? '' : '--fix'} --cache --ext ts --ext tsx --ext js --ext jsx`; | ||
if (isStagedChanges) { | ||
await lintStaged({ | ||
config: { | ||
'*.{js,jsx,ts,tsx}': [ | ||
`npx prettier --config ./node_modules/bounce-in-style/prettier-config-bouncedinc --write`, | ||
`npx eslint -c ./node_modules/bounce-in-style/eslint-config-bouncedinc --cache --fix` | ||
] | ||
'*.{js,jsx,ts,tsx}': [prettierCommand, eslintCommand], | ||
'*.{json,css,md,yml,yaml}': [prettierCommand] | ||
} | ||
}); | ||
} else { | ||
// append "." for files to format and lint | ||
if (!isCheck) execSync(prettierCommand + ' .', { stdio: 'inherit' }); | ||
console.log(success ? 'Format and lint was successful 🏀' : 'Linting failed!'); | ||
} catch (e) { | ||
// Failed to load configuration | ||
console.error(e); | ||
try { | ||
// errors already get printed automatically, we dont need to | ||
// print more | ||
execSync(eslintCommand + ' .', { stdio: 'inherit' }); | ||
} catch (err) { | ||
return; | ||
} | ||
} | ||
console.log('Formating and linting was successful 🏀'); | ||
})(); |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
7877
153
48
7
3
1
+ Addedarg@^5.0.0
+ Addedarg@5.0.2(transitive)