-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
build-release.ts
82 lines (69 loc) · 4.01 KB
/
build-release.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import {join} from 'path';
import {mkdirpSync} from 'fs-extra';
import {copyFiles} from './copy-files';
import {addPureAnnotationsToFile} from './pure-annotations';
import {replaceVersionPlaceholders} from './version-placeholders';
import {inlinePackageMetadataFiles} from './metadata-inlining';
import {createTypingsReexportFile} from './typings-reexport';
import {createMetadataReexportFile} from './metadata-reexport';
import {getSecondaryEntryPointsForPackage} from './secondary-entry-points';
import {createEntryPointPackageJson} from './entry-point-package-json';
import {buildConfig} from './build-config';
const {packagesDir, outputDir, projectDir} = buildConfig;
/** Directory where all bundles will be created in. */
const bundlesDir = join(outputDir, 'bundles');
/**
* Copies different output files into a folder structure that follows the `angular/angular`
* release folder structure. The output will also contain a README and the according package.json
* file. Additionally the package will be Closure Compiler and AOT compatible.
*/
export function composeRelease(packageName: string, options: ComposeReleaseOptions = {}) {
// To avoid refactoring of the project the package material will map to the source path `lib/`.
const sourcePath = join(packagesDir, packageName === 'material' ? 'lib' : packageName);
const packagePath = join(outputDir, 'packages', packageName);
const releasePath = join(outputDir, 'releases', packageName);
inlinePackageMetadataFiles(packagePath);
copyFiles(packagePath, '**/*.+(d.ts|metadata.json)', join(releasePath, 'typings'));
copyFiles(bundlesDir, `${packageName}?(-*).umd.js?(.map)`, join(releasePath, 'bundles'));
copyFiles(bundlesDir, `${packageName}?(.es5).js?(.map)`, join(releasePath, '@angular'));
copyFiles(join(bundlesDir, packageName), '**', join(releasePath, '@angular', packageName));
copyFiles(projectDir, 'LICENSE', releasePath);
copyFiles(packagesDir, 'README.md', releasePath);
copyFiles(sourcePath, 'package.json', releasePath);
replaceVersionPlaceholders(releasePath);
createTypingsReexportFile(releasePath, './typings/index', packageName);
createMetadataReexportFile(releasePath, './typings/index', packageName);
if (options.useSecondaryEntryPoints) {
createFilesForSecondaryEntryPoint(packageName, packagePath, releasePath);
}
addPureAnnotationsToFile(join(releasePath, '@angular', `${packageName}.es5.js`));
}
/** Creates files necessary for a secondary entry-point. */
function createFilesForSecondaryEntryPoint(packageName: string, packagePath: string,
releasePath: string) {
getSecondaryEntryPointsForPackage(packageName).forEach(entryPointName => {
// Create a directory in the root of the package for this entry point that contains
// * A package.json that lists the different bundle locations
// * An index.d.ts file that re-exports the index.d.ts from the typings/ directory
// * A metadata.json re-export for this entry-point's metadata.
const entryPointDir = join(releasePath, entryPointName);
mkdirpSync(entryPointDir);
createEntryPointPackageJson(entryPointDir, packageName, entryPointName);
// Copy typings and metadata from tsc output location into the entry-point.
copyFiles(
join(packagePath, entryPointName),
'**/*.+(d.ts|metadata.json)',
join(entryPointDir, 'typings'));
// Create a typings and a metadata re-export within the entry-point to point to the
// typings we just copied.
createTypingsReexportFile(entryPointDir, `./typings/index`, 'index');
createMetadataReexportFile(entryPointDir, `./typings/index`, 'index');
// Finally, create both a d.ts and metadata file for this entry-point in the root of
// the package that re-exports from the entry-point's directory.
createTypingsReexportFile(releasePath, `./${entryPointName}/index`, entryPointName);
createMetadataReexportFile(releasePath, `./${entryPointName}/index`, entryPointName);
});
}
interface ComposeReleaseOptions {
useSecondaryEntryPoints?: boolean;
}