Skip to content

Commit e680cb6

Browse files
cironunesrodyhaddad
authored andcommitted
feat(new command): override the initial commit message
Closes angular#19 Closes angular#20
1 parent 3aca170 commit e680cb6

File tree

4 files changed

+123
-2
lines changed

4 files changed

+123
-2
lines changed

addon/ng2/commands/new.js

+71-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
'use strict';
22

3+
var chalk = require('chalk');
4+
var Command = require('ember-cli/lib/models/command');
5+
var Promise = require('ember-cli/lib/ext/promise');
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 normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option');
10+
311
var NewCommand = require('ember-cli/lib/commands/new');
12+
var GitInit = require('../tasks/git-init');
413

514
module.exports = NewCommand.extend({
615
availableOptions: [
@@ -11,7 +20,68 @@ module.exports = NewCommand.extend({
1120
{ name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] },
1221
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
1322
{ name: 'directory', type: String , aliases: ['dir'] }
14-
]
23+
],
24+
run: function(commandOptions, rawArgs) {
25+
var packageName = rawArgs[0],
26+
message;
27+
28+
commandOptions.name = rawArgs.shift();
29+
30+
if (!packageName) {
31+
message = chalk.yellow('The `ember ' + this.name + '` command requires a ' +
32+
'name to be specified. For more details, use `ember help`.');
33+
34+
return Promise.reject(new SilentError(message));
35+
}
36+
37+
if (commandOptions.dryRun){
38+
commandOptions.skipGit = true;
39+
}
40+
41+
if (packageName === '.') {
42+
message = 'Trying to generate an application structure in this directory? Use `ember init` instead.';
43+
44+
return Promise.reject(new SilentError(message));
45+
}
46+
47+
if (!validProjectName(packageName)) {
48+
message = 'We currently do not support a name of `' + packageName + '`.';
49+
50+
return Promise.reject(new SilentError(message));
51+
}
52+
53+
commandOptions.blueprint = normalizeBlueprint(commandOptions.blueprint);
54+
55+
if (!commandOptions.directory) {
56+
commandOptions.directory = packageName;
57+
}
58+
59+
var createAndStepIntoDirectory = new this.tasks.CreateAndStepIntoDirectory({
60+
ui: this.ui,
61+
analytics: this.analytics
62+
});
63+
var InitCommand = this.commands.Init;
64+
65+
var gitInit = new GitInit({
66+
ui: this.ui,
67+
project: this.project
68+
});
69+
70+
var initCommand = new InitCommand({
71+
ui: this.ui,
72+
analytics: this.analytics,
73+
tasks: this.tasks,
74+
project: Project.nullProject(this.ui, this.cli)
75+
});
76+
77+
return createAndStepIntoDirectory
78+
.run({
79+
directoryName: commandOptions.directory,
80+
dryRun: commandOptions.dryRun
81+
})
82+
.then(initCommand.run.bind(initCommand, commandOptions, rawArgs))
83+
.then(gitInit.run.bind(gitInit, commandOptions, rawArgs));
84+
}
1585
});
1686

1787
module.exports.overrideCore = true;

addon/ng2/tasks/git-init.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'use strict';
2+
3+
var Promise = require('ember-cli/lib/ext/promise');
4+
var exec = Promise.denodeify(require('child_process').exec);
5+
var path = require('path');
6+
var pkg = require('../package.json');
7+
var fs = require('fs');
8+
var template = require('lodash/string/template');
9+
10+
var gitEnvironmentVariables = {
11+
GIT_AUTHOR_NAME: 'angular-cli',
12+
GIT_AUTHOR_EMAIL: '[email protected]',
13+
get GIT_COMMITTER_NAME(){ return this.GIT_AUTHOR_NAME; },
14+
get GIT_COMMITTER_EMAIL(){ return this.GIT_AUTHOR_EMAIL; }
15+
};
16+
17+
var GitInit = require('ember-cli/lib/tasks/git-init');
18+
19+
module.exports = GitInit.extend({
20+
run: function(commandOptions) {
21+
var chalk = require('chalk');
22+
var ui = this.ui;
23+
24+
if(commandOptions.skipGit) { return Promise.resolve(); }
25+
26+
return exec('git --version')
27+
.then(function() {
28+
return exec('git init')
29+
.then(function() {
30+
return exec('git add .');
31+
})
32+
.then(function(){
33+
var commitTemplate = fs.readFileSync(path.join(__dirname, '../utilities/INITIAL_COMMIT_MESSAGE.txt'));
34+
var commitMessage = template(commitTemplate)(pkg);
35+
return exec('git commit -m "' + commitMessage + '"', {env: gitEnvironmentVariables});
36+
})
37+
.then(function(){
38+
ui.writeLine(chalk.green('Successfully initialized git.'));
39+
});
40+
}).catch(function(/*error*/){
41+
// if git is not found or an error was thrown during the `git`
42+
// init process just swallow any errors here
43+
});
44+
}
45+
});
46+
47+
module.exports.overrideCore = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Initial Commit from Angular CLI v<%= version %>

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@
2727
"broccoli-funnel": "^0.2.3",
2828
"broccoli-merge-trees": "^0.2.1",
2929
"broccoli-writer": "^0.1.1",
30-
"ember-cli": "rodyhaddad/ember-cli#overrideCoreCommand",
30+
"chalk": "^1.1.0",
31+
"ember-cli": "rodyhaddad/ember-cli#rodyhaddad/overrideCoreCommand",
3132
"exit": "^0.1.2",
3233
"fs-extra": "^0.18.4",
34+
"lodash": "^3.10.0",
3335
"resolve": "^1.0.0",
36+
"silent-error": "^1.0.0",
3437
"symlink-or-copy": "^1.0.1",
3538
"typescript": "^1.5.0-beta"
3639
},

0 commit comments

Comments
 (0)