build: use version placeholder in packages (#4065)

* 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.
This commit is contained in:
Paul Gschwendtner
2017-04-12 17:19:18 -07:00
committed by Jeremy Elbourn
parent abd2ac6489
commit 60ea218c67
3 changed files with 17 additions and 3 deletions
+1 -1
View File
@@ -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",
+1 -1
View File
@@ -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",
+15 -1
View File
@@ -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`),