Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] ember init fails on NULL_PROJECT #546

Merged
merged 1 commit into from
May 1, 2014
Merged

[BUGFIX] ember init fails on NULL_PROJECT #546

merged 1 commit into from
May 1, 2014

Conversation

twokul
Copy link
Contributor

@twokul twokul commented Apr 30, 2014

Previously, if you try to run ember init inside an empty directory, it will
fail because environment.project was not set to NULL_PROJECT.

Steps:

mkdir foo && cd foo && ember init

thanks to @abuiles for initial spike, #529

Closes #540

@twokul
Copy link
Contributor Author

twokul commented Apr 30, 2014

@@ -23,7 +23,7 @@ module.exports = new Command({
var installBlueprint = environment.tasks.installBlueprint;
var npmInstall = environment.tasks.npmInstall;
var bowerInstall = environment.tasks.bowerInstall;
var packageName = environment.project ? environment.project.pkg.name : path.basename(cwd);
var packageName = environment.project.isEmberCLIProject() ? environment.project.pkg.name : path.basename(cwd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make project a var, I'm not a fan of lines that long

var project = environment.project;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure.

@abuiles
Copy link
Member

abuiles commented Apr 30, 2014

@twokul I did this at the beginning but it was breaking ember new can you please verify that is still working? ember new foo

@twokul
Copy link
Contributor Author

twokul commented Apr 30, 2014

@abuiles it works.

@abuiles
Copy link
Member

abuiles commented Apr 30, 2014

@twokul 👍 thanks!

@@ -23,7 +23,8 @@ module.exports = new Command({
var installBlueprint = environment.tasks.installBlueprint;
var npmInstall = environment.tasks.npmInstall;
var bowerInstall = environment.tasks.bowerInstall;
var packageName = environment.project ? environment.project.pkg.name : path.basename(cwd);
var project = environment.project;
var packageName = project.isEmberCLIProject() ? environment.project.pkg.name : path.basename(cwd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would prefer if the null project return a null package name, as the null pattern is to reduce such branching.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

project.isEmberCLIProject() ? environment.project.pkg.name : path.basename(cwd);
-> project.isEmberCLIProject() ? project.pkg.name : path.basename(cwd);

@stefanpenner I'm not so sure if we should extend the NULL_PROJECT to include these things. I even think that the pkg === undefined is the desired thing because the file really doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change it to something like:

var packageName = project.name();
// ...
if (!packageName) {
  packageName = path.basename(cwd);
}

That will reduce branching.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I'm generally ok with

project.isEmberCLIProject() ? environment.project.pkg.name : path.basename(cwd);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kinda seems like if no name exists, the NULL_PROJECT's name should be set to basename of root, and root should be the cwd

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to clutter Project with this special case. It's already a one-liner.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MajorBreakfast i think that is the point of this pattern

@stefanpenner
Copy link
Contributor

LGTM

name: function() {
return 'test';
},
isEmberCLIProject: function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably isEmberCLIProject is not longer required here ?

@@ -33,6 +33,10 @@ NULL_PROJECT.isEmberCLIProject = function() {
return false;
};

Project.prototype.name = function() {
return path.basename(process.cwd());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not correct, this is the behavior only of the NULL_PROJECT, otherwise name should come form this.pkg.name

Previously, if you try to run `ember init` inside an empty directory, it
will fail because `environment.project` was not set to `NULL_PROJECT`.

thanks to @abuiles for initial spike, [#529](#529)

Steps:

```bash
mkdir foo && cd foo && ember init
```

Closes #540
@abuiles
Copy link
Member

abuiles commented May 1, 2014

@twokul LGTM @rjackson @stefanpenner @MajorBreakfast mind giving a last look before merging .

@twokul
Copy link
Contributor Author

twokul commented May 1, 2014

@abuiles thanks for the feedback

rwjblue added a commit that referenced this pull request May 1, 2014
[BUGFIX] `ember init` fails on `NULL_PROJECT`
@rwjblue rwjblue merged commit bb2f49f into ember-cli:master May 1, 2014
@twokul twokul deleted the init-fix branch May 1, 2014 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"ember init" doesn't work on an empty folder
5 participants