Skip to content

Commit e004464

Browse files
hanslKeen Yee Liau
authored and
Keen Yee Liau
committed
ci: build script uses bazel to generate the schemas
1 parent 9b0d5fa commit e004464

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

scripts/build.ts

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*/
88
// tslint:disable:no-implicit-dependencies
99
import { JsonObject, logging } from '@angular-devkit/core';
10+
import * as child_process from 'child_process';
1011
import * as fs from 'fs';
1112
import * as glob from 'glob';
1213
import * as path from 'path';
13-
import * as ts from 'typescript';
1414
import { packages } from '../lib/packages';
1515

1616
const minimatch = require('minimatch');
@@ -160,41 +160,38 @@ function _sortPackages() {
160160
return sortedPackages;
161161
}
162162

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+
163177

164178
function _build(logger: logging.Logger) {
165179
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);
191187
}
192188

193189

194190
export default function(argv: { local?: boolean, snapshot?: boolean }, logger: logging.Logger) {
195191
_clean(logger);
196192

197193
const sortedPackages = _sortPackages();
194+
_bazel(logger);
198195
_build(logger);
199196

200197
logger.info('Moving packages to dist/');

0 commit comments

Comments
 (0)