From bc11d4b36ed6656c91074196b18c47c7a31bea83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20APLAK?= Date: Thu, 12 May 2022 14:56:18 +0300 Subject: [PATCH] add pnpm support --- package.json | 4 ++-- src/Helper/binary/index.ts | 8 ++++++++ src/Helper/tips/index.ts | 10 +++++----- src/saofile.ts | 31 ++++++++++++++++++++++++------- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index ded7df17..cbe4c61c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "superplate-cli", - "version": "1.4.3", + "version": "1.5.0", "description": "The frontend boilerplate with superpowers", "license": "MIT", "repository": { @@ -19,7 +19,7 @@ "templates" ], "scripts": { - "dev:cli": "nodemon --watch src -e ts --ignore lib --exec npm run build:cli", + "dev:cli": "SEGMENT_KEY=xx nodemon --watch src -e ts --ignore lib --exec npm run build:cli", "dev:global": "nodemon --watch src -e ts --ignore lib --exec \"npm run build:cli & npm run global\"", "build:cli": "npm run clean:cli && tsc && babel src --out-dir lib --extensions \".ts,.js,.json\" --source-maps inline", "clean:cli": "rm -rf ./lib", diff --git a/src/Helper/binary/index.ts b/src/Helper/binary/index.ts index da93cc29..f8d2b06f 100644 --- a/src/Helper/binary/index.ts +++ b/src/Helper/binary/index.ts @@ -9,4 +9,12 @@ export const BinaryHelper = { return false; } }, + CanUsePnpm: (): boolean => { + try { + execSync("pnpm --version", { stdio: "ignore" }); + return true; + } catch (e) { + return false; + } + }, }; diff --git a/src/Helper/tips/index.ts b/src/Helper/tips/index.ts index 5ecab8e9..9bf98445 100644 --- a/src/Helper/tips/index.ts +++ b/src/Helper/tips/index.ts @@ -9,7 +9,7 @@ const preInstall = (): void => undefined; type PostInstallFn = (opts: { name: string; dir: string; - pm: "yarn" | "npm"; + pm: "yarn" | "npm" | "pnpm"; }) => void; const postInstall: PostInstallFn = ({ name, dir, pm }) => { @@ -26,21 +26,21 @@ const postInstall: PostInstallFn = ({ name, dir, pm }) => { console.log( `${indent()}${chalk.blueBright( - pm === "yarn" ? "yarn dev" : "npm run dev", + pm === "yarn" || pm === "pnpm" ? `${pm} dev` : "npm run dev", )}`, ); console.log(`${indent(2)}Starts the development server.`); console.log(""); console.log( `${indent()}${chalk.blueBright( - pm === "yarn" ? "yarn build" : "npm run build", + pm === "yarn" || pm === "pnpm" ? `${pm} build` : "npm run build", )}`, ); console.log(`${indent(2)}Bundles the app for production.`); console.log(""); console.log( `${indent()}${chalk.blueBright( - pm === "yarn" ? "yarn start" : "npm run start", + pm === "yarn" || pm === "pnpm" ? `${pm} start` : "npm run start", )}`, ); console.log(`${indent(2)}Starts the production server.`); @@ -49,7 +49,7 @@ const postInstall: PostInstallFn = ({ name, dir, pm }) => { console.log(`${indent()}${chalk.blueBright("cd")} ${name}`); console.log( `${indent()}${chalk.blueBright( - pm === "yarn" ? "yarn dev" : "npm run dev", + pm === "yarn" || pm === "pnpm" ? `${pm} dev` : "npm run dev", )}`, ); console.log(""); diff --git a/src/saofile.ts b/src/saofile.ts index 47db2a9a..de346165 100644 --- a/src/saofile.ts +++ b/src/saofile.ts @@ -35,6 +35,18 @@ const saoConfig: GeneratorConfig = { "prompt.js", )); + const pmQuestionChoises = [{ message: "Npm", value: "npm" }]; + const canUseYarn = BinaryHelper.CanUseYarn(); + const canUsePnpm = BinaryHelper.CanUsePnpm(); + + if (canUseYarn) { + pmQuestionChoises.push({ message: "Yarn", value: "yarn" }); + } + + if (canUsePnpm) { + pmQuestionChoises.push({ message: "PnPM", value: "pnpm" }); + } + return [ { type: "input", @@ -42,15 +54,12 @@ const saoConfig: GeneratorConfig = { message: "What will be the name of your app", default: appName, }, - ...(BinaryHelper.CanUseYarn() + ...(pmQuestionChoises.length > 1 ? [ { name: "pm", message: "Package manager:", - choices: [ - { message: "Npm", value: "npm" }, - { message: "Yarn", value: "yarn" }, - ], + choices: pmQuestionChoises, type: "select", default: "npm", }, @@ -79,9 +88,17 @@ const saoConfig: GeneratorConfig = { * Package Manager */ - sao.answers.pm = BinaryHelper.CanUseYarn() ? sao.answers.pm : "npm"; + sao.answers.pm = + BinaryHelper.CanUseYarn() || BinaryHelper.CanUsePnpm() + ? sao.answers.pm + : "npm"; - const pmRun = sao.answers.pm === "yarn" ? "yarn" : "npm run"; + let pmRun = "npm run"; + if (sao.answers.pm === "yarn") { + pmRun = "yarn"; + } else if (sao.answers.pm === "pnpm") { + pmRun = "pnpm"; + } /** * Extend.js data