-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
new.js
129 lines (104 loc) · 4 KB
/
new.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'use strict';
const chalk = require('chalk');
const Command = require('../models/command');
const Project = require('../models/project');
const SilentError = require('silent-error');
const isValidProjectName = require('../utilities/valid-project-name');
const normalizeBlueprint = require('../utilities/normalize-blueprint-option');
const mergeBlueprintOptions = require('../utilities/merge-blueprint-options');
module.exports = Command.extend({
name: 'new',
description: `Creates a new directory and runs ${chalk.green('ember init')} in it.`,
works: 'outsideProject',
availableOptions: [
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
{ name: 'blueprint', type: String, default: 'app', aliases: ['b'] },
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn', 'skip-install', 'si'] },
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
{
name: 'welcome',
type: Boolean,
default: true,
description: 'Installs and uses {{ember-welcome-page}}. Use --no-welcome to skip it.',
},
{
name: 'package-manager',
type: ['npm', 'pnpm', 'yarn'],
aliases: [{ npm: 'npm' }, { pnpm: 'pnpm' }, { yarn: 'yarn' }],
},
{ name: 'directory', type: String, aliases: ['dir'] },
{
name: 'lang',
type: String,
description: 'Sets the base human language of the application via index.html',
},
{ name: 'embroider', type: Boolean, default: false, description: 'Enables the build system to use Embroider' },
{
name: 'ci-provider',
type: ['travis', 'github'],
description: 'Installs the default CI blueprint. Either Travis or Github Actions is supported.',
},
{
name: 'interactive',
type: Boolean,
default: false,
aliases: ['i'],
description: 'Create a new Ember app/addon in an interactive way.',
},
{ name: 'typescript', type: Boolean, default: false, description: 'Set up the app to use TypeScript' },
],
anonymousOptions: ['<app-name>'],
beforeRun: mergeBlueprintOptions,
async run(commandOptions, rawArgs) {
let projectName = rawArgs[0],
message;
commandOptions.name = rawArgs.shift();
if (!projectName || commandOptions.interactive) {
let answers = await this.runTask('InteractiveNew', commandOptions);
commandOptions.blueprint = answers.blueprint;
if (answers.name) {
projectName = answers.name;
commandOptions.name = answers.name;
}
if (answers.lang) {
commandOptions.lang = answers.lang;
}
if (answers.packageManager) {
commandOptions.packageManager = answers.packageManager;
}
if (answers.ciProvider) {
commandOptions.ciProvider = answers.ciProvider;
}
}
if (!commandOptions.ciProvider) {
commandOptions.ciProvider = 'github';
}
if (commandOptions.dryRun) {
commandOptions.skipGit = true;
}
if (projectName === '.') {
let blueprintName = commandOptions.blueprint === 'app' ? 'application' : commandOptions.blueprint;
message = `Trying to generate an ${blueprintName} structure in this directory? Use \`ember init\` instead.`;
return Promise.reject(new SilentError(message));
}
if (!isValidProjectName(projectName)) {
message = `We currently do not support a name of \`${projectName}\`.`;
return Promise.reject(new SilentError(message));
}
commandOptions.blueprint = normalizeBlueprint(commandOptions.blueprint);
let InitCommand = this.commands.Init;
let initCommand = new InitCommand({
ui: this.ui,
tasks: this.tasks,
project: Project.nullProject(this.ui, this.cli),
});
await this.runTask('CreateAndStepIntoDirectory', {
projectName,
directoryName: commandOptions.directory,
dryRun: commandOptions.dryRun,
});
initCommand.project.root = process.cwd();
return await initCommand.run(commandOptions, rawArgs);
},
});