UNPKG

1.53 kBJavaScriptView Raw
1"use strict";
2const common_tags_1 = require('common-tags');
3const SilentError = require('silent-error');
4const projectNameRegexp = /^[a-zA-Z][.0-9a-zA-Z]*(-[a-zA-Z][.0-9a-zA-Z]*)*$/;
5const unsupportedProjectNames = ['test', 'ember', 'ember-cli', 'vendor', 'app'];
6function getRegExpFailPosition(str) {
7 const parts = str.split('-');
8 const matched = [];
9 parts.forEach(part => {
10 if (part.match(projectNameRegexp)) {
11 matched.push(part);
12 }
13 });
14 const compare = matched.join('-');
15 return (str !== compare) ? compare.length : null;
16}
17function validateProjectName(projectName) {
18 const errorIndex = getRegExpFailPosition(projectName);
19 if (errorIndex !== null) {
20 const firstMessage = common_tags_1.oneLine `
21 Project name "${projectName}" is not valid. New project names must
22 start with a letter, and must contain only alphanumeric characters or dashes.
23 When adding a dash the segment after the dash must also start with a letter.
24 `;
25 const msg = common_tags_1.stripIndent `
26 ${firstMessage}
27 ${projectName}
28 ${Array(errorIndex + 1).join(' ') + '^'}
29 `;
30 throw new SilentError(msg);
31 }
32 else if (unsupportedProjectNames.indexOf(projectName) !== -1) {
33 throw new SilentError(`Project name "${projectName}" is not a supported name.`);
34 }
35}
36exports.validateProjectName = validateProjectName;
37//# sourceMappingURL=/Users/hansl/Sources/angular-cli/packages/@angular/cli/utilities/validate-project-name.js.map
\No newline at end of file