From d7c1cbb44a0dfe218b890eecb02df63d2ea9fb75 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Wed, 12 Apr 2017 17:07:50 -0700 Subject: [PATCH] build: use version placeholder in packages * Introduces a version placeholder (as in angular/angular) that will be replaced with the version string form the root `package.json` file. * This ensures that the different packages are always having the correct version and it also ensures that there is no version-mismatch. --- src/lib/package.json | 2 +- src/material-examples/package.json | 2 +- tools/gulp/util/package-build.ts | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/lib/package.json b/src/lib/package.json index 08b839c25346..4f9f0db55c0a 100644 --- a/src/lib/package.json +++ b/src/lib/package.json @@ -1,6 +1,6 @@ { "name": "@angular/material", - "version": "2.0.0-beta.3", + "version": "0.0.0-PLACEHOLDER", "description": "Angular Material", "main": "./bundles/material.umd.js", "module": "./@angular/material.es5.js", diff --git a/src/material-examples/package.json b/src/material-examples/package.json index a3f8bf2af809..ad8a5041849f 100644 --- a/src/material-examples/package.json +++ b/src/material-examples/package.json @@ -1,6 +1,6 @@ { "name": "@angular/material-examples", - "version": "2.0.0-beta.3", + "version": "0.0.0-PLACEHOLDER", "description": "Angular Material Examples", "main": "./bundles/material-examples.umd.js", "module": "./@angular/material-examples.es5.js", diff --git a/tools/gulp/util/package-build.ts b/tools/gulp/util/package-build.ts index 0a6e516f20b7..1eb32be3a006 100644 --- a/tools/gulp/util/package-build.ts +++ b/tools/gulp/util/package-build.ts @@ -1,5 +1,4 @@ import {join, basename, dirname} from 'path'; -import {DIST_BUNDLES, DIST_ROOT, SOURCE_ROOT, PROJECT_ROOT, LICENSE_BANNER} from '../constants'; import {createRollupBundle} from './rollup-helper'; import {inlineMetadataResources} from './inline-resources'; import {transpileFile} from './ts-compiler'; @@ -8,6 +7,9 @@ import {sync as glob} from 'glob'; import { writeFileSync, copySync, mkdirpSync, readFileSync } from 'fs-extra'; +import { + DIST_BUNDLES, DIST_ROOT, SOURCE_ROOT, PROJECT_ROOT, LICENSE_BANNER, MATERIAL_VERSION +} from '../constants'; // There are no type definitions available for these imports. const uglify = require('uglify-js'); @@ -32,6 +34,7 @@ export function composeRelease(packageName: string) { copyFiles(SOURCE_ROOT, 'README', releasePath); copyFiles(sourcePath, 'package.json', releasePath); + updatePackageVersion(releasePath); createTypingFile(releasePath, packageName); createMetadataFile(releasePath, packageName); } @@ -81,6 +84,17 @@ function copyFiles(fromPath: string, fileGlob: string, outDir: string) { }); } +/** Updates the `package.json` file of the specified package. Replaces the version placeholder. */ +function updatePackageVersion(packageDir: string) { + let packagePath = join(packageDir, 'package.json'); + let 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', MATERIAL_VERSION); + + writeFileSync(packagePath, JSON.stringify(packageConfig, null, 2)); +} + /** Create a typing file that links to the bundled definitions of NGC. */ function createTypingFile(outputDir: string, entryName: string) { writeFileSync(join(outputDir, `${entryName}.d.ts`),