Skip to content

Commit

Permalink
Merge pull request #6 from AlexBedley/master
Browse files Browse the repository at this point in the history
Use semver instead of regex for version validation
  • Loading branch information
dlockhart committed Oct 20, 2015
2 parents 25bc158 + faaf222 commit 98dd5ca
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/appConfigBuilder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var semver = require('semver');
var packageJson = require('./packageJson');

function build(opts, loader) {
Expand Down Expand Up @@ -45,14 +46,13 @@ function validateId(id) {
}
}

var VERSION_REGEX = new RegExp('^[0-9]+\\.[0-9]+\\.[0-9]+(\\.[0-9]+)?$');
function validateVersion(version) {
if (!version) {
throw new Error( 'version was not specified and can\'t be found in package.json' );
}

if (!VERSION_REGEX.test(version)) {
throw new Error( 'version "' + version + '" is not in the form "#.#.#" or "#.#.#.#"');
if (!semver.valid(version)) {
throw new Error( 'version "' + version + '" is not a valid version number. See semver.org for more details.');
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"frau-local-appresolver": "^0.2.0",
"frau-publisher": "^2.5.1",
"q": "^1.4.1",
"semver": "^5.0.3",
"streamifier": "^0.1.0",
"vinyl-fs": "^1.0.0",
"vinyl-source-stream": "^1.0.0",
Expand Down
10 changes: 5 additions & 5 deletions test/appConfigBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('appConfigBuilder', () => {

const spy = sinon.stub(require('../lib/packageJson'), 'read')
.returns({
version: '1.0.0.1',
version: '1.0.0-alpha.1',
description: 'It is a small world',
appId: 'urn:d2l:fra:id:some-id'
});
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('appConfigBuilder', () => {

describe('defaults', () => {

const VERSION = '1.0.0.1',
const VERSION = '1.0.0-alpha.1',
DESCRIPTION = 'It is a small world',
ID = 'urn:d2l:fra:id:some-id';

Expand Down Expand Up @@ -107,7 +107,7 @@ describe('appConfigBuilder', () => {
'urn:d2l:fra:id:some-id',
'urn:d2l:fra:id:some.id'
],
version: [ '0.0.0.0', '1.0.0' ],
version: [ '0.0.0', '1.0.0-alpha.1' ],
description: [
'A simple description.',
longString(1024)
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('appConfigBuilder', () => {

const VALUES = {
id: [ '....', '----', 'some--name', 'urn', 'urn:', 'urn:d2l:fra:id:some/id', 'urn:d2l:fra:id:some-id2' ],
version: [ '....', '1.0-something', '1.0.0.0.1', '1.0' ],
version: [ '....', '1.0-something', '1.0.0.1', '1.0', '1' ],
description: [ longString(1025) ],
};

Expand Down Expand Up @@ -203,7 +203,7 @@ describe('appConfigBuilder', () => {

function createValidOpts() {
return {
version: '1.0.0.1',
version: '1.0.0-alpha.1',
description: 'It is a small world',
id: 'urn:d2l:fra:id:some-id',
loader: 'test'
Expand Down
2 changes: 1 addition & 1 deletion test/htmlAppConfigBuilder .js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('htmlAppConfigBuilder', () => {

function createValidOpts() {
return {
version: '1.0.0.1',
version: '1.0.0-alpha.1',
description: 'It is a small world',
id: 'urn:d2l:fra:id:some-id',
defaultResource: 'test'
Expand Down
2 changes: 1 addition & 1 deletion test/iframeAppConfigBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const expect = chai.expect;

const TARGET = 'example.com/path/app.js';
const OPTS = {
version: '1.0.0.1',
version: '1.0.0-alpha.1',
description: 'It is a small world',
id: 'urn:d2l:fra:id:some-id'
};
Expand Down
2 changes: 1 addition & 1 deletion test/umdAppConfigBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('umdAppConfigBuilder', () => {

function createValidOpts() {
return {
version: '1.0.0.1',
version: '1.0.0-alpha.1',
description: 'It is a small world',
id: 'urn:d2l:fra:id:some-id',
showLoading: true
Expand Down

0 comments on commit 98dd5ca

Please sign in to comment.