UNPKG

@sap/cds-dk

Version:

Command line client and development toolkit for the SAP Cloud Application Programming Model

34 lines (31 loc) 1.29 kB
const fs = require('fs') const cds = require('../cds') const BuildTaskEngine = require('./buildTaskEngine') const Plugin = require('./plugin') const { BuildError } = require('./util') module.exports = { build, register, Plugin, BuildError } /** * Executes cds build in the directory defined by cds.root. * * @param {object} options - command options as defined by build command. */ async function build(options = {}) { if (!fs.existsSync(cds.root) || !fs.lstatSync(cds.root).isDirectory()) { throw `Project folder '${cds.root}' does not exist` } try { return await new BuildTaskEngine(options).processTasks() } catch (e) { if (e instanceof BuildError || e.constructor.name === 'CompilationError') { cds._log(e.messages.length ? e.messages : e.message, { 'log-level': options['log-level'] || cds.env['log-level'] }) console.log('') // CompilationError.message also includes the detail messages - do not log twice const message = e.constructor.name === 'CompilationError' ? 'CDS compilation failed' : e.messages.length ? e.message : 'CDS build failed' throw message } throw e } } function register(id, plugin) { return require('./plugins').register(id, plugin) }