UNPKG

@sap/cds-dk

Version:

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

40 lines (33 loc) 1.38 kB
const { join } = require('path') const cds = require('../../../cds') const { exists, mkdirp, path } = cds.utils const { env4 } = require('../../projectReader') const { URLS, OPTIONS: { NODEJS, JAVA }, COMMAND_ADD } = require('../../constants') const term = require('../../../util/term') const { renderAndCopy } = require('../../template') module.exports = class NodejsTemplate extends require('../../plugin') { static help() { return 'creates a Node.js-based project' } static hasInProduction() { return !exists('pom.xml') && !cds.cli.options?.add?.has(JAVA) } async canRun() { if (cds.cli.command === COMMAND_ADD) { throw `You can't change the runtime of an existing project.` } if (cds.cli.options.add?.has(JAVA)) { throw `only one runtime per project is supported – specify either ${term.bold(JAVA)} or ${term.bold(NODEJS)}` } return true } async run() { const { db, srv, app } = env4('production').folders await renderAndCopy(join(__dirname, 'files'), cds.root, { projectName: path.basename(cds.root) }) await Promise.all([db, srv, app].map(p => mkdirp(p))) } async finalize() { console.log(`\nfind samples on ${term.link(URLS.SAMPLES)}`) console.log(`learn about next steps at ${term.link(URLS.CAPIRE)}`) } }