Skip to content

Commit a5f13e7

Browse files
committedApr 26, 2020
remove cliRegister
1 parent 890fa4e commit a5f13e7

File tree

8 files changed

+40
-53
lines changed

8 files changed

+40
-53
lines changed
 

‎example/harkfile.ts

+21-23
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@ import { monorepo } from "@hark/plugin-monorepo";
44
import { spawn } from "@hark/plugin-spawn";
55
import { BaseCommand, MyMonorepo, MyPackage } from "../harkfile";
66

7-
export default extendCli<HarkMonorepoCommandContext<MyMonorepo>, HarkMonorepoCommandContext<MyMonorepo>>(
8-
async ({ cli, cliRegister }) => {
9-
return {
10-
...(await cliExtendMonorepo(BaseCommand)({ cli, cliRegister })),
11-
monorepo: monorepo(
12-
["foo", "bar"],
13-
plugin.map(({ packages }) => {
14-
const myMonorepo = new MyMonorepo(packages.map((p) => new MyPackage(p.packageJson.name, p.path)));
15-
const foo = myMonorepo.getProject("hark-example-foo");
16-
const bar = myMonorepo.getProject("hark-example-bar");
17-
foo.registerTask("dev", () =>
18-
plugin.pipe(
19-
//
20-
foo.task.build(),
21-
spawn(`node -r @babel/register foo/dist/index.js`),
22-
),
23-
);
24-
return myMonorepo;
25-
}),
26-
),
27-
};
28-
},
29-
);
7+
export default extendCli<HarkMonorepoCommandContext<MyMonorepo>, HarkMonorepoCommandContext<MyMonorepo>>(async ({ cli }) => {
8+
return {
9+
...(await cliExtendMonorepo(BaseCommand)({ cli })),
10+
monorepo: monorepo(
11+
["foo", "bar"],
12+
plugin.map(({ packages }) => {
13+
const myMonorepo = new MyMonorepo(packages.map((p) => new MyPackage(p.packageJson.name, p.path)));
14+
const foo = myMonorepo.getProject("hark-example-foo");
15+
const bar = myMonorepo.getProject("hark-example-bar");
16+
foo.registerTask("dev", () =>
17+
plugin.pipe(
18+
//
19+
foo.task.build(),
20+
spawn(`node -r @babel/register foo/dist/index.js`),
21+
),
22+
);
23+
return myMonorepo;
24+
}),
25+
),
26+
};
27+
});

‎harkfile.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ export abstract class BaseCommand extends HarkMonorepoCommand<
9090
}
9191

9292
export default extendCli<HarkMonorepoCommandContext<MyMonorepo>, HarkMonorepoCommandContext<MyMonorepo>>(
93-
async ({ cli, cliRegister }) => {
94-
@cliRegister
93+
async ({ cli }) => {
9594
class PrepareCommand extends BaseCommand {
9695
@Command.Path("prepare")
9796
async execute() {
@@ -106,7 +105,6 @@ export default extendCli<HarkMonorepoCommandContext<MyMonorepo>, HarkMonorepoCom
106105
}
107106
}
108107

109-
@cliRegister
110108
class PublishCommand extends BaseCommand {
111109
static usage = Command.Usage({
112110
category: "Distribute",
@@ -154,8 +152,11 @@ export default extendCli<HarkMonorepoCommandContext<MyMonorepo>, HarkMonorepoCom
154152
}
155153
}
156154

155+
cli.register(PrepareCommand);
156+
cli.register(PublishCommand);
157+
157158
return {
158-
...(await cliExtendMonorepo(BaseCommand)({ cli, cliRegister })),
159+
...(await cliExtendMonorepo(BaseCommand)({ cli })),
159160
monorepo: myMonorepoPlugin,
160161
};
161162
},

‎packages/cli/src/cli-extend-monorepo.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { HarkMonorepoCommand, HarkMonorepoCommandClass, HarkMonorepoCommandConte
66
export const cliExtendMonorepo = <M extends Monorepo<BaseProjectContext, BaseProjectTasks<BaseProjectContext>>>(
77
commandClass: HarkMonorepoCommandClass,
88
) =>
9-
extendCli<any, HarkMonorepoCommandContext<M>>(async ({ cliRegister }) => {
9+
extendCli<any, HarkMonorepoCommandContext<M>>(async ({ cli }) => {
1010
const { Command } = await import("clipanion");
1111
const { of } = await import("rxjs");
1212
const { switchMap, tap } = await import("rxjs/operators");
@@ -15,7 +15,6 @@ export const cliExtendMonorepo = <M extends Monorepo<BaseProjectContext, BasePro
1515
Monorepo<BaseProjectContext, BaseProjectTasks<BaseProjectContext>>
1616
> {}
1717

18-
@cliRegister
1918
class CleanCommand extends BaseCommand {
2019
@Command.Rest()
2120
projects: string[] = [];
@@ -36,7 +35,6 @@ export const cliExtendMonorepo = <M extends Monorepo<BaseProjectContext, BasePro
3635
}
3736
}
3837

39-
@cliRegister
4038
class FormatCommand extends BaseCommand {
4139
@Command.Rest()
4240
projects: string[] = [];
@@ -57,7 +55,6 @@ export const cliExtendMonorepo = <M extends Monorepo<BaseProjectContext, BasePro
5755
}
5856
}
5957

60-
@cliRegister
6158
class TaskCommand extends BaseCommand {
6259
@Command.Boolean("-w,--watch")
6360
watchMode: boolean = false;
@@ -107,7 +104,6 @@ export const cliExtendMonorepo = <M extends Monorepo<BaseProjectContext, BasePro
107104
}
108105
}
109106

110-
@cliRegister
111107
class BuildCommand extends BaseCommand {
112108
@Command.Boolean("-w,--watch")
113109
watchMode: boolean = false;
@@ -131,7 +127,6 @@ export const cliExtendMonorepo = <M extends Monorepo<BaseProjectContext, BasePro
131127
}
132128
}
133129

134-
@cliRegister
135130
class PackageJsonFormatCommand extends BaseCommand {
136131
@Command.Rest()
137132
projects: string[] = [];
@@ -152,7 +147,6 @@ export const cliExtendMonorepo = <M extends Monorepo<BaseProjectContext, BasePro
152147
}
153148
}
154149

155-
@cliRegister
156150
class ImportsCheckCommand extends BaseCommand {
157151
@Command.Boolean("--json")
158152
jsonOutput = false;
@@ -215,7 +209,6 @@ export const cliExtendMonorepo = <M extends Monorepo<BaseProjectContext, BasePro
215209
}
216210
}
217211

218-
@cliRegister
219212
class DevCommand extends BaseCommand {
220213
@Command.Rest()
221214
projects: string[] = [];
@@ -236,6 +229,14 @@ export const cliExtendMonorepo = <M extends Monorepo<BaseProjectContext, BasePro
236229
}
237230
}
238231

232+
cli.register(CleanCommand);
233+
cli.register(FormatCommand);
234+
cli.register(TaskCommand);
235+
cli.register(BuildCommand);
236+
cli.register(PackageJsonFormatCommand);
237+
cli.register(ImportsCheckCommand);
238+
cli.register(DevCommand);
239+
239240
const result: HarkMonorepoCommandContext<M> = {
240241
monorepo: plugin.throwError("Monorepo not given."),
241242
rootProjectFilter: "name:root",

‎packages/cli/src/cli-init.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { HarkCliInitOptions } from "./models";
2-
import { RegisterCommand } from "./register-command";
32

43
export async function cliInit(options?: HarkCliInitOptions) {
54
const { Cli, Command } = await import("clipanion");
@@ -8,7 +7,6 @@ export async function cliInit(options?: HarkCliInitOptions) {
87
binaryName: options?.binaryName ?? `hark`,
98
binaryVersion: options?.binaryVersion ?? `0.0.0-unknown`,
109
});
11-
const cliRegister = RegisterCommand(cli);
1210

1311
class HelpCommand extends Command {
1412
@Command.Path(`--help`)
@@ -17,13 +15,11 @@ export async function cliInit(options?: HarkCliInitOptions) {
1715
this.context.stdout.write(this.cli.usage(null));
1816
}
1917
}
18+
cli.register(HelpCommand);
2019

2120
if (options?.useDefaultHelpCommand ?? true) {
2221
cli.register(HelpCommand);
2322
}
2423

25-
return {
26-
cli,
27-
cliRegister,
28-
};
24+
return { cli };
2925
}

‎packages/cli/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ export * from "./extend-cli";
55
export * from "./hark-command";
66
export * from "./hark-monorepo-command";
77
export * from "./models";
8-
export * from "./register-command";

‎packages/cli/src/models.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface HarkCliStartOptions<T extends Partial<BaseContext>> extends Har
1010
harkfilePath?: string;
1111
registerBabelOptions?: null | {
1212
extensions: string[];
13-
[k:string]: unknown;
13+
[k: string]: unknown;
1414
};
1515
}
1616

@@ -20,5 +20,4 @@ import { BaseContext, Cli, CommandClass } from "clipanion";
2020

2121
export type HarkfileFunction<CliContext, ReturnContext> = (input: {
2222
cli: Cli<CliContext & BaseContext>;
23-
cliRegister: CliCommandRegisterDecorator;
2423
}) => Promise<ReturnContext> | ReturnContext;

‎packages/cli/src/register-command.ts

-7
This file was deleted.

‎release/harkfile.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export abstract class ACommand extends HarkMonorepoCommand<AMonorepo, "version">
3232
}
3333
}
3434

35-
export default extendCli(async ({ cli, cliRegister }) => {
35+
export default extendCli(async ({ cli }) => {
3636
return {
37-
...(await cliExtendMonorepo(ACommand)({ cli, cliRegister })),
37+
...(await cliExtendMonorepo(ACommand)({ cli })),
3838
monorepo: monorepo(
3939
["packages/*/dist"],
4040
plugin.map(({ packages }) => new AMonorepo(packages.map((p) => new APackage(p.packageJson.name, p.path)))),

0 commit comments

Comments
 (0)
Please sign in to comment.