File tree Expand file tree Collapse file tree 3 files changed +88
-0
lines changed Expand file tree Collapse file tree 3 files changed +88
-0
lines changed Original file line number Diff line number Diff line change 1+ // parsing is slow and blocking right now
2+ // so we do it in a separate process
3+ var fs = require ( 'fs' ) ,
4+ parser = require ( './parser/pbxproj' ) ,
5+ path = process . argv [ 2 ] ,
6+ fileContents , obj ;
7+
8+ try {
9+ fileContents = fs . readFileSync ( path , 'utf-8' ) ,
10+ obj = parser . parse ( fileContents )
11+ process . send ( obj )
12+ process . exit ( )
13+ } catch ( e ) {
14+ process . send ( e )
15+ process . exit ( 1 )
16+ }
Original file line number Diff line number Diff line change 1+ var util = require ( 'util' ) ,
2+ EventEmitter = require ( 'events' ) . EventEmitter ,
3+ path = require ( 'path' ) ,
4+ fork = require ( 'child_process' ) . fork
5+
6+ function pbxProject ( filename ) {
7+ this . filepath = path . resolve ( filename )
8+ }
9+
10+ util . inherits ( pbxProject , EventEmitter )
11+
12+ pbxProject . prototype . parse = function ( cb ) {
13+ var worker = fork ( __dirname + '/parseJob.js' , [ this . filepath ] )
14+
15+ worker . on ( 'message' , function ( msg ) {
16+ if ( msg . code ) {
17+ this . emit ( 'error' , msg ) ;
18+ } else {
19+ this . hash = msg ;
20+ this . emit ( 'end' , null , msg )
21+ }
22+ } . bind ( this ) ) ;
23+
24+ if ( cb )
25+ this . on ( 'end' , cb ) ;
26+
27+ return this ;
28+ }
29+
30+ module . exports = pbxProject ;
Original file line number Diff line number Diff line change 1+ var pbx = require ( '../lib/pbxProject' )
2+
3+ exports [ 'parse function' ] = {
4+ 'should emit an "end" event' : function ( test ) {
5+ var myProj = new pbx ( 'test/parser/projects/hash.pbxproj' ) ;
6+
7+ myProj . parse ( ) . on ( 'end' , function ( err , projHash ) {
8+ test . done ( ) ;
9+ } )
10+ } ,
11+ 'should take the end callback as a parameter' : function ( test ) {
12+ var myProj = new pbx ( 'test/parser/projects/hash.pbxproj' ) ;
13+
14+ myProj . parse ( function ( err , projHash ) {
15+ test . done ( ) ;
16+ } )
17+ } ,
18+ 'should allow evented error handling' : function ( test ) {
19+ var myProj = new pbx ( 'NotARealPath.pbxproj' ) ;
20+
21+ myProj . parse ( ) . on ( 'error' , function ( err ) {
22+ test . equal ( typeof err , "object" ) ;
23+ test . done ( ) ;
24+ } )
25+ } ,
26+ 'should pass the hash object to the callback function' : function ( test ) {
27+ var myProj = new pbx ( 'test/parser/projects/hash.pbxproj' ) ;
28+
29+ myProj . parse ( function ( err , projHash ) {
30+ test . ok ( projHash ) ;
31+ test . done ( ) ;
32+ } )
33+ } ,
34+ 'should attach the hash object to the pbx object' : function ( test ) {
35+ var myProj = new pbx ( 'test/parser/projects/hash.pbxproj' ) ;
36+
37+ myProj . parse ( function ( err , projHash ) {
38+ test . ok ( myProj . hash ) ;
39+ test . done ( ) ;
40+ } )
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments