Skip to content

Commit

Permalink
make cli source code more understandable
Browse files Browse the repository at this point in the history
  • Loading branch information
blefnk committed Oct 28, 2024
1 parent f803d79 commit 5d91024
Show file tree
Hide file tree
Showing 23 changed files with 211 additions and 240 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
# Reliverse CLI
# Reliverse

*Build the Sites. Build the Apps. Build the Games. Build Anything.*
[GitHub](https://github.com/reliverse/cli), [npmjs](https://npmjs.com/package/reliverse)

**Reliverse** is a CLI tool designed to streamline the setup of JavaScript, TypeScript, and other types of projects, with a primary focus on Next.js templates, though it is not limited to them. It allows you to effortlessly bootstrap projects, including the [Relivator Next.js template](https://github.com/blefnk/relivator-nextjs-template) or any other template from GitHub or other Git-based sources. Additionally, Reliverse assists in managing configuration files and resolving potential conflicts between tools like ESLint, Prettier, and Biome.
**Reliverse** is a CLI tool designed to streamline the setup of JavaScript, TypeScript, and other types of projects, with a primary focus on Next.js templates, though it is not limited to them.

It allows you to effortlessly bootstrap projects, including the [Relivator Next.js template](https://github.com/blefnk/relivator-nextjs-template) or any other template from GitHub or other Git-based sources. Additionally, Reliverse assists in managing configuration files and resolving potential conflicts between tools like ESLint, Prettier, and Biome.

Reliverse is more than just the easiest way to install Relivator. It’s also the most convenient new way to download any repository from GitHub and automatically prepare it for work. Especially if it’s a project from the JavaScript ecosystem.

The mission of this project is not only to help you install templates in seconds. It is also a desire to make web development more accessible to everyone. It’s a commitment to fixing many things that don’t work in the ecosystem. It’s a wish to share templates, libraries, and tools with the world that deserve attention. It’s also a drive to motivate developers to become contributors to various projects that need and deserve it.

## TL;DR

**It's a single tool for everything.** At its current stage, Reliverse CLI is a powerful website builder and project bootstrapper, right in your terminal. However, it won’t just be a website builder in the future. Even now, you can start from scratch or with a template, setting everything up automatically or customizing it to your exact preferences. With all the tools pre-configured and ready to go, you can build exactly what you envision.
**It's a single tool for everything.** At its current stage, Reliverse CLI is a powerful website builder and project bootstrapper, right in your terminal. However, it won’t be only a website builder in the future, it will be a tool for building anything. Even now, you can start from scratch or with a template, setting everything up automatically or customizing it to your exact preferences. With all the tools pre-configured and ready to go, you can build exactly what you envision.

Remember the feeling of empowerment when you first used a website builder like WordPress? It gave you the freedom to create. But eventually, you hit limits—PageSpeed Insights flagged issues, performance lagged, and the bloated size of your site became hard to ignore.

*That’s where Reliverse comes in.* Reliverse is designed to fix the problems of traditional website builders, offering a universal toolset that lets you create anything you can imagine—efficiently and with ease.

## Get Started

Reliverse is still in its early stages, but it already allows you to bootstrap websites quickly. Soon, advanced customization options will be available, along with game-building tools and other exciting features. You're going to love what's coming.
Reliverse is still in its early stages, but it already allows you to bootstrap websites quickly. Soon, advanced customization options will be available, along with other exciting features. You're going to love what's coming.

By the way, you might think that a CLI doing so many things would become bloated, like an elephant in the room, but don’t worry—it’s going to be lean. This is the dream of a creator, a dream that must become reality. Everything has to be perfect.

*Psst... We’re already working on a frontend version of the builder too!* 😉

## Installation

You should install [Git](https://git-scm.com), [VSCode](https://code.visualstudio.com), and [Node.js LTS](https://nodejs.org/en/download/package-manager) first. Then use one of the following commands to install **Reliverse**:
Expand Down Expand Up @@ -48,7 +52,7 @@ reliverse
- **Interactive Prompts**: Customize your setup through interactive prompts that allow you to select which file categories to include.
- **Template-Driven**: Automatically clones and installs templates from GitHub to kickstart your development.
- **Unlimited Possibilities**: It can work not only with templates! Are you going to clone a JS library? Feel free to use Reliverse!
- **Anything Else?!**: Currently, the CLI is optimized for JS/TS projects (like React, Astro, Vue, Svelte, etc.). In the future, it will even support native video game applications! This is the dream of Reliverse's founder—a single tool designed for everything.
- **Anything Else?!**: Currently, the CLI is optimized for JS/TS projects (like React, Astro, Vue, Svelte, etc). This is the dream of Reliverse's founder—a single tool designed for everything.

### Commands

Expand Down
3 changes: 1 addition & 2 deletions knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"src/prompts/utils/putout.ts",
"src/prompts/utils/string.ts",
"src/prompts/utils/types.ts",
"src/prompts/utils/with.ts",
"src/prompts/05-askTemplate.ts"
"src/prompts/utils/with.ts"
],
"ignoreBinaries": [],
"ignoreDependencies": [
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"default": "./dist/index.js"
}
},
"homepage": "https://reliverse.org",
"repository": "https://github.com/reliverse/cli",
"bugs": "https://github.com/reliverse/cli/issues",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"bin": {
Expand Down
6 changes: 3 additions & 3 deletions src/prompts/00-showReliverseMenu.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import consola from "consola";
import { buildOwnRelivator } from "~/prompts/02-buildOwnRelivator";
import { justInstallRelivator } from "~/prompts/01-justInstallRelivator";
import { installRepository } from "~/prompts/03-installAnyGitRepo";
import { installAnyGitRepo } from "~/prompts/03-installAnyGitRepo";

export async function showReliverseMenu() {
const option = await consola.prompt(
"Reliverse will allow you to do many things in the future. It's already able to create new projects and make some codebase modifications. How do you want to proceed?",
"Welcome to Reliverse! How do you want to proceed? Reliverse will allow you to do many things in the future. It's already able to create new projects and make some codebase modifications.",
{
options: [
"1. Install pre-configured Relivator",
Expand All @@ -21,7 +21,7 @@ export async function showReliverseMenu() {
} else if (option === "2. Build your own Relivator from scratch") {
await buildOwnRelivator();
} else if (option === "3. Install any other repository from GitHub") {
await installRepository();
await installAnyGitRepo();
} else {
consola.error("Invalid option selected. Exiting.");
}
Expand Down
52 changes: 26 additions & 26 deletions src/prompts/01-justInstallRelivator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@ import { consola } from "consola";
import path from "pathe";

import { askAppName } from "~/prompts/04-askAppName";
import { askUserName } from "~/prompts/06-askUserName";
import { askAppDomain } from "~/prompts/07-askAppDomain";
import { askGitInitialization } from "~/prompts/08-askGitInitialization";
import { askInstallDependencies } from "~/prompts/09-askInstallDependencies";
import { askSummaryConfirmation } from "~/prompts/10-askSummaryConfirmation";
import { askInternationalizationSetup } from "~/prompts/11-askInternationalizationSetup";
import { askCheckAndDownloadFiles } from "~/prompts/13-askCheckAndDownloadFiles";
import { showCongratulationMenu } from "~/prompts/14-showCongratulationMenu";
import { askUserName } from "~/prompts/05-askUserName";
import { askAppDomain } from "~/prompts/06-askAppDomain";
import { askGitInitialization } from "~/prompts/07-askGitInitialization";
import { askInstallDependencies } from "~/prompts/08-askInstallDependencies";
import { askSummaryConfirmation } from "~/prompts/09-askSummaryConfirmation";
import { askInternationalizationSetup } from "~/prompts/10-askInternationalizationSetup";
import { askCheckAndDownloadFiles } from "~/prompts/12-askCheckAndDownloadFiles";
import { showCongratulationMenu } from "~/prompts/13-showCongratulationMenu";
import { downloadI18nFiles } from "~/prompts/utils/downloadI18nFiles";
import { getCurrentWorkingDirectory } from "~/prompts/utils/fs";
import { handleReplacements } from "~/prompts/utils/handleReplacements";
import { installTemplate } from "~/prompts/utils/installTemplate";
import { handleStringReplacements } from "~/prompts/utils/handleStringReplacements";
import { downloadGitRepo } from "~/prompts/utils/downloadGitRepo";
import { moveAppToLocale } from "~/prompts/utils/moveAppToLocale";
import { isDev } from "~/settings";
import { isDev, REPO_SHORT_URLS } from "~/settings";

export async function justInstallRelivator() {
const cwd = getCurrentWorkingDirectory();
consola.info(
"Let's create a brand-new web app using the Relivator Next.js template. After that, you can customize everything however you like.",
);

const template = REPO_SHORT_URLS.relivatorGithubLink;
const appName = await askAppName();
const template = "blefnk/relivator-nextjs-template";
const username = await askUserName();
const domain = await askAppDomain();
const git = await askGitInitialization();
Expand All @@ -38,33 +40,31 @@ export async function justInstallRelivator() {

if (!confirmed) {
consola.info("Project creation process was canceled.");

return;
}

// Install the selected template
await installTemplate(appName, template, deps, git);
await downloadGitRepo(appName, template, deps, git);

// Set the target directory
const cwd = getCurrentWorkingDirectory();
const targetDir = isDev
? path.join(cwd, "..", appName)
: path.join(cwd, appName);

// Handle string replacements in the project files (e.g., replace placeholders)
await handleReplacements(targetDir, template, appName, username, domain);
await handleStringReplacements(
targetDir,
template,
appName,
username,
domain,
);

// Ask if the user wants i18n support
const enableI18n = await askInternationalizationSetup();
const shouldAddI18n = await askInternationalizationSetup();

if (enableI18n) {
// Move all content to src/app/[locale] and handle i18n files
if (shouldAddI18n) {
await moveAppToLocale(targetDir);
await downloadI18nFiles(targetDir, isDev);
}

// Check and download any necessary files
await askCheckAndDownloadFiles(targetDir, appName);

// Display the final congratulation menu with the next steps
await showCongratulationMenu(targetDir, deps, template, targetDir);
}
57 changes: 26 additions & 31 deletions src/prompts/02-buildOwnRelivator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,58 @@ import { consola } from "consola";
import path from "pathe";

import { askAppName } from "~/prompts/04-askAppName";
import { askUserName } from "~/prompts/06-askUserName";
import { askAppDomain } from "~/prompts/07-askAppDomain";
import { askGitInitialization } from "~/prompts/08-askGitInitialization";
import { askInstallDependencies } from "~/prompts/09-askInstallDependencies";
import { askSummaryConfirmation } from "~/prompts/10-askSummaryConfirmation";
import { askInternationalizationSetup } from "~/prompts/11-askInternationalizationSetup";
import { askCheckAndDownloadFiles } from "~/prompts/13-askCheckAndDownloadFiles";
import { showCongratulationMenu } from "~/prompts/14-showCongratulationMenu";
import { askUserName } from "~/prompts/05-askUserName";
import { askAppDomain } from "~/prompts/06-askAppDomain";
import { askGitInitialization } from "~/prompts/07-askGitInitialization";
import { askInstallDependencies } from "~/prompts/08-askInstallDependencies";
import { askSummaryConfirmation } from "~/prompts/09-askSummaryConfirmation";
import { askInternationalizationSetup } from "~/prompts/10-askInternationalizationSetup";
import { askCheckAndDownloadFiles } from "~/prompts/12-askCheckAndDownloadFiles";
import { showCongratulationMenu } from "~/prompts/13-showCongratulationMenu";
import { downloadI18nFiles } from "~/prompts/utils/downloadI18nFiles";
import { getCurrentWorkingDirectory } from "~/prompts/utils/fs";
import { handleReplacements } from "~/prompts/utils/handleReplacements";
import { installTemplate } from "~/prompts/utils/installTemplate";
import { handleStringReplacements } from "~/prompts/utils/handleStringReplacements";
import { downloadGitRepo } from "~/prompts/utils/downloadGitRepo";
import { moveAppToLocale } from "~/prompts/utils/moveAppToLocale";
import { isDev } from "~/settings";

export async function buildOwnRelivator() {
const cwd = getCurrentWorkingDirectory();

consola.info(
// "blefnk/relivator template is a highly modified sadmann7/skateshop. This template can be a good starting point to build your own Relivator as well.",
"Let's build your own Relivator from scratch! We'll use the reliverse/next-react-js-minimal template as a starting point.",
"Let's build your own Relivator from scratch! We'll use the blefnk/versator-nextjs-template as a starting point.",
);

// const template = await buildRelivatorTemplate(); // 04-buildTemplate.ts
const template = "reliverse/next-react-js-minimal";

const projectName = await askAppName(); // 05-askAppName.ts
const githubUser = await askUserName(); // 06-gitUsername.ts
const website = await askAppDomain(); // 07-askAppDomain.ts
const gitOption = await askGitInitialization(); // 08-askGitInitialization.ts
const deps = await askInstallDependencies("buildRelivator"); // 09-installDependencies.ts
const template = "blefnk/versator-nextjs-template";
const appName = await askAppName();
const githubUser = await askUserName();
const website = await askAppDomain();
const git = await askGitInitialization();
const deps = await askInstallDependencies("buildOwnRelivator");

const confirmed = await askSummaryConfirmation(
template,
projectName,
appName,
githubUser,
website,
gitOption,
git,
deps,
);

if (!confirmed) {
consola.info("Project creation process was canceled.");

return;
}

await installTemplate(projectName, template, deps, gitOption);
await downloadGitRepo(appName, template, deps, git);

const cwd = getCurrentWorkingDirectory();
const targetDir = isDev
? path.join(cwd, "..", projectName)
: path.join(cwd, projectName);
? path.join(cwd, "..", appName)
: path.join(cwd, appName);

await handleReplacements(
await handleStringReplacements(
targetDir,
template,
projectName,
appName,
githubUser,
website,
);
Expand All @@ -70,6 +65,6 @@ export async function buildOwnRelivator() {
await downloadI18nFiles(targetDir, isDev);
}

await askCheckAndDownloadFiles(targetDir, projectName);
await askCheckAndDownloadFiles(targetDir, appName);
await showCongratulationMenu(targetDir, deps, template, targetDir);
}
Loading

0 comments on commit 5d91024

Please sign in to comment.