Skip to content

Commit 3bd323e

Browse files
committed
feat: expose version object in releases
* 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.
1 parent 549d622 commit 3bd323e

File tree

6 files changed

+44
-3
lines changed

6 files changed

+44
-3
lines changed

src/cdk/public_api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const __TEMP__ = -1;
1+
export * from './version';

src/cdk/version.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {Version} from '@angular/core';
2+
3+
/** Current version of the Angular Component Development Kit. */
4+
export const VERSION = new Version('0.0.0-PLACEHOLDER');

src/lib/public_api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Entry point for all public APIs of Angular Material.
55
*/
66

7+
export * from './version';
78
export * from './core';
89
export * from './module';
910

src/lib/version.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {Version} from '@angular/core';
2+
3+
/** Current version of Angular Material. */
4+
export const VERSION = new Version('0.0.0-PLACEHOLDER');

tools/gulp/packaging/build-release.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {join} from 'path';
22
import {copyFiles} from '../util/copy-files';
33
import {addPureAnnotationsToFile} from './pure-annotations';
4-
import {updatePackageVersion} from './package-versions';
4+
import {replaceVersionPlaceholders} from './version-placeholders';
55
import {inlinePackageMetadataFiles} from './metadata-inlining';
66
import {createTypingsReexportFile} from './typings-reexport';
77
import {createMetadataReexportFile} from './metadata-reexport';
@@ -32,7 +32,7 @@ export function composeRelease(packageName: string) {
3232
copyFiles(packagesDir, 'README.md', releasePath);
3333
copyFiles(sourcePath, 'package.json', releasePath);
3434

35-
updatePackageVersion(releasePath);
35+
replaceVersionPlaceholders(releasePath);
3636
createTypingsReexportFile(releasePath, packageName);
3737
createMetadataReexportFile(releasePath, packageName);
3838
addPureAnnotationsToFile(join(releasePath, '@angular', `${packageName}.es5.js`));
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {readFileSync, writeFileSync} from 'fs';
2+
import {MATERIAL_VERSION} from '../build-config';
3+
import {spawnSync} from 'child_process';
4+
5+
/** Variable that is set to the string for version placeholders. */
6+
const versionPlaceholderText = '0.0.0-PLACEHOLDER';
7+
8+
/** RegExp that matches version placeholders inside of a file. */
9+
const versionPlaceholderRegex = new RegExp(versionPlaceholderText);
10+
11+
/**
12+
* Walks through every file in a directory and replaces the version placeholders with the current
13+
* version of Material.
14+
*/
15+
export function replaceVersionPlaceholders(packageDir: string) {
16+
// Resolve files that contain version placeholders using Grep since it's super fast and also
17+
// does have a very simple usage.
18+
const files = spawnSync('grep', ['-ril', versionPlaceholderText, packageDir]).stdout
19+
.toString()
20+
.split('\n')
21+
.filter(String);
22+
23+
// Walk through every file that contains version placeholders and replace those with the current
24+
// version of the root package.json file.
25+
files.forEach(filePath => {
26+
let fileContent = readFileSync(filePath, 'utf-8');
27+
28+
fileContent = fileContent.replace(versionPlaceholderRegex, MATERIAL_VERSION);
29+
30+
writeFileSync(filePath, fileContent);
31+
});
32+
}

0 commit comments

Comments
 (0)