|
1 | 1 | import { writeFileSync, readFileSync, existsSync } from '@ionic/utils-fs'; |
2 | 2 | import { join } from 'path'; |
3 | 3 | import rimraf from 'rimraf'; |
4 | | -import { coerce, gt, gte } from 'semver'; |
| 4 | +import { coerce, gt, gte, lt } from 'semver'; |
5 | 5 |
|
6 | 6 | import { getAndroidPlugins } from '../android/common'; |
7 | 7 | import c from '../colors'; |
@@ -284,35 +284,48 @@ export async function migrateCommand( |
284 | 284 | for (const variable of Object.keys( |
285 | 285 | variablesAndClasspaths.variables, |
286 | 286 | )) { |
| 287 | + let replaceStart = `${variable} = '`; |
| 288 | + let replaceEnd = `'\n`; |
287 | 289 | if ( |
288 | | - !(await updateFile( |
289 | | - config, |
290 | | - variablesPath, |
291 | | - `${variable} = '`, |
292 | | - `'`, |
293 | | - variablesAndClasspaths.variables[variable].toString(), |
294 | | - true, |
295 | | - )) |
| 290 | + typeof variablesAndClasspaths.variables[variable] === 'number' |
296 | 291 | ) { |
297 | | - const didWork = await updateFile( |
298 | | - config, |
299 | | - variablesPath, |
300 | | - `${variable} = `, |
301 | | - `\n`, |
302 | | - variablesAndClasspaths.variables[variable].toString(), |
303 | | - true, |
| 292 | + replaceStart = `${variable} = `; |
| 293 | + replaceEnd = `\n`; |
| 294 | + } |
| 295 | + |
| 296 | + if (txt.includes(replaceStart)) { |
| 297 | + const first = txt.indexOf(replaceStart) + replaceStart.length; |
| 298 | + const value = txt.substring( |
| 299 | + first, |
| 300 | + txt.indexOf(replaceEnd, first), |
304 | 301 | ); |
305 | | - if (!didWork) { |
306 | | - let file = readFile(variablesPath); |
307 | | - if (file) { |
308 | | - file = file.replace( |
309 | | - '}', |
310 | | - ` ${variable} = '${variablesAndClasspaths.variables[ |
311 | | - variable |
312 | | - ].toString()}'\n}`, |
313 | | - ); |
314 | | - writeFileSync(variablesPath, file); |
315 | | - } |
| 302 | + if ( |
| 303 | + (typeof variablesAndClasspaths.variables[variable] === |
| 304 | + 'number' && |
| 305 | + value <= variablesAndClasspaths.variables[variable]) || |
| 306 | + (typeof variablesAndClasspaths.variables[variable] === |
| 307 | + 'string' && |
| 308 | + lt(value, variablesAndClasspaths.variables[variable])) |
| 309 | + ) { |
| 310 | + await updateFile( |
| 311 | + config, |
| 312 | + variablesPath, |
| 313 | + replaceStart, |
| 314 | + replaceEnd, |
| 315 | + variablesAndClasspaths.variables[variable].toString(), |
| 316 | + true, |
| 317 | + ); |
| 318 | + } |
| 319 | + } else { |
| 320 | + let file = readFile(variablesPath); |
| 321 | + if (file) { |
| 322 | + file = file.replace( |
| 323 | + '}', |
| 324 | + ` ${replaceStart}${variablesAndClasspaths.variables[ |
| 325 | + variable |
| 326 | + ].toString()}${replaceEnd}}`, |
| 327 | + ); |
| 328 | + writeFileSync(variablesPath, file); |
316 | 329 | } |
317 | 330 | } |
318 | 331 | } |
|
0 commit comments