Skip to content

Commit bb90a45

Browse files
committed
feat: add --force flag to all make commands
Allow overwriting existing files during stub generation by passing --force (-f) to any make:* command. Sets codemods.overwriteExisting before calling makeUsingStub.
1 parent 9eff2e1 commit bb90a45

13 files changed

Lines changed: 91 additions & 0 deletions

File tree

commands/make/command.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ export default class MakeCommand extends BaseCommand {
4848
@flags.string({ description: 'Use the contents of the given file as the generated output' })
4949
declare contentsFrom: string
5050

51+
/**
52+
* Forcefully overwrite existing files
53+
*/
54+
@flags.boolean({ description: 'Forcefully overwrite existing files', alias: 'f' })
55+
declare force: boolean
56+
5157
/**
5258
* The stub template file to use for generating the command class
5359
*/
@@ -59,6 +65,7 @@ export default class MakeCommand extends BaseCommand {
5965
*/
6066
async run() {
6167
const codemods = await this.createCodemods()
68+
codemods.overwriteExisting = this.force === true
6269
await codemods.makeUsingStub(
6370
stubsRoot,
6471
this.stubPath,

commands/make/controller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ export default class MakeController extends BaseCommand {
8989
@flags.string({ description: 'Use the contents of the given file as the generated output' })
9090
declare contentsFrom: string
9191

92+
/**
93+
* Forcefully overwrite existing files
94+
*/
95+
@flags.boolean({ description: 'Forcefully overwrite existing files', alias: 'f' })
96+
declare force: boolean
97+
9298
/**
9399
* The stub to use for generating the controller
94100
*/
@@ -137,6 +143,7 @@ export default class MakeController extends BaseCommand {
137143

138144
async run() {
139145
const codemods = await this.createCodemods()
146+
codemods.overwriteExisting = this.force === true
140147
await codemods.makeUsingStub(
141148
stubsRoot,
142149
this.stubPath,

commands/make/event.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ export default class MakeEvent extends BaseCommand {
5656
@flags.string({ description: 'Use the contents of the given file as the generated output' })
5757
declare contentsFrom: string
5858

59+
/**
60+
* Forcefully overwrite existing files
61+
*/
62+
@flags.boolean({ description: 'Forcefully overwrite existing files', alias: 'f' })
63+
declare force: boolean
64+
5965
/**
6066
* The stub template file to use for generating the event class
6167
*/
@@ -67,6 +73,7 @@ export default class MakeEvent extends BaseCommand {
6773
*/
6874
async run() {
6975
const codemods = await this.createCodemods()
76+
codemods.overwriteExisting = this.force === true
7077
await codemods.makeUsingStub(
7178
stubsRoot,
7279
this.stubPath,

commands/make/exception.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ export default class MakeException extends BaseCommand {
5656
@flags.string({ description: 'Use the contents of the given file as the generated output' })
5757
declare contentsFrom: string
5858

59+
/**
60+
* Forcefully overwrite existing files
61+
*/
62+
@flags.boolean({ description: 'Forcefully overwrite existing files', alias: 'f' })
63+
declare force: boolean
64+
5965
/**
6066
* The stub template file to use for generating the exception class
6167
*/
@@ -67,6 +73,7 @@ export default class MakeException extends BaseCommand {
6773
*/
6874
async run() {
6975
const codemods = await this.createCodemods()
76+
codemods.overwriteExisting = this.force === true
7077
await codemods.makeUsingStub(
7178
stubsRoot,
7279
this.stubPath,

commands/make/listener.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ export default class MakeListener extends BaseCommand {
6565
@flags.string({ description: 'Use the contents of the given file as the generated output' })
6666
declare contentsFrom: string
6767

68+
/**
69+
* Forcefully overwrite existing files
70+
*/
71+
@flags.boolean({ description: 'Forcefully overwrite existing files', alias: 'f' })
72+
declare force: boolean
73+
6874
/**
6975
* The stub template file to use for generating the event listener
7076
*/
@@ -87,6 +93,7 @@ export default class MakeListener extends BaseCommand {
8793
*/
8894
async run() {
8995
const codemods = await this.createCodemods()
96+
codemods.overwriteExisting = this.force === true
9097

9198
if (this.event) {
9299
const { exitCode } = await this.kernel.exec('make:event', [this.event])

commands/make/middleware.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export default class MakeMiddleware extends BaseCommand {
6464
@flags.string({ description: 'Use the contents of the given file as the generated output' })
6565
declare contentsFrom: string
6666

67+
/**
68+
* Forcefully overwrite existing files
69+
*/
70+
@flags.boolean({ description: 'Forcefully overwrite existing files', alias: 'f' })
71+
declare force: boolean
72+
6773
/**
6874
* The stub to use for generating the middleware
6975
*/
@@ -98,6 +104,7 @@ export default class MakeMiddleware extends BaseCommand {
98104
* Create middleware
99105
*/
100106
const codemods = await this.createCodemods()
107+
codemods.overwriteExisting = this.force === true
101108
const { destination } = await codemods.makeUsingStub(
102109
stubsRoot,
103110
this.stubPath,

commands/make/preload.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ export default class MakePreload extends BaseCommand {
7575
@flags.string({ description: 'Use the contents of the given file as the generated output' })
7676
declare contentsFrom: string
7777

78+
/**
79+
* Forcefully overwrite existing files
80+
*/
81+
@flags.boolean({ description: 'Forcefully overwrite existing files', alias: 'f' })
82+
declare force: boolean
83+
7884
/**
7985
* The stub template file to use for generating the preload file
8086
*/
@@ -119,6 +125,7 @@ export default class MakePreload extends BaseCommand {
119125
}
120126

121127
const codemods = await this.createCodemods()
128+
codemods.overwriteExisting = this.force === true
122129
const { destination } = await codemods.makeUsingStub(
123130
stubsRoot,
124131
this.stubPath,

commands/make/provider.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ export default class MakeProvider extends BaseCommand {
7474
@flags.string({ description: 'Use the contents of the given file as the generated output' })
7575
declare contentsFrom: string
7676

77+
/**
78+
* Forcefully overwrite existing files
79+
*/
80+
@flags.boolean({ description: 'Forcefully overwrite existing files', alias: 'f' })
81+
declare force: boolean
82+
7783
/**
7884
* The stub template file to use for generating the provider class
7985
*/
@@ -117,6 +123,7 @@ export default class MakeProvider extends BaseCommand {
117123
}
118124

119125
const codemods = await this.createCodemods()
126+
codemods.overwriteExisting = this.force === true
120127
const { destination } = await codemods.makeUsingStub(
121128
stubsRoot,
122129
this.stubPath,

commands/make/service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,20 @@ export default class MakeService extends BaseCommand {
5252
@flags.string({ description: 'Use the contents of the given file as the generated output' })
5353
declare contentsFrom: string
5454

55+
/**
56+
* Forcefully overwrite existing files
57+
*/
58+
@flags.boolean({ description: 'Forcefully overwrite existing files', alias: 'f' })
59+
declare force: boolean
60+
5561
/**
5662
* The stub to use for generating the service class
5763
*/
5864
protected stubPath: string = 'make/service/main.stub'
5965

6066
async run() {
6167
const codemods = await this.createCodemods()
68+
codemods.overwriteExisting = this.force === true
6269
await codemods.makeUsingStub(
6370
stubsRoot,
6471
this.stubPath,

commands/make/test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ export default class MakeTest extends BaseCommand {
5353
@flags.string({ description: 'Use the contents of the given file as the generated output' })
5454
declare contentsFrom: string
5555

56+
/**
57+
* Forcefully overwrite existing files
58+
*/
59+
@flags.boolean({ description: 'Forcefully overwrite existing files', alias: 'f' })
60+
declare force: boolean
61+
5662
/**
5763
* The stub template file to use for generating the test file
5864
*/
@@ -147,6 +153,7 @@ export default class MakeTest extends BaseCommand {
147153
* Generate entity
148154
*/
149155
const codemods = await this.createCodemods()
156+
codemods.overwriteExisting = this.force === true
150157
await codemods.makeUsingStub(
151158
stubsRoot,
152159
this.stubPath,

0 commit comments

Comments
 (0)