Skip to content

Commit

Permalink
Validate version strategy and fall back when invalid/not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisa Backer authored and eshtadc committed Dec 14, 2018
1 parent c78cb28 commit c6a9fb4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/index-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ const fs = require('fs');
const path = require('path');
const Plugin = require('broccoli-plugin');

const VERSION_STRATEGIES = {
EVERY_BUILD: 'every-build',
PROJECT_REVISION: 'project-revision',
PROJECT_VERSION: 'project-version'
};

function baseModule(options) {
return `
export const PROJECT_VERSION = '${options.projectVersion}';
Expand Down Expand Up @@ -48,17 +54,18 @@ module.exports = class Config extends Plugin {
options.buildTime = (new Date).getTime() + '|' + Math.random();

let module = baseModule(options);
let versionStrategy = options.versionStrategy;
let validVersionStrategies = [VERSION_STRATEGIES.EVERY_BUILD, VERSION_STRATEGIES.PROJECT_REVISION, VERSION_STRATEGIES.PROJECT_VERSION];
let versionStrategy = validVersionStrategies.indexOf(options.versionStrategy) !== -1 ? options.versionStrategy : VERSION_STRATEGIES.EVERY_BUILD;

if (!('versionStrategy' in options) || options.versionStrategy === 'every-build') {
if (versionStrategy === VERSION_STRATEGIES.EVERY_BUILD) {
module += EVERY_BUILD_STRATEGY;
}

if (options.versionStrategy === 'project-revision') {
if (versionStrategy === VERSION_STRATEGIES.PROJECT_REVISION) {
module += PROJECT_REVISION_STRATEGY;
}

if (options.versionStrategy === 'project-version') {
if (versionStrategy === VERSION_STRATEGIES.PROJECT_VERSION) {
module += PROJECT_VERSION_STRATEGY;
}

Expand Down

0 comments on commit c6a9fb4

Please sign in to comment.