File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 11var 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+
5468module . exports = pbxProject ;
Original file line number Diff line number Diff 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 - F 0 - 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+ }
You can’t perform that action at this time.
0 commit comments