@@ -31,8 +31,10 @@ BT.Framework = SC.Object.extend({
31
31
if ( BT . runMode === BT . RM_DEBUG ) return true ;
32
32
else return false ;
33
33
} . property ( ) ,
34
- watchFiles : true ,
35
- defaultLanguage : 'english' ,
34
+ watchFiles : function ( ) {
35
+ if ( BT . runMode === BT . RM_DEBUG ) return true ;
36
+ else return false ;
37
+ } . property ( ) ,
36
38
createSprite : false ,
37
39
scriptExtensions : function ( ) {
38
40
return BT . projectManager . get ( 'scriptExtensions' ) ;
@@ -125,6 +127,8 @@ BT.Framework = SC.Object.extend({
125
127
this . scanFiles ( {
126
128
skipDirs : [ 'apps' ]
127
129
} ) ;
130
+ var belongsTo = this . belongsTo ;
131
+ if ( belongsTo ) belongsTo . addObserver ( 'language' , this , 'setFilesForLanguage' ) ;
128
132
if ( BT . runBenchmarks ) SC . Benchmark . end ( 'framework:scanFiles' ) ;
129
133
} ,
130
134
@@ -166,14 +170,18 @@ BT.Framework = SC.Object.extend({
166
170
} . property ( ) ,
167
171
168
172
scanFiles : function ( opts ) {
169
- var pathlib = require ( 'path' ) ;
170
- var fslib = require ( 'fs' ) ;
171
- var files = [ ] ;
172
- var me = this ;
173
+ var pathlib = require ( 'path' ) ,
174
+ fslib = require ( 'fs' ) ,
175
+ files = [ ] ,
176
+ me = this ,
177
+ app = this . get ( 'belongsTo' ) ,
178
+ language = app ? app . get ( 'language' ) : null ,
179
+ languages = SC . Set . create ( ) ,
180
+
181
+ // get all registered extensions first
182
+ exts = BT . projectManager . get ( 'extensions' ) ,
183
+ skipDirs = opts . skipDirs || [ ] ;
173
184
174
- // get all registered extensions first
175
- var exts = BT . projectManager . get ( 'extensions' ) ;
176
- var skipDirs = opts . skipDirs || [ ] ;
177
185
if ( ! this . get ( 'includeFixtures' ) ) skipDirs . push ( 'fixtures' ) ;
178
186
if ( ! this . includeTests ) skipDirs . push ( 'tests' ) ;
179
187
@@ -184,34 +192,49 @@ BT.Framework = SC.Object.extend({
184
192
files . push ( BT . ModuleScriptFile . create ( { path : modulePath , framework : me , } ) ) ;
185
193
}
186
194
187
- var scanDir = function ( dir ) {
195
+ var scanDir = function ( dir , language ) {
196
+ if ( language === 'es' ) console . log ( dir ) ;
188
197
var ret = [ ] ;
189
198
var fileList = fslib . readdirSync ( dir ) ;
190
199
fileList . forEach ( function ( fn ) {
191
200
var p = pathlib . join ( dir , fn ) ;
192
201
var ext = pathlib . extname ( p ) ;
193
202
ext = ( ext [ 0 ] === "." ) ? ext . slice ( 1 ) : ext ;
194
203
var stat = fslib . statSync ( p ) ;
195
- if ( stat . isFile ( ) && exts . contains ( ext ) ) {
196
- var k = BT . projectManager . fileClassFor ( ext ) ;
197
- var f = k . create ( { path : p ,
198
- framework : me ,
199
- //watchForChanges: this.watchFiles, // this works differently now
200
- } ) ;
201
- files . push ( f ) ;
204
+ if ( stat . isFile ( ) ) {
205
+ if ( exts . contains ( ext ) ) {
206
+ var k = BT . projectManager . fileClassFor ( ext ) ;
207
+ var f = k . create ( { path : p ,
208
+ framework : me ,
209
+ language : language || 'any'
210
+ //watchForChanges: this.get('watchFiles'), // this works differently now
211
+ } ) ;
212
+ files . push ( f ) ;
213
+ }
202
214
}
203
- else if ( stat . isDirectory ( ) && ! skipDirs . contains ( fn ) ) {
204
- allDirs . push ( p ) ; // store full path for dir, for watchers
205
- //ret = ret.concat(scanDir(p));
206
- scanDir ( p ) ;
215
+ else if ( stat . isDirectory ( ) ) {
216
+ if ( ! skipDirs . contains ( fn ) ) {
217
+ allDirs . push ( p ) ; // store full path for dir, for watchers
218
+ //ret = ret.concat(scanDir(p));
219
+ if ( fn . slice ( fn . length - 6 , fn . length ) === '.lproj' ) {
220
+ language = BT . languageFor ( fn . slice ( 0 , fn . length - 6 ) ) ;
221
+ languages . add ( language ) ;
222
+ }
223
+ scanDir ( p , language ) ;
224
+ }
207
225
}
226
+ language = null ;
208
227
} ) ;
209
228
return ret ;
210
229
} ;
211
230
231
+ // set the languages to build for this app only if they are not preset
232
+ if ( app && ! app . get ( 'languages' ) ) app . set ( 'languages' , languages ) ;
233
+
212
234
//var found = scanDir(this.get('path'));
213
235
scanDir ( this . get ( 'path' ) ) ;
214
- this . files . set ( 'content' , files ) ;
236
+ this . allFiles = files ;
237
+ this . setFilesForLanguage ( ) ;
215
238
// now we set the rawContent of all the files. If we do it earlier
216
239
// we get into trouble with slicing. so we start with resources on purpose
217
240
// as slicing will need access to the content during css parsing
@@ -227,7 +250,7 @@ BT.Framework = SC.Object.extend({
227
250
} ) ;
228
251
229
252
// find folders and add watchers
230
- if ( this . watchFiles ) {
253
+ if ( this . get ( ' watchFiles' ) ) {
231
254
var os = require ( 'os' ) ;
232
255
if ( os . platform ( ) === "darwin" ) {
233
256
var sysver = os . release ( ) . split ( "." ) ;
@@ -245,6 +268,16 @@ BT.Framework = SC.Object.extend({
245
268
246
269
} ,
247
270
271
+ setFilesForLanguage : function ( ) {
272
+ var language = this . getPath ( 'belongsTo.language' ) ,
273
+ locFiles = this . allFiles . filter ( function ( f ) {
274
+ var l = f . get ( 'language' ) ;
275
+ return l === 'any' || l === language ;
276
+ } ) ;
277
+ this . files . set ( 'content' , locFiles ) ;
278
+ //this._scripts.notifyPropertyChange('content');
279
+ } ,
280
+
248
281
setupDirectoryWatchers : function ( alldirs ) {
249
282
// The system of directory watchers is going to be difficult
250
283
// it seems there is only one event (on osx?), which is "rename", and doesn't provide any extra information
@@ -474,7 +507,7 @@ BT.Framework = SC.Object.extend({
474
507
if ( k ) { // only create when the file class is known.
475
508
if ( ! this . getPath ( 'files.filenames' ) [ filename ] ) {
476
509
SC . Logger . log ( "creating new file..." ) ;
477
- var f = k . create ( { path : filename , framework : this , watchForChanges : this . watchFiles } ) ;
510
+ var f = k . create ( { path : filename , framework : this , watchForChanges : this . get ( ' watchFiles' ) } ) ;
478
511
this . get ( 'files' ) . pushObject ( f ) ;
479
512
f . fileDidChange ( ) ; // trigger initial loading of content
480
513
SC . Logger . log ( "should be in files now..." ) ;
0 commit comments