Skip to content

Commit

Permalink
fix: add node version restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaz committed Jun 12, 2024
1 parent 8a6fb21 commit 9cf3416
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@
},
"dependencies": {
"@expressots/boost-ts": "1.1.1",
"@expressots/cli": "file:expressots-cli-1.8.0.tgz",
"chalk-animation": "2.0.3",
"cli-progress": "3.11.2",
"cli-table3": "^0.6.4",
"degit": "2.8.4",
"glob": "10.2.6",
"inquirer": "8.0.0",
"mustache": "4.2.0",
"semver": "^7.6.2",
"ts-node": "10.9.1",
"yargs": "17.6.2"
},
Expand All @@ -70,7 +72,7 @@
"@types/degit": "2.8.3",
"@types/inquirer": "9.0.3",
"@types/mustache": "4.2.2",
"@types/node": "20.12.7",
"@types/node": "20.14.2",
"@types/yargs": "17.0.22",
"@typescript-eslint/eslint-plugin": "7.6.0",
"@typescript-eslint/parser": "7.6.0",
Expand Down
15 changes: 15 additions & 0 deletions src/new/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Argv, CommandModule } from "yargs";
import { projectForm } from "./form";
import semver from "semver";

type CommandModuleArgs = object;

Expand Down Expand Up @@ -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<CommandModuleArgs, any> => {
return {
command: "new <project-name> [package-manager] [template] [directory]",
Expand All @@ -48,6 +62,7 @@ const createProject = (): CommandModule<CommandModuleArgs, any> => {
template,
directory,
}) => {
checkNodeVersion();
return await projectForm(projectName, [
packageManager,
template,
Expand Down
8 changes: 6 additions & 2 deletions src/new/form.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9cf3416

Please sign in to comment.