Skip to content

Commit b104dfc

Browse files
committed
[pbxProject] generateUuid function
1 parent d4e58b5 commit b104dfc

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/pbxProject.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var util = require('util'),
22
EventEmitter = require('events').EventEmitter,
33
path = require('path'),
4+
uuid = require('node-uuid'),
45
fork = require('child_process').fork,
56
pbxWriter = require('./pbxWriter')
67

@@ -51,4 +52,17 @@ pbxProject.prototype.allUuids = function () {
5152
return uuids;
5253
}
5354

55+
pbxProject.prototype.generateUuid = function () {
56+
var id = uuid.v4()
57+
.replace(/-/g,'')
58+
.substr(0,24)
59+
.toUpperCase()
60+
61+
if (this.allUuids().indexOf(id) >= 0) {
62+
return this.generateUuid();
63+
} else {
64+
return id;
65+
}
66+
}
67+
5468
module.exports = pbxProject;

test/pbxProject.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,27 @@ exports['allUuids function'] = {
5555
test.done();
5656
}
5757
}
58+
59+
exports['generateUuid function'] = {
60+
'should return a 24 character string': function (test) {
61+
var project = new pbx('.'),
62+
newUUID;
63+
64+
project.hash = buildConfig;
65+
newUUID = project.generateUuid();
66+
67+
test.equal(newUUID.length, 24);
68+
test.done();
69+
},
70+
'should be an uppercase hex string': function (test) {
71+
var project = new pbx('.'),
72+
uHex = /^[A-F0-9]{24}$/,
73+
newUUID;
74+
75+
project.hash = buildConfig;
76+
newUUID = project.generateUuid();
77+
78+
test.ok(uHex.test(newUUID));
79+
test.done();
80+
}
81+
}

0 commit comments

Comments
 (0)