| 
									
										
										
										
											2020-02-29 22:25:49 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2020-02-29 22:25:49 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-29 21:05:23 +02:00
										 |  |  | const {resolve} = require('path'); | 
					
						
							| 
									
										
										
										
											2020-08-31 13:48:41 +09:00
										 |  |  | const {chmod, cp, mkdir, mv, rm, test} = require('shelljs'); | 
					
						
							|  |  |  | const zonePackageJson = require('../../packages/zone.js/package.json'); | 
					
						
							| 
									
										
										
										
											2020-02-29 22:25:49 +02:00
										 |  |  | const {baseDir, bazelBin, bazelCmd, exec, scriptPath} = require('./package-builder'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |   buildZoneJsPackage, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Build the `zone.js` npm package into `dist/bin/packages/zone.js/npm_package/` and copy it to | 
					
						
							| 
									
										
										
										
											2021-04-05 19:05:54 +03:00
										 |  |  |  * `destDir` for other scripts/tests to use. | 
					
						
							| 
									
										
										
										
											2020-02-29 22:25:49 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * NOTE: The `zone.js` package is not built as part of `package-builder`'s `buildTargetPackages()` | 
					
						
							|  |  |  |  *       nor is it copied into the same directory as the Angular packages (e.g. | 
					
						
							|  |  |  |  *       `dist/packages-dist/`) despite its source's being inside `packages/`, because it is not | 
					
						
							|  |  |  |  *       published to npm under the `@angular` scope (as happens for the rest of the packages). | 
					
						
							| 
									
										
										
										
											2020-02-29 21:05:23 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-05 19:05:54 +03:00
										 |  |  |  * @param {string} destDir Path to the output directory into which we copy the npm package. | 
					
						
							| 
									
										
										
										
											2020-02-29 21:05:23 +02:00
										 |  |  |  *     This path should either be absolute or relative to the project root. | 
					
						
							| 
									
										
										
										
											2020-02-29 22:25:49 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-04-05 19:05:54 +03:00
										 |  |  | function buildZoneJsPackage(destDir) { | 
					
						
							| 
									
										
										
										
											2020-02-29 22:25:49 +02:00
										 |  |  |   console.info('##############################'); | 
					
						
							|  |  |  |   console.info(`${scriptPath}:`); | 
					
						
							|  |  |  |   console.info('  Building zone.js npm package'); | 
					
						
							|  |  |  |   console.info('##############################'); | 
					
						
							| 
									
										
										
										
											2021-01-27 19:09:36 +02:00
										 |  |  |   exec(`${bazelCmd} run //packages/zone.js:npm_package.pack`); | 
					
						
							| 
									
										
										
										
											2020-02-29 22:25:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-29 21:05:23 +02:00
										 |  |  |   // Create the output directory.
 | 
					
						
							| 
									
										
										
										
											2021-04-05 19:05:54 +03:00
										 |  |  |   const absDestDir = resolve(baseDir, destDir); | 
					
						
							|  |  |  |   if (!test('-d', absDestDir)) { | 
					
						
							|  |  |  |     mkdir('-p', absDestDir); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-02-29 21:05:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-05 19:05:54 +03:00
										 |  |  |   // Copy artifacts to `destDir`, so they can be easier persisted on CI and used by non-bazel
 | 
					
						
							| 
									
										
										
										
											2020-02-29 21:05:23 +02:00
										 |  |  |   // scripts/tests.
 | 
					
						
							| 
									
										
										
										
											2020-02-29 22:25:49 +02:00
										 |  |  |   const buildOutputDir = `${bazelBin}/packages/zone.js/npm_package`; | 
					
						
							| 
									
										
										
										
											2021-04-05 19:05:54 +03:00
										 |  |  |   const distTargetDir = `${absDestDir}/zone.js`; | 
					
						
							| 
									
										
										
										
											2020-02-29 22:25:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-31 13:48:41 +09:00
										 |  |  |   console.info(`# Copy npm_package artifacts to ${distTargetDir}`); | 
					
						
							| 
									
										
										
										
											2020-02-29 22:25:49 +02:00
										 |  |  |   rm('-rf', distTargetDir); | 
					
						
							|  |  |  |   cp('-R', buildOutputDir, distTargetDir); | 
					
						
							|  |  |  |   chmod('-R', 'u+w', distTargetDir); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-05 19:05:54 +03:00
										 |  |  |   // Copy `zone.js.tgz` to `destDir`, so we can test
 | 
					
						
							| 
									
										
										
										
											2020-08-31 13:48:41 +09:00
										 |  |  |   // the archive generated by the `npm_package.pack` rule.
 | 
					
						
							| 
									
										
										
										
											2021-04-05 19:05:54 +03:00
										 |  |  |   const distArchiveTargetDir = `${absDestDir}/archive`; | 
					
						
							| 
									
										
										
										
											2020-08-31 13:48:41 +09:00
										 |  |  |   console.info(`# Copy npm_package archive file to ${distArchiveTargetDir}`); | 
					
						
							|  |  |  |   rm('-rf', distArchiveTargetDir); | 
					
						
							|  |  |  |   mkdir('-p', distArchiveTargetDir); | 
					
						
							|  |  |  |   mv(`${baseDir}/zone.js-${zonePackageJson.version}.tgz`, `${distArchiveTargetDir}/zone.js.tgz`); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-29 22:25:49 +02:00
										 |  |  |   console.info(''); | 
					
						
							|  |  |  | } |