Skip to content

Commit 6cad6c3

Browse files
committed
fix(): initial commit message
1 parent e7e722c commit 6cad6c3

File tree

4 files changed

+135
-33
lines changed

4 files changed

+135
-33
lines changed

addon/ng2/commands/init.js

Lines changed: 117 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,123 @@
11
'use strict';
22

3-
var InitCommand = require('ember-cli/lib/commands/init');
4-
5-
module.exports = InitCommand .extend({
6-
availableOptions: [
7-
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
8-
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
9-
{ name: 'blueprint', type: String, aliases: ['b'] },
10-
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
11-
{ name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] },
12-
{ name: 'name', type: String, default: '', aliases: ['n'] }
13-
],
14-
15-
_defaultBlueprint: function() {
16-
if (this.project.isEmberCLIAddon()) {
17-
return 'addon';
18-
} else {
19-
return 'ng2';
3+
var Command = require('ember-cli/lib/models/command');
4+
var Promise = require('ember-cli/lib/ext/promise');
5+
var SilentError = require('silent-error');
6+
var validProjectName = require('ember-cli/lib/utilities/valid-project-name');
7+
var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option');
8+
var GitInit = require('../tasks/git-init');
9+
10+
module.exports = Command.extend({
11+
name: 'init',
12+
description: 'Creates a new angular-cli project in the current folder.',
13+
aliases: ['i'],
14+
works: 'everywhere',
15+
16+
availableOptions: [
17+
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
18+
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
19+
{ name: 'blueprint', type: String, aliases: ['b'] },
20+
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
21+
{ name: 'skip-bower', type: Boolean, default: false, aliases: ['sb'] },
22+
{ name: 'name', type: String, default: '', aliases: ['n'] }
23+
],
24+
25+
anonymousOptions: [
26+
'<glob-pattern>'
27+
],
28+
29+
_defaultBlueprint: function() {
30+
if (this.project.isEmberCLIAddon()) {
31+
return 'addon';
32+
} else {
33+
return 'ng2';
34+
}
35+
},
36+
37+
run: function(commandOptions, rawArgs) {
38+
if (commandOptions.dryRun) {
39+
commandOptions.skipNpm = true;
40+
commandOptions.skipBower = true;
41+
}
42+
43+
var installBlueprint = new this.tasks.InstallBlueprint({
44+
ui: this.ui,
45+
analytics: this.analytics,
46+
project: this.project
47+
});
48+
49+
// needs an explicit check in case it's just 'undefined'
50+
// due to passing of options from 'new' and 'addon'
51+
if (commandOptions.skipGit === false) {
52+
var gitInit = new GitInit({
53+
ui: this.ui,
54+
project: this.project
55+
});
56+
}
57+
58+
if (!commandOptions.skipNpm) {
59+
var npmInstall = new this.tasks.NpmInstall({
60+
ui: this.ui,
61+
analytics: this.analytics,
62+
project: this.project
63+
});
64+
}
65+
66+
if (!commandOptions.skipBower) {
67+
var bowerInstall = new this.tasks.BowerInstall({
68+
ui: this.ui,
69+
analytics: this.analytics,
70+
project: this.project
71+
});
72+
}
73+
74+
var project = this.project;
75+
var packageName = commandOptions.name !== '.' && commandOptions.name || project.name();
76+
77+
if (!packageName) {
78+
var message = 'The `ng ' + this.name + '` command requires a ' +
79+
'package.json in current folder with name attribute or a specified name via arguments. ' +
80+
'For more details, use `ng help`.';
81+
82+
return Promise.reject(new SilentError(message));
83+
}
84+
85+
var blueprintOpts = {
86+
dryRun: commandOptions.dryRun,
87+
blueprint: commandOptions.blueprint || this._defaultBlueprint(),
88+
rawName: packageName,
89+
targetFiles: rawArgs || '',
90+
rawArgs: rawArgs.toString()
91+
};
92+
93+
if (!validProjectName(packageName)) {
94+
return Promise.reject(new SilentError('We currently do not support a name of `' + packageName + '`.'));
95+
}
96+
97+
blueprintOpts.blueprint = normalizeBlueprint(blueprintOpts.blueprint);
98+
99+
return installBlueprint.run(blueprintOpts)
100+
.then(function() {
101+
if (commandOptions.skipGit === false) {
102+
return gitInit.run(commandOptions, rawArgs);
103+
}
104+
}.bind(this))
105+
.then(function() {
106+
if (!commandOptions.skipNpm) {
107+
return npmInstall.run({
108+
verbose: commandOptions.verbose,
109+
optional: false
110+
});
111+
}
112+
})
113+
.then(function() {
114+
if (!commandOptions.skipBower) {
115+
return bowerInstall.run({
116+
verbose: commandOptions.verbose
117+
});
20118
}
21-
},
119+
});
120+
}
22121
});
23122

24123
module.exports.overrideCore = true;

addon/ng2/commands/new.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ var SilentError = require('silent-error');
88
var validProjectName = require('ember-cli/lib/utilities/valid-project-name');
99
var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option');
1010

11-
var NewCommand = require('ember-cli/lib/commands/new');
12-
var GitInit = require('../tasks/git-init');
11+
var Command = require('ember-cli/lib/models/command');
12+
var InitCommand = require('./init');
13+
14+
module.exports = Command.extend({
15+
name: 'new',
16+
description: 'Creates a new directory and runs ' + chalk.green('ng init') + ' in it.',
17+
works: 'outsideProject',
1318

14-
module.exports = NewCommand.extend({
1519
availableOptions: [
1620
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
1721
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
@@ -60,12 +64,6 @@ module.exports = NewCommand.extend({
6064
ui: this.ui,
6165
analytics: this.analytics
6266
});
63-
var InitCommand = this.commands.Init;
64-
65-
var gitInit = new GitInit({
66-
ui: this.ui,
67-
project: this.project
68-
});
6967

7068
var initCommand = new InitCommand({
7169
ui: this.ui,
@@ -79,8 +77,7 @@ module.exports = NewCommand.extend({
7977
directoryName: commandOptions.directory,
8078
dryRun: commandOptions.dryRun
8179
})
82-
.then(initCommand.run.bind(initCommand, commandOptions, rawArgs))
83-
.then(gitInit.run.bind(gitInit, commandOptions, rawArgs));
80+
.then(initCommand.run.bind(initCommand, commandOptions, rawArgs));
8481
}
8582
});
8683

addon/ng2/tasks/git-init.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var path = require('path');
66
var pkg = require('../package.json');
77
var fs = require('fs');
88
var template = require('lodash/string/template');
9+
var Task = require('ember-cli/lib/models/task');
910

1011
var gitEnvironmentVariables = {
1112
GIT_AUTHOR_NAME: 'angular-cli',
@@ -14,9 +15,7 @@ var gitEnvironmentVariables = {
1415
get GIT_COMMITTER_EMAIL(){ return this.GIT_AUTHOR_EMAIL; }
1516
};
1617

17-
var GitInit = require('ember-cli/lib/tasks/git-init');
18-
19-
module.exports = GitInit.extend({
18+
module.exports = Task.extend({
2019
run: function(commandOptions) {
2120
var chalk = require('chalk');
2221
var ui = this.ui;
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
chore: initial commit from angular-cli v<%= version %>
1+
chore: initial commit from angular-cli
2+
_ _ _
3+
__ _ _ __ __ _ _ _| | __ _ _ __ ___| (_)
4+
/ _ | _ \ / _ | | | | |/ _ | __|____ / __| | |
5+
| (_| | | | | (_| | |_| | | (_| | | |_____| (__| | |
6+
\____|_| |_|\__ |\____|_|\____|_| \___|_|_|
7+
|___/
8+

0 commit comments

Comments
 (0)