Skip to content

Commit

Permalink
fix(Install): Use configured bootstrapVersion if present
Browse files Browse the repository at this point in the history
* Remove the `--bootstrap-version` option default because there is no way to distinguish between an omitted and defaulted value. Use the configured `bootstrapVersion` as the first fallback if the `--bootstrap-version` option is not supplied and fall back to "3" as a last resort.

Fixes #276

* Review feedback and added radix to existing `parseInt`.
  • Loading branch information
srvance authored and simonihmig committed Mar 22, 2017
1 parent 7a49316 commit e68d372
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
14 changes: 12 additions & 2 deletions blueprints/ember-bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
description: 'Configure ember-bootstrap',

availableOptions: [
{ name: 'bootstrap-version', type: Number, default: 3, aliases: ['bootstrap', 'bv'] },
{ name: 'bootstrap-version', type: Number, aliases: ['bootstrap', 'bv'] },
{ name: 'preprocessor', type: String, aliases: ['pp'] }
],

Expand All @@ -34,7 +34,7 @@ module.exports = {
},

beforeInstall(option) {
let bootstrapVersion = parseInt(option.bootstrapVersion) || 3;
let bootstrapVersion = parseInt(option.bootstrapVersion, 10) || this.retrieveBootstrapVersion() || 3;
let preprocessor = option.preprocessor;

if (bootstrapVersion !== 3 && bootstrapVersion !== 4) {
Expand Down Expand Up @@ -202,5 +202,15 @@ module.exports = {
let settingsString = JSON.stringify(settings);
this.ui.writeLine(chalk.red(`Configuration file could not be edited. Manually update your ember-cli-build.js to include '${this.name}': ${settingsString}`));
}
},

retrieveBootstrapVersion() {
let file = 'ember-cli-build.js';

let source = fs.readFileSync(file);
let build = new BuildConfigEditor(source);
let config = build.retrieve(this.name);

return config && parseInt(config.bootstrapVersion, 10);
}
};
18 changes: 15 additions & 3 deletions node-tests/blueprints/dependencyScenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ const scenarios = [
}
}
},
{
installed: {
config: {
bootstrapVersion: 4
}
},
dependencies: {
npm: {
bootstrap: bs4Regex
}
}
},
{
installed: {
npm: ['ember-cli-less']
Expand Down Expand Up @@ -341,7 +353,7 @@ const scenarios = [
},
dependencies: {
npm: {
bootstrap: bs3Regex,
bootstrap: bs3Regex
},
addon: {
'ember-cli-less': true,
Expand Down Expand Up @@ -568,7 +580,7 @@ const scenarios = [
},
dependencies: {
npm: {
bootstrap: bs4Regex,
bootstrap: bs4Regex
},
addon: {
'ember-cli-less': null,
Expand All @@ -579,4 +591,4 @@ const scenarios = [

];

module.exports = scenarios;
module.exports = scenarios;
24 changes: 19 additions & 5 deletions node-tests/blueprints/ember-bootstrap-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const emberNew = blueprintHelpers.emberNew;
const emberGenerate = blueprintHelpers.emberGenerate;
const modifyPackages = blueprintHelpers.modifyPackages;

const BuildConfigEditor = require('ember-cli-build-config-editor');

const chai = require('ember-cli-blueprint-test-helpers/chai');
const file = chai.file;
const chaiThings = require('chai-things');
Expand Down Expand Up @@ -182,8 +184,8 @@ describe('Acceptance: ember generate ember-bootstrap', function() {

describe('install dependencies', function() {

const Blueprint = require('ember-cli/lib/models/blueprint');
const origTaskFor = Blueprint.prototype.taskFor;
let Blueprint = require('ember-cli/lib/models/blueprint');
let origTaskFor = Blueprint.prototype.taskFor;
let installed = {
npm: [],
bower: [],
Expand Down Expand Up @@ -260,13 +262,23 @@ describe('Acceptance: ember generate ember-bootstrap', function() {
}
}

function editConfiguration(config) {
let buildFile = 'ember-cli-build.js';
let source = fs.readFileSync(buildFile);
let editor = new BuildConfigEditor(source);
editor.edit('ember-bootstrap', config);
fs.writeFileSync(buildFile, editor.code());
}

scenarios.forEach(function(scenario) {
let args = [];
let options = scenario.options || {};
let preprocessor = options.preprocessor;
let bootstrapVersion = options.bootstrapVersion;
let installed = scenario.installed || {};
let npmInstalled = installed.npm || [];
let config = installed.config;
let configuredBootstrapVersion = config && config.bootstrapVersion;

if (preprocessor) {
args.push(`--preprocessor=${preprocessor}`);
Expand All @@ -276,12 +288,14 @@ describe('Acceptance: ember generate ember-bootstrap', function() {
}

let preInstalledText = npmInstalled.length > 0 ? `, preInstalled: ${npmInstalled.join(', ')}` : '';
let configuredVersionText = configuredBootstrapVersion ? `, configured version: ${configuredBootstrapVersion}` : '';

it(`installs dependencies for ember g ember-bootstrap ${args.join(' ')}${preInstalledText}`, function() {
it(`installs dependencies for ember g ember-bootstrap ${args.join(' ')}${preInstalledText}${configuredVersionText}`, function() {
args = ['ember-bootstrap'].concat(args);

return emberNew()
.then(() => modifyPackages(npmInstalled.map((pkg) => ({ name: pkg, dev: true }))))
.then(() => editConfiguration(config))
.then(() => emberGenerate(args))
.then(() => {
for (let pkg in scenario.dependencies.bower) {
Expand All @@ -297,7 +311,7 @@ describe('Acceptance: ember generate ember-bootstrap', function() {
}

});
})
});
});
});
});
});
8 changes: 4 additions & 4 deletions tests/dummy/app/templates/getting-started/assets.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<pre class="highlight">ember generate ember-bootstrap --bootstrap-version=4 --preprocessor=sass
</pre>

<p>The <code>--bootstrap-version</code> can be "3" or "4" and defaults to "3" if the option is omitted. The
<code>--preprocessor</code> can be "none", "less", or "sass". The blueprint will use the currently installed
preprocessor as its cue if this option is omitted. We explicitly support ember-cli-less and ember-cli-sass. You will
need to install and configure other preprocessors yourself.</p>
<p>The <code>--bootstrap-version</code> can be "3" or "4" and if omitted, defaults to the currently configured version,
if present, or "3". The <code>--preprocessor</code> can be "none", "less", or "sass". The blueprint will use the
currently installed preprocessor as its cue if this option is omitted. We explicitly support ember-cli-less and
ember-cli-sass. You will need to install and configure other preprocessors yourself.</p>

<p>The default blueprint does the following:</p>

Expand Down

0 comments on commit e68d372

Please sign in to comment.