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

Auto update dummy config #44

Merged
merged 2 commits into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ First you need to install ember-cli-github-pages:
ember install ember-cli-github-pages
```

In order to have any assets you have in your repo load correctly you need to add the following to your `tests/dummy/config/environment.js` file:
```javascript
if (environment === 'production') {
ENV.baseURL = '/name-of-your-repo'
}
```
Upon install, this addon will modify your 'tests/dummy/config/environment.js'.
Commit these changes with the following command:

Commit these changes `git add -A && git commit -m "Added ember-cli-github-pages addon"`
```sh
git add -A && git commit -m "Added ember-cli-github-pages addon"
```

Then you need to create the gh-pages branch and remove the unnecessary files:
Then you need to create the `gh-pages` branch and remove the unnecessary files:

```sh
git checkout --orphan gh-pages && rm -rf `ls -a | grep -vE '\.gitignore|\.git|node_modules|bower_components|(^[.]{1,2}/?$)'` && git add -A && git commit -m "initial gh-pages commit"
Expand Down
26 changes: 10 additions & 16 deletions blueprints/ember-cli-github-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,28 @@ var fs = require('fs');
var writeFile = RSVP.denodeify(fs.writeFile);

module.exports = {
description: 'Updates baseURL in config to work on gh-pages',
description: 'Updates baseURL in dummy config to work on gh-pages',
normalizeEntityName: function() { },

afterInstall: function() {
return this.updateBaseURL().then(function() {
return this.updateLocationType();
}.bind(this)).then(function() {
return this.updateDummyConfig().then(function() {
this.ui.writeLine('Updated config/environment.js baseURL and locationType.');
}.bind(this));
},

updateLocationType: function() {
var search = "locationType: 'auto'";
var replace = "locationType: 'hash'";

return this.replaceEnvironment(search, replace);
},

updateBaseURL: function() {
var name = this.project.config('production').modulePrefix;
var search = "baseURL: '/'";
var replace = "baseURL: '/" + name + "'";
updateDummyConfig: function() {
var name = this.project.pkg.name;
var search = " if (environment === 'production') {";

Choose a reason for hiding this comment

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

Mixed double and single quotes.

var replace = " if (environment === 'production') {\n ENV.locationType = 'hash';\n ENV.baseURL = '/" + name + "';";

Choose a reason for hiding this comment

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

Line is too long.
Mixed double and single quotes.


return this.replaceEnvironment(search, replace);
},

replaceEnvironment: function(search, replace) {
return this.replaceInFile('config/environment.js', search, replace);
var addon = this.project.pkg['ember-addon'];
var configPath = addon ? addon.configPath : 'config';

return this.replaceInFile(configPath + '/environment.js', search, replace);
},

replaceInFile: function(pathRelativeToProjectRoot, searchTerm, contentsToInsert) {
Expand Down