parent
							
								
									026b7e34b3
								
							
						
					
					
						commit
						a72250bace
					
				| @ -33,6 +33,7 @@ | ||||
|   }, | ||||
|   "// 1": "dependencies are used locally and by bazel", | ||||
|   "dependencies": { | ||||
|     "@angular-devkit/architect": "^0.10.6", | ||||
|     "@angular-devkit/core": "^7.0.4", | ||||
|     "@angular-devkit/schematics": "^7.0.4", | ||||
|     "@bazel/typescript": "0.21.0", | ||||
|  | ||||
| @ -14,6 +14,7 @@ npm_package( | ||||
|     ], | ||||
|     tags = ["release-with-framework"], | ||||
|     deps = [ | ||||
|         "//packages/bazel/src/builders", | ||||
|         "//packages/bazel/src/ng_package:lib", | ||||
|         "//packages/bazel/src/ngc-wrapped:ngc_lib", | ||||
|         "//packages/bazel/src/protractor/utils", | ||||
|  | ||||
| @ -12,6 +12,7 @@ | ||||
|   }, | ||||
|   "typings": "./src/ngc-wrapped/index.d.ts", | ||||
|   "dependencies": { | ||||
|     "@angular-devkit/architect": "^0.10.6", | ||||
|     "@angular-devkit/core": "^7.0.4", | ||||
|     "@angular-devkit/schematics": "^7.0.4", | ||||
|     "@bazel/typescript": "^0.21.0", | ||||
| @ -28,6 +29,7 @@ | ||||
|     "type": "git", | ||||
|     "url": "https://github.com/angular/angular.git" | ||||
|   }, | ||||
|   "builders": "./src/builders/builders.json", | ||||
|   "schematics": "./src/schematics/collection.json", | ||||
|   "ng-update": { | ||||
|     "packageGroup": "NG_UPDATE_PACKAGE_GROUP" | ||||
|  | ||||
							
								
								
									
										30
									
								
								packages/bazel/src/builders/BUILD.bazel
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								packages/bazel/src/builders/BUILD.bazel
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | ||||
| package(default_visibility = ["//visibility:public"]) | ||||
| 
 | ||||
| filegroup( | ||||
|     name = "package_assets", | ||||
|     srcs = [ | ||||
|         "builders.json", | ||||
|     ], | ||||
|     visibility = ["//packages/bazel:__subpackages__"], | ||||
| ) | ||||
| 
 | ||||
| load("//tools:defaults.bzl", "ts_library") | ||||
| 
 | ||||
| ts_library( | ||||
|     name = "builders", | ||||
|     srcs = [ | ||||
|         "bazel.ts", | ||||
|         "index.ts", | ||||
|         "schema.d.ts", | ||||
|     ], | ||||
|     data = [ | ||||
|         "schema.json", | ||||
|     ], | ||||
|     deps = [ | ||||
|         "@ngdeps//@angular-devkit/architect", | ||||
|         "@ngdeps//@angular-devkit/core", | ||||
|         "@ngdeps//@types/node", | ||||
|         "@rxjs", | ||||
|         "@rxjs//operators", | ||||
|     ], | ||||
| ) | ||||
							
								
								
									
										43
									
								
								packages/bazel/src/builders/bazel.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								packages/bazel/src/builders/bazel.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,43 @@ | ||||
| /** | ||||
|  * @license | ||||
|  * Copyright Google Inc. All Rights Reserved. | ||||
|  * | ||||
|  * 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
 | ||||
|  */ | ||||
| 
 | ||||
| /// <reference types='node'/>
 | ||||
| import {spawn, spawnSync} from 'child_process'; | ||||
| import {Observable, Subject} from 'rxjs'; | ||||
| 
 | ||||
| export type Executable = 'bazel' | 'ibazel'; | ||||
| export type Command = 'build' | 'test' | 'run' | 'coverage' | 'query'; | ||||
| 
 | ||||
| export function runBazel( | ||||
|     projectDir: string, executable: Executable, command: Command, workspaceTarget: string, | ||||
|     flags: string[]): Observable<void> { | ||||
|   const doneSubject = new Subject<void>(); | ||||
|   const buildProcess = spawn(executable, [command, workspaceTarget, ...flags], { | ||||
|     cwd: projectDir, | ||||
|     stdio: 'inherit', | ||||
|     shell: false, | ||||
|   }); | ||||
| 
 | ||||
|   buildProcess.once('close', (code: number) => { | ||||
|     if (code === 0) { | ||||
|       doneSubject.next(); | ||||
|     } else { | ||||
|       doneSubject.error(`${executable} failed with code ${code}.`); | ||||
|     } | ||||
|   }); | ||||
| 
 | ||||
|   return doneSubject.asObservable(); | ||||
| } | ||||
| 
 | ||||
| export function checkInstallation(executable: Executable, projectDir: string) { | ||||
|   const child = spawnSync(executable, ['version'], { | ||||
|     cwd: projectDir, | ||||
|     shell: false, | ||||
|   }); | ||||
|   return child.status === 0; | ||||
| } | ||||
							
								
								
									
										9
									
								
								packages/bazel/src/builders/builders.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								packages/bazel/src/builders/builders.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| { | ||||
|   "builders": { | ||||
|     "build": { | ||||
|       "class": "./index#Builder", | ||||
|       "schema": "./schema.json", | ||||
|       "description": "Executes Bazel on a target." | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										40
									
								
								packages/bazel/src/builders/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								packages/bazel/src/builders/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,40 @@ | ||||
| /** | ||||
|  * @license | ||||
|  * Copyright Google Inc. All Rights Reserved. | ||||
|  * | ||||
|  * 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
 | ||||
|  * | ||||
|  * @fileoverview Bazel bundle builder | ||||
|  */ | ||||
| 
 | ||||
| import {BuildEvent, Builder as BuilderInterface, BuilderConfiguration, BuilderContext} from '@angular-devkit/architect'; | ||||
| import {getSystemPath, resolve} from '@angular-devkit/core'; | ||||
| import {Observable, of } from 'rxjs'; | ||||
| import {catchError, map, tap} from 'rxjs/operators'; | ||||
| 
 | ||||
| import {checkInstallation, runBazel} from './bazel'; | ||||
| import {Schema} from './schema'; | ||||
| 
 | ||||
| export class Builder implements BuilderInterface<Schema> { | ||||
|   constructor(private context: BuilderContext) {} | ||||
| 
 | ||||
|   run(builderConfig: BuilderConfiguration<Partial<Schema>>): Observable<BuildEvent> { | ||||
|     const projectRoot = getSystemPath(resolve(this.context.workspace.root, builderConfig.root)); | ||||
|     const targetLabel = builderConfig.options.targetLabel; | ||||
| 
 | ||||
|     const executable = builderConfig.options.watch ? 'ibazel' : 'bazel'; | ||||
| 
 | ||||
|     if (!checkInstallation(executable, projectRoot)) { | ||||
|       throw new Error( | ||||
|           `Could not run ${executable}. Please make sure that the ` + | ||||
|           `"${executable}" command is available in the $PATH.`); | ||||
|     } | ||||
| 
 | ||||
|     // TODO: Support passing flags.
 | ||||
|     return runBazel( | ||||
|                projectRoot, executable, builderConfig.options.bazelCommand !, targetLabel !, | ||||
|                [] /* flags */) | ||||
|         .pipe(map(() => ({success: true})), catchError(() => of ({success: false})), ); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										24
									
								
								packages/bazel/src/builders/schema.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								packages/bazel/src/builders/schema.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | ||||
| 
 | ||||
| // THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE THE
 | ||||
| // CORRESPONDING JSON SCHEMA FILE, THEN RUN devkit-admin build (or bazel build ...).
 | ||||
| 
 | ||||
| // tslint:disable:no-global-tslint-disable
 | ||||
| // tslint:disable
 | ||||
| 
 | ||||
| /** | ||||
|  * Options for Bazel Builder | ||||
|  */ | ||||
| export interface Schema { | ||||
|   bazelCommand: BazelCommand; | ||||
|   /** | ||||
|    * Target to be executed under Bazel. | ||||
|    */ | ||||
|   targetLabel: string; | ||||
|   watch?: boolean; | ||||
| } | ||||
| 
 | ||||
| export enum BazelCommand { | ||||
|   Build = 'build', | ||||
|   Run = 'run', | ||||
|   Test = 'test', | ||||
| } | ||||
							
								
								
									
										29
									
								
								packages/bazel/src/builders/schema.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								packages/bazel/src/builders/schema.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,29 @@ | ||||
| { | ||||
|     "$schema": "http://json-schema.org/schema", | ||||
|     "title": "Bazel builder schema", | ||||
|     "description": "Options for Bazel Builder", | ||||
|     "type": "object", | ||||
|     "properties": { | ||||
|         "targetLabel": { | ||||
|             "type": "string", | ||||
|             "description": "Target to be executed under Bazel." | ||||
|         }, | ||||
|         "bazelCommand": { | ||||
|             "type": "string", | ||||
|             "enum": [ | ||||
|                 "run", | ||||
|                 "build", | ||||
|                 "test" | ||||
|             ] | ||||
|         }, | ||||
|         "watch": { | ||||
|             "type": "boolean", | ||||
|             "default": false | ||||
|         } | ||||
|     }, | ||||
|     "additionalProperties": false, | ||||
|     "required": [ | ||||
|         "targetLabel", | ||||
|         "bazelCommand" | ||||
|     ] | ||||
| } | ||||
| @ -1693,7 +1693,7 @@ karma-sourcemap-loader@0.3.7: | ||||
|   dependencies: | ||||
|     graceful-fs "^4.1.2" | ||||
| 
 | ||||
| "karma@github:alexeagle/karma#fa1a84ac881485b5657cb669e9b4e5da77b79f0a": | ||||
| karma@alexeagle/karma#fa1a84ac881485b5657cb669e9b4e5da77b79f0a: | ||||
|   version "1.7.1" | ||||
|   resolved "https://codeload.github.com/alexeagle/karma/tar.gz/fa1a84ac881485b5657cb669e9b4e5da77b79f0a" | ||||
|   dependencies: | ||||
|  | ||||
							
								
								
									
										19
									
								
								yarn.lock
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								yarn.lock
									
									
									
									
									
								
							| @ -2,6 +2,14 @@ | ||||
| # yarn lockfile v1 | ||||
| 
 | ||||
| 
 | ||||
| "@angular-devkit/architect@^0.10.6": | ||||
|   version "0.10.6" | ||||
|   resolved "https://registry.yarnpkg.com/@angular-devkit/architect/-/architect-0.10.6.tgz#7007e7591be21eeb478951106c84c83802ca21a4" | ||||
|   integrity sha512-IygpkXNn946vVUFFWKWEDxRqRy888vOAUWcmkZzqPEBYkuwWt7WnLfe8Sjw4fH/+HLWEMS8RXbdSTHiiaP9qOg== | ||||
|   dependencies: | ||||
|     "@angular-devkit/core" "7.0.6" | ||||
|     rxjs "6.3.3" | ||||
| 
 | ||||
| "@angular-devkit/core@7.0.5", "@angular-devkit/core@^7.0.4": | ||||
|   version "7.0.5" | ||||
|   resolved "https://registry.yarnpkg.com/@angular-devkit/core/-/core-7.0.5.tgz#60866c0a2367cea44b436a359ac9be99a138e180" | ||||
| @ -13,6 +21,17 @@ | ||||
|     rxjs "6.3.3" | ||||
|     source-map "0.7.3" | ||||
| 
 | ||||
| "@angular-devkit/core@7.0.6": | ||||
|   version "7.0.6" | ||||
|   resolved "https://registry.yarnpkg.com/@angular-devkit/core/-/core-7.0.6.tgz#26c4cd4d271e8cd03f6e50b4ec30cbc606f3346e" | ||||
|   integrity sha512-RPSXUtLrpYDTqAEL0rCyDKxES76EomsPBvUUZTD6UkE2pihoh9ZIxkzhzlE+HU/xdqm28+smQYFhvvEAXFWwSQ== | ||||
|   dependencies: | ||||
|     ajv "6.5.3" | ||||
|     chokidar "2.0.4" | ||||
|     fast-json-stable-stringify "2.0.0" | ||||
|     rxjs "6.3.3" | ||||
|     source-map "0.7.3" | ||||
| 
 | ||||
| "@angular-devkit/schematics@7.0.5", "@angular-devkit/schematics@^7.0.4": | ||||
|   version "7.0.5" | ||||
|   resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-7.0.5.tgz#527bf0af5352172e92c5473a33bc07af44c77796" | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user