@springtree/coding
Advanced tools
Comparing version 1.0.15 to 1.1.0
{ | ||
"extends": "airbnb", | ||
"extends": ["airbnb-typescript"], | ||
"parserOptions": { | ||
"project": "./tsconfig.json" | ||
}, | ||
"ignorePatterns": [ | ||
"node_modules/", | ||
"bower_components/", | ||
"dist" | ||
], | ||
"rules": { | ||
@@ -4,0 +12,0 @@ "max-len": [ "error", { "code": 160 } ], |
{ | ||
"name": "@springtree/coding", | ||
"version": "1.0.15", | ||
"version": "1.1.0", | ||
"private": false, | ||
"description": "The SpringTree coding guidelines and helper scripts", | ||
"bin": "index.js", | ||
"main": "index.js", | ||
"bin": "dist/index.js", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"tslint": "tslint -p tsconfig.json", | ||
"tslint:fix": "tslint -p tsconfig.json --fix" | ||
"prepublish": "tsc", | ||
"build": "tsc", | ||
"lint": "eslint --ext .js,.jsx,.ts,.tsx ./" | ||
}, | ||
@@ -31,26 +32,23 @@ "repository": { | ||
"dependencies": { | ||
"commander": "^4.0.1", | ||
"jsonfile": "^5.0.0" | ||
"jsonfile": "^6.0.1", | ||
"prompts": "^2.3.2" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-push": "npm run tslint && check-git-branch-name -e", | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS" | ||
} | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^8.2.0", | ||
"@commitlint/config-conventional": "^8.2.0", | ||
"@springtree/check-git-branch-name": "^1.0.4", | ||
"eslint": "^6.7.2", | ||
"eslint-config-airbnb": "^18.0.1", | ||
"eslint-plugin-import": "^2.19.1", | ||
"@commitlint/cli": "^8.3.5", | ||
"@commitlint/config-conventional": "^8.3.4", | ||
"@springtree/check-git-branch-name": "^1.0.5", | ||
"@types/jsonfile": "^5.0.0", | ||
"@types/node": "^13.13.4", | ||
"@types/prompts": "^2.0.6", | ||
"@typescript-eslint/eslint-plugin": "^2.30.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-airbnb-typescript": "^7.2.1", | ||
"eslint-plugin-import": "^2.20.2", | ||
"eslint-plugin-jsx-a11y": "^6.2.3", | ||
"eslint-plugin-react": "^7.17.0", | ||
"husky": "^3.1.0", | ||
"tslint": "^5.20.1", | ||
"tslint-config-airbnb": "^5.11.2", | ||
"tslint-eslint-rules": "^5.4.0", | ||
"typescript": "^3.7.3" | ||
"eslint-plugin-react": "^7.19.0", | ||
"eslint-plugin-react-hooks": "^2.5.1", | ||
"husky": "^4.2.5", | ||
"lint-staged": "^10.2.1", | ||
"typescript": "^3.8.3" | ||
} | ||
} |
@@ -12,11 +12,7 @@ # SpringTree coding guidelines | ||
```bash | ||
npx @springtree/coding --init | ||
npx @springtree/coding | ||
``` | ||
If you are using a project without TypeScript run: | ||
It will ask you a series of questions for what to setup. | ||
```bash | ||
npx @springtree/coding --init --skip-ts | ||
``` | ||
## Style guide | ||
@@ -38,3 +34,10 @@ | ||
```bash | ||
npm i -D eslint eslint-config-airbnb eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-import tslint tslint-config-airbnb | ||
npm install eslint \ | ||
eslint-config-airbnb-typescript \ | ||
eslint-plugin-import@^2.20.1 \ | ||
eslint-plugin-jsx-a11y@^6.2.3 \ | ||
eslint-plugin-react@^7.19.0 \ | ||
eslint-plugin-react-hooks@^2.5.0 \ | ||
@typescript-eslint/eslint-plugin@^2.24.0 \ | ||
--save-dev | ||
``` | ||
@@ -97,3 +100,3 @@ | ||
We use the Angular commit log format which we enforce using a combination of [commitlint](https://github.com/marionebl/commitlint) and [husky](https://github.com/typicode/husky). | ||
We use the conventional commit log format which we enforce using a combination of [commitlint](https://github.com/marionebl/commitlint) and [husky](https://github.com/typicode/husky). | ||
@@ -103,3 +106,3 @@ You can install these tools using npm: | ||
```bash | ||
npm i -D husky @commitlint/cli @commitlint/config-angular | ||
npm i -D husky @commitlint/cli @commitlint/config-conventional | ||
``` | ||
@@ -120,3 +123,3 @@ | ||
```bash | ||
echo "module.exports = { extends: ['@commitlint/config-angular'] }" > commitlint.config.js | ||
echo "module.exports = { extends: ['@commitlint/config-conventional'] }" > commitlint.config.js | ||
``` | ||
@@ -126,4 +129,6 @@ | ||
This tool provides configuration for both eslint and tslint. | ||
An on push hook is setup to run tslint on your project sources configured in `tsconfig.json`. | ||
This tool provides configuration for both eslint with TypeScript support. | ||
The use of tslint is deprecated. | ||
A hook will be installed by this tool run `lint-staged` on your git staged files. | ||
This will auto-fix possible issues and prevent a commit of unlinted code. | ||
@@ -143,2 +148,4 @@ ## Build using CI | ||
We highly recommend using [semantic-release](https://github.com/semantic-release/semantic-release) for un-opinionated versioning. | ||
### Pull request validation with CI | ||
@@ -145,0 +152,0 @@ |
163
src/index.ts
@@ -1,3 +0,164 @@ | ||
export default class MyClass { | ||
#!/usr/bin/env node | ||
import * as childProcess from 'child_process'; | ||
import * as jsonfile from 'jsonfile'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as prompts from 'prompts'; | ||
// Determine location of package root so we can get our example files | ||
// | ||
const appRoot = path.resolve(__dirname, '..'); | ||
// Read our package.json file | ||
// | ||
const selfPkg = jsonfile.readFileSync(path.resolve(appRoot, 'package.json')); | ||
console.log(`SpringTree coding tool version ${selfPkg.version}`); | ||
console.log('This tool will setup linting, commit hooks and other standard best practices'); | ||
console.log('We use the AirBnB rules with TypeScript support'); | ||
console.log('Default source folder is assumed to be `src/`'); | ||
console.log('Setting up your current directory for SpringTree coding...'); | ||
// Prepare the prompt questions | ||
// | ||
const questions: prompts.PromptObject[] = []; | ||
// First check if the current folder has a .git folder | ||
// | ||
const isGitRepository = fs.existsSync('.git'); | ||
if (!isGitRepository) { | ||
questions.push({ | ||
type: 'confirm', | ||
name: 'git', | ||
message: 'Current folder is not a Git repository. Run `git init`?', | ||
initial: true, | ||
}); | ||
} | ||
// Setup the main feature questions | ||
// | ||
questions.push({ | ||
type: 'confirm', | ||
name: 'eslintReact', | ||
message: 'Setup eslint with React support?', | ||
initial: true, | ||
}); | ||
questions.push({ | ||
type: 'confirm', | ||
name: 'gitFlow', | ||
message: 'Setup git flow branch name checker?', | ||
initial: true, | ||
}); | ||
questions.push({ | ||
type: 'confirm', | ||
name: 'commitLint', | ||
message: 'Setup commit-lint?', | ||
initial: true, | ||
}); | ||
questions.push({ | ||
type: 'confirm', | ||
name: 'tsconfig', | ||
message: 'Create a tsconfig.json file?', | ||
initial: false, | ||
}); | ||
// int main(void) with async support | ||
// | ||
(async () => { | ||
const responses = await prompts(questions); | ||
if (responses.git) { | ||
console.log('SCM: Initializing new Git repository...'); | ||
childProcess.execSync('git init'); | ||
// Check if an gitignore file exists | ||
// | ||
const gitignoreFile = path.resolve('./.gitignore'); | ||
if (!fs.existsSync(gitignoreFile)) { | ||
console.log('SCM: Adding gitignore file...'); | ||
fs.writeFileSync(gitignoreFile, 'node_modules'); | ||
} | ||
} | ||
// Check if an editor-config file exists | ||
// | ||
const editorConfigFile = path.resolve('./.editorconfig'); | ||
if (!fs.existsSync(editorConfigFile)) { | ||
const templateEditorConfig = fs.readFileSync(path.resolve(appRoot, '.editorconfig')); | ||
console.log('LINTER: Adding editorconfig file...'); | ||
fs.writeFileSync(editorConfigFile, templateEditorConfig); | ||
} | ||
// We always install the linter and husky | ||
// | ||
const packagesToInstall: string[] = [ | ||
'husky', | ||
'lint-staged', | ||
'eslint', | ||
'eslint-config-airbnb-typescript', | ||
'eslint-plugin-import@^2.20.1', | ||
'@typescript-eslint/eslint-plugin@^2.24.0', | ||
]; | ||
if (responses.eslintReact) { | ||
// Eslint with TypeScript support and React plugins | ||
// | ||
console.log('LINTER: Configuring ESLint with TypeScript and React support using AirBnB rules...'); | ||
packagesToInstall.push('eslint-plugin-jsx-a11y@^6.2.3'); | ||
packagesToInstall.push('eslint-plugin-react@^7.19.0'); | ||
packagesToInstall.push('eslint-plugin-react-hooks@^2.5.0'); | ||
} else { | ||
// Only basic eslint with TypeScript support | ||
// | ||
console.log('Configuring ESLint with TypeScript using AirBnB rules...'); | ||
} | ||
childProcess.execSync(`npm i -D ${packagesToInstall.join(' ')}`); | ||
// The configuration file in this project is the template | ||
// | ||
console.log('LINTER: Setting up linter config file...'); | ||
const templateEslintConfig = fs.readFileSync(path.resolve(appRoot, '.eslintrc.json')); | ||
fs.writeFileSync(path.resolve('./.eslintrc.json'), templateEslintConfig); | ||
console.log('HOOKS: Setting up linter commit check...'); | ||
const templateLintStagedConfig = fs.readFileSync(path.resolve(appRoot, '.lintstagedrc.json')); | ||
fs.writeFileSync(path.resolve('./.lintstagedrc.json'), templateLintStagedConfig); | ||
// Prepare the husky configuration | ||
// | ||
const huskyConfig: any = { | ||
hooks: { | ||
'pre-commit': 'lint-staged', | ||
}, | ||
}; | ||
if (responses.commitLint) { | ||
console.log('HOOKS: Installing commit-lint...'); | ||
childProcess.execSync('npm i -D @commitlint/cli @commitlint/config-conventional'); | ||
huskyConfig.hooks['commit-msg'] = 'commitlint -E HUSKY_GIT_PARAMS'; | ||
} | ||
if (responses.gitFlow) { | ||
console.log('HOOKS: Installing git-flow branch check...'); | ||
childProcess.execSync('npm i -D @springtree/check-git-branch-name'); | ||
huskyConfig.hooks['pre-push'] = 'check-git-branch-name -e'; | ||
} | ||
console.log('HOOKS: Configuring...'); | ||
jsonfile.writeFileSync(path.resolve('./.huskyrc.json'), huskyConfig, { spaces: 2 }); | ||
if (responses.tsconfig) { | ||
console.log('TSC: Setting up project config file...'); | ||
const templateTSConfig = fs.readFileSync(path.resolve(appRoot, 'tsconfig.json')); | ||
fs.writeFileSync(path.resolve('./tsconfig.json'), templateTSConfig); | ||
} | ||
// Check if an nvmrc file exists | ||
// | ||
const nvmrcFile = path.resolve('./.nvmrc'); | ||
if (!fs.existsSync(nvmrcFile)) { | ||
console.log('NVM: Adding nvmrc file for node v12...'); | ||
fs.writeFileSync(nvmrcFile, 'v12'); | ||
} | ||
console.log('DONE: Happy coding!'); | ||
})(); |
@@ -17,3 +17,3 @@ { | ||
// "outFile": "./dist/index.js", /* Concatenate and emit output to single file. */ | ||
"outDir": "./lib", /* Redirect output structure to the directory. */ | ||
"outDir": "./dist", /* Redirect output structure to the directory. */ | ||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ | ||
@@ -20,0 +20,0 @@ "removeComments": false, /* Do not emit comments to output. */ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
47200
12
404
148
16
2
+ Addedprompts@^2.3.2
+ Addedjsonfile@6.1.0(transitive)
+ Addedkleur@3.0.3(transitive)
+ Addedprompts@2.4.2(transitive)
+ Addedsisteransi@1.0.5(transitive)
+ Addeduniversalify@2.0.1(transitive)
- Removedcommander@^4.0.1
- Removedcommander@4.1.1(transitive)
- Removedjsonfile@5.0.0(transitive)
- Removeduniversalify@0.1.2(transitive)
Updatedjsonfile@^6.0.1