lenne.Tech helper for handling npm packages.
For example, the versions of package.json and package-lock.json can be synchronized very easily.
$ npm install --save-dev @lenne.tech/npm-package-helper
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'
}
}
// ...
}
MIT - see LICENSE