Skip to content

Commit afcf9ff

Browse files
authored
Merge pull request #356 from isleofcode/fix/force-on-validate-locationtype
Fix/force on validate locationtype
2 parents 790e6a0 + 85fdd2f commit afcf9ff

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

lib/commands/build.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ module.exports = Command.extend({
7676

7777
validations.push(
7878
new ValidateLocationType({
79-
config: projectConfig
79+
config: projectConfig,
80+
force: options.force
8081
}).run()
8182
);
8283
}

lib/tasks/validate/location-type.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
var Task = require('../-task');
22
var Promise = require('rsvp').Promise;
33
var chalk = require('chalk');
4+
var logger = require('../../utils/logger');
45

56
var MUST_SPECIFY_HASH =
67
chalk.red('* config/environment.js: Cordova applications require:') +
78
chalk.grey('\n`ENV.locationType = \'hash\'; \n');
89

910
module.exports = Task.extend({
1011
config: undefined,
12+
force: false,
1113

1214
run: function() {
1315
var config = this.config;
1416
var locationType = config.locationType;
1517
var isHashLocation = locationType === 'hash';
1618

17-
if (!isHashLocation) {
19+
if (!isHashLocation && this.force === false) {
1820
return Promise.reject(MUST_SPECIFY_HASH);
21+
} else {
22+
var msg = MUST_SPECIFY_HASH;
23+
msg += 'You have passed the --force flag, so continuing';
24+
logger.warn(msg);
1925
}
2026

2127
return Promise.resolve();

node-tests/unit/tasks/validate/location-type-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var td = require('testdouble');
44
var expect = require('../../../helpers/expect');
55
var mockProject = require('../../../fixtures/ember-cordova-mock/project');
66
var ValidateLocType = require('../../../../lib/tasks/validate/location-type');
7+
var logger = require('../../../../lib/utils/logger');
8+
var contains = td.matchers.contains;
79

810
describe('Validate Location Type', function() {
911
var validateLoc;
@@ -32,4 +34,15 @@ describe('Validate Location Type', function() {
3234
validateLoc.config = { locationType: 'hash' };
3335
return expect(validateLoc.run()).to.be.fulfilled;
3436
});
37+
38+
it('when force is true, it warns vs rejects', function() {
39+
validateLoc.config = { locationType: 'auto' };
40+
validateLoc.force = true;
41+
42+
var warnDouble = td.replace(logger, 'warn');
43+
44+
return validateLoc.run().then(function() {
45+
td.verify(warnDouble(contains('You have passed the --force flag')));
46+
})
47+
});
3548
});

0 commit comments

Comments
 (0)