Skip to content

Commit

Permalink
feat: expose version object in releases (#4962)
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 authored and andrewseguin committed Jul 27, 2017
1 parent b34b440 commit 3bfe7f0
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 22 deletions.
4 changes: 1 addition & 3 deletions src/cdk/public_api.ts
Expand Up @@ -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';
12 changes: 12 additions & 0 deletions src/cdk/version.ts
@@ -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');
1 change: 1 addition & 0 deletions src/lib/public_api.ts
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
12 changes: 12 additions & 0 deletions src/lib/version.ts
@@ -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');
4 changes: 2 additions & 2 deletions tools/package-tools/build-release.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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);

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
@@ -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 3bfe7f0

Please sign in to comment.