@sap/cds-dk
Version:
Command line client and development toolkit for the SAP Cloud Application Programming Model
87 lines (61 loc) • 2.43 kB
JavaScript
const { join } = require('path')
const { URLS } = require('../lib/init/constants')
// REVISIT: necessary because module is loaded too early -> shouldn't be necessary
const cds = require('../lib/cds')
cds.root = join(process.cwd(), process.argv[3]?.startsWith('--') ? '.' : process.argv[3] ?? '')
module.exports = Object.assign(init, {
handleCompletion,
options: ['--add', '--java:mvn', '--java:package', '--lint:custom', '--lint:custom:example', '--no-db', '--base'],
shortcuts: ['-a'],
flags: ['--java', '--force', '--verbose'],
help: `
*cds init* [<project>] [<options>]
Initializes a new project in folder ./<project>, with the current
working directory as default.
*--add* <feature | comma-separated list of features>
Add one or more features while creating the project.
<feature> can be one of the following:
${require('../lib/init').help()}
*--java*
Create a CAP Java project.
*--java:mvn* <Comma separated maven archetype specific parameters>
Add the given parameters to the archetype call.
See _${URLS.MAVEN_ARCHETYPE_HELP}_
for parameters supported by the archetype.
*--force*
Overwrite all files.
*cds init* bookshop
*cds init* bookshop --java
*cds init* bookshop --add hana
*cds init* bookshop --add multitenancy,mta
*cds init* --java --java:mvn groupId=myGroup,artifactId=newId,package=my.company
*cds add* - to augment your projects later on
`})
async function handleCompletion(currentWord, previousWord, argv, util) {
const allOptionsFlags = [
...init.options ?? [],
...init.flags ?? []
].filter(e => !argv.includes(e));
if (currentWord?.startsWith('-')) {
return allOptionsFlags;
}
if (previousWord === '--java:package') {
const excludes = ['_merging'];
return (await util.completionFs.readdir(currentWord, { files: false }))
.filter(e => !excludes.includes(e));
}
const templates = await util.completionFs.readTemplates(argv);
if (previousWord === '--add' || argv.includes('--add') && previousWord.endsWith(',')) {
return templates;
}
return allOptionsFlags;
}
async function init(args) {
const CDSGenerator = require('../lib/init')
const generator = new CDSGenerator()
await generator.init(args[0])
}