New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@springtree/coding

Package Overview
Dependencies
Maintainers
5
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@springtree/coding - npm Package Compare versions

Comparing version 1.0.13 to 1.0.14

docs/document_this.png

182

index.js
#!/usr/bin/env node
const program = require( 'commander' );
const childProcess = require( 'child_process' );
const fs = require( 'fs' );
const jsonfile = require( 'jsonfile' );
const path = require( 'path' );
const program = require('commander');
const childProcess = require('child_process');
const fs = require('fs');
const jsonfile = require('jsonfile');
const path = require('path');
// Determine script location
//
const appRoot = path.resolve( __dirname );
const appRoot = path.resolve(__dirname);
// Load package.json
//
const selfPkg = jsonfile.readFileSync( path.resolve( appRoot, 'package.json' ) );
const selfPkg = jsonfile.readFileSync(path.resolve(appRoot, 'package.json'));

@@ -19,24 +19,24 @@ // Collect command-line options and arguments

program
.version( selfPkg.version )
.usage( '[options]' )
.version(selfPkg.version)
.usage('[options]')
.option( '--linter', 'Setup linting and git commit for the current folder' )
.option( '--gitcommit', 'Setup husky and commitlint' )
.option('--linter', 'Setup linting and git commit for the current folder')
.option('--gitcommit', 'Setup husky and commitlint')
.option( '--skip-ts', 'Disable adding typescript related features' )
.option('--skip-ts', 'Disable adding typescript related features')
.option( '--gitflow', 'Setup husky to ensure git flow branch naming is enforced' )
.option('--gitflow', 'Setup husky to ensure git flow branch naming is enforced')
.option( '--init', 'Setup linting and commitlog' )
.option('--init', 'Setup linting and commitlog')
.parse( process.argv );
.parse(process.argv);
// Check if any options was specified
//
if ( !program.linter && !program.gitignore && !program.gitcommit && !program.gitflow && !program.init ) {
if (!program.linter && !program.gitignore && !program.gitcommit && !program.gitflow && !program.init) {
program.help();
}
if ( program.skipTs ) {
console.log( 'Skipping TypeScript support' );
if (program.skipTs) {
console.log('Skipping TypeScript support');
}

@@ -46,4 +46,4 @@

//
if ( program.linter || program.init ) {
console.log( 'Installing linter dependencies...' );
if (program.linter || program.init) {
console.log('Installing linter dependencies...');
const packagesToInstall = [

@@ -57,14 +57,14 @@ 'eslint',

if ( !program.skipTs ) {
packagesToInstall.push( 'tslint' );
packagesToInstall.push( 'tslint-config-airbnb' );
packagesToInstall.push( 'tslint-eslint-rules' );
packagesToInstall.push( 'typescript' );
if (!program.skipTs) {
packagesToInstall.push('tslint');
packagesToInstall.push('tslint-config-airbnb');
packagesToInstall.push('tslint-eslint-rules');
packagesToInstall.push('typescript');
}
childProcess.execSync( `npm i -D ${packagesToInstall.join( ' ' )}` );
childProcess.execSync(`npm i -D ${packagesToInstall.join(' ')}`);
console.log( 'Writing linter config files...' );
const templateEslintrc = fs.readFileSync( path.resolve( appRoot, '.eslintrc.json' ) );
fs.writeFileSync( path.resolve( './.eslintrc.json' ), templateEslintrc );
console.log('Writing linter config files...');
const templateEslintrc = fs.readFileSync(path.resolve(appRoot, '.eslintrc.json'));
fs.writeFileSync(path.resolve('./.eslintrc.json'), templateEslintrc);

@@ -75,10 +75,10 @@ // Open the target project package.json

//
const packageJsonFile = path.resolve( './package.json' );
const packageJson = jsonfile.readFileSync( packageJsonFile );
const packageJsonFile = path.resolve('./package.json');
const packageJson = jsonfile.readFileSync(packageJsonFile);
// Add tslint based run scripts
//
if ( !program.skipTs ) {
const templateTslintrc = fs.readFileSync( path.resolve( appRoot, 'tslint.json' ) );
fs.writeFileSync( path.resolve( './tslint.json' ), templateTslintrc );
if (!program.skipTs) {
const templateTslintrc = fs.readFileSync(path.resolve(appRoot, 'tslint.json'));
fs.writeFileSync(path.resolve('./tslint.json'), templateTslintrc);

@@ -90,3 +90,3 @@ // Add npm run scripts for tslint based linting

//
if ( !packageJson.scripts ) {
if (!packageJson.scripts) {
packageJson.scripts = {};

@@ -100,4 +100,4 @@ }

//
console.log( 'Updating package.json...' );
jsonfile.writeFileSync( packageJsonFile, packageJson, { spaces: 2 } );
console.log('Updating package.json...');
jsonfile.writeFileSync(packageJsonFile, packageJson, { spaces: 2 });
}

@@ -107,7 +107,7 @@

//
if ( program.gitcommit || program.init ) {
console.log( 'Installing git commit dependencies...' );
childProcess.execSync( 'npm i -D husky @commitlint/cli @commitlint/config-conventional' );
if (program.gitcommit || program.init) {
console.log('Installing git commit dependencies...');
childProcess.execSync('npm i -D husky @commitlint/cli @commitlint/config-conventional');
console.log( 'Adding git commit hook to package.json...' );
console.log('Adding git commit hook to package.json...');

@@ -118,14 +118,17 @@ // Open the target project package.json

//
const packageJsonFile = path.resolve( './package.json' );
const packageJson = jsonfile.readFileSync( packageJsonFile );
const packageJsonFile = path.resolve('./package.json');
const packageJson = jsonfile.readFileSync(packageJsonFile);
// Add husky entry to package.json if missing
//
if ( !packageJson.husky ) {
if (!packageJson.husky) {
packageJson.husky = {};
}
if ( !packageJson.husky.hooks ) {
if (!packageJson.husky.hooks) {
packageJson.husky.hooks = {};
}
if ( packageJson.husky.hooks['commit-msg'] && packageJson.husky.hooks['commit-msg'] !== 'commitlint -E HUSKY_GIT_PARAMS' ) {
// Setup commit message validation hook
//
if (packageJson.husky.hooks['commit-msg'] && packageJson.husky.hooks['commit-msg'] !== 'commitlint -E HUSKY_GIT_PARAMS') {
packageJson.husky.hooks['commit-msg'] += ' && commitlint -E HUSKY_GIT_PARAMS';

@@ -135,12 +138,23 @@ } else {

}
jsonfile.writeFileSync( packageJsonFile, packageJson, { spaces: 2 } );
// Setup tslint on push
//
if (!program.skipTs) {
if (packageJson.husky.hooks['pre-push'] && packageJson.husky.hooks['pre-push'] !== 'npm run tslint') {
packageJson.husky.hooks['pre-push'] += ' && npm run tslint';
} else {
packageJson.husky.hooks['pre-push'] = 'npm run tslint';
}
}
jsonfile.writeFileSync(packageJsonFile, packageJson, { spaces: 2 });
// Update the package.json file
//
console.log( 'Updating package.json...' );
jsonfile.writeFileSync( packageJsonFile, packageJson, { spaces: 2 } );
console.log('Updating package.json...');
jsonfile.writeFileSync(packageJsonFile, packageJson, { spaces: 2 });
console.log( 'Writing commitlint config...' );
const templateCommitlintConfig = fs.readFileSync( path.resolve( appRoot, 'commitlint.config.js' ) );
fs.writeFileSync( path.resolve( './commitlint.config.js' ), templateCommitlintConfig );
console.log('Writing commitlint config...');
const templateCommitlintConfig = fs.readFileSync(path.resolve(appRoot, 'commitlint.config.js'));
fs.writeFileSync(path.resolve('./commitlint.config.js'), templateCommitlintConfig);
}

@@ -150,7 +164,7 @@

//
if ( program.gitflow ) {
console.log( 'Installing gitflow dependencies...' );
childProcess.execSync( 'npm i -D husky @springtree/check-git-branch-name' );
if (program.gitflow) {
console.log('Installing gitflow dependencies...');
childProcess.execSync('npm i -D husky @springtree/check-git-branch-name');
console.log( 'Adding gitflow pre-push hook to package.json...' );
console.log('Adding gitflow pre-push hook to package.json...');

@@ -161,11 +175,11 @@ // Open the target project package.json

//
const packageJsonFile = path.resolve( './package.json' );
const packageJson = jsonfile.readFileSync( packageJsonFile );
const packageJsonFile = path.resolve('./package.json');
const packageJson = jsonfile.readFileSync(packageJsonFile);
// Add husky entry to package.json if missing
//
if ( !packageJson.husky ) {
if (!packageJson.husky) {
packageJson.husky = {};
}
if ( !packageJson.husky.hooks ) {
if (!packageJson.husky.hooks) {
packageJson.husky.hooks = {};

@@ -176,3 +190,3 @@ }

//
if ( packageJson.husky.hooks['pre-push'] && packageJson.husky.hooks['pre-push'] !== 'check-git-branch-name -e' ) {
if (packageJson.husky.hooks['pre-push'] && packageJson.husky.hooks['pre-push'] !== 'check-git-branch-name -e') {
packageJson.husky.hooks['pre-push'] += ' && check-git-branch-name -e';

@@ -185,4 +199,4 @@ } else {

//
console.log( 'Updating package.json...' );
jsonfile.writeFileSync( packageJsonFile, packageJson, { spaces: 2 } );
console.log('Updating package.json...');
jsonfile.writeFileSync(packageJsonFile, packageJson, { spaces: 2 });
}

@@ -192,9 +206,9 @@

//
if ( program.init ) {
if (program.init) {
// Check if an gitignore file exists
//
const gitignoreFile = path.resolve( './.gitignore' );
if ( !fs.existsSync( gitignoreFile ) ) {
console.log( 'Adding gitignore file...' );
fs.writeFileSync( gitignoreFile, 'node_modules' );
const gitignoreFile = path.resolve('./.gitignore');
if (!fs.existsSync(gitignoreFile)) {
console.log('Adding gitignore file...');
fs.writeFileSync(gitignoreFile, 'node_modules');
}

@@ -204,6 +218,6 @@

//
const nvmrcFile = path.resolve( './.nvmrc' );
if ( !fs.existsSync( nvmrcFile ) ) {
console.log( 'Adding nvmrc file...' );
fs.writeFileSync( nvmrcFile, 'v10' );
const nvmrcFile = path.resolve('./.nvmrc');
if (!fs.existsSync(nvmrcFile)) {
console.log('Adding nvmrc file...');
fs.writeFileSync(nvmrcFile, 'v10');
}

@@ -213,7 +227,7 @@

//
const editorconfigFile = path.resolve( './.editorconfig' );
if ( !fs.existsSync( editorconfigFile ) ) {
const templateEditorConfig = fs.readFileSync( path.resolve( appRoot, '.editorconfig' ) );
console.log( 'Adding editorconfig file...' );
fs.writeFileSync( editorconfigFile, templateEditorConfig );
const editorconfigFile = path.resolve('./.editorconfig');
if (!fs.existsSync(editorconfigFile)) {
const templateEditorConfig = fs.readFileSync(path.resolve(appRoot, '.editorconfig'));
console.log('Adding editorconfig file...');
fs.writeFileSync(editorconfigFile, templateEditorConfig);
}

@@ -224,8 +238,8 @@

//
if ( !program.skipTs ) {
const tsconfigFile = path.resolve( './tsconfig.json' );
if ( !fs.existsSync( tsconfigFile ) ) {
const templateTsConfig = fs.readFileSync( path.resolve( appRoot, 'tsconfig.json' ) );
console.log( 'Adding tsconfig.json file...' );
fs.writeFileSync( tsconfigFile, templateTsConfig );
if (!program.skipTs) {
const tsconfigFile = path.resolve('./tsconfig.json');
if (!fs.existsSync(tsconfigFile)) {
const templateTsConfig = fs.readFileSync(path.resolve(appRoot, 'tsconfig.json'));
console.log('Adding tsconfig.json file...');
fs.writeFileSync(tsconfigFile, templateTsConfig);
}

@@ -235,2 +249,2 @@ }

console.log( 'Done. Happy coding!' );
console.log('Done. Happy coding!');
{
"name": "@springtree/coding",
"version": "1.0.13",
"version": "1.0.14",
"private": false,

@@ -31,3 +31,3 @@ "description": "The SpringTree coding guidelines and helper scripts",

"dependencies": {
"commander": "^2.19.0",
"commander": "^4.0.1",
"jsonfile": "^5.0.0"

@@ -37,2 +37,3 @@ },

"hooks": {
"pre-push": "npm run tslint && check-git-branch-name -e",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"

@@ -42,15 +43,16 @@ }

"devDependencies": {
"@commitlint/cli": "^7.5.2",
"@commitlint/config-conventional": "^7.5.0",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4",
"husky": "^1.3.1",
"tslint": "^5.15.0",
"tslint-config-airbnb": "^5.11.1",
"@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",
"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.4.1"
"typescript": "^3.7.3"
}
}

@@ -50,2 +50,4 @@ # SpringTree coding guidelines

For your VSCode you can install the [document this plugin](https://marketplace.visualstudio.com/itemdetails?itemName=joelday.docthis) to help with the automatic generation of JSDoc style comments for your code.
Please disable the memberOf generation in your vscode preferences for this plugin.
![document this setting](docs/document_this.png)

@@ -118,2 +120,7 @@ ## Human language

## Linting
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`.
## Build using CI

@@ -120,0 +127,0 @@

{
"exclude": [ "./test" ],
"include": [
"src/**/*"
],
"compilerOptions": {

@@ -4,0 +6,0 @@ /* Basic Options */

{
"extends": "tslint-config-airbnb",
"linterOptions": {
"exclude": [
"node_modules/**"
]
},
"rules": {
"max-line-length": [ true, 160 ],
"no-console": false
"no-console": false,
"variable-name": { "options": [ "allow-leading-underscore" ] }
},

@@ -7,0 +13,0 @@ "rulesDirectory": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc