Skip to content

Commit

Permalink
build: use version placeholder in packages (#4065)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
devversion authored and jelbourn committed Apr 13, 2017
1 parent abd2ac6 commit 60ea218
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lib/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/material-examples/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 15 additions & 1 deletion tools/gulp/util/package-build.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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');
Expand All @@ -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);
}
Expand Down Expand Up @@ -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`),
Expand Down

0 comments on commit 60ea218

Please sign in to comment.