UNPKG

@onereach/get-version-data

Version:
83 lines (73 loc) 2.35 kB
#!/usr/bin/env node 'use strict'; const fs = require('fs/promises'); const lib = require('../src'); const {resolve, dirname} = require('path'); const args = require('minimist')(process.argv.slice(2), { boolean: ['help', 'version', 'deploy-platform', 'git', 'prettify', 'devDeps'], string: ['dir', 'feature', 'output'], alias: { h: 'help', v: 'version', d: 'dir', f: 'feature', p: 'prettify', e: 'devDeps', 'dev-deps': 'devDeps', o: 'output', g: 'git', dp: 'deploy-platform', }, default: { dir: '.', feature: 'master', prettify: true, devDeps: false, git: true, 'deploy-platform': true, }, }); if (args.help) { console.log(` Installation: using npm: npm install -D @onereach/get-version-data using pnpm: pnpm add -D @onereach/get-version-data using yarn: yarn add -D @onereach/get-version-data Usage: using npm: npx or-get-version-data [options] using pnpm: pnpm exec or-get-version-data [options] using yarn: yarn or-get-version-data [options] Options: -h, --help Show this help message -v, --version Show version information -d, --dir Set the directory (default: ".") -f, --feature Set the feature (default: "master") -p, --prettify Prettify the output (default: true) -dp, --deploy-platform Include deploy-platform information (default: true) -g, --git Include git information (default: true) -e, --dev-deps Include dev dependencies (default: false) -o, --output Set the output file (default: stdout) `); process.exit(0); } if (args.version) { const pkg = require(resolve(__dirname, '..', 'package.json')); console.log(pkg.version); process.exit(0); } async function printVersionData (args) { const rootPath = resolve(process.cwd(), args.dir); const versionInfo = JSON.stringify( await lib.getData(rootPath, args), null, args.prettify ? 2 : null ); if (args.output) { const outputPath = resolve(process.cwd(), args.output); await fs.mkdir(dirname(outputPath), {recursive: true}); await fs.writeFile(outputPath, versionInfo, 'utf8'); } else { console.log(versionInfo); } } printVersionData(args)