@3xpo/pkgmetatool
v0.1.9
Published
No Package Description Yet
Downloads
15
Readme
@3xpo/pkgmetatool
Simple tool for managing package metadata.
Installation
pnpm i -D @3xpo/pkgmetatool
Usage
This is an example of usage within nx
:
#!/usr/bin/env node
import { processPackage } from '@3xpo/pkgmetatool';
import fs from 'fs';
import path from 'path';
import process from 'process';
import { execSync } from 'child_process';
const monorepoRoot = process.cwd();
const packages = execSync('nx exec -- pwd')
.toString()
.split('\n')
.map(x => x.trim())
.filter(x => x.length > 0 && fs.existsSync(x))
.map(x => path.relative(monorepoRoot, x));
packages.forEach(pkg => {
const pkgPath = path.join(monorepoRoot, pkg, 'package.json');
const pkgJson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
fs.writeFileSync(
pkgPath,
JSON.stringify(
processPackage(
// the inputted package.json object:
pkgJson,
// the options object:
{
path: pkg, // this will set the repository's relative path properly
license: 'MIT', // this will ensure that this license is used if there is no license field
author: 'Expo', // this will ensure that this author is used if there is no author field
repository: 'https://codeberg.org/Expo/example-repo.git', // this will ensure that this repository is used
bugs: {
url: 'AUTO', // this will ensure that the bugs.url field is set to the repository's issues page - only works on codeberg; specify a url elsewhere
email: '[email protected]', // this will ensure that the bugs.email field is set to this email
},
ensureExports: true, // this will ensure that the exports field is present and is in the correct order
fallbackTypings: true, // this will ensure that the typings field is set to the value of the types field if it is missing, and vice-versa
sort: true, // this will ensure that the package.json keys are sorted - if you want to specify a custom sorting array, pass it here
},
),
null,
2,
) + '\n',
);
});
This is an example of usage within a non-monorepo project:
import { processPackage } from '@3xpo/pkgmetatool';
import fs from 'fs';
const pkgPath = 'path/to/package.json';
const pkgJson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
fs.writeFileSync(
pkgPath,
JSON.stringify(
processPackage(
// the inputted package.json object:
pkgJson,
// the above options object would go here, with `path` omitted
{},
),
null,
2,
) + '\n',
);