UNPKG

@sap/cds-dk

Version:

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

94 lines (66 loc) 2.56 kB
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: ['--nodejs', '--java', '--force', '--verbose'], help: ` # SYNOPSIS *cds init* [<project>] [<options>] Initializes a new project in folder ./<project>, with the current working directory as default. # OPTIONS *--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()} *--nodejs* Create a CAP Node.js project. *--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. # EXAMPLES *cds init* bookshop *cds init* bookshop --nodejs *cds init* bookshop --java *cds init* bookshop --add hana *cds init* bookshop --add multitenancy,mta *cds init* --java --java:mvn DgroupId=myGroup,DartifactId=newId,Dpackage=my.company # SEE ALSO *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) { console.log() const CDSGenerator = require('../lib/init') const generator = new CDSGenerator() await generator.init(args[0]) console.log() }