Skip to content

Commit

Permalink
Merge pull request #55 from expressots/fix/remove-nodejs-version-limi…
Browse files Browse the repository at this point in the history
…tation

Fix/remove nodejs version limitation
  • Loading branch information
rsaz authored Aug 1, 2024
2 parents c2300e4 + b7ac564 commit 79f9458
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
5 changes: 3 additions & 2 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.18.0"
"node": ">=18.0.0"
},
"funding": {
"type": "github",
Expand All @@ -31,7 +31,7 @@
"Scaffolding"
],
"scripts": {
"prepare": "husky install",
"prepare": "husky",
"start:build": "npm run build && npm run start",
"start": "node ./bin/cli.js",
"start:dev": "tsnd ./src/cli.ts",
Expand All @@ -58,6 +58,7 @@
"inquirer": "8.2.6",
"mustache": "4.2.0",
"semver": "7.6.2",
"ts-node": "10.9.2",
"yargs": "17.7.2"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions src/new/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Argv, CommandModule } from "yargs";
import { projectForm } from "./form";
import semver from "semver";
import { printWarning } from "../utils/cli-ui";
import chalk from "chalk";

type CommandModuleArgs = object;

Expand Down Expand Up @@ -40,14 +42,12 @@ const commandOptions = (yargs: Argv): Argv => {

const checkNodeVersion = (): void => {
const minVersion = "18.0.0";
const maxVersion = "20.7.0";
const maxVersion = "22.5.1";
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 msg: string = `Node.js version [${chalk.bold(chalk.white(currentVersion))}] is not tested. Please use a version between ${minVersion} and ${maxVersion}.`;
printWarning(msg);
}
};

Expand Down
21 changes: 13 additions & 8 deletions src/new/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ async function packageManagerInstall({
? `${packageManager}.cmd`
: packageManager;

const installProcess = spawn(command, ["install"], {
const installProcess = spawn(command, ["install", "--prefer-offline"], {
cwd: directory,
shell: true,
timeout: 600000,
});

// eslint-disable-next-line prefer-const
let installTimeout: NodeJS.Timeout;

installProcess.on("error", (error) => {
clearTimeout(installTimeout);
reject(new Error(`Failed to start subprocess: ${error.message}`));
});

Expand All @@ -50,6 +56,7 @@ async function packageManagerInstall({
});

installProcess.on("close", (code) => {
clearTimeout(installTimeout);
if (code === 0) {
resolve("Installation Done!");
} else {
Expand All @@ -60,6 +67,11 @@ async function packageManagerInstall({
);
}
});

installTimeout = setTimeout(() => {
installProcess.kill("SIGKILL");
reject(new Error("Installation took too long. Aborted!"));
}, 600000);
});
}

Expand All @@ -80,18 +92,11 @@ function changePackageName({
directory: string;
name: string;
}): void {
// Get the absolute path of the input directory parameter
const absDirPath = path.resolve(directory);

// Load the package.json file
const packageJsonPath = path.join(absDirPath, "package.json");
const fileContents = fs.readFileSync(packageJsonPath, "utf-8");
const packageJson = JSON.parse(fileContents);

// Change the name
packageJson.name = name;

// Save the package.json file
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
}

Expand Down
14 changes: 14 additions & 0 deletions src/utils/cli-ui.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import chalk from "chalk";
import { stdout } from "process";

export function printError(message: string, component: string): void {
console.error(
chalk.red(`${message}:`, chalk.bold(chalk.white(`[${component}] ❌`))),
);
}

export function printWarning(message: string, component?: string): void {
if (component === undefined) {
stdout.write(chalk.yellow(`${message} ⚠️\n`));
return;
}
stdout.write(
chalk.yellow(
`${message}:`,
chalk.bold(chalk.white(`[${component}] ⚠️\n`)),
),
);
}

export async function printGenerateError(schematic: string, file: string) {
console.error(
" ",
Expand Down

0 comments on commit 79f9458

Please sign in to comment.