UNPKG

@sap/cds-dk

Version:

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

40 lines (34 loc) 1.39 kB
const { join } = require('path') const { readProject } = require('../../projectReader') const { merge } = require('../../merge') const { warn } = require('../../../util/term') const { TYPESCRIPT } = require('../../constants').OPTIONS const { exists } = require('../../../cds').utils const TyperTemplate = require('../typer') module.exports = class TypescriptTemplate extends require('../../plugin') { static help() { return 'add minimum configuration for a bare TypeScript project' } async canRun() { const { isJava } = readProject() if (isJava) { console.warn(warn(`This appears to be a Java project. 'cds add ${TYPESCRIPT}' is intended to be used in Node.js projects. Proceeding anyway.\n`)) } return true } static hasInProduction() { return exists('tsconfig.ts') } async run() { const tsconfig = join(__dirname, 'files', 'tsconfig.json') try { await merge(tsconfig).into('tsconfig.json') } catch (e) { throw e instanceof SyntaxError ? `SyntaxError in existing tsconfig.json. This could indicate a JSON file with comments, which is not supported at this time. Remove all comments from your tsconfig.json and rerun` : e } await merge(join(__dirname, 'files', 'package.json')).into('package.json') await new TyperTemplate().run() // REVISIT: we should avoid referencing other plugins } }