diff --git a/lib/loadByFileSync.js b/lib/loadByFileSync.js index 1f0ee00..7b6f5fd 100644 --- a/lib/loadByFileSync.js +++ b/lib/loadByFileSync.js @@ -16,17 +16,31 @@ module.exports = function( packagePath ) { { 'noblanks' : true } ); + var filePaths = { }; + var jsFiles = xml.get( '//xmlns:JavaScript', 'http://schemas.desire2learn.com/xml/schemas/package.xsd' ).childNodes(); - - var filePaths = []; + filePaths.JavaScript = []; jsFiles.forEach(function( jsFile ) { var filePath = jsFile.attr("Path"); if( filePath ) { filePath = path.join( dir, filePath.value() ); - filePaths.push( filePath ); + filePaths.JavaScript.push( filePath ); + } + }); + + var cssFiles = xml.get( + '//xmlns:Css', + 'http://schemas.desire2learn.com/xml/schemas/package.xsd' + ).childNodes(); + filePaths.Css = []; + cssFiles.forEach(function( jsFile ) { + var filePath = jsFile.attr("Path"); + if( filePath ) { + filePath = path.join( dir, filePath.value() ); + filePaths.Css.push( filePath ); } }); diff --git a/lib/loadByNameSync.js b/lib/loadByNameSync.js index 2d7e901..1b61f6b 100644 --- a/lib/loadByNameSync.js +++ b/lib/loadByNameSync.js @@ -18,11 +18,12 @@ module.exports = function( packageName, opts ) { packageName + '.definition.xml' ); - var files = []; + var files = {}; loadDefinitionSync( definitionPath ).forEach( function( def ) { - loadByFileSync( def ).forEach( function( file ) { - files.push( file ); - }); + var filesObj = loadByFileSync( def ); + for( var k in filesObj ) { + files[k] = (files[k] || []).concat(filesObj[k]); + } }); return files; diff --git a/test/data/test1.package.xml b/test/data/test1.package.xml index ca5340e..b0bc77f 100644 --- a/test/data/test1.package.xml +++ b/test/data/test1.package.xml @@ -1,4 +1,9 @@ + + + + + diff --git a/test/data/test2.package.xml b/test/data/test2.package.xml index 2e00bb3..5b1eecf 100644 --- a/test/data/test2.package.xml +++ b/test/data/test2.package.xml @@ -1,4 +1,9 @@ + + + + + diff --git a/test/loadByFileSpec.js b/test/loadByFileSpec.js index c114018..5ca9362 100644 --- a/test/loadByFileSpec.js +++ b/test/loadByFileSpec.js @@ -30,15 +30,22 @@ describe( 'Load By File (Asynchronous)', function() { describe( 'Load By File (Synchronous)', function() { it( 'Should load 2 files', function( ) { - var files = webPackageReader.loadByFileSync( path.join( dataPath, 'test1.package.xml' ) ) - expect( files.length ).toBe( 2 ); - expect( files[0] ).toBe( path.join( dataPath, 'file1.js' ) ); - expect( files[1] ).toBe( path.join( dataPath, 'file2.js' ) ); + var files = webPackageReader.loadByFileSync( path.join( dataPath, 'test1.package.xml' ) ); + expect( files.JavaScript.length ).toBe( 2 ); + expect( files.JavaScript[0] ).toBe( path.join( dataPath, 'file1.js' ) ); + expect( files.JavaScript[1] ).toBe( path.join( dataPath, 'file2.js' ) ); + } ); + + it( 'Should load 2 files', function( ) { + var files = webPackageReader.loadByFileSync( path.join( dataPath, 'test1.package.xml' ) ); + expect( files.Css.length ).toBe( 2 ); + expect( files.Css[0] ).toBe( path.join( dataPath, 'file1.css' ) ); + expect( files.Css[1] ).toBe( path.join( dataPath, 'file2.css' ) ); } ); it( 'Should throw on invalid XML input', function() { expect( function() { - webPackageReader.loadByFileSync( path.join( dataPath, 'invalidxml.package.xml' ) ) + webPackageReader.loadByFileSync( path.join( dataPath, 'invalidxml.package.xml' ) ); }).toThrow(); } ); diff --git a/test/loadByNameSpec.js b/test/loadByNameSpec.js index 24250ac..00b953a 100644 --- a/test/loadByNameSpec.js +++ b/test/loadByNameSpec.js @@ -39,11 +39,11 @@ describe( 'Load By Name (Synchronous)', function() { it( 'should load 4 files across 2 package files', function() { var files = webPackageReader.loadByNameSync( 'definition1', opts ); - expect( files.length ).toBe( 4 ); - expect( files[0] ).toBe( path.join( dataPath, 'file1.js' ) ); - expect( files[1] ).toBe( path.join( dataPath, 'file2.js' ) ); - expect( files[2] ).toBe( path.join( dataPath, 'file3.js' ) ); - expect( files[3] ).toBe( path.join( dataPath, 'file4.js' ) ); + expect( files.JavaScript.length ).toBe( 4 ); + expect( files.JavaScript[0] ).toBe( path.join( dataPath, 'file1.js' ) ); + expect( files.JavaScript[1] ).toBe( path.join( dataPath, 'file2.js' ) ); + expect( files.JavaScript[2] ).toBe( path.join( dataPath, 'file3.js' ) ); + expect( files.JavaScript[3] ).toBe( path.join( dataPath, 'file4.js' ) ); } ); it( 'should throw if no web package path is defined', function() { diff --git a/test/loadDefinitionSpec.js b/test/loadDefinitionSpec.js index 8812027..03191a7 100644 --- a/test/loadDefinitionSpec.js +++ b/test/loadDefinitionSpec.js @@ -44,14 +44,14 @@ describe( 'Load Definition (Asynchronous)', function() { describe( 'Load Definition (Synchronous)', function() { it( 'Should resolve relative paths', function() { - var files = loadDefinitionSync( path.join( dataPath, 'packages', 'definition1.definition.xml' ) ) + var files = loadDefinitionSync( path.join( dataPath, 'packages', 'definition1.definition.xml' ) ); expect( files.length ).toBe( 2 ); expect( files[0] ).toBe( path.join( dataPath, 'test1.package.xml' ) ); expect( files[1] ).toBe( path.join( dataPath, 'test2.package.xml' ) ); } ); it( 'Should leave absolute paths alone', function() { - var files = loadDefinitionSync( path.join( dataPath, 'packages', 'definition2.definition.xml' ) ) + var files = loadDefinitionSync( path.join( dataPath, 'packages', 'definition2.definition.xml' ) ); expect( files.length ).toBe( 2 ); if( path.sep === '/' ) { expect( files[1] ).toBe( '/abc/test1.package.xml' );