diff --git a/contributors.yml b/contributors.yml index b670d4d0791..463c853eb28 100644 --- a/contributors.yml +++ b/contributors.yml @@ -95,6 +95,7 @@ - donavon - Dueen - dunglas +- dvargas92495 - dwightwatson - dwt47 - dylanplayer diff --git a/packages/remix-dev/__tests__/create-test.ts b/packages/remix-dev/__tests__/create-test.ts index 4e8208cdcf2..d83d285ef11 100644 --- a/packages/remix-dev/__tests__/create-test.ts +++ b/packages/remix-dev/__tests__/create-test.ts @@ -446,6 +446,22 @@ describe("the create command", () => { expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeFalsy(); }); + it("runs remix.init script when using index.ts", async () => { + let projectDir = await getProjectDir("remix-init-ts"); + await run([ + "create", + projectDir, + "--template", + path.join(__dirname, "fixtures", "stack-init-ts.tar.gz"), + "--install", + "--typescript", + ]); + expect(output).toContain(`Running init script on ${projectDir.replace(TEMP_DIR, "")}`); + expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy(); + expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy(); + expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeFalsy(); + }); + it("runs remix.init script when using `remix init`", async () => { let projectDir = await getProjectDir("remix-init-manual"); await run([ diff --git a/packages/remix-dev/__tests__/fixtures/stack-init-ts.tar.gz b/packages/remix-dev/__tests__/fixtures/stack-init-ts.tar.gz new file mode 100644 index 00000000000..61600d6f2a7 Binary files /dev/null and b/packages/remix-dev/__tests__/fixtures/stack-init-ts.tar.gz differ diff --git a/packages/remix-dev/cli/commands.ts b/packages/remix-dev/cli/commands.ts index 0441b1adddf..eef2788c89e 100644 --- a/packages/remix-dev/cli/commands.ts +++ b/packages/remix-dev/cli/commands.ts @@ -10,6 +10,7 @@ import type { Server } from "http"; import type * as Express from "express"; import type { createApp as createAppType } from "@remix-run/serve"; import getPort, { makeRange } from "get-port"; +import * as esbuild from "esbuild"; import { BuildMode, isBuildMode } from "../build"; import * as colors from "../colors"; @@ -64,8 +65,17 @@ export async function init( { deleteScript = true }: InitFlags = {} ) { let initScriptDir = path.join(projectDir, "remix.init"); + let initScriptTs = path.resolve(initScriptDir, "index.ts"); let initScript = path.resolve(initScriptDir, "index.js"); + if (await fse.pathExists(initScriptTs)) { + await esbuild.build({ + entryPoints: [initScriptTs], + format: "cjs", + platform: "node", + outfile: initScript, + }) + } if (!(await fse.pathExists(initScript))) { return; } @@ -74,6 +84,7 @@ export async function init( let isTypeScript = fse.existsSync(path.join(projectDir, "tsconfig.json")); let packageManager = getPreferredPackageManager(); + if (await fse.pathExists(initPackageJson)) { execSync(`${packageManager} install`, { cwd: initScriptDir, @@ -82,6 +93,9 @@ export async function init( } let initFn = require(initScript); + if (typeof initFn !== 'function' && initFn.default) { + initFn = initFn.default; + } try { await initFn({ isTypeScript, packageManager, rootDirectory: projectDir }); diff --git a/packages/remix-dev/cli/create.ts b/packages/remix-dev/cli/create.ts index de0fbbb18a0..caa3c43635c 100644 --- a/packages/remix-dev/cli/create.ts +++ b/packages/remix-dev/cli/create.ts @@ -243,7 +243,8 @@ async function extractLocalTarball( throw Error( "🚨 There was a problem extracting the file from the provided template.\n\n" + ` Template filepath: \`${filePath}\`\n` + - ` Destination directory: \`${projectDir}\`` + ` Destination directory: \`${projectDir}\`\n` + + ` ${err}` ); } }