Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: v1 implementation of create-permissionless-app CLI #96

Open
wants to merge 43 commits into
base: main
Choose a base branch
from

Conversation

SouravInsights
Copy link

This pull request introduces the v1 implementation of our create-permissionless-app CLI.

Commits Overview:

  1. Commit 1: CLI Core Implementation
  2. Commit 2: Project Scaffolding Helpers
  3. Commit 3: Project Template and Boilerplate

How to run the cli app:

cd src
bun run ./index.ts

Add a new CLI module located at `src/cli/index.ts` to encapsulate all CLI-related functionality. This module includes prompts for project configuration, bundler, paymaster, signer, and account system selection. Additionally, it provides the `runCli` function for handling CLI interactions.

This commit includes some new files, mainly:
- `src/cli/index.ts`
- `src/utils/validateAppName.ts`
- `src/utils/general.ts`
- `src/constants.ts`
- `src/utils/logger.ts`
This commit adds new modules and functionality for scaffolding our Permissionless applications and selecting boilerplate files based on user input.

### Notable changes:

#### `selectBoilerplate.ts`:
- Introduces the `selectBoilerplate` function to handle the selection of boilerplate files.
- Defines helper functions for copying files and overwriting file content.
- Accesses the base & extras dir and selects specific files based on bundler, paymaster, signer, and account system.

#### `scaffoldProject.ts`:
- Implements the `scaffoldProject` function for bootstrapping the base Permissionless application.
- Provides options to clear the directory, overwrite conflicting files, or abort installation based on existing directory status.
- Copies the entire `template/base` directory to the target directory and displays appropriate success or error messages.

#### `createProject.ts`:
- Defines the `createProject` function for orchestrating the entire project creation process.
- Calls `scaffoldProject` to bootstrap the base application and `selectBoilerplate` to choose boilerplate based on user options.
- Returns the project directory path.

#### `src/index.ts`:
- Integrates the new modules into the main CLI script.
- Extracts user preferences from CLI input using `runCli` and invokes `createProject` with the selected options.
- Writes the project name to the `package.json` file.

Known issue: There are a couple of bugs in the first attempt of the `selectBoilerplate` method, which need further investigation and correction.
This commit adds a template directory that serves as a foundational structure for the generated Permissionless app, providing a starting point for development.

**base:** This directory contains the common essential files and structure for the final boilerplate.

- **extras:** This directory extends the base functionality by providing boilerplate configurations for specific choices, such as:
  - Bundler configurations (`bundler` directory), e.g., 'pimlico'.
  - Paymaster configurations (`paymaster` directory), e.g., 'pimlico'.
  - Signer configurations (`signers` directory), e.g., 'privy'.
    - Signer-specific hooks (`hooks` directory) for different account systems.
    - Signer-specific components (`components` directory), e.g., 'PrivyAuth'.
  - Additional page content for specific signers (`pages` directory), e.g., '_app/with-privy.tsx', 'index/with-privy.tsx'.
Copy link

changeset-bot bot commented Jan 25, 2024

⚠️ No Changeset found

Latest commit: f5e771f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

…ate setup

this commit introduces enhancements to the `selectBoilerplate.ts` file, focusing on the methods responsible for file selection and setup. The modifications include:

- fixed the file path resolution & implemented robust error handling mechanisms in the all these methods: `selectBundlerConfigFile`, `selectPaymasterConfigFile`, `selectSignerConfigFile`, `selectAppFile`, `selectIndexFile`, and `selectSignerHooks`.
- added detailed logging to provide clear information in case of missing files or unsuccessful file copying.
…r utility

Added two new functions to enhance the project setup process:
- `installDependencies`: A standalone helper function to install project dependencies based on the detected package manager (npm, yarn, pnpm, bun).
- `detectPackageManager`: A utility function to detect the package manager being used in the current environment.

These additions improve the user experience by automatically handling dependency installation using the appropriate package manager and providing flexibility in supporting multiple package managers.
Copy link
Contributor

@plusminushalf plusminushalf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work overall, After the changes can we publish like 0.0.1 version? I will test it out with a few configuration myself

# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add these to the global .gitignore

accountSystem: () => {
return p.select({
message: "Pick your account system",
options: [{ value: "safe", label: "Safe" }],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you have simple account & kernel as well right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep we have, was gonna add support for them later.. i ignored them since Kristof wanted to just have Safe for the v1 launch..

// Stop spinner and notify users
spinner.succeed(chalk.green("Dependencies installed successfully."))
} catch (error) {
console.error(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey I saw you have a logger class, I think we can replace such console logs with it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right right, missed this in an hurry..


// If the first part is a @, it's a scoped package
const indexOfDelimiter = paths.findIndex((p) => p.startsWith("@"))
if (paths.findIndex((p) => p.startsWith("@")) !== -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use indexOfDelimiter !== -1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

silly of me, yeah will replace it..

return (
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex flex-col w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
Get started by cloning&nbsp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might want to change this, as this template shouldn't need to clone anything.

Copy link
Author

@SouravInsights SouravInsights Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah sure.. i just copied the template code from one of our starter kit & forgot to replace it..

import { sepolia } from "wagmi"

export const createSafeAccount = async (publicClient: PublicClient) => {
const safeAccount: SafeSmartAccount = await privateKeyToSafeSmartAccount(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are creating safe account but the directory is called simple

import { goerli } from "viem/chains"

export const bundlerClient = createPimlicoBundlerClient({
chain: goerli,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wagmi config is with sepolia, we might want to change this to sepolia too.

Also we can use transport as:

https://api.pimlico.io/v1/sepolia/rpc?apikey=API_KEY

@plusminushalf
Copy link
Contributor

Also can you take a pull and redo bun i as there is a conflict with bun's locked file

- rename the module from `bundlerClient` to `pimlicoBundlerConfig`
- rename the module from `pimlicoPaymaster ` to `pimlicoPaymasterConfig `
- use `NEXT_PUBLIC_PIMLICO_BUNDLER_RPC_HOST`  env instead of directly passing the rpc host
This commit adds a new utility function called 'updateIndexFile' to dynamically update/create the index.ts files in the target directory. The function ensures that import & export statements are correctly appended to the index.ts files whenever new files are copied based on the selected options.
Changes:

- Introduced `runInstallCommand` function for executing package manager install commands with spinner animations.
- Refactored `installDependencies` function to orchestrate the installation process, including directory handling, package manager detection, and error logging.
- Improved error handling and logging messages for better user feedback.
- replaced console.log statements with Ora spinner messages for better user feedback during boilerplate setup
- utilized chalk for colored and formatted success and failure messages
- removed unnecessary console logs
This commit introduces a new feature to the CLI module in `src/cli/index.ts`. Specifically, it adds a new interactive prompt that allows users to confirm whether they want the CLI to run the package manager's install command.

It also adds new CLI flags:
   - `--noInstall`: Allows users to explicitly skip running the package manager's install command.
   - `-y, --default`: Offers an option to bypass the CLI and utilize default settings for bootstrapping a new permissionless app.
- Added informative next steps for users after CLI execution.
- Included some thank you note and apology message for beta issues.
- Added a Telegram invitation link for users for feedback & potential issues.
- ensure that newly created index files include the new module in the export statement.
- fix the issue where the export statement was appending the new module multiple times in existing index files.
- corrected the positioning of the export statement to be at the end of the file in both new and existing index files.
- updated the `updateIndexFile` function to correctly handle both scenarios: creating new index files and updating existing ones.
- implemented a check to prevent adding the new module to the export statement multiple times if it already exists.
- tested the changes to ensure correct behavior in both cases of creating new index files and updating existing ones.
packages/create-permissionless-app/README.md Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a few lines/replace this default next.js README with a README specific to the create-permissionless-app template?

@SouravInsights
Copy link
Author

hey, @mouseless-eth resolved most of the issues!

Added several utility functions to enhance Git-related operations in the CLI template generator tool:

1. `isGitInstalled`:
   - Checks if Git is installed by executing `git --version`.
   - Returns a boolean indicating the installation status of Git.

2. `isRootGitRepo`:
   - Determines if the specified directory contains a `.git` subdirectory.
   - Returns a boolean indicating the presence of a `.git` directory.

3. `isInsideGitRepo`:
   - Checks if the current directory or any parent directory contains a `.git` directory.
   - Executes `git rev-parse --is-inside-work-tree` to determine if within a Git repo.
   - Returns a boolean indicating whether a `.git` directory was found.

4. `getGitVersion`:
   - Retrieves the installed Git version by executing `git --version`.
   - Parses and returns the major and minor version numbers.

5. `getDefaultBranch`:
   - Returns the Git config value of `init.defaultBranch`.
   - Defaults to "main" if `init.defaultBranch` is not set.

6. `initializeGit`:
   - Initializes a Git repository in the specified directory.
   - Checks for existing Git installations and configurations.
   - Provides options to overwrite existing Git history or initialize a new repo within an existing worktree.
   - Uses the appropriate Git commands based on the Git version to initialize the repo and set the default branch.

Enhanced user experience by adding prompts and warnings for operations that might affect existing Git repositories. Utilized `execa` for executing shell commands, `fs-extra` for file system operations, and `ora` for spinner animations to provide feedback during the initialization process.

Logging and error handling have been integrated to ensure smooth operations and clear user communication.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants