UNPKG

@sap/cds-dk

Version:

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

42 lines (37 loc) 1.69 kB
const { join } = require('path') const { readProject } = require('../../projectReader') const { merge, mergeGitignore } = require('../../merge') const { warn, dim, bold } = require('../../../util/term') const { TYPER } = require('../../constants').OPTIONS const { exists, read } = require('../../../cds').utils module.exports = class TyperTemplate extends require('../../plugin') { static help() { return 'type generation for CDS models' } async canRun() { const { isJava } = readProject() if (isJava) { console.warn(warn(`This appears to be a Java project. 'cds add ${TYPER}' is intended to be used in Node.js projects. Proceeding anyway.\n`)) } return true } async run() { const template = name => join(__dirname, 'files', name) const source = await read(template('xsconfig.json')) let target = 'jsconfig.json' if (exists('tsconfig.json')) { target = 'tsconfig.json' } await merge(template('package.json')).into('package.json') await mergeGitignore('.gitignore', template('gitignore')) console.log(dim(` adding '@cds-models' to .gitignore to ignore generated types`)) // REVISIT: other facets are silent wrt. what they change console.log(dim(' added new dependencies to the project. Run ') + bold('npm i') + dim(' to install.')) try { await merge(source).into(target) } catch (e) { throw e instanceof SyntaxError ? `SyntaxError in ${target}. This could indicate a JSON file with comments, which is not supported at this time. Remove all comments from ${target} and rerun or add the following entries manually:\n${JSON.stringify(source, null, 2)}` : e } } }