UNPKG

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