Skip to content

Commit

Permalink
feat: expose version object in releases
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
devversion committed Jun 26, 2017
1 parent 38b365c commit da3295c
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/cdk/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
*/

export * from './coercion/index';
export * from './version';
4 changes: 4 additions & 0 deletions src/cdk/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {Version} from '@angular/core';

/** Current version of the Angular Component Development Kit. */
export const VERSION = new Version('0.0.0-PLACEHOLDER');
1 change: 1 addition & 0 deletions src/lib/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Entry point for all public APIs of Angular Material.
*/

export * from './version';
export * from './core';
export * from './module';

Expand Down
4 changes: 4 additions & 0 deletions src/lib/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {Version} from '@angular/core';

/** Current version of Angular Material. */
export const VERSION = new Version('0.0.0-PLACEHOLDER');
32 changes: 32 additions & 0 deletions tools/gulp/packaging/version-placeholders.ts
Original file line number Diff line number Diff line change
@@ -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);
});
}
4 changes: 2 additions & 2 deletions tools/package-tools/build-release.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {join} from 'path';
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';
Expand Down Expand Up @@ -32,7 +32,7 @@ export function composeRelease(packageName: string) {
copyFiles(packagesDir, 'README.md', releasePath);
copyFiles(sourcePath, 'package.json', releasePath);

updatePackageVersion(releasePath);
replaceVersionPlaceholders(releasePath);
createTypingsReexportFile(releasePath, packageName);
createMetadataReexportFile(releasePath, packageName);
addPureAnnotationsToFile(join(releasePath, '@angular', `${packageName}.es5.js`));
Expand Down
17 changes: 0 additions & 17 deletions tools/package-tools/package-versions.ts

This file was deleted.

32 changes: 32 additions & 0 deletions tools/package-tools/version-placeholders.ts
Original file line number Diff line number Diff line change
@@ -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);
});
}

0 comments on commit da3295c

Please sign in to comment.