diff --git a/src/cdk/public_api.ts b/src/cdk/public_api.ts index cef0ea58855f..2a5af4f06cb7 100644 --- a/src/cdk/public_api.ts +++ b/src/cdk/public_api.ts @@ -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'; diff --git a/src/cdk/version.ts b/src/cdk/version.ts new file mode 100644 index 000000000000..4d5a1335755f --- /dev/null +++ b/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'); diff --git a/src/lib/public_api.ts b/src/lib/public_api.ts index fbaf29694867..a42ab73d968b 100644 --- a/src/lib/public_api.ts +++ b/src/lib/public_api.ts @@ -12,6 +12,7 @@ * Entry point for all public APIs of Angular Material. */ +export * from './version'; export * from './core'; export * from './module'; diff --git a/src/lib/version.ts b/src/lib/version.ts new file mode 100644 index 000000000000..7d04cb1fda3f --- /dev/null +++ b/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'); diff --git a/tools/package-tools/build-release.ts b/tools/package-tools/build-release.ts index 0792176b52cd..bfe1e642c2a0 100644 --- a/tools/package-tools/build-release.ts +++ b/tools/package-tools/build-release.ts @@ -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); diff --git a/tools/package-tools/package-versions.ts b/tools/package-tools/package-versions.ts deleted file mode 100644 index 110297e59a12..000000000000 --- a/tools/package-tools/package-versions.ts +++ /dev/null @@ -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)); -} diff --git a/tools/package-tools/version-placeholders.ts b/tools/package-tools/version-placeholders.ts new file mode 100644 index 000000000000..61d81aa6000e --- /dev/null +++ b/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); + }); +}