{"version":3,"file":"command.mjs","sources":["../../src/publish/command.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { alias, createHelp, createHelpSnippet, cue, flag, option, parseOptions, string } from '@seahax/args';\nimport { getPackages } from '@seahax/monorepo';\n\nimport { getGitCommit } from './get-git-commit.ts';\nimport { getPublishCommand } from './get-publish-command.ts';\nimport { publish } from './publish.ts';\n\nconst help = createHelp`\n{bold Usage:} rev publish {blue [options]} {yellow [-- <pm-options...>]}\n\nPublish packages to an npm registry. Only versions that are not already\npublished will be published. If a package version already exists in the\nregistry, it will be siliently skipped.\n\nPublication is delegated to your package manager, which will be detected\nautomatically (npm, pnpm, or yarn berry) based on the presence of a lockfile\nin the current directory or a parent directory. If there is no recognized\nlockfile, the command will fail. You can override package manager detection\nwith the {blue --pm} option. Authentication and registry configuration are\nhandled by the package manager. All extra args are passed through to the\npackage manager command.\n\nExample: Just publish with the detected package manager.\n\n  {gray > rev publish}\n\nExample: PNPM publish dry run.\n\n  {gray > rev publish --command \"pnpm publish\" --dry-run}\n\nExample: PNPM Pack instead of publish.\n\n  {gray > rev publish --command \"pnpm pack\"}\n\nRead the docs:\nhttps://github.com/seahax/workshop/blob/main/packages/rev/README.md#publish\n\n{bold Options:}\n  {blue --dry-run}       Do not actually publish, just show what would be done.\n  {blue --command, -c}   Publish command (default: detected by lockfile)\n  {blue --help, -h}      Show this help message.\n`;\n\nconst noPackageManager = createHelpSnippet`\n{red Could not detect the package manager. Please use the --command option.}\n`;\n\nexport async function publishCommand(args: string[]): Promise<void> {\n  const options = await parseOptions(args, {\n    '--dry-run': flag(),\n    '--command': option(),\n    '-c': alias('--command'),\n    '--help': cue(),\n    '-h': alias('--help'),\n    extraPositional: string(),\n  });\n\n  if (options.value === '--help') return help().exit();\n  if (options.issues) return help.error`{red ${options.issues[0]}}`.exit(1);\n\n  const {\n    '--dry-run': dryRun,\n    '--command': command = await getPublishCommand(process.cwd()),\n    positional,\n  } = options.value;\n\n  if (!command) return help.error`${noPackageManager}`.exit(1);\n\n  const packages = await getPackages(process.cwd());\n  const commit = await getGitCommit({ dir: process.cwd() });\n\n  for (const pkg of packages) {\n    const result = await publish({ pkg, command, dryRun, extraArgs: positional, commit });\n\n    if (result && result.exitCode !== 0) {\n      process.exit(result.exitCode);\n    }\n  }\n}\n"],"names":[],"mappings":";;;;;AAQA,MAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoCb,MAAM,mBAAmB;AAAA;AAAA;AAIzB,eAAsB,eAAe,MAA+B;AAClE,QAAM,UAAU,MAAM,aAAa,MAAM;AAAA,IACvC,aAAa,KAAA;AAAA,IACb,aAAa,OAAA;AAAA,IACb,MAAM,MAAM,WAAW;AAAA,IACvB,UAAU,IAAA;AAAA,IACV,MAAM,MAAM,QAAQ;AAAA,IACpB,iBAAiB,OAAA;AAAA,EAAO,CACzB;AAED,MAAI,QAAQ,UAAU,SAAU,QAAO,KAAA,EAAO,KAAA;AAC9C,MAAI,QAAQ,OAAQ,QAAO,KAAK,aAAa,QAAQ,OAAO,CAAC,CAAC,IAAI,KAAK,CAAC;AAExE,QAAM;AAAA,IACJ,aAAa;AAAA,IACb,aAAa,UAAU,MAAM,kBAAkB,QAAQ,KAAK;AAAA,IAC5D;AAAA,EAAA,IACE,QAAQ;AAEZ,MAAI,CAAC,QAAS,QAAO,KAAK,QAAQ,gBAAgB,GAAG,KAAK,CAAC;AAE3D,QAAM,WAAW,MAAM,YAAY,QAAQ,KAAK;AAChD,QAAM,SAAS,MAAM,aAAa,EAAE,KAAK,QAAQ,IAAA,GAAO;AAExD,aAAW,OAAO,UAAU;AAC1B,UAAM,SAAS,MAAM,QAAQ,EAAE,KAAK,SAAS,QAAQ,WAAW,YAAY,QAAQ;AAEpF,QAAI,UAAU,OAAO,aAAa,GAAG;AACnC,cAAQ,KAAK,OAAO,QAAQ;AAAA,IAC9B;AAAA,EACF;AACF;"}