diff --git a/README.md b/README.md index 88d2063..77beab8 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,40 @@ -# NpmGitInit +# NpmGitInit 🚀 - Your Go-To for npm, yarn & pnpm Init Hooks! ## Description -NpmGitInit is a powerful shell script designed to streamline the process of initializing Node.js projects. It integrates the creation and configuration of GitHub repositories directly into your project setup workflow. Perfect for developers looking to automate their initial setup tasks for Node.js projects, this script simplifies the process to a single command execution. +🛠️ **NpmGitInit** is your magic wand for Node.js project setups! It serves as a nifty hook for `npm`, `yarn`, and `pnpm`, turbocharging your project initialization. It's like having a personal assistant for setting up GitHub repositories, perfect for Node.js enthusiasts. + +🌐 Seamlessly integrate repository creation and configuration into your `init` command with **NpmGitInit**. Transform the mundane into the extraordinary! Whether you prefer `npm`, `yarn`, or `pnpm`, this script has got your back, ensuring a smooth, automated setup for your Node.js adventure. + +🔍 Need an `npm init hook`? Want to bypass the usual `npm init` drill? Or searching for something similar for `yarn` and `pnpm`? Look no further, **NpmGitInit** is here to jazz up your workflow! ## Features -- **Automated GitHub Repository Creation**: Creates a GitHub repository for your Node.js project with ease. -- **Project Directory Initialization**: Sets up your project directory with essential Node.js configurations. -- **Choice of GitHub Organization**: Allows selection of a GitHub organization for your repository, defaulting to your personal account. -- **Compatibility with npm, yarn, and pnpm**: Seamlessly integrates with popular Node.js package managers. -- **Open Source Contribution**: Open to community contributions and improvements. +- **Automated GitHub Repository Creation**: Simplify GitHub repository setup for `npm`, `yarn`, and `pnpm`. +- **Universal Init Hook**: Automate the `init` command across `npm`, `yarn`, and `pnpm`. +- **Project Directory Initialization**: Set up your project directory along with a new repository. +- **Custom GitHub Organization Selection**: Choose a GitHub organization during initialization. +- **Enhanced Initialization Process**: Automate Git and GitHub setup for `npm init`, `yarn init`, or `pnpm init`. ## Getting Started ### Prerequisites -- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) installed and configured on your system. +- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) installed and configured. - [GitHub CLI](https://cli.github.com/manual/installation) installed and authenticated. - [`jq`](https://stedolan.github.io/jq/download/) command-line JSON processor installed. -- A GitHub account for repository creation and management. [Sign up here](https://github.com/join) if you don't have one. +- [GitHub account](https://github.com/join) for repository creation and management. ### Installation -Execute the following command in your terminal to install: +Run this command in your terminal to install: ```bash -curl -sSL https://raw.githubusercontent.com/seriouslyjs/NpmGitInit/main/install.sh | bash +curl -sSL https://raw.githubusercontent.com/seriouslyjs/NpmGitInit/master/install.sh | bash ``` -This command will download and execute the `install.sh` script, which in turn will set up `node-init-wrapper.sh` and the required aliases. +This command downloads and executes the `install.sh` script, setting up `node-init-wrapper.sh` and the required aliases. + ### Usage @@ -51,7 +56,72 @@ Or with pnpm: pnpm init ``` -Then follow the interactive prompts to select an organization and configure your repository. +Follow the interactive prompts to select an organization and configure your repository. + +## How It Works + +The `node-init-wrapper.sh` script streamlines the process of setting up a new Node.js project by automating several steps. **The script only cares if you call `init`** and returns early if not. Here's an overview of what happens behind the scenes: + +### Detecting the Current Folder + +- When you execute `npm init`, `yarn init`, or `pnpm init`, the script detects the name of the current working directory. This name is used to create a new GitHub repository. + +### Creating a GitHub Repository + +- The script prompts you to choose a GitHub organization for the new repository. It presents the list of organizations you are a part of using the GitHub CLI. +- If you don't choose an organization, it defaults to creating the repository under your personal GitHub account. +- The repository is created with the name matching your current directory and is set to private by default. + +### Cloning the Repository + +- After creating the GitHub repository, the script clones it into your current working directory. This sets up a Git remote named `origin` pointing to your new GitHub repository. +- This step links your local directory and the GitHub repository, ready for version control and collaboration. + +### Running the Original Init Command + +- The script executes the original `npm init`, `yarn init`, or `pnpm init` command. This initializes your project as a Node.js project, creating a `package.json` file. +- You'll be prompted with the usual questions by `npm`, `yarn`, or `pnpm` to configure your `package.json`. + +### Staging and Committing + +- Finally, the script stages the `package.json` file and makes an initial commit to your repository. It then pushes this commit to the `main` branch of your new GitHub repository. + +### Transparency and Control + +- By automating these steps, `node-init-wrapper.sh` saves time and reduces repetitive tasks when starting a new Node.js project. +- The script is open source, allowing you to review, modify, and extend it as you see fit. This transparency ensures full control over what happens in your development environment. + +## Ideal for + +- Node.js developers using `npm`, `yarn`, or `pnpm` for project management. +- Those looking to automate the link between `npm init`, `yarn init`, or `pnpm init` and GitHub repository creation. +- Users seeking an extended functionality hook for any of these package managers. +- Developers aiming to streamline their initial project setup process in Node.js. + +## Enhancing Your Experience + +Beyond the basic setup, you can further customize and enhance your Node.js project initialization experience. Here are some additional steps you can take: + +### Setting Npm Defaults + +Using `npm set`, define default values for your `npm init` process. This saves time and ensures consistency across projects. For example: + +- Set your default author name and email: + + ```bash + npm set init-author-name "Your Name" + npm set init-author-email "your.email@example.com" + npm set init-author-url "http://yourwebsite.com" + ``` + +- Set a default license: + + ```bash + npm set init-license "MIT" + ``` + +These defaults will be used every time you run `npm|yarn|pnpm init`, streamlining the process. + ## Contributing @@ -73,3 +143,6 @@ Jason Nathan - [@jason_nathan](https://twitter.com/jason_nathan) Project Link: [https://github.com/seriouslyjs/NpmGitInit](https://github.com/seriouslyjs/NpmGitInit) +## Keywords + +- Npm init hook, yarn init automation, pnpm setup script, GitHub repository integration, Node.js project initialization, automate npm/yarn/pnpm setup, npm/yarn/pnpm and GitHub automation tool. diff --git a/install.sh b/install.sh index c09e10e..7bcc8fd 100644 --- a/install.sh +++ b/install.sh @@ -1,7 +1,8 @@ #!/bin/bash # Download and store the script -SCRIPT_URL="https://raw.githubusercontent.com/seriouslyjs/NpmGitInit/main/node-init-wrapper.sh" +SCRIPT_URL="https://raw.githubusercontent.com/seriouslyjs/NpmGitInit/master/node-init-wrapper.sh" + INSTALL_DIR="$HOME" SCRIPT_NAME="node-init-wrapper.sh" @@ -32,6 +33,7 @@ chmod +x "$INSTALL_DIR/$SCRIPT_NAME" if [ "$SHELL" = "*/fish" ]; then # Fish shell syntax for alias if ! grep -q "function npm;" "$ALIAS_FILE"; then + echo "\n" echo "function npm; $INSTALL_DIR/$SCRIPT_NAME npm \$argv; end" >> "$ALIAS_FILE" echo "function yarn; $INSTALL_DIR/$SCRIPT_NAME yarn \$argv; end" >> "$ALIAS_FILE" echo "function pnpm; $INSTALL_DIR/$SCRIPT_NAME pnpm \$argv; end" >> "$ALIAS_FILE" @@ -39,6 +41,7 @@ if [ "$SHELL" = "*/fish" ]; then else # Bash/Zsh syntax for alias if ! grep -q "alias npm=" "$ALIAS_FILE"; then + echo "\n" echo "alias npm=\"$INSTALL_DIR/$SCRIPT_NAME npm\"" >> "$ALIAS_FILE" echo "alias yarn=\"$INSTALL_DIR/$SCRIPT_NAME yarn\"" >> "$ALIAS_FILE" echo "alias pnpm=\"$INSTALL_DIR/$SCRIPT_NAME pnpm\"" >> "$ALIAS_FILE" diff --git a/node-init-wrapper.sh b/node-init-wrapper.sh index 2970fe1..f0462a0 100755 --- a/node-init-wrapper.sh +++ b/node-init-wrapper.sh @@ -14,34 +14,35 @@ DIR_NAME=$(basename "$(pwd)") # Get the GitHub username GH_USERNAME=$(gh api /user --jq '.login') -# Check if the first argument is 'init' -if [ "$1" = "init" ]; then - # 1. Get the directory it was called in - echo "Current directory: $DIR_NAME" - echo "Fetching available organizations..." - ORGS=$(gh api -X GET /user/orgs --paginate --jq '.[].login' | tr '\n' ' ') - - echo "Available organizations:" - PS3="Please select the number above (or press Enter for $GH_USERNAME): " - select ORG_CHOICE in $ORGS; do - ORG_CHOICE=${ORG_CHOICE:-$GH_USERNAME} - break - done - # 2. Run 'gh repo create' - gh repo create $ORG_CHOICE/$DIR_NAME --private -g Node - - # 3. Clone the repo into the current directory - # Assuming you want to clone into the current directory - gh repo clone $ORG_CHOICE/$DIR_NAME . - - # 4. Run the original init command - "$ORIGINAL_CMD_PATH" "$@" - - # 5. Stage and commit the files - git add package.json - git commit -m "Initial commit" - git push -u origin main -else - # Pass all arguments to the original command +# Check if the first argument is NOT 'init' +if [ "$1" != "init" ]; then + # If not 'init', immediately pass all arguments to the original command "$ORIGINAL_CMD_PATH" "$@" + exit fi + +# 1. Get the directory it was called in +echo "Current directory: $DIR_NAME" +echo "Fetching available organizations..." +ORGS=$(gh api -X GET /user/orgs --paginate --jq '.[].login' | tr '\n' ' ') + +echo "Available organizations:" +PS3="Please select the number above (or press Enter for $GH_USERNAME): " +select ORG_CHOICE in $ORGS; do + ORG_CHOICE=${ORG_CHOICE:-$GH_USERNAME} + break +done +# 2. Run 'gh repo create' +gh repo create $ORG_CHOICE/$DIR_NAME --private -g Node + +# 3. Clone the repo into the current directory +# Assuming you want to clone into the current directory +gh repo clone $ORG_CHOICE/$DIR_NAME . + +# 4. Run the original init command +"$ORIGINAL_CMD_PATH" "$@" + +# 5. Stage and commit the files +git add package.json +git commit -m "Initial commit" +git push -u origin main