-
Notifications
You must be signed in to change notification settings - Fork 6.8k
build: make packaging more flexible #6143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tinayuangao
merged 1 commit into
angular:master
from
devversion:build/more-generic-packaging
Aug 1, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {BuildPackage, buildConfig} from 'material2-build-tools'; | ||
import {join} from 'path'; | ||
|
||
export const cdkPackage = new BuildPackage('cdk'); | ||
export const materialPackage = new BuildPackage('material', [cdkPackage]); | ||
export const examplesPackage = new BuildPackage('material-examples', [materialPackage, cdkPackage]); | ||
|
||
// To avoid refactoring of the project the material package will map to the source path `lib/`. | ||
materialPackage.packageRoot = join(buildConfig.packagesDir, 'lib'); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import {join} from 'path'; | ||
import {main as tsc} from '@angular/tsc-wrapped'; | ||
import {buildConfig} from './build-config'; | ||
import {getSecondaryEntryPointsForPackage} from './secondary-entry-points'; | ||
import { | ||
buildPrimaryEntryPointBundles, | ||
buildSecondaryEntryPointBundles | ||
} from 'material2-build-tools'; | ||
|
||
const {packagesDir, outputDir} = buildConfig; | ||
|
||
/** Name of the tsconfig file that is responsible for building a package. */ | ||
const buildTsconfigName = 'tsconfig-build.json'; | ||
|
||
/** Name of the tsconfig file that is responsible for building the tests. */ | ||
const testsTsconfigName = 'tsconfig-tests.json'; | ||
|
||
export class BuildPackage { | ||
|
||
/** Path to the package sources. */ | ||
packageRoot: string; | ||
|
||
/** Path to the package output. */ | ||
packageOut: string; | ||
|
||
/** Secondary entry points for the package. */ | ||
secondaryEntryPoints: string[]; | ||
|
||
/** Path to the entry file of the package in the output directory. */ | ||
private entryFilePath: string; | ||
|
||
/** Path to the tsconfig file, which will be used to build the package. */ | ||
private tsconfigBuild: string; | ||
|
||
/** Path to the tsconfig file, which will be used to build the tests. */ | ||
private tsconfigTests: string; | ||
|
||
constructor(public packageName: string, public dependencies: BuildPackage[] = []) { | ||
this.packageRoot = join(packagesDir, packageName); | ||
this.packageOut = join(outputDir, 'packages', packageName); | ||
|
||
this.tsconfigBuild = join(this.packageRoot, buildTsconfigName); | ||
this.tsconfigTests = join(this.packageRoot, testsTsconfigName); | ||
|
||
this.entryFilePath = join(this.packageOut, 'index.js'); | ||
|
||
this.secondaryEntryPoints = getSecondaryEntryPointsForPackage(packageName); | ||
} | ||
|
||
/** Compiles the package sources with all secondary entry points. */ | ||
async compile() { | ||
await this._compileEntryPoint(buildTsconfigName); | ||
|
||
// Walk through every secondary entry point and build the TypeScript sources sequentially. | ||
for (const entryPoint of this.secondaryEntryPoints) { | ||
await this._compileEntryPoint(buildTsconfigName, entryPoint); | ||
} | ||
} | ||
|
||
/** Compiles the TypeScript test source files for the package. */ | ||
async compileTests() { | ||
await this._compileEntryPoint(testsTsconfigName); | ||
} | ||
|
||
/** Creates all bundles for the package and all associated entry points. */ | ||
async createBundles() { | ||
await buildPrimaryEntryPointBundles(this.entryFilePath, this.packageName); | ||
|
||
for (const entryPoint of this.secondaryEntryPoints) { | ||
const entryPointEntryFilePath = join(this.packageOut, entryPoint, 'index.js'); | ||
await buildSecondaryEntryPointBundles(entryPointEntryFilePath, this.packageName, entryPoint); | ||
} | ||
} | ||
|
||
/** Compiles the TypeScript sources of a primary or secondary entry point. */ | ||
private async _compileEntryPoint(tsconfigName: string, secondaryEntryPoint?: string) { | ||
const entryPointPath = join(this.packageRoot, secondaryEntryPoint || ''); | ||
const entryPointTsconfigPath = join(entryPointPath, tsconfigName); | ||
|
||
await tsc(entryPointTsconfigPath, {basePath: entryPointPath}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you you think of making the second constructor arg a config / options object so that it looks like
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to avoid something like that. It's really a special case that we want to overwrite the
packageRoot
here and it should not really be done through the build package.Normally the build config is responsible for changing such things, but since this is really a special case I think this would be fine (it's just a single line; which is pretty clear IMO)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel strongly either way