1 | "use strict";
|
2 | var chalk = require('chalk');
|
3 | var init_1 = require('./init');
|
4 | var common_tags_1 = require('common-tags');
|
5 | var Command = require('../ember-cli/lib/models/command');
|
6 | var Project = require('../ember-cli/lib/models/project');
|
7 | var SilentError = require('silent-error');
|
8 | var validProjectName = require('../ember-cli/lib/utilities/valid-project-name');
|
9 | var packageNameRegexp = /^[a-zA-Z][.0-9a-zA-Z]*(-[a-zA-Z][.0-9a-zA-Z]*)*$/;
|
10 | function getRegExpFailPosition(str) {
|
11 | var parts = str.split('-');
|
12 | var matched = [];
|
13 | parts.forEach(function (part) {
|
14 | if (part.match(packageNameRegexp)) {
|
15 | matched.push(part);
|
16 | }
|
17 | });
|
18 | var compare = matched.join('-');
|
19 | return (str !== compare) ? compare.length : null;
|
20 | }
|
21 | var NewCommand = Command.extend({
|
22 | name: 'new',
|
23 | description: "Creates a new directory and runs " + chalk.green('ng init') + " in it.",
|
24 | works: 'outsideProject',
|
25 | availableOptions: [
|
26 | { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
|
27 | { name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
|
28 | { name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
|
29 | { name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
|
30 | { name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
|
31 | { name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
|
32 | { name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] },
|
33 | { name: 'directory', type: String, aliases: ['dir'] },
|
34 | { name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
|
35 | { name: 'style', type: String, default: 'css' },
|
36 | { name: 'prefix', type: String, default: 'app', aliases: ['p'] },
|
37 | { name: 'routing', type: Boolean, default: false },
|
38 | { name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
|
39 | { name: 'inline-template', type: Boolean, default: false, aliases: ['it'] }
|
40 | ],
|
41 | run: function (commandOptions, rawArgs) {
|
42 | var packageName = rawArgs.shift();
|
43 | if (!packageName) {
|
44 | return Promise.reject(new SilentError(("The \"ng " + this.name + "\" command requires a name argument to be specified. ") +
|
45 | "For more details, use \"ng help\"."));
|
46 | }
|
47 | if (!packageName.match(packageNameRegexp)) {
|
48 | var firstMessage = (_a = ["\n Project name \"", "\" is not valid. New project names must\n start with a letter, and must contain only alphanumeric characters or dashes.\n When adding a dash the segment after the dash must start with a letter too.\n "], _a.raw = ["\n Project name \"", "\" is not valid. New project names must\n start with a letter, and must contain only alphanumeric characters or dashes.\n When adding a dash the segment after the dash must start with a letter too.\n "], common_tags_1.oneLine(_a, packageName));
|
49 | var msg = (_b = ["\n ", "\n ", "\n ", "\n "], _b.raw = ["\n ", "\n ", "\n ", "\n "], common_tags_1.stripIndent(_b, firstMessage, packageName, Array(getRegExpFailPosition(packageName) + 1).join(' ') + '^'));
|
50 | return Promise.reject(new SilentError(msg));
|
51 | }
|
52 | commandOptions.name = packageName;
|
53 | if (commandOptions.dryRun) {
|
54 | commandOptions.skipGit = true;
|
55 | }
|
56 | if (packageName === '.') {
|
57 | return Promise.reject(new SilentError("Trying to generate an application structure in this directory? Use \"ng init\" " +
|
58 | "instead."));
|
59 | }
|
60 | if (!validProjectName(packageName)) {
|
61 | return Promise.reject(new SilentError("We currently do not support a name of \"" + packageName + "\"."));
|
62 | }
|
63 | if (!commandOptions.directory) {
|
64 | commandOptions.directory = packageName;
|
65 | }
|
66 | var createAndStepIntoDirectory = new this.tasks.CreateAndStepIntoDirectory({ ui: this.ui });
|
67 | var initCommand = new init_1.default({
|
68 | ui: this.ui,
|
69 | tasks: this.tasks,
|
70 | project: Project.nullProject(this.ui, this.cli)
|
71 | });
|
72 | return createAndStepIntoDirectory
|
73 | .run({
|
74 | directoryName: commandOptions.directory,
|
75 | dryRun: commandOptions.dryRun
|
76 | })
|
77 | .then(initCommand.run.bind(initCommand, commandOptions, rawArgs));
|
78 | var _a, _b;
|
79 | }
|
80 | });
|
81 | NewCommand.overrideCore = true;
|
82 | Object.defineProperty(exports, "__esModule", { value: true });
|
83 | exports.default = NewCommand;
|
84 |
|
\ | No newline at end of file |