File tree Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ type InfuseOptions = {
16
16
target : string
17
17
locales : string
18
18
match ?: string
19
+ dryRun : boolean
19
20
}
20
21
21
22
export const command = 'infuse'
@@ -41,6 +42,12 @@ export const builder = (args: Argv): Argv<InfuseOptions> => {
41
42
alias : 'm' ,
42
43
describe : 'option should be accepted a regex filenames, must be specified together --messages'
43
44
} )
45
+ . option ( 'dryRun' , {
46
+ type : 'boolean' ,
47
+ alias : 'd' ,
48
+ default : false ,
49
+ describe : 'run the infuse command, but do not apply them'
50
+ } )
44
51
}
45
52
46
53
export const handler = ( args : Arguments < InfuseOptions > ) : void => {
@@ -51,7 +58,7 @@ export const handler = (args: Arguments<InfuseOptions>): void => {
51
58
const meta = squeeze ( targetPath , sources )
52
59
apply ( messages , meta )
53
60
const newSources = infuse ( targetPath , sources , meta )
54
- writeSFC ( newSources )
61
+ if ( ! args . dryRun ) writeSFC ( newSources )
55
62
}
56
63
57
64
function readLocaleMessages ( targetPath : string , matchRegex ?: string ) : LocaleMessages {
Original file line number Diff line number Diff line change @@ -12,7 +12,9 @@ Options:
12
12
[string] [required]
13
13
--locales, -l locale messages path to be infused [string] [required]
14
14
--match, -m option should be accepted a regex filenames, must be specified
15
- together --messages [string]"
15
+ together --messages [string]
16
+ --dryRun, -d run the infuse command, but do not apply them
17
+ [boolean] [default: false]"
16
18
` ;
17
19
18
20
exports [` squeeze command output help 1` ] = `
Original file line number Diff line number Diff line change @@ -131,6 +131,34 @@ test('relative path', async () => {
131
131
}
132
132
} )
133
133
134
+ test ( 'dryRun option' , async ( ) => {
135
+ // setup mock'
136
+ const mockUtils = utils as jest . Mocked < typeof utils >
137
+ mockUtils . resolve
138
+ . mockImplementationOnce ( ( ) => `${ TARGET_PATH } /src` )
139
+ . mockImplementationOnce ( ( ...paths ) => `${ TARGET_PATH } /${ paths [ 0 ] } ` )
140
+ const mockFS = fs as jest . Mocked < typeof fs >
141
+ mockFS . readFileSync . mockImplementation ( path => {
142
+ if ( MOCK_FILES [ path as string ] ) {
143
+ return MOCK_FILES [ path as string ]
144
+ } else {
145
+ return JSON . stringify ( json )
146
+ }
147
+ } )
148
+
149
+ // run
150
+ const infuse = await import ( '../../src/commands/infuse' )
151
+ const cmd = yargs . command ( infuse )
152
+ await new Promise ( resolve => {
153
+ cmd . parse ( `infuse --target=./src --locales=locales-2.json --dry-run` , ( ) => {
154
+ resolve ( )
155
+ } )
156
+ } )
157
+
158
+ // check
159
+ expect ( mockFS . writeFileSync ) . not . toHaveBeenCalled ( )
160
+ } )
161
+
134
162
test ( 'match option' , async ( ) => {
135
163
// setup mocks
136
164
const mockUtils = utils as jest . Mocked < typeof utils >
You can’t perform that action at this time.
0 commit comments