MCPcopy Create free account
hub / github.com/dmno-dev/bumpy / initCommand

Function initCommand

packages/bumpy/src/commands/init.ts:36–147  ·  view source on GitHub ↗
(rootDir: string, opts: InitOptions = {})

Source from the content-addressed store, hash-verified

34}
35
36export async function initCommand(rootDir: string, opts: InitOptions = {}): Promise<void> {
37 const bumpyDir = resolve(rootDir, '.bumpy');
38 const changesetDir = resolve(rootDir, '.changeset');
39 const hasChangeset = await exists(changesetDir);
40 const hasBumpy = await exists(resolve(bumpyDir, '_config.json'));
41
42 if (hasBumpy) {
43 log.info("🐸 Detected .bumpy/ directory - looks like we're ready to go!");
44 return;
45 }
46
47 const pm = await detectPackageManager(rootDir);
48
49 if (!opts.force) {
50 p.intro(pc.bgCyan(pc.black(' bumpy init ')));
51 }
52
53 // ── Migrate from changesets ──────────────────────────────────────────
54 if (hasChangeset) {
55 log.step('🦋 Detected .changeset/ directory — migrating to .bumpy/ 🐸');
56
57 // Rename .changeset → .bumpy
58 await rename(changesetDir, bumpyDir);
59 log.dim(' Renamed .changeset/ → .bumpy/');
60
61 // Migrate config.json → _config.json
62 const oldConfigPath = resolve(bumpyDir, 'config.json');
63 if (await exists(oldConfigPath)) {
64 const csConfig = await readJson<Record<string, unknown>>(oldConfigPath);
65 const bumpyConfig = migrateChangesetConfig(csConfig);
66 await writeJson(resolve(bumpyDir, '_config.json'), bumpyConfig);
67 await rm(oldConfigPath);
68 log.dim(' Migrated config.json → _config.json');
69
70 const migratedFields = Object.keys(bumpyConfig).filter((k) => k !== '$schema');
71 if (migratedFields.length > 0) {
72 log.dim(' Migrated fields: ' + migratedFields.join(', '));
73 }
74 } else {
75 // No changeset config, write defaults
76 await writeJson(resolve(bumpyDir, '_config.json'), makeDefaultConfig());
77 }
78
79 // Replace changeset README with bumpy README
80 const readmeContent = readmeTemplate.replaceAll('bunx bumpy', PM_RUNNER[pm] || 'npx bumpy');
81 await writeText(resolve(bumpyDir, 'README.md'), readmeContent);
82 log.dim(' Replaced README.md');
83
84 // Count pending changeset files (they're already compatible)
85 const files = await readdir(bumpyDir);
86 const pendingFiles = files.filter((f) => f.endsWith('.md') && f !== 'README.md');
87 if (pendingFiles.length > 0) {
88 log.dim(` Kept ${pendingFiles.length} pending bump file(s)`);
89 }
90
91 // Check for changesets/cli and offer to uninstall
92 const hasChangesetsCli = await isPackageInstalled(rootDir, '@changesets/cli');
93 if (hasChangesetsCli) {

Callers 2

migrate.test.tsFile · 0.90
mainFunction · 0.85

Calls 12

existsFunction · 0.90
detectPackageManagerFunction · 0.90
writeJsonFunction · 0.90
writeTextFunction · 0.90
unwrapFunction · 0.90
ensureDirFunction · 0.90
migrateChangesetConfigFunction · 0.85
makeDefaultConfigFunction · 0.85
isPackageInstalledFunction · 0.85
uninstallPackageFunction · 0.85
warnChangesetWorkflowsFunction · 0.85
installPackageFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…