diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9b013b7..903db5c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v2 with: - node-version: "18.11.0" + node-version: "18.18.0" - name: Install Dependencies run: npm install diff --git a/package.json b/package.json index b4aa502..d8a3f1c 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "expressots": "bin/cli.js" }, "engines": { - "node": ">=18.10.0" + "node": ">=18.18.0" }, "funding": { "type": "github", @@ -52,16 +52,17 @@ "@expressots/boost-ts": "1.1.1", "chalk-animation": "2.0.3", "cli-progress": "3.11.2", - "cli-table3": "^0.6.4", + "cli-table3": "0.6.4", "degit": "2.8.4", - "glob": "10.2.6", + "glob": "10.4.1", "inquirer": "8.0.0", "mustache": "4.2.0", + "semver": "7.6.2", "ts-node": "10.9.1", "yargs": "17.6.2" }, "devDependencies": { - "@codecov/vite-plugin": "0.0.1-beta.5", + "@codecov/vite-plugin": "^0.0.1-beta.9", "@commitlint/cli": "19.2.1", "@commitlint/config-conventional": "19.1.0", "@release-it/conventional-changelog": "7.0.2", diff --git a/src/new/cli.ts b/src/new/cli.ts index 5599fed..7b02655 100644 --- a/src/new/cli.ts +++ b/src/new/cli.ts @@ -1,5 +1,6 @@ import { Argv, CommandModule } from "yargs"; import { projectForm } from "./form"; +import semver from "semver"; type CommandModuleArgs = object; @@ -37,6 +38,19 @@ const commandOptions = (yargs: Argv): Argv => { .implies("template", "package-manager"); }; +const checkNodeVersion = (): void => { + const minVersion = "18.0.0"; + const maxVersion = "20.7.0"; + const currentVersion = process.version; + + if (!semver.satisfies(currentVersion, `>=${minVersion} <=${maxVersion}`)) { + console.error( + `Node.js version ${currentVersion} is not supported. Please use a version between ${minVersion} and ${maxVersion}.`, + ); + process.exit(1); + } +}; + const createProject = (): CommandModule => { return { command: "new [package-manager] [template] [directory]", @@ -48,6 +62,7 @@ const createProject = (): CommandModule => { template, directory, }) => { + checkNodeVersion(); return await projectForm(projectName, [ packageManager, template, diff --git a/src/new/form.ts b/src/new/form.ts index 54c19a2..83a84cb 100644 --- a/src/new/form.ts +++ b/src/new/form.ts @@ -1,5 +1,5 @@ import chalk from "chalk"; -import { execSync, spawn } from "child_process"; +import { execSync, spawn } from "node:child_process"; import { Presets, SingleBar } from "cli-progress"; import degit from "degit"; import inquirer from "inquirer"; @@ -27,7 +27,11 @@ async function packageManagerInstall({ cwd: directory, }); - installProcess.stdout.on("data", (data: Buffer) => { + installProcess.on("error", (error) => { + reject(new Error(`Failed to start subprocess: ${error.message}`)); + }); + + installProcess.stdout?.on("data", (data: Buffer) => { const output = data.toString().trim(); const npmProgressMatch = output.match(