Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add
one change show
(#663)
**Problem:** While it's easy to inspect the files in the `.changes` folder(s), it would be more helpful to have a command that could list and preview the changes together, including dependencies that need versioning. **Solution:** Adds `one change show` to preview versions and changelogs. Minimal for now, ripe for making prettier. **Related issues:** Fixes #656 **Checklist:** - [x] Added or updated tests - [x] Added or updated documentation - [x] Ensured the pre-commit hooks ran successfully
- Loading branch information
1 parent
f22e04d
commit 15bff1b
Showing
8 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
type: minor | ||
--- | ||
|
||
Adds `one change show` to help preview changes in Workspaces" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import path from 'node:path'; | ||
import { getCommand } from '@onerepo/test-cli'; | ||
import { getGraph } from '@onerepo/graph'; | ||
import * as show from '../show'; | ||
|
||
const graph = getGraph(path.join(__dirname, '__fixtures__/with-entries')); | ||
const { run } = getCommand(show, graph); | ||
|
||
describe('show changes', () => { | ||
test('adds change files', async () => { | ||
vi.spyOn(process.stdout, 'write').mockReturnValue(true); | ||
await run('-w tacos --format json'); | ||
|
||
expect(process.stdout.write).toHaveBeenCalledWith( | ||
expect.stringContaining( | ||
'{"cheese":{"type":"minor","version":"2.1.0","entries":[{"type":"minor","content":"A minor change\\n"', | ||
), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import cliui from 'cliui'; | ||
import pc from 'picocolors'; | ||
import type { WithWorkspaces } from '@onerepo/builders'; | ||
import { withWorkspaces } from '@onerepo/builders'; | ||
import type { Workspace } from '@onerepo/graph'; | ||
import type { Builder, Handler } from '@onerepo/yargs'; | ||
import type { VersionPlan } from './utils'; | ||
import { buildChangelog, getVersionable } from './utils'; | ||
|
||
export const command = ['show']; | ||
|
||
export const description = 'Preview the next versions and changelogs for Workspaces.'; | ||
|
||
type Argv = WithWorkspaces & { | ||
format: 'json' | 'plain'; | ||
}; | ||
|
||
export const builder: Builder<Argv> = (yargs) => | ||
withWorkspaces(yargs.usage(`$0 ${command[0]}`)).option('format', { | ||
type: 'string', | ||
choices: ['json', 'plain'] as const, | ||
default: 'plain' as const, | ||
description: 'Choose how the results will be returned.', | ||
}); | ||
|
||
export const handler: Handler<Argv> = async (argv, { getWorkspaces, graph }) => { | ||
const { format } = argv; | ||
|
||
const workspaces = await getWorkspaces(); | ||
|
||
const versionPlans = await getVersionable(graph); | ||
|
||
const deps = graph.dependencies(workspaces, true); | ||
|
||
const toVersion: Array<Workspace> = Array.from(versionPlans.keys()).filter((ws) => deps.includes(ws)); | ||
|
||
if (format === 'json') { | ||
process.stdout.write( | ||
JSON.stringify( | ||
toVersion.reduce( | ||
(memo, ws) => { | ||
memo[ws.name] = versionPlans.get(ws)!; | ||
return memo; | ||
}, | ||
{} as Record<string, VersionPlan>, | ||
), | ||
) + '\n', | ||
); | ||
return; | ||
} | ||
|
||
const ui = cliui({ width: Math.min(160, process.stdout.columns) }); | ||
for (const ws of toVersion) { | ||
const plan = versionPlans.get(ws)!; | ||
ui.div( | ||
{ text: pc.cyan(pc.bold(pc.underline(ws.name))), padding: [1, 0, 0, 0] }, | ||
{ text: `${ws.version} ${pc.dim('→')} ${pc.bold(plan.version)}`, padding: [1, 0, 0, 0] }, | ||
); | ||
|
||
const deps = graph.dependencies(ws); | ||
const depPlans = new Map<Workspace, VersionPlan>(); | ||
for (const dep of deps) { | ||
const depPlan = versionPlans.get(dep); | ||
if (depPlan) { | ||
depPlans.set(dep, depPlan); | ||
} | ||
} | ||
|
||
ui.div({ text: await buildChangelog(plan, depPlans), padding: [0, 2, 0, 2] }); | ||
} | ||
process.stdout.write(ui.toString() + '\n'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters