Skip to content

Commit

Permalink
refactor(cli): add module path aliasing (t3-oss#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
abui-am committed Jul 24, 2022
1 parent b8a5b3b commit 5aa3865
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 58 deletions.
14 changes: 7 additions & 7 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { AvailablePackages } from "../installers/index.js";
import type { AvailablePackages } from "~/installers/index.js";
import chalk from "chalk";
import { Command } from "commander";
import inquirer from "inquirer";
import { CREATE_T3_APP, DEFAULT_APP_NAME } from "../consts.js";
import { availablePackages } from "../installers/index.js";
import { getVersion } from "../utils/getT3Version.js";
import { getUserPkgManager } from "../utils/getUserPkgManager.js";
import { logger } from "../utils/logger.js";
import { validateAppName } from "../utils/validateAppName.js";
import { CREATE_T3_APP, DEFAULT_APP_NAME } from "~/consts.js";
import { availablePackages } from "~/installers/index.js";
import { getVersion } from "~/utils/getT3Version.js";
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
import { logger } from "~/utils/logger.js";
import { validateAppName } from "~/utils/validateAppName.js";

interface CliFlags {
noGit: boolean;
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/createProject.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { PkgInstallerMap } from "../installers/index.js";
import type { PkgInstallerMap } from "~/installers/index.js";
import path from "path";
import { getUserPkgManager } from "../utils/getUserPkgManager.js";
import { curryRunPkgManagerInstall } from "../utils/runPkgManagerInstall.js";
import { installPackages } from "./installPackages.js";
import { scaffoldProject } from "./scaffoldProject.js";
import { selectAppFile, selectIndexFile } from "./selectBoilerplate.js";
import { installPackages } from "~/helpers/installPackages.js";
import { scaffoldProject } from "~/helpers/scaffoldProject.js";
import { selectAppFile, selectIndexFile } from "~/helpers/selectBoilerplate.js";
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
import { curryRunPkgManagerInstall } from "~/utils/runPkgManagerInstall.js";

interface CreateProjectOptions {
projectName: string;
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/initGit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chalk from "chalk";
import ora from "ora";
import { execa } from "../utils/execAsync.js";
import { logger } from "../utils/logger.js";
import { execa } from "~/utils/execAsync.js";
import { logger } from "~/utils/logger.js";

// This initializes the Git-repository for the project
export const initializeGit = async (projectDir: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/installPackages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { InstallerOptions, PkgInstallerMap } from "../installers/index.js";
import chalk from "chalk";
import ora from "ora";
import { logger } from "../utils/logger.js";
import { logger } from "~/utils/logger.js";

type InstallPackagesOptions = {
packages: PkgInstallerMap;
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/logNextSteps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { InstallerOptions } from "../installers/index.js";
import { DEFAULT_APP_NAME } from "../consts.js";
import { getUserPkgManager } from "../utils/getUserPkgManager.js";
import { logger } from "../utils/logger.js";
import type { InstallerOptions } from "~/installers/index.js";
import { DEFAULT_APP_NAME } from "~/consts.js";
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
import { logger } from "~/utils/logger.js";

// This logs the next steps that the user should take in order to advance the project
export const logNextSteps = ({
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/scaffoldProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import chalk from "chalk";
import fs from "fs-extra";
import inquirer from "inquirer";
import ora from "ora";
import { PKG_ROOT } from "../consts.js";
import { InstallerOptions } from "../installers/index.js";
import { execa } from "../utils/execAsync.js";
import { logger } from "../utils/logger.js";
import { PKG_ROOT } from "~/consts.js";
import { InstallerOptions } from "~/installers/index.js";
import { execa } from "~/utils/execAsync.js";
import { logger } from "~/utils/logger.js";

// This bootstraps the base Next.js application
export const scaffoldProject = async ({
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/selectBoilerplate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { InstallerOptions } from "../installers/index.js";
import type { InstallerOptions } from "~/installers/index.js";
import path from "path";
import fs from "fs-extra";
import { PKG_ROOT } from "../consts.js";
import { PKG_ROOT } from "~/consts.js";

type SelectBoilerplateProps = Required<
Pick<InstallerOptions, "projectDir" | "packages">
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import type { PackageJson } from "type-fest";
import path from "path";
import fs from "fs-extra";
import { runCli } from "./cli/index.js";
import { createProject } from "./helpers/createProject.js";
import { initializeGit } from "./helpers/initGit.js";
import { logNextSteps } from "./helpers/logNextSteps.js";
import { buildPkgInstallerMap } from "./installers/index.js";
import { logger } from "./utils/logger.js";
import { parseNameAndPath } from "./utils/parseNameAndPath.js";
import { renderTitle } from "./utils/renderTitle.js";
import { runCli } from "~/cli/index.js";
import { createProject } from "~/helpers/createProject.js";
import { initializeGit } from "~/helpers/initGit.js";
import { logNextSteps } from "~/helpers/logNextSteps.js";
import { buildPkgInstallerMap } from "~/installers/index.js";
import { logger } from "~/utils/logger.js";
import { parseNameAndPath } from "~/utils/parseNameAndPath.js";
import { renderTitle } from "~/utils/renderTitle.js";

const main = async () => {
renderTitle();
Expand Down
4 changes: 2 additions & 2 deletions src/installers/envVars.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Installer } from "./index.js";
import type { Installer } from "~/installers/index.js";
import path from "path";
import fs from "fs-extra";
import { PKG_ROOT } from "../consts.js";
import { PKG_ROOT } from "~/consts.js";

export const envVariablesInstaller: Installer = async ({
projectDir,
Expand Down
14 changes: 7 additions & 7 deletions src/installers/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { PackageManager } from "../utils/getUserPkgManager.js";
import type { CurriedRunPkgManagerInstallOptions } from "../utils/runPkgManagerInstall.js";
import { envVariablesInstaller as envVariablesInstaller } from "./envVars.js";
import { nextAuthInstaller } from "./next-auth.js";
import { prismaInstaller } from "./prisma.js";
import { tailwindInstaller } from "./tailwind.js";
import { trpcInstaller } from "./trpc.js";
import type { PackageManager } from "~/utils/getUserPkgManager.js";
import type { CurriedRunPkgManagerInstallOptions } from "~/utils/runPkgManagerInstall.js";
import { envVariablesInstaller as envVariablesInstaller } from "~/installers/envVars.js";
import { nextAuthInstaller } from "~/installers/next-auth.js";
import { prismaInstaller } from "~/installers/prisma.js";
import { tailwindInstaller } from "~/installers/tailwind.js";
import { trpcInstaller } from "~/installers/trpc.js";

// Turning this into a const allows the list to be iterated over for programatically creating prompt options
// Should increase extensability in the future
Expand Down
4 changes: 2 additions & 2 deletions src/installers/next-auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Installer } from "./index.js";
import type { Installer } from "~/installers/index.js";
import path from "path";
import fs from "fs-extra";
import { PKG_ROOT } from "../consts.js";
import { PKG_ROOT } from "~/consts.js";

export const nextAuthInstaller: Installer = async ({
projectDir,
Expand Down
6 changes: 3 additions & 3 deletions src/installers/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Installer } from "./index.js";
import type { PackageJson } from "type-fest";
import type { Installer } from "~/installers/index.js";
import path from "path";
import fs from "fs-extra";
import { PKG_ROOT } from "../consts.js";
import { execa } from "../utils/execAsync.js";
import { PKG_ROOT } from "~/consts.js";
import { execa } from "~/utils/execAsync.js";

export const prismaInstaller: Installer = async ({
projectDir,
Expand Down
4 changes: 2 additions & 2 deletions src/installers/tailwind.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Installer } from "./index.js";
import type { Installer } from "~/installers/index.js";
import path from "path";
import fs from "fs-extra";
import { PKG_ROOT } from "../consts.js";
import { PKG_ROOT } from "~/consts.js";

export const tailwindInstaller: Installer = async ({
projectDir,
Expand Down
4 changes: 2 additions & 2 deletions src/installers/trpc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Installer } from "./index.js";
import type { Installer } from "~/installers/index.js";
import path from "path";
import fs from "fs-extra";
import { PKG_ROOT } from "../consts.js";
import { PKG_ROOT } from "~/consts.js";

export const trpcInstaller: Installer = async ({
projectDir,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getT3Version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PackageJson } from "type-fest";
import path from "path";
import fs from "fs-extra";
import { PKG_ROOT } from "../consts.js";
import { PKG_ROOT } from "~/consts.js";

export const getVersion = () => {
const packageJsonPath = path.join(PKG_ROOT, "package.json");
Expand Down
4 changes: 2 additions & 2 deletions src/utils/renderTitle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gradient from "gradient-string";
import { TITLE_TEXT } from "../consts.js";
import { getUserPkgManager } from "./getUserPkgManager.js";
import { TITLE_TEXT } from "~/consts.js";
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";

// colors brought in from vscode poimandres theme
const poimandresTheme = {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/runPkgManagerInstall.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { PackageManager } from "./getUserPkgManager.js";
import type { PackageManager } from "~/utils/getUserPkgManager.js";
import path from "path";
import fs from "fs-extra";
import { type PackageJson } from "type-fest";
import { execa } from "./execAsync.js";
import { logger } from "./logger.js";
import { execa } from "~/utils/execAsync.js";
import { logger } from "~/utils/logger.js";

export interface RunPkgManagerInstallOptions {
pkgManager: PackageManager;
Expand Down
6 changes: 6 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
// "exactOptionalPropertyTypes": true, // TLDR - Setting to undefined is not the same as a property not being defined at all
// "noPropertyAccessFromIndexSignature": true, // TLDR - Use dot notation for objects if youre sure it exists, use ['index'] notaion if unsure

/* MODULE PATH ALIAS*/
"baseUrl": "./",
"paths": {
"~/*": ["./src/*"]
},

/* OTHER OPTIONS */
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
Expand Down

0 comments on commit 5aa3865

Please sign in to comment.