UNPKG

syncpack

Version:

Manage multiple package.json files, such as in Lerna Monorepos and Yarn/Pnpm Workspaces

49 lines (48 loc) 4.51 kB
#!/usr/bin/env node "use strict"; var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _a; exports.__esModule = true; var chalk_1 = __importDefault(require("chalk")); var format_1 = require("./commands/format"); var constants_1 = require("./constants"); var get_config_1 = require("./lib/get-config"); var program = require("commander"); program.description("\n Organise package.json files according to a conventional format, where fields\n appear in a predictable order and nested fields are ordered alphabetically.\n Shorthand properties are used where available, such as the \"repository\" and\n \"bugs\" fields.".replace(/^\n/, '')); program.on('--help', function () { console.log(chalk_1["default"](templateObject_1 || (templateObject_1 = __makeTemplateObject(["\nExamples:\n {dim # uses defaults for resolving packages}\n syncpack format\n {dim # uses packages defined by --source when provided}\n syncpack format --source {yellow \"apps/*/package.json\"}\n {dim # multiple globs can be provided like this}\n syncpack format --source {yellow \"apps/*/package.json\"} --source {yellow \"core/*/package.json\"}\n {dim # indent package.json with 4 spaces instead of 2}\n syncpack format --indent {yellow \" \"}\n\nResolving Packages:\n 1. If {yellow --source} globs are provided, use those.\n 2. If using Pnpm Workspaces, read {yellow packages} from {yellow pnpm-workspace.yaml} in the root of the project.\n 3. If using Yarn Workspaces, read {yellow workspaces} from {yellow package.json}.\n 4. If using Lerna, read {yellow packages} from {yellow lerna.json}.\n 5. Default to {yellow \"package.json\"} and {yellow \"packages/*/package.json\"}.\n\nReference:\n globs {blue.underline https://github.com/isaacs/node-glob#glob-primer}\n lerna.json {blue.underline https://github.com/lerna/lerna#lernajson}\n Yarn Workspaces {blue.underline https://yarnpkg.com/lang/en/docs/workspaces}\n Pnpm Workspaces {blue.underline https://pnpm.js.org/en/workspaces}\n"], ["\nExamples:\n {dim # uses defaults for resolving packages}\n syncpack format\n {dim # uses packages defined by --source when provided}\n syncpack format --source {yellow \"apps/*/package.json\"}\n {dim # multiple globs can be provided like this}\n syncpack format --source {yellow \"apps/*/package.json\"} --source {yellow \"core/*/package.json\"}\n {dim # indent package.json with 4 spaces instead of 2}\n syncpack format --indent {yellow \" \"}\n\nResolving Packages:\n 1. If {yellow --source} globs are provided, use those.\n 2. If using Pnpm Workspaces, read {yellow packages} from {yellow pnpm-workspace.yaml} in the root of the project.\n 3. If using Yarn Workspaces, read {yellow workspaces} from {yellow package.json}.\n 4. If using Lerna, read {yellow packages} from {yellow lerna.json}.\n 5. Default to {yellow \"package.json\"} and {yellow \"packages/*/package.json\"}.\n\nReference:\n globs {blue.underline https://github.com/isaacs/node-glob#glob-primer}\n lerna.json {blue.underline https://github.com/lerna/lerna#lernajson}\n Yarn Workspaces {blue.underline https://yarnpkg.com/lang/en/docs/workspaces}\n Pnpm Workspaces {blue.underline https://pnpm.js.org/en/workspaces}\n"])))); }); (_a = program .option.apply(program, __spread(constants_1.option.source))) .option.apply(_a, __spread(constants_1.option.indent)).parse(process.argv); format_1.formatToDisk(get_config_1.getConfig({ indent: program.indent, source: program.source })); var templateObject_1;