UNPKG

@sap/cds-dk

Version:

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

28 lines (24 loc) 920 B
const { join } = require('path') const DEBUG = /\b(y|all|cli)\b/.test(process.env.DEBUG) ? console.debug : undefined module.exports = require(global('@sap/cds-gen', 'bin/cds-gen')) function global (id, subpath) { const pkgPath = join(id, 'package.json') // package.json gives a stable entry path let mod try { mod = require.resolve (pkgPath, { paths: [ process.cwd(), __dirname ] }) } catch (err) { // one more try w/ NPM global paths const paths = [ process.cwd(), __dirname, npmGlobalModules() ] try { mod = require.resolve (pkgPath, { paths }) } catch (error) { DEBUG?.(error) throw `\nNo '${id}' package found. Install it with\n\n npm i -g ${id}\n` } } return join(mod, '..', subpath) } function npmGlobalModules() { try { return require ('child_process').execSync('npm root -g').toString().trim() } catch (err) { DEBUG?.(err); return '' } }