Skip to content

Latest commit

 

History

History
69 lines (52 loc) · 2.06 KB

README.md

File metadata and controls

69 lines (52 loc) · 2.06 KB

Npm package helper

lenne.Tech helper for handling npm packages.

For example, the versions of package.json and package-lock.json can be synchronized very easily.

License CircleCI Dependency Status devDependency Status

Installation

$ npm install --save-dev @lenne.tech/npm-package-helper

Usage

After installing this package, the root directory of the project should contain the following script, which synchronizes the package.json and package-lock.json versions:

extras/sync-version.ts

import NpmPackageHelper from '@lenne.tech/npm-package-helper';
import { join } from 'path';

// Sync version of package.json and package-lock.json
const run = () => {
  // Init
  const nph = NpmPackageHelper;
  const dir = process.cwd();

  // Set highest version
  nph
    .setHighestVersion([
      nph.getFileData(join(dir, 'package-lock.json')),
      nph.getFileData(join(dir, 'package.json'))
    ])
    .then(version => {
      // Log version
      console.log(version);
    });
};
run();

This script can be used by husky, for example:

package.json

{
  // ...
  husky: {
    hooks: {
      'pre-commit': 'ts-node extras/sync-version.ts && pretty-quick --staged',
      'pre-push': 'npm run lint && npm run test'
    }
  }
  // ...
}

License

MIT - see LICENSE