Skip to content

Commit

Permalink
add pnpm support
Browse files Browse the repository at this point in the history
  • Loading branch information
omeraplak committed May 12, 2022
1 parent b20eace commit bc11d4b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "superplate-cli",
"version": "1.4.3",
"version": "1.5.0",
"description": "The frontend boilerplate with superpowers",
"license": "MIT",
"repository": {
Expand All @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/Helper/binary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ export const BinaryHelper = {
return false;
}
},
CanUsePnpm: (): boolean => {
try {
execSync("pnpm --version", { stdio: "ignore" });
return true;
} catch (e) {
return false;
}
},
};
10 changes: 5 additions & 5 deletions src/Helper/tips/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand All @@ -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.`);
Expand All @@ -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("");
Expand Down
31 changes: 24 additions & 7 deletions src/saofile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,31 @@ 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",
name: "name",
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",
},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bc11d4b

Please sign in to comment.