| 60 | } |
| 61 | |
| 62 | async function _executeTarget( |
| 63 | parentLogger: logging.Logger, |
| 64 | workspace: workspaces.WorkspaceDefinition, |
| 65 | root: string, |
| 66 | targetStr: string, |
| 67 | options: json.JsonObject, |
| 68 | registry: schema.SchemaRegistry, |
| 69 | ) { |
| 70 | const architectHost = new WorkspaceNodeModulesArchitectHost(workspace, root); |
| 71 | const architect = new Architect(architectHost, registry); |
| 72 | |
| 73 | // Split a target into its parts. |
| 74 | const [project, target, configuration] = targetStr.split(':'); |
| 75 | const targetSpec = { project, target, configuration }; |
| 76 | |
| 77 | const logger = new logging.Logger('jobs'); |
| 78 | const logs: logging.LogEntry[] = []; |
| 79 | logger.subscribe((entry) => logs.push({ ...entry, message: `${entry.name}: ` + entry.message })); |
| 80 | |
| 81 | const run = await architect.scheduleTarget(targetSpec, options, { logger }); |
| 82 | |
| 83 | // Wait for full completion of the builder. |
| 84 | try { |
| 85 | const result = await run.lastOutput; |
| 86 | if (result.success) { |
| 87 | parentLogger.info(styleText(['green'], 'SUCCESS')); |
| 88 | } else { |
| 89 | parentLogger.info(styleText(['red'], 'FAILURE')); |
| 90 | } |
| 91 | parentLogger.info('Result: ' + JSON.stringify({ ...result, info: undefined }, null, 4)); |
| 92 | |
| 93 | parentLogger.info('\nLogs:'); |
| 94 | logs.forEach((l) => parentLogger.next(l)); |
| 95 | logs.splice(0); |
| 96 | |
| 97 | await run.stop(); |
| 98 | |
| 99 | return result.success ? 0 : 1; |
| 100 | } catch (err) { |
| 101 | parentLogger.info(styleText(['red'], 'ERROR')); |
| 102 | parentLogger.info('\nLogs:'); |
| 103 | logs.forEach((l) => parentLogger.next(l)); |
| 104 | |
| 105 | parentLogger.fatal('Exception:'); |
| 106 | parentLogger.fatal((err instanceof Error && err.stack) || `${err}`); |
| 107 | |
| 108 | return 2; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | const CLI_OPTION_DEFINITIONS = { |
| 113 | 'help': { type: 'boolean' }, |