diff --git a/bun.lockb b/bun.lockb index cc251bb..3f75e61 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/make-repo-ssh.sh b/make-repo-ssh.sh index 97e0a2f..7f2ea20 100755 --- a/make-repo-ssh.sh +++ b/make-repo-ssh.sh @@ -9,7 +9,7 @@ if [[ $CURRENT_URL == https://* ]]; then REPO_NAME=$(basename "$CURRENT_URL" ".git") # Update the Git remote URL to use SSH - NEW_URL="git@github.com:$(basename $(dirname "$CURRENT_URL"))/${REPO_NAME}.git" + NEW_URL="git+ssh://git@github.com:$(basename $(dirname "$CURRENT_URL"))/${REPO_NAME}.git" git remote set-url origin "$NEW_URL" # Verify the changes diff --git a/package.json b/package.json index d4ac9df..a522e35 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "tsc": "tsc", "start": "bun run index.ts", "test": "bun test", - "build": "bun i && bun scripts/update-package.ts && rm *.tsbuildinfo && rm -rf dist/*.* && bun run bundler/bundler.ts && bun run test && bun run build:declaration", + "build": "bun i && bun run fix-package-name && rm *.tsbuildinfo && rm -rf dist/*.* && bun run bundler/bundler.ts && bun run test && bun run build:declaration", "build:declaration": "tsc --emitDeclarationOnly --project tsconfig.types.json", "build:example": "cd example && bun i && bun run build && cd ..", "list": "bun run samples/list-scripts.tsx", @@ -41,6 +41,7 @@ "fileSample": "bun run samples/file.tsx && cat samples/data/test.json", "httpSample": "bun run samples/server.tsx", "make-repo-ssh": "./make-repo-ssh.sh", + "fix-package-name": "npm start --prefix node_modules/package-name-fixer", "autocommit": "npm explore @dobuki/autocommit -- bun run autocommit \"$(pwd)\"", "np": "bun run build && bun run build:example && bun run make-repo-ssh && bun run autocommit && np" }, @@ -60,7 +61,7 @@ "bun-types": "^1.0.2", "jest": "^29.7.0", "np": "^9.2.0", - "png-to-ico": "^2.1.8", + "package-name-fixer": "^1.0.2", "prettier": "^3.0.3", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -68,6 +69,5 @@ }, "peerDependencies": { "typescript": "^5.0.0" - }, - "dependencies": {} + } } diff --git a/scripts/update-package.ts b/scripts/update-package.ts deleted file mode 100644 index 00b3458..0000000 --- a/scripts/update-package.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { execSync } from 'child_process'; -function getRepoName() { - try { - // Get the remote URL of the origin repository - const remoteUrl = execSync('git remote get-url origin').toString().trim(); - - // Extract the repository name from the remote URL - const repoName = remoteUrl.match(/\/([^\/]+?)(?:\.git)?$/)?.[1] || 'unknown'; - - return repoName; - } catch (error) { - throw new Error("Unable to get repo name: ", error.message); - } -} - -function getAuthorEmail() { - try { - // Get the email of the author of the initial commit - const authorEmail = execSync('git log --format=%ae --reverse | head -n 1').toString().trim(); - return authorEmail; - } catch (error) { - throw new Error('Error retrieving repository author:', error.message); - } -} - -function getAuthorName() { - - try { - // Get the name and email of the author of the initial commit - const authorName = execSync('git log --format="%an" --reverse | head -n 1').toString().trim(); - return authorName; - } catch (error) { - throw new Error('Error retrieving repository author:', error.message); - } -} - -function getRepoOwner(repoUrl: string): string { - const match = repoUrl.match(/[:/]([^/]+)\/([^/]+)(\.git)?$/); - return match?.[1] ?? ""; -} - -function getRepoUrl() { - try { - // Get the HTTPS URL of the origin repository - const repoUrl = execSync('git remote get-url origin').toString().trim(); - return repoUrl; - } catch (error) { - throw new Error('Error retrieving repository URL:', error.message); - } -} - -async function getRepoDetails(owner: string, repo: string) { - try { - const response = await fetch(`https://api.github.com/repos/${owner}/${repo}`); - const data: any = await response.json(); - - if (response.ok) { - return { - description: data.description || null, - owner: data.owner ? { id: data.owner.id } : null, - homepage: data.homepage || null, - }; - } else { - console.error(`Failed to fetch repository details: ${data.message}`); - return null; - } - } catch (error) { - console.error('Error fetching repository details:', error.message); - return null; - } -} - -async function updatePackage() { - const file = Bun.file('package.json'); - - const repoName = getRepoName(); - const repoAuthor = getAuthorName(); - const repoEmail = getAuthorEmail(); - const repoUrl = getRepoUrl(); - const repoDetails = await getRepoDetails(getRepoOwner(repoUrl), repoName); - - const pkg = JSON.parse(await file.text()); - if (pkg.name !== repoName) { - pkg.name = repoName; - pkg.version = "1.0.0"; - } - pkg.repository.url = getRepoUrl(); - pkg.author = { - name: repoAuthor, - email: repoEmail, - }; - pkg.description = repoDetails?.description ?? ""; - pkg.homepage = repoDetails?.homepage ?? ""; - - await Bun.write(file, JSON.stringify(pkg, null, " ") + "\n"); -} - -updatePackage();