diff --git a/src/cdk/public_api.ts b/src/cdk/public_api.ts index 91fb8910ff6b..94446f63d16a 100644 --- a/src/cdk/public_api.ts +++ b/src/cdk/public_api.ts @@ -15,3 +15,4 @@ export * from './portal/index'; export * from './rxjs/index'; export * from './observe-content/index'; export * from './keyboard/keycodes'; +export * from './version'; diff --git a/src/cdk/version.ts b/src/cdk/version.ts new file mode 100644 index 000000000000..4defe332aeee --- /dev/null +++ b/src/cdk/version.ts @@ -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'); 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..c453475ba706 --- /dev/null +++ b/src/lib/version.ts @@ -0,0 +1,4 @@ +import {Version} from '@angular/core'; + +/** Current version of Angular Material. */ +export const VERSION = new Version('0.0.0-PLACEHOLDER'); diff --git a/tools/gulp/packaging/version-placeholders.ts b/tools/gulp/packaging/version-placeholders.ts new file mode 100644 index 000000000000..61d81aa6000e --- /dev/null +++ b/tools/gulp/packaging/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); + }); +} diff --git a/tools/package-tools/build-release.ts b/tools/package-tools/build-release.ts index 4b355a885275..e9d0d94cbc16 100644 --- a/tools/package-tools/build-release.ts +++ b/tools/package-tools/build-release.ts @@ -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'; @@ -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`)); 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); + }); +}