From 6cad6c39df29f5ec369d1bb406f59b6bfd0933c6 Mon Sep 17 00:00:00 2001 From: jkuri Date: Mon, 29 Feb 2016 02:48:03 +0100 Subject: [PATCH] fix(): initial commit message --- addon/ng2/commands/init.js | 131 +++++++++++++++--- addon/ng2/commands/new.js | 19 ++- addon/ng2/tasks/git-init.js | 5 +- .../ng2/utilities/INITIAL_COMMIT_MESSAGE.txt | 9 +- 4 files changed, 133 insertions(+), 31 deletions(-) diff --git a/addon/ng2/commands/init.js b/addon/ng2/commands/init.js index b2deca2278..1740d32f59 100644 --- a/addon/ng2/commands/init.js +++ b/addon/ng2/commands/init.js @@ -1,24 +1,123 @@ 'use strict'; -var InitCommand = require('ember-cli/lib/commands/init'); +var Command = require('ember-cli/lib/models/command'); +var Promise = require('ember-cli/lib/ext/promise'); +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 GitInit = require('../tasks/git-init'); -module.exports = InitCommand .extend({ - availableOptions: [ - { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }, - { name: 'verbose', type: Boolean, default: false, aliases: ['v'] }, - { name: 'blueprint', type: String, aliases: ['b'] }, - { name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] }, - { name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] }, - { name: 'name', type: String, default: '', aliases: ['n'] } - ], +module.exports = Command.extend({ + name: 'init', + description: 'Creates a new angular-cli project in the current folder.', + aliases: ['i'], + works: 'everywhere', - _defaultBlueprint: function() { - if (this.project.isEmberCLIAddon()) { - return 'addon'; - } else { - return 'ng2'; + availableOptions: [ + { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }, + { name: 'verbose', type: Boolean, default: false, aliases: ['v'] }, + { name: 'blueprint', type: String, aliases: ['b'] }, + { name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] }, + { name: 'skip-bower', type: Boolean, default: false, aliases: ['sb'] }, + { name: 'name', type: String, default: '', aliases: ['n'] } + ], + + anonymousOptions: [ + '' + ], + + _defaultBlueprint: function() { + if (this.project.isEmberCLIAddon()) { + return 'addon'; + } else { + return 'ng2'; + } + }, + + run: function(commandOptions, rawArgs) { + if (commandOptions.dryRun) { + commandOptions.skipNpm = true; + commandOptions.skipBower = true; + } + + var installBlueprint = new this.tasks.InstallBlueprint({ + ui: this.ui, + analytics: this.analytics, + project: this.project + }); + + // needs an explicit check in case it's just 'undefined' + // due to passing of options from 'new' and 'addon' + if (commandOptions.skipGit === false) { + var gitInit = new GitInit({ + ui: this.ui, + project: this.project + }); + } + + if (!commandOptions.skipNpm) { + var npmInstall = new this.tasks.NpmInstall({ + ui: this.ui, + analytics: this.analytics, + project: this.project + }); + } + + if (!commandOptions.skipBower) { + var bowerInstall = new this.tasks.BowerInstall({ + ui: this.ui, + analytics: this.analytics, + project: this.project + }); + } + + var project = this.project; + var packageName = commandOptions.name !== '.' && commandOptions.name || project.name(); + + if (!packageName) { + var message = 'The `ng ' + this.name + '` command requires a ' + + 'package.json in current folder with name attribute or a specified name via arguments. ' + + 'For more details, use `ng help`.'; + + return Promise.reject(new SilentError(message)); + } + + var blueprintOpts = { + dryRun: commandOptions.dryRun, + blueprint: commandOptions.blueprint || this._defaultBlueprint(), + rawName: packageName, + targetFiles: rawArgs || '', + rawArgs: rawArgs.toString() + }; + + if (!validProjectName(packageName)) { + return Promise.reject(new SilentError('We currently do not support a name of `' + packageName + '`.')); + } + + blueprintOpts.blueprint = normalizeBlueprint(blueprintOpts.blueprint); + + return installBlueprint.run(blueprintOpts) + .then(function() { + if (commandOptions.skipGit === false) { + return gitInit.run(commandOptions, rawArgs); } - }, + }.bind(this)) + .then(function() { + if (!commandOptions.skipNpm) { + return npmInstall.run({ + verbose: commandOptions.verbose, + optional: false + }); + } + }) + .then(function() { + if (!commandOptions.skipBower) { + return bowerInstall.run({ + verbose: commandOptions.verbose + }); + } + }); + } }); module.exports.overrideCore = true; diff --git a/addon/ng2/commands/new.js b/addon/ng2/commands/new.js index 2bb97a4750..0d047434a5 100644 --- a/addon/ng2/commands/new.js +++ b/addon/ng2/commands/new.js @@ -8,10 +8,14 @@ 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'); +var Command = require('ember-cli/lib/models/command'); +var InitCommand = require('./init'); + +module.exports = Command.extend({ + name: 'new', + description: 'Creates a new directory and runs ' + chalk.green('ng init') + ' in it.', + works: 'outsideProject', -module.exports = NewCommand.extend({ availableOptions: [ { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }, { name: 'verbose', type: Boolean, default: false, aliases: ['v'] }, @@ -60,12 +64,6 @@ module.exports = NewCommand.extend({ 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, @@ -79,8 +77,7 @@ module.exports = NewCommand.extend({ directoryName: commandOptions.directory, dryRun: commandOptions.dryRun }) - .then(initCommand.run.bind(initCommand, commandOptions, rawArgs)) - .then(gitInit.run.bind(gitInit, commandOptions, rawArgs)); + .then(initCommand.run.bind(initCommand, commandOptions, rawArgs)); } }); diff --git a/addon/ng2/tasks/git-init.js b/addon/ng2/tasks/git-init.js index c9d1d6387a..9dc27fb42d 100644 --- a/addon/ng2/tasks/git-init.js +++ b/addon/ng2/tasks/git-init.js @@ -6,6 +6,7 @@ var path = require('path'); var pkg = require('../package.json'); var fs = require('fs'); var template = require('lodash/string/template'); +var Task = require('ember-cli/lib/models/task'); var gitEnvironmentVariables = { GIT_AUTHOR_NAME: 'angular-cli', @@ -14,9 +15,7 @@ var gitEnvironmentVariables = { get GIT_COMMITTER_EMAIL(){ return this.GIT_AUTHOR_EMAIL; } }; -var GitInit = require('ember-cli/lib/tasks/git-init'); - -module.exports = GitInit.extend({ +module.exports = Task.extend({ run: function(commandOptions) { var chalk = require('chalk'); var ui = this.ui; diff --git a/addon/ng2/utilities/INITIAL_COMMIT_MESSAGE.txt b/addon/ng2/utilities/INITIAL_COMMIT_MESSAGE.txt index 70e89ac828..0c4e932255 100644 --- a/addon/ng2/utilities/INITIAL_COMMIT_MESSAGE.txt +++ b/addon/ng2/utilities/INITIAL_COMMIT_MESSAGE.txt @@ -1 +1,8 @@ -chore: initial commit from angular-cli v<%= version %> +chore: initial commit from angular-cli + _ _ _ + __ _ _ __ __ _ _ _| | __ _ _ __ ___| (_) + / _ | _ \ / _ | | | | |/ _ | __|____ / __| | | + | (_| | | | | (_| | |_| | | (_| | | |_____| (__| | | + \____|_| |_|\__ |\____|_|\____|_| \___|_|_| + |___/ + \ No newline at end of file