mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-20 21:42:38 +08:00
feat(new command): override the initial commit message
Closes #19 Closes #20
This commit is contained in:
parent
3aca170112
commit
e680cb687e
@ -1,6 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var chalk = require('chalk');
|
||||
var Command = require('ember-cli/lib/models/command');
|
||||
var Promise = require('ember-cli/lib/ext/promise');
|
||||
var Project = require('ember-cli/lib/models/project');
|
||||
var SilentError = require('silent-error');
|
||||
var validProjectName = require('ember-cli/lib/utilities/valid-project-name');
|
||||
var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option');
|
||||
|
||||
var NewCommand = require('ember-cli/lib/commands/new');
|
||||
var GitInit = require('../tasks/git-init');
|
||||
|
||||
module.exports = NewCommand.extend({
|
||||
availableOptions: [
|
||||
@ -11,7 +20,68 @@ module.exports = NewCommand.extend({
|
||||
{ name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] },
|
||||
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
|
||||
{ name: 'directory', type: String , aliases: ['dir'] }
|
||||
]
|
||||
],
|
||||
run: function(commandOptions, rawArgs) {
|
||||
var packageName = rawArgs[0],
|
||||
message;
|
||||
|
||||
commandOptions.name = rawArgs.shift();
|
||||
|
||||
if (!packageName) {
|
||||
message = chalk.yellow('The `ember ' + this.name + '` command requires a ' +
|
||||
'name to be specified. For more details, use `ember help`.');
|
||||
|
||||
return Promise.reject(new SilentError(message));
|
||||
}
|
||||
|
||||
if (commandOptions.dryRun){
|
||||
commandOptions.skipGit = true;
|
||||
}
|
||||
|
||||
if (packageName === '.') {
|
||||
message = 'Trying to generate an application structure in this directory? Use `ember init` instead.';
|
||||
|
||||
return Promise.reject(new SilentError(message));
|
||||
}
|
||||
|
||||
if (!validProjectName(packageName)) {
|
||||
message = 'We currently do not support a name of `' + packageName + '`.';
|
||||
|
||||
return Promise.reject(new SilentError(message));
|
||||
}
|
||||
|
||||
commandOptions.blueprint = normalizeBlueprint(commandOptions.blueprint);
|
||||
|
||||
if (!commandOptions.directory) {
|
||||
commandOptions.directory = packageName;
|
||||
}
|
||||
|
||||
var createAndStepIntoDirectory = new this.tasks.CreateAndStepIntoDirectory({
|
||||
ui: this.ui,
|
||||
analytics: this.analytics
|
||||
});
|
||||
var InitCommand = this.commands.Init;
|
||||
|
||||
var gitInit = new GitInit({
|
||||
ui: this.ui,
|
||||
project: this.project
|
||||
});
|
||||
|
||||
var initCommand = new InitCommand({
|
||||
ui: this.ui,
|
||||
analytics: this.analytics,
|
||||
tasks: this.tasks,
|
||||
project: Project.nullProject(this.ui, this.cli)
|
||||
});
|
||||
|
||||
return createAndStepIntoDirectory
|
||||
.run({
|
||||
directoryName: commandOptions.directory,
|
||||
dryRun: commandOptions.dryRun
|
||||
})
|
||||
.then(initCommand.run.bind(initCommand, commandOptions, rawArgs))
|
||||
.then(gitInit.run.bind(gitInit, commandOptions, rawArgs));
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.overrideCore = true;
|
||||
|
47
addon/ng2/tasks/git-init.js
Normal file
47
addon/ng2/tasks/git-init.js
Normal file
@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('ember-cli/lib/ext/promise');
|
||||
var exec = Promise.denodeify(require('child_process').exec);
|
||||
var path = require('path');
|
||||
var pkg = require('../package.json');
|
||||
var fs = require('fs');
|
||||
var template = require('lodash/string/template');
|
||||
|
||||
var gitEnvironmentVariables = {
|
||||
GIT_AUTHOR_NAME: 'angular-cli',
|
||||
GIT_AUTHOR_EMAIL: 'angular-cli@angular339.com',
|
||||
get GIT_COMMITTER_NAME(){ return this.GIT_AUTHOR_NAME; },
|
||||
get GIT_COMMITTER_EMAIL(){ return this.GIT_AUTHOR_EMAIL; }
|
||||
};
|
||||
|
||||
var GitInit = require('ember-cli/lib/tasks/git-init');
|
||||
|
||||
module.exports = GitInit.extend({
|
||||
run: function(commandOptions) {
|
||||
var chalk = require('chalk');
|
||||
var ui = this.ui;
|
||||
|
||||
if(commandOptions.skipGit) { return Promise.resolve(); }
|
||||
|
||||
return exec('git --version')
|
||||
.then(function() {
|
||||
return exec('git init')
|
||||
.then(function() {
|
||||
return exec('git add .');
|
||||
})
|
||||
.then(function(){
|
||||
var commitTemplate = fs.readFileSync(path.join(__dirname, '../utilities/INITIAL_COMMIT_MESSAGE.txt'));
|
||||
var commitMessage = template(commitTemplate)(pkg);
|
||||
return exec('git commit -m "' + commitMessage + '"', {env: gitEnvironmentVariables});
|
||||
})
|
||||
.then(function(){
|
||||
ui.writeLine(chalk.green('Successfully initialized git.'));
|
||||
});
|
||||
}).catch(function(/*error*/){
|
||||
// if git is not found or an error was thrown during the `git`
|
||||
// init process just swallow any errors here
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.overrideCore = true;
|
1
addon/ng2/utilities/INITIAL_COMMIT_MESSAGE.txt
Normal file
1
addon/ng2/utilities/INITIAL_COMMIT_MESSAGE.txt
Normal file
@ -0,0 +1 @@
|
||||
Initial Commit from Angular CLI v<%= version %>
|
@ -27,10 +27,13 @@
|
||||
"broccoli-funnel": "^0.2.3",
|
||||
"broccoli-merge-trees": "^0.2.1",
|
||||
"broccoli-writer": "^0.1.1",
|
||||
"ember-cli": "rodyhaddad/ember-cli#overrideCoreCommand",
|
||||
"chalk": "^1.1.0",
|
||||
"ember-cli": "rodyhaddad/ember-cli#rodyhaddad/overrideCoreCommand",
|
||||
"exit": "^0.1.2",
|
||||
"fs-extra": "^0.18.4",
|
||||
"lodash": "^3.10.0",
|
||||
"resolve": "^1.0.0",
|
||||
"silent-error": "^1.0.0",
|
||||
"symlink-or-copy": "^1.0.1",
|
||||
"typescript": "^1.5.0-beta"
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user