Skip to content

Commit

Permalink
Merge 7b5319b into 91eeef1
Browse files Browse the repository at this point in the history
  • Loading branch information
njostonehouse committed Nov 24, 2014
2 parents 91eeef1 + 7b5319b commit a8a4b9a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
20 changes: 17 additions & 3 deletions lib/loadByFileSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
});

Expand Down
9 changes: 5 additions & 4 deletions lib/loadByNameSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions test/data/test1.package.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<Package Name="TestPackage1" xmlns="http://schemas.desire2learn.com/xml/schemas/package.xsd">
<Css>
<File Path="file1.css" />
<File Path="file2.css" />
</Css>

<JavaScript>
<File Path="file1.js" />
<File Path="file2.js" />
Expand Down
5 changes: 5 additions & 0 deletions test/data/test2.package.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<Package Name="TestPackage1" xmlns="http://schemas.desire2learn.com/xml/schemas/package.xsd">
<Css>
<File Path="file3.css" />
<File Path="file4.css" />
<File/>
</Css>
<JavaScript>
<File Path="file3.js" />
<File Path="file4.js" />
Expand Down
17 changes: 12 additions & 5 deletions test/loadByFileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );

Expand Down
10 changes: 5 additions & 5 deletions test/loadByNameSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions test/loadDefinitionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down

0 comments on commit a8a4b9a

Please sign in to comment.