@bobfrankston/npmglobalize 1.0.100 → 1.0.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib.js +60 -3
- package/package.json +1 -1
package/lib.js
CHANGED
|
@@ -1567,15 +1567,72 @@ export async function initGit(cwd, visibility, dryRun) {
|
|
|
1567
1567
|
runCommandOrThrow('git', ['config', 'core.autocrlf', 'false'], { cwd });
|
|
1568
1568
|
runCommandOrThrow('git', ['config', 'core.eol', 'lf'], { cwd });
|
|
1569
1569
|
console.log(' ✓ Configured git for LF line endings');
|
|
1570
|
-
|
|
1570
|
+
let initAddResult = runCommand('git', ['add', '-A'], { cwd, silent: true });
|
|
1571
|
+
if (!initAddResult.success) {
|
|
1572
|
+
const errText = initAddResult.stderr + initAddResult.output;
|
|
1573
|
+
const deniedFiles = parseDeniedFiles(errText);
|
|
1574
|
+
if (deniedFiles.length > 0) {
|
|
1575
|
+
console.error(colors.red(` git add failed — ${deniedFiles.length} file(s) locked/permission denied:`));
|
|
1576
|
+
for (const f of deniedFiles) {
|
|
1577
|
+
console.error(colors.red(` ${f}`));
|
|
1578
|
+
}
|
|
1579
|
+
const ok = await confirm('Add these files to .gitignore and retry?', true);
|
|
1580
|
+
if (ok) {
|
|
1581
|
+
const gitignorePath = path.join(cwd, '.gitignore');
|
|
1582
|
+
let gitignoreContent = fs.existsSync(gitignorePath) ? fs.readFileSync(gitignorePath, 'utf-8') : '';
|
|
1583
|
+
if (gitignoreContent && !gitignoreContent.endsWith('\n'))
|
|
1584
|
+
gitignoreContent += '\n';
|
|
1585
|
+
for (const f of deniedFiles) {
|
|
1586
|
+
gitignoreContent += f + '\n';
|
|
1587
|
+
}
|
|
1588
|
+
fs.writeFileSync(gitignorePath, gitignoreContent);
|
|
1589
|
+
console.log(colors.green(' ✓ Updated .gitignore'));
|
|
1590
|
+
initAddResult = runCommand('git', ['add', '-A'], { cwd, silent: true });
|
|
1591
|
+
}
|
|
1592
|
+
if (!initAddResult.success) {
|
|
1593
|
+
console.error(colors.red(' git add still failing. Fix manually and retry.'));
|
|
1594
|
+
return false;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
else {
|
|
1598
|
+
console.error(colors.red(` git add failed: ${errText}`));
|
|
1599
|
+
return false;
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1571
1602
|
// Only commit if there are staged changes (repo may already have commits)
|
|
1572
1603
|
const staged = spawnSafe('git', ['diff', '--cached', '--quiet'], { cwd });
|
|
1573
1604
|
if (staged.status !== 0) {
|
|
1574
1605
|
runCommandOrThrow('git', ['commit', '-m', 'Initial commit'], { cwd });
|
|
1575
1606
|
}
|
|
1576
|
-
// Create GitHub repo
|
|
1607
|
+
// Create GitHub repo (or link to existing one)
|
|
1577
1608
|
const visFlag = visibility === 'private' ? '--private' : '--public';
|
|
1578
|
-
|
|
1609
|
+
const createResult = runCommand('gh', ['repo', 'create', repoName, visFlag, '--source=.', '--push'], { cwd, silent: true });
|
|
1610
|
+
if (!createResult.success) {
|
|
1611
|
+
const errText = createResult.stderr + createResult.output;
|
|
1612
|
+
if (errText.includes('Name already exists')) {
|
|
1613
|
+
// Repo exists on GitHub — look up the owner and add as remote
|
|
1614
|
+
console.log(colors.yellow(` GitHub repo '${repoName}' already exists — linking as remote...`));
|
|
1615
|
+
const whoResult = runCommand('gh', ['api', 'user', '--jq', '.login'], { cwd, silent: true });
|
|
1616
|
+
const ghUser = (whoResult.output || '').trim();
|
|
1617
|
+
if (!ghUser) {
|
|
1618
|
+
console.error(colors.red(' Could not determine GitHub username. Run: gh auth status'));
|
|
1619
|
+
return false;
|
|
1620
|
+
}
|
|
1621
|
+
const remoteUrl = `https://github.com/${ghUser}/${repoName}.git`;
|
|
1622
|
+
const addRemote = runCommand('git', ['remote', 'add', 'origin', remoteUrl], { cwd, silent: true });
|
|
1623
|
+
if (!addRemote.success) {
|
|
1624
|
+
// Remote might already exist with wrong URL
|
|
1625
|
+
runCommand('git', ['remote', 'set-url', 'origin', remoteUrl], { cwd, silent: true });
|
|
1626
|
+
}
|
|
1627
|
+
// Push existing commits
|
|
1628
|
+
runCommand('git', ['push', '-u', 'origin', 'master'], { cwd, silent: true });
|
|
1629
|
+
console.log(colors.green(` ✓ Linked to existing repo: ${remoteUrl}`));
|
|
1630
|
+
}
|
|
1631
|
+
else {
|
|
1632
|
+
console.error(colors.red(`Failed to create GitHub repo: ${errText}`));
|
|
1633
|
+
return false;
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1579
1636
|
// Update package.json with repository field
|
|
1580
1637
|
try {
|
|
1581
1638
|
const remoteUrl = execSync('git remote get-url origin', { cwd, encoding: 'utf-8' }).trim();
|