UNPKG

@angular/cli

Version:
38 lines 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const common_tags_1 = require("common-tags"); const SilentError = require('silent-error'); const projectNameRegexp = /^[a-zA-Z][.0-9a-zA-Z]*(-[.0-9a-zA-Z]*)*$/; const unsupportedProjectNames = ['test', 'ember', 'ember-cli', 'vendor', 'app']; function getRegExpFailPosition(str) { const parts = str.split('-'); const matched = []; parts.forEach(part => { if (part.match(projectNameRegexp)) { matched.push(part); } }); const compare = matched.join('-'); return (str !== compare) ? compare.length : null; } function validateProjectName(projectName) { const errorIndex = getRegExpFailPosition(projectName); if (errorIndex !== null) { const firstMessage = common_tags_1.oneLine ` Project name "${projectName}" is not valid. New project names must start with a letter, and must contain only alphanumeric characters or dashes. When adding a dash the segment after the dash must also start with a letter. `; const msg = common_tags_1.stripIndent ` ${firstMessage} ${projectName} ${Array(errorIndex + 1).join(' ') + '^'} `; throw new SilentError(msg); } else if (unsupportedProjectNames.indexOf(projectName) !== -1) { throw new SilentError(`Project name "${projectName}" is not a supported name.`); } } exports.validateProjectName = validateProjectName; //# sourceMappingURL=/users/hansl/sources/angular-cli/utilities/validate-project-name.js.map