mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-24 16:16:27 +08:00
With this change we add migration to replace the deprecated `--prod` with `--configuration production` in the scripts section of the package.json. Closes #21036
31 lines
895 B
TypeScript
31 lines
895 B
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import { Rule } from '@angular-devkit/schematics';
|
|
import { JSONFile } from '../../utility/json-file';
|
|
|
|
export default function (): Rule {
|
|
return (tree) => {
|
|
const file = new JSONFile(tree, 'package.json');
|
|
const scripts = file.get(['scripts']);
|
|
if (!scripts || typeof scripts !== 'object') {
|
|
return;
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
const updatedScripts = Object.entries(scripts!).map(([key, value]) => [
|
|
key,
|
|
typeof value === 'string'
|
|
? value.replace(/ --prod(?!\w)/g, ' --configuration production')
|
|
: value,
|
|
]);
|
|
|
|
file.modify(['scripts'], Object.fromEntries(updatedScripts));
|
|
};
|
|
}
|