mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
feat: expose version object in releases (#4962)
* In releases there will be a constant called `VERSION` that holds the current version of the installed package (material or cdk) * This is similar as for every @angular package like core, forms, compiler.
This commit is contained in:
committed by
Andrew Seguin
parent
b34b440ee3
commit
3bfe7f0f92
@@ -6,6 +6,4 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
|
||||
// TODO(jelbourn): add version here
|
||||
export const __TMP__ = 0;
|
||||
export * from './version';
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. 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 {Version} from '@angular/core';
|
||||
|
||||
/** Current version of the Angular Component Development Kit. */
|
||||
export const VERSION = new Version('0.0.0-PLACEHOLDER');
|
||||
@@ -12,6 +12,7 @@
|
||||
* Entry point for all public APIs of Angular Material.
|
||||
*/
|
||||
|
||||
export * from './version';
|
||||
export * from './core';
|
||||
export * from './module';
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. 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 {Version} from '@angular/core';
|
||||
|
||||
/** Current version of Angular Material. */
|
||||
export const VERSION = new Version('0.0.0-PLACEHOLDER');
|
||||
@@ -2,7 +2,7 @@ import {join} from 'path';
|
||||
import {mkdirpSync} from 'fs-extra';
|
||||
import {copyFiles} from './copy-files';
|
||||
import {addPureAnnotationsToFile} from './pure-annotations';
|
||||
import {updatePackageVersion} from './package-versions';
|
||||
import {replaceVersionPlaceholders} from './version-placeholders';
|
||||
import {inlinePackageMetadataFiles} from './metadata-inlining';
|
||||
import {createTypingsReexportFile} from './typings-reexport';
|
||||
import {createMetadataReexportFile} from './metadata-reexport';
|
||||
@@ -36,7 +36,7 @@ export function composeRelease(packageName: string, options: ComposeReleaseOptio
|
||||
copyFiles(packagesDir, 'README.md', releasePath);
|
||||
copyFiles(sourcePath, 'package.json', releasePath);
|
||||
|
||||
updatePackageVersion(releasePath);
|
||||
replaceVersionPlaceholders(releasePath);
|
||||
createTypingsReexportFile(releasePath, './typings/index', packageName);
|
||||
createMetadataReexportFile(releasePath, './typings/index', packageName);
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import {writeFileSync} from 'fs';
|
||||
import {join} from 'path';
|
||||
import {buildConfig} from './build-config';
|
||||
|
||||
/** Version of the project that will be used to replace the placeholder. */
|
||||
const {projectVersion} = buildConfig;
|
||||
|
||||
/** Updates the `package.json` file of the specified package. Replaces the version placeholder. */
|
||||
export function updatePackageVersion(packageDir: string) {
|
||||
const packagePath = join(packageDir, 'package.json');
|
||||
const packageConfig = require(packagePath);
|
||||
|
||||
// Replace the `0.0.0-PLACEHOLDER` version name with the version of the root package.json file.
|
||||
packageConfig.version = packageConfig.version.replace('0.0.0-PLACEHOLDER', projectVersion);
|
||||
|
||||
writeFileSync(packagePath, JSON.stringify(packageConfig, null, 2));
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import {readFileSync, writeFileSync} from 'fs';
|
||||
import {buildConfig} from './build-config';
|
||||
import {spawnSync} from 'child_process';
|
||||
|
||||
/** Variable that is set to the string for version placeholders. */
|
||||
const versionPlaceholderText = '0.0.0-PLACEHOLDER';
|
||||
|
||||
/** RegExp that matches version placeholders inside of a file. */
|
||||
const versionPlaceholderRegex = new RegExp(versionPlaceholderText);
|
||||
|
||||
/**
|
||||
* Walks through every file in a directory and replaces the version placeholders with the current
|
||||
* version of Material.
|
||||
*/
|
||||
export function replaceVersionPlaceholders(packageDir: string) {
|
||||
// Resolve files that contain version placeholders using Grep since it's super fast and also
|
||||
// does have a very simple usage.
|
||||
const files = spawnSync('grep', ['-ril', versionPlaceholderText, packageDir]).stdout
|
||||
.toString()
|
||||
.split('\n')
|
||||
.filter(String);
|
||||
|
||||
// Walk through every file that contains version placeholders and replace those with the current
|
||||
// version of the root package.json file.
|
||||
files.forEach(filePath => {
|
||||
let fileContent = readFileSync(filePath, 'utf-8');
|
||||
|
||||
fileContent = fileContent.replace(versionPlaceholderRegex, buildConfig.projectVersion);
|
||||
|
||||
writeFileSync(filePath, fileContent);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user