sort-package-json
Advanced tools
Comparing version 2.1.0 to 2.2.0
29
cli.js
#!/usr/bin/env node | ||
import { globbySync } from 'globby' | ||
import fs from 'node:fs' | ||
import { globbySync } from 'globby' | ||
import sortPackageJson from './index.js' | ||
const isCheckFlag = (argument) => argument === '--check' || argument === '-c' | ||
const isHelpFlag = (argument) => argument === '--help' || argument === '-h' | ||
const isVersionFlag = (argument) => | ||
argument === '--version' || argument === '-v' | ||
const cliArguments = process.argv.slice(2) | ||
const isCheck = cliArguments.some(isCheckFlag) | ||
const isHelp = cliArguments.some(isHelpFlag) | ||
const isVersion = cliArguments.some(isVersionFlag) | ||
if (isHelp) { | ||
console.log( | ||
`Usage: sort-package-json [OPTION...] [FILE...] | ||
Sort npm package.json files. Default: ./package.json | ||
Strings passed as files are parsed as globs. | ||
-c, --check check if FILES are sorted | ||
-h, --help display this help and exit | ||
-v, --version display the version and exit | ||
`, | ||
) | ||
process.exit(0) | ||
} | ||
if (isVersion) { | ||
const packageJsonUrl = new URL('package.json', import.meta.url) | ||
const packageJsonBuffer = fs.readFileSync(packageJsonUrl) | ||
const { version } = JSON.parse(packageJsonBuffer) | ||
console.log(`sort-package-json ${version}`) | ||
process.exit(0) | ||
} | ||
const patterns = cliArguments.filter((argument) => !isCheckFlag(argument)) | ||
@@ -12,0 +39,0 @@ |
{ | ||
"name": "sort-package-json", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Sort an Object or package.json based on the well-known package.json keys", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24154
462