Skip to content

Commit

Permalink
Bug/fixed git urls (#4)
Browse files Browse the repository at this point in the history
* feature: Introduce node initialization script, aliases, and documentation

- Added `node-init-wrapper.sh` file that prompts the user to select an organization and creates a new repository using `gh` CLI
- Added `install.sh` script to download and set up aliases for package managers
- Added MIT License file
- Added `README.md` with detailed instructions and information about the project

* Update branch references in installation script and README

- Update SCRIPT_URL variable in install.sh to use correct branch name
- Update URL in curl command in README.md to use "master" branch instead of "main" branch

* docs: Improve project documentation and script execution condition

- Update project name, description, features, and additional information in README.md
- Add ideal users and enhancing project experience sections to README.md
- Add section on setting npm defaults in README.md
- Add keywords section in README.md
- Modify condition to check if first argument is NOT 'init' in node-init-wrapper.sh
- Remove else block and move its content inside new if block in node-init-wrapper.sh
- Add empty lines before appending npm function and npm alias in install.sh

* docs: Revise and clarify project README file

- Modify project setup script description for readability and clarity
- Simplify and clarify explanations in the features section
- Remove mention of GitHub account requirement in prerequisites section
- Clarify that installation command should be run in terminal
- Simplify instructions in the usage section
- Remove repetitive language and clarify process in "How It Works" section
- Remove repetitive language in "Transparency and Control" section
- Remove repetitive language in "Setting Npm Defaults" section
  • Loading branch information
jasonnathan authored Dec 14, 2023
1 parent d7d8056 commit 0fe52c1
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 43 deletions.
99 changes: 86 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -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.
5 changes: 4 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -32,13 +33,15 @@ 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"
fi
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"
Expand Down
59 changes: 30 additions & 29 deletions node-init-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0fe52c1

Please sign in to comment.