Skip to content

Commit

Permalink
Merge pull request #47 from expressots/fix/version-spawn-child_proces…
Browse files Browse the repository at this point in the history
…s-issue

fix: add node version restriction
  • Loading branch information
rsaz committed Jun 12, 2024
2 parents 8a6fb21 + 8ebc317 commit 5d29285
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"expressots": "bin/cli.js"
},
"engines": {
"node": ">=18.10.0"
"node": ">=18.18.0"
},
"funding": {
"type": "github",
Expand Down Expand Up @@ -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",
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 5d29285

Please sign in to comment.