UNPKG

@sap/cds-dk

Version:

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

26 lines (23 loc) 1.21 kB
const { PROJECT_FILES } = require('./constants') const REGEX_PROJECT_NAME = /[^0-9a-zA-Z_-]+/g const cds = require('../../lib/cds') const { exists } = cds.utils const { bold } = require('../../lib/util/term') module.exports.projectName = projectName => { if (!projectName) throw 'specify a project name' const invalidChars = new Set(projectName.match(REGEX_PROJECT_NAME)) // remove duplicates if (invalidChars.size > 0) { throw `project name '${projectName}' contains at least one character ('${[...invalidChars]}') which is not supported in npm package names. Specify a different project name by replacing characters with '_' or '-', for example '${projectName.replace(REGEX_PROJECT_NAME, '_')}' or '${projectName.replace(REGEX_PROJECT_NAME, '-')}'.` } } module.exports.projectFolder = cwd => { if (cds.cli.options.force) return const existingProjectFile = PROJECT_FILES.find(exists) if (existingProjectFile) { if (cwd === cds.root) { throw `project already initialized (existing ${existingProjectFile})\nuse ${bold('cds add')} to add more features` } throw `project already initialized (existing ${existingProjectFile})\nuse a different project name instead` } }