Skip to content

Commit 5aa3865

Browse files
authored
refactor(cli): add module path aliasing (#247)
1 parent b8a5b3b commit 5aa3865

18 files changed

+64
-58
lines changed

src/cli/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import type { AvailablePackages } from "../installers/index.js";
1+
import type { AvailablePackages } from "~/installers/index.js";
22
import chalk from "chalk";
33
import { Command } from "commander";
44
import inquirer from "inquirer";
5-
import { CREATE_T3_APP, DEFAULT_APP_NAME } from "../consts.js";
6-
import { availablePackages } from "../installers/index.js";
7-
import { getVersion } from "../utils/getT3Version.js";
8-
import { getUserPkgManager } from "../utils/getUserPkgManager.js";
9-
import { logger } from "../utils/logger.js";
10-
import { validateAppName } from "../utils/validateAppName.js";
5+
import { CREATE_T3_APP, DEFAULT_APP_NAME } from "~/consts.js";
6+
import { availablePackages } from "~/installers/index.js";
7+
import { getVersion } from "~/utils/getT3Version.js";
8+
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
9+
import { logger } from "~/utils/logger.js";
10+
import { validateAppName } from "~/utils/validateAppName.js";
1111

1212
interface CliFlags {
1313
noGit: boolean;

src/helpers/createProject.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { PkgInstallerMap } from "../installers/index.js";
1+
import type { PkgInstallerMap } from "~/installers/index.js";
22
import path from "path";
3-
import { getUserPkgManager } from "../utils/getUserPkgManager.js";
4-
import { curryRunPkgManagerInstall } from "../utils/runPkgManagerInstall.js";
5-
import { installPackages } from "./installPackages.js";
6-
import { scaffoldProject } from "./scaffoldProject.js";
7-
import { selectAppFile, selectIndexFile } from "./selectBoilerplate.js";
3+
import { installPackages } from "~/helpers/installPackages.js";
4+
import { scaffoldProject } from "~/helpers/scaffoldProject.js";
5+
import { selectAppFile, selectIndexFile } from "~/helpers/selectBoilerplate.js";
6+
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
7+
import { curryRunPkgManagerInstall } from "~/utils/runPkgManagerInstall.js";
88

99
interface CreateProjectOptions {
1010
projectName: string;

src/helpers/initGit.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import chalk from "chalk";
22
import ora from "ora";
3-
import { execa } from "../utils/execAsync.js";
4-
import { logger } from "../utils/logger.js";
3+
import { execa } from "~/utils/execAsync.js";
4+
import { logger } from "~/utils/logger.js";
55

66
// This initializes the Git-repository for the project
77
export const initializeGit = async (projectDir: string) => {

src/helpers/installPackages.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { InstallerOptions, PkgInstallerMap } from "../installers/index.js";
22
import chalk from "chalk";
33
import ora from "ora";
4-
import { logger } from "../utils/logger.js";
4+
import { logger } from "~/utils/logger.js";
55

66
type InstallPackagesOptions = {
77
packages: PkgInstallerMap;

src/helpers/logNextSteps.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { InstallerOptions } from "../installers/index.js";
2-
import { DEFAULT_APP_NAME } from "../consts.js";
3-
import { getUserPkgManager } from "../utils/getUserPkgManager.js";
4-
import { logger } from "../utils/logger.js";
1+
import type { InstallerOptions } from "~/installers/index.js";
2+
import { DEFAULT_APP_NAME } from "~/consts.js";
3+
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
4+
import { logger } from "~/utils/logger.js";
55

66
// This logs the next steps that the user should take in order to advance the project
77
export const logNextSteps = ({

src/helpers/scaffoldProject.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import chalk from "chalk";
33
import fs from "fs-extra";
44
import inquirer from "inquirer";
55
import ora from "ora";
6-
import { PKG_ROOT } from "../consts.js";
7-
import { InstallerOptions } from "../installers/index.js";
8-
import { execa } from "../utils/execAsync.js";
9-
import { logger } from "../utils/logger.js";
6+
import { PKG_ROOT } from "~/consts.js";
7+
import { InstallerOptions } from "~/installers/index.js";
8+
import { execa } from "~/utils/execAsync.js";
9+
import { logger } from "~/utils/logger.js";
1010

1111
// This bootstraps the base Next.js application
1212
export const scaffoldProject = async ({

src/helpers/selectBoilerplate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { InstallerOptions } from "../installers/index.js";
1+
import type { InstallerOptions } from "~/installers/index.js";
22
import path from "path";
33
import fs from "fs-extra";
4-
import { PKG_ROOT } from "../consts.js";
4+
import { PKG_ROOT } from "~/consts.js";
55

66
type SelectBoilerplateProps = Required<
77
Pick<InstallerOptions, "projectDir" | "packages">

src/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import type { PackageJson } from "type-fest";
33
import path from "path";
44
import fs from "fs-extra";
5-
import { runCli } from "./cli/index.js";
6-
import { createProject } from "./helpers/createProject.js";
7-
import { initializeGit } from "./helpers/initGit.js";
8-
import { logNextSteps } from "./helpers/logNextSteps.js";
9-
import { buildPkgInstallerMap } from "./installers/index.js";
10-
import { logger } from "./utils/logger.js";
11-
import { parseNameAndPath } from "./utils/parseNameAndPath.js";
12-
import { renderTitle } from "./utils/renderTitle.js";
5+
import { runCli } from "~/cli/index.js";
6+
import { createProject } from "~/helpers/createProject.js";
7+
import { initializeGit } from "~/helpers/initGit.js";
8+
import { logNextSteps } from "~/helpers/logNextSteps.js";
9+
import { buildPkgInstallerMap } from "~/installers/index.js";
10+
import { logger } from "~/utils/logger.js";
11+
import { parseNameAndPath } from "~/utils/parseNameAndPath.js";
12+
import { renderTitle } from "~/utils/renderTitle.js";
1313

1414
const main = async () => {
1515
renderTitle();

src/installers/envVars.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { Installer } from "./index.js";
1+
import type { Installer } from "~/installers/index.js";
22
import path from "path";
33
import fs from "fs-extra";
4-
import { PKG_ROOT } from "../consts.js";
4+
import { PKG_ROOT } from "~/consts.js";
55

66
export const envVariablesInstaller: Installer = async ({
77
projectDir,

src/installers/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { PackageManager } from "../utils/getUserPkgManager.js";
2-
import type { CurriedRunPkgManagerInstallOptions } from "../utils/runPkgManagerInstall.js";
3-
import { envVariablesInstaller as envVariablesInstaller } from "./envVars.js";
4-
import { nextAuthInstaller } from "./next-auth.js";
5-
import { prismaInstaller } from "./prisma.js";
6-
import { tailwindInstaller } from "./tailwind.js";
7-
import { trpcInstaller } from "./trpc.js";
1+
import type { PackageManager } from "~/utils/getUserPkgManager.js";
2+
import type { CurriedRunPkgManagerInstallOptions } from "~/utils/runPkgManagerInstall.js";
3+
import { envVariablesInstaller as envVariablesInstaller } from "~/installers/envVars.js";
4+
import { nextAuthInstaller } from "~/installers/next-auth.js";
5+
import { prismaInstaller } from "~/installers/prisma.js";
6+
import { tailwindInstaller } from "~/installers/tailwind.js";
7+
import { trpcInstaller } from "~/installers/trpc.js";
88

99
// Turning this into a const allows the list to be iterated over for programatically creating prompt options
1010
// Should increase extensability in the future

src/installers/next-auth.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { Installer } from "./index.js";
1+
import type { Installer } from "~/installers/index.js";
22
import path from "path";
33
import fs from "fs-extra";
4-
import { PKG_ROOT } from "../consts.js";
4+
import { PKG_ROOT } from "~/consts.js";
55

66
export const nextAuthInstaller: Installer = async ({
77
projectDir,

src/installers/prisma.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { Installer } from "./index.js";
21
import type { PackageJson } from "type-fest";
2+
import type { Installer } from "~/installers/index.js";
33
import path from "path";
44
import fs from "fs-extra";
5-
import { PKG_ROOT } from "../consts.js";
6-
import { execa } from "../utils/execAsync.js";
5+
import { PKG_ROOT } from "~/consts.js";
6+
import { execa } from "~/utils/execAsync.js";
77

88
export const prismaInstaller: Installer = async ({
99
projectDir,

src/installers/tailwind.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { Installer } from "./index.js";
1+
import type { Installer } from "~/installers/index.js";
22
import path from "path";
33
import fs from "fs-extra";
4-
import { PKG_ROOT } from "../consts.js";
4+
import { PKG_ROOT } from "~/consts.js";
55

66
export const tailwindInstaller: Installer = async ({
77
projectDir,

src/installers/trpc.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { Installer } from "./index.js";
1+
import type { Installer } from "~/installers/index.js";
22
import path from "path";
33
import fs from "fs-extra";
4-
import { PKG_ROOT } from "../consts.js";
4+
import { PKG_ROOT } from "~/consts.js";
55

66
export const trpcInstaller: Installer = async ({
77
projectDir,

src/utils/getT3Version.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { PackageJson } from "type-fest";
22
import path from "path";
33
import fs from "fs-extra";
4-
import { PKG_ROOT } from "../consts.js";
4+
import { PKG_ROOT } from "~/consts.js";
55

66
export const getVersion = () => {
77
const packageJsonPath = path.join(PKG_ROOT, "package.json");

src/utils/renderTitle.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import gradient from "gradient-string";
2-
import { TITLE_TEXT } from "../consts.js";
3-
import { getUserPkgManager } from "./getUserPkgManager.js";
2+
import { TITLE_TEXT } from "~/consts.js";
3+
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
44

55
// colors brought in from vscode poimandres theme
66
const poimandresTheme = {

src/utils/runPkgManagerInstall.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { PackageManager } from "./getUserPkgManager.js";
1+
import type { PackageManager } from "~/utils/getUserPkgManager.js";
22
import path from "path";
33
import fs from "fs-extra";
44
import { type PackageJson } from "type-fest";
5-
import { execa } from "./execAsync.js";
6-
import { logger } from "./logger.js";
5+
import { execa } from "~/utils/execAsync.js";
6+
import { logger } from "~/utils/logger.js";
77

88
export interface RunPkgManagerInstallOptions {
99
pkgManager: PackageManager;

tsconfig.json

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
// "exactOptionalPropertyTypes": true, // TLDR - Setting to undefined is not the same as a property not being defined at all
3636
// "noPropertyAccessFromIndexSignature": true, // TLDR - Use dot notation for objects if youre sure it exists, use ['index'] notaion if unsure
3737

38+
/* MODULE PATH ALIAS*/
39+
"baseUrl": "./",
40+
"paths": {
41+
"~/*": ["./src/*"]
42+
},
43+
3844
/* OTHER OPTIONS */
3945
"allowSyntheticDefaultImports": true,
4046
"esModuleInterop": true,

0 commit comments

Comments
 (0)