|
7 | 7 | */
|
8 | 8 | // tslint:disable:no-implicit-dependencies
|
9 | 9 | import { JsonObject, logging } from '@angular-devkit/core';
|
| 10 | +import * as child_process from 'child_process'; |
10 | 11 | import * as fs from 'fs';
|
11 | 12 | import * as glob from 'glob';
|
12 | 13 | import * as path from 'path';
|
13 |
| -import * as ts from 'typescript'; |
14 | 14 | import { packages } from '../lib/packages';
|
15 | 15 |
|
16 | 16 | const minimatch = require('minimatch');
|
@@ -160,41 +160,38 @@ function _sortPackages() {
|
160 | 160 | return sortedPackages;
|
161 | 161 | }
|
162 | 162 |
|
| 163 | +function _exec(command: string, args: string[], opts: { cwd?: string }, logger: logging.Logger) { |
| 164 | + const { status, error, stderr } = child_process.spawnSync(command, args, { ...opts }); |
| 165 | + |
| 166 | + if (status != 0) { |
| 167 | + logger.error(`Command failed: ${command} ${args.map(x => JSON.stringify(x)).join(', ')}`); |
| 168 | + if (error) { |
| 169 | + logger.error('Error: ' + (error ? error.message : 'undefined')); |
| 170 | + } else { |
| 171 | + logger.error(`STDERR:\n${stderr}`); |
| 172 | + } |
| 173 | + throw error; |
| 174 | + } |
| 175 | +} |
| 176 | + |
163 | 177 |
|
164 | 178 | function _build(logger: logging.Logger) {
|
165 | 179 | logger.info('Building...');
|
166 |
| - const tsConfigPath = path.relative(process.cwd(), path.join(__dirname, '../tsconfig.json')); |
167 |
| - // Load the Compiler Options. |
168 |
| - const tsConfig = ts.readConfigFile(tsConfigPath, ts.sys.readFile); |
169 |
| - const parsedTsConfig = ts.parseJsonConfigFileContent(tsConfig.config, ts.sys, '.'); |
170 |
| - |
171 |
| - // Create the program and emit. |
172 |
| - const program = ts.createProgram(parsedTsConfig.fileNames, parsedTsConfig.options); |
173 |
| - const result = program.emit(); |
174 |
| - if (result.emitSkipped) { |
175 |
| - logger.error(`TypeScript compiler failed:`); |
176 |
| - const diagLogger = logger.createChild('diagnostics'); |
177 |
| - result.diagnostics.forEach(diagnostic => { |
178 |
| - const messageText = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); |
179 |
| - |
180 |
| - if (diagnostic.file) { |
181 |
| - const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start || 0); |
182 |
| - const fileName = diagnostic.file.fileName; |
183 |
| - const { line, character } = position; |
184 |
| - diagLogger.error(`${fileName} (${line + 1},${character + 1}): ${messageText}`); |
185 |
| - } else { |
186 |
| - diagLogger.error(messageText); |
187 |
| - } |
188 |
| - }); |
189 |
| - process.exit(1); |
190 |
| - } |
| 180 | + _exec('node_modules/.bin/tsc', ['-p', 'tsconfig.json'], {}, logger); |
| 181 | +} |
| 182 | + |
| 183 | + |
| 184 | +function _bazel(logger: logging.Logger) { |
| 185 | + logger.info('Bazel build...'); |
| 186 | + _exec('bazel', ['build', '//packages/...'], {}, logger); |
191 | 187 | }
|
192 | 188 |
|
193 | 189 |
|
194 | 190 | export default function(argv: { local?: boolean, snapshot?: boolean }, logger: logging.Logger) {
|
195 | 191 | _clean(logger);
|
196 | 192 |
|
197 | 193 | const sortedPackages = _sortPackages();
|
| 194 | + _bazel(logger); |
198 | 195 | _build(logger);
|
199 | 196 |
|
200 | 197 | logger.info('Moving packages to dist/');
|
|
0 commit comments