@bobfrankston/npmglobalize 1.0.99 → 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.
Files changed (2) hide show
  1. package/lib.js +119 -9
  2. package/package.json +1 -1
package/lib.js CHANGED
@@ -116,6 +116,27 @@ function repairGitIndex(cwd) {
116
116
  return false;
117
117
  }
118
118
  }
119
+ /** Parse file paths from git add "Permission denied" / "unable to index file" errors.
120
+ * Matches lines like: error: open("data/PingDB.mdf"): Permission denied
121
+ * and: error: unable to index file 'data/PingDB.mdf' */
122
+ function parseDeniedFiles(errText) {
123
+ const files = [];
124
+ for (const line of errText.split('\n')) {
125
+ // error: open("path"): Permission denied
126
+ let m = line.match(/error:\s*open\(["'](.+?)["']\):\s*Permission denied/i);
127
+ if (m) {
128
+ files.push(m[1]);
129
+ continue;
130
+ }
131
+ // error: unable to index file 'path'
132
+ m = line.match(/error:\s*unable to index file\s+['"](.+?)['"]/i);
133
+ if (m) {
134
+ files.push(m[1]);
135
+ continue;
136
+ }
137
+ }
138
+ return files;
139
+ }
119
140
  /** Get npm command for current platform (npm.cmd on Windows, npm elsewhere) */
120
141
  function getNpmCommand() {
121
142
  return process.platform === 'win32' ? 'npm.cmd' : 'npm';
@@ -1275,7 +1296,10 @@ const RECOMMENDED_GITIGNORE = [
1275
1296
  '.globalize.json5',
1276
1297
  '*.log',
1277
1298
  '.DS_Store',
1278
- 'Thumbs.db'
1299
+ 'Thumbs.db',
1300
+ '*.mdf',
1301
+ '*.ldf',
1302
+ '*.ndf'
1279
1303
  ];
1280
1304
  /** Recommended .npmignore patterns */
1281
1305
  const RECOMMENDED_NPMIGNORE = [
@@ -1543,15 +1567,72 @@ export async function initGit(cwd, visibility, dryRun) {
1543
1567
  runCommandOrThrow('git', ['config', 'core.autocrlf', 'false'], { cwd });
1544
1568
  runCommandOrThrow('git', ['config', 'core.eol', 'lf'], { cwd });
1545
1569
  console.log(' ✓ Configured git for LF line endings');
1546
- runCommandOrThrow('git', ['add', '-A'], { cwd });
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
+ }
1547
1602
  // Only commit if there are staged changes (repo may already have commits)
1548
1603
  const staged = spawnSafe('git', ['diff', '--cached', '--quiet'], { cwd });
1549
1604
  if (staged.status !== 0) {
1550
1605
  runCommandOrThrow('git', ['commit', '-m', 'Initial commit'], { cwd });
1551
1606
  }
1552
- // Create GitHub repo
1607
+ // Create GitHub repo (or link to existing one)
1553
1608
  const visFlag = visibility === 'private' ? '--private' : '--public';
1554
- runCommandOrThrow('gh', ['repo', 'create', repoName, visFlag, '--source=.', '--push'], { cwd });
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
+ }
1555
1636
  // Update package.json with repository field
1556
1637
  try {
1557
1638
  const remoteUrl = execSync('git remote get-url origin', { cwd, encoding: 'utf-8' }).trim();
@@ -2588,13 +2669,42 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
2588
2669
  if (nulCount > 0 && verbose) {
2589
2670
  console.log(` Removed ${nulCount} 'nul' file(s) (Windows reserved name)`);
2590
2671
  }
2591
- const addResult = runCommand('git', ['add', '-A'], { cwd });
2672
+ let addResult = runCommand('git', ['add', '-A'], { cwd, silent: true });
2592
2673
  if (!addResult.success) {
2593
- console.error(colors.red('ERROR: Failed to add files to git:'), addResult.stderr);
2594
- if (!force) {
2595
- return false;
2674
+ const errText = addResult.stderr + addResult.output;
2675
+ const deniedFiles = parseDeniedFiles(errText);
2676
+ if (deniedFiles.length > 0) {
2677
+ console.error(colors.red(`git add failed — ${deniedFiles.length} file(s) locked/permission denied:`));
2678
+ for (const f of deniedFiles) {
2679
+ console.error(colors.red(` ${f}`));
2680
+ }
2681
+ const ok = await confirm('Add these files to .gitignore and retry?', true);
2682
+ if (ok) {
2683
+ const gitignorePath = path.join(cwd, '.gitignore');
2684
+ let gitignoreContent = fs.existsSync(gitignorePath) ? fs.readFileSync(gitignorePath, 'utf-8') : '';
2685
+ if (gitignoreContent && !gitignoreContent.endsWith('\n'))
2686
+ gitignoreContent += '\n';
2687
+ for (const f of deniedFiles) {
2688
+ gitignoreContent += f + '\n';
2689
+ }
2690
+ fs.writeFileSync(gitignorePath, gitignoreContent);
2691
+ console.log(colors.green('✓ Updated .gitignore'));
2692
+ addResult = runCommand('git', ['add', '-A'], { cwd, silent: true });
2693
+ if (addResult.success) {
2694
+ console.log(colors.green('✓ git add succeeded after updating .gitignore'));
2695
+ }
2696
+ }
2697
+ if (!addResult.success) {
2698
+ return false;
2699
+ }
2700
+ }
2701
+ else {
2702
+ console.error(colors.red('ERROR: Failed to add files to git:'), errText);
2703
+ if (!force) {
2704
+ return false;
2705
+ }
2706
+ console.log(colors.yellow('Continuing with --force...'));
2596
2707
  }
2597
- console.log(colors.yellow('Continuing with --force...'));
2598
2708
  }
2599
2709
  let commitResult = runCommand('git', ['commit', '-m', commitMsg], { cwd });
2600
2710
  if (!commitResult.success) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/npmglobalize",
3
- "version": "1.0.99",
3
+ "version": "1.0.101",
4
4
  "description": "Transform file: dependencies to npm versions for publishing",
5
5
  "main": "index.js",
6
6
  "type": "module",