@sap/cds-dk
Version:
Command line client and development toolkit for the SAP Cloud Application Programming Model
31 lines (26 loc) • 1.13 kB
JavaScript
const { PROJECT_FILES } = require('./constants')
// max. 64 chars, starts with letter, number, '_', contains only letters (upper and lower case), numbers, '_' or '-'
const REGEX_PROJECT_NAME = /^[0-9a-z_][0-9a-z_-]{0,63}$/i
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.'
if (!projectName.match(REGEX_PROJECT_NAME)) {
throw `This project name is not supported.
Specify a different project name which
starts with a letter, number or '_' and
contains only letters, numbers, '_' or '-' and
is 64 characters or less.`
}
}
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`
}
}