Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] add init option --use-pnpm #624

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Install and configure reg-suit and plugins into your project.

- `--use-yarn` : By the default cli installs packages using `npm`. If you prefer yarn pkg, turn this option on.
- `--use-yarn-ws` : If you use yarn workspace, turn this option on.
- `--use-pnpm` : By the default cli installs packages using `pnpm`. If you prefer yarn pkg, turn this option on.

### `prepare` command

Expand Down
2 changes: 1 addition & 1 deletion packages/reg-suit-cli/src/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface CliOptions {
configFileName?: string;
logLevel: "verbose" | "info" | "silent";
noEmit: boolean;
npmClient: "npm" | "yarn" | "yarn workspace";
npmClient: "npm" | "yarn" | "yarn workspace" | "pnpm";
plugins: string[];
notification: boolean;
noInstallCore: boolean;
Expand Down
17 changes: 15 additions & 2 deletions packages/reg-suit-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function createOptions() {
.command("init", "Install and set up reg-suit and plugins into your project.", {
useYarn: { desc: "Whether to use yarn as npm client.", boolean: true, default: false },
useYarnWs: { desc: "Whether to use yarn workspace.", boolean: true, default: false },
usePnpm: { desc: "Whether to use pnpm as npm client.", boolean: true, default: false },
})
.command("prepare", "Configure installed plugin", {
p: { alias: "plugin", array: true, desc: "Plugin name(s) you want to set up(e.g. slack-notify)." },
Expand All @@ -64,10 +65,22 @@ function createOptions() {
})
.wrap(120)
.locale("en");
const { config, verbose, quiet, test, useYarn, useYarnWs, plugin, useDevCore, notification } = yargs.argv;
const { config, verbose, quiet, test, useYarn, useYarnWs, plugin, useDevCore, notification, usePnpm } = yargs.argv;

const command = yargs.argv._[0];
const logLevel = verbose ? "verbose" : quiet ? "silent" : "info";
const npmClient = useYarn || useYarnWs ? (useYarnWs ? "yarn workspace" : "yarn") : "npm";
const npmClient = (() => {
switch (true) {
case useYarn:
return "yarn";
case useYarnWs:
return "yarn workspace";
case usePnpm:
return "pnpm";
default:
return "npm";
}
})();
const plugins = (plugin || []) as string[];
const noInstallCore = !!useDevCore;
return {
Expand Down
6 changes: 5 additions & 1 deletion packages/reg-suit-cli/src/package-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fsUtil } from "reg-suit-util";
export const PLUGIN_NAME_REGEXP = /^reg-.*-plugin$/;
const CLI_MODULE_ID = require(path.join(__dirname, "..", "package.json"))["name"] as string;

export type NpmClient = "npm" | "yarn" | "yarn workspace";
export type NpmClient = "npm" | "yarn" | "yarn workspace" | "pnpm";

export class PackageUtil {
installPackages(client: NpmClient, packageNames: string[]): Promise<string[]> {
Expand All @@ -25,6 +25,10 @@ export class PackageUtil {
cliArguments.push("add");
cliArguments.push("-D");
cliArguments.push("-W");
} else if (client === "pnpm") {
cliArguments.push("pnpm");
cliArguments.push("install");
cliArguments.push("-D");
}
const args = [...cliArguments, ...packageNames];
return new Promise((resolve, reject) => {
Expand Down
Loading