1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const common_tags_1 = require("common-tags");
|
4 | const SilentError = require('silent-error');
|
5 | const projectNameRegexp = /^[a-zA-Z][.0-9a-zA-Z]*(-[.0-9a-zA-Z]*)*$/;
|
6 | const unsupportedProjectNames = ['test', 'ember', 'ember-cli', 'vendor', 'app'];
|
7 | function 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 | }
|
18 | function 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 | }
|
37 | exports.validateProjectName = validateProjectName;
|
38 |
|
\ | No newline at end of file |