Skip to content

Commit

Permalink
Merge 81814a7 into 76bc923
Browse files Browse the repository at this point in the history
  • Loading branch information
njostonehouse committed Dec 18, 2014
2 parents 76bc923 + 81814a7 commit 2246a4a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
39 changes: 21 additions & 18 deletions lib/loadByFileSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@

var fs = require( 'fs' ),
path = require( 'path' ),
xmlParser = require('node-xml-lite');
et = require('elementtree');

module.exports = function( packagePath ) {

var dir = path.dirname( packagePath );

var xml = et.parse(
fs.readFileSync(
packagePath,
{ encoding: "UTF-8" }
)
);

var filePaths = { JavaScript: [], Css: [] };

var xml = xmlParser.parseFileSync( packagePath );
xml.childs.forEach(function( type ) {
var readFiles;
switch(type.name) {
case 'Css':
readFiles = filePaths.Css;
break;
case 'JavaScript':
readFiles = filePaths.JavaScript;
break;
default:
return;
xml.findall('.//JavaScript/*').forEach( function( jsFile ) {
var filePath = jsFile.get('Path');
if( filePath ) {
filePath = path.join( dir, filePath );
filePaths.JavaScript.push( filePath );
}
});

type.childs.forEach( function( filePath ) {
if( filePath.name == "File" && filePath.attrib && filePath.attrib.Path ) {
readFiles.push( path.join( dir, filePath.attrib.Path ) );
}
});
xml.findall('.//Css/*').forEach( function( cssFile ) {
var filePath = cssFile.get('Path');
if( filePath ) {
filePath = path.join( dir, filePath );
filePaths.Css.push( filePath );
}
});

return filePaths;
Expand Down
30 changes: 17 additions & 13 deletions lib/loadDefinitionSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@

var fs = require('fs'),
path = require('path'),
xmlParser = require('node-xml-lite');
et = require('elementtree');

module.exports = function( definitionPath ) {

var dir = path.dirname( definitionPath );
var filePaths = [];

var xml = xmlParser.parseFileSync( definitionPath );
var xml = et.parse(
fs.readFileSync(
definitionPath,
{ encoding: "UTF-8" }
).toString()
);

var pathsFiles = xml.findall('.//Paths/*');

xml.childs.forEach( function( paths ) {
if( paths.name == "Paths" && paths.childs ) {
paths.childs.forEach( function( pathsFile ) {
if( pathsFile.name == "File" && pathsFile.attrib && pathsFile.attrib.Path ) {
if( path.resolve( pathsFile.attrib.Path ) !== pathsFile.attrib.Path ) {
pathsFile.attrib.Path = path.join( dir, pathsFile.attrib.Path );
}
filePaths.push( pathsFile.attrib.Path );
}
});
var filePaths = [];
pathsFiles.forEach( function( pFile ) {
var filePath = pFile.get('Path');
if( filePath ) {
if(path.resolve( filePath ) !== filePath ) {
filePath = path.join( dir, filePath );
}
filePaths.push( filePath );
}
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"homepage": "https://github.com/Brightspace/web-package-reader",
"dependencies": {
"node-xml-lite": "0.0.3",
"elementtree": "^0.1.6",
"q": "^1.0.1",
"q-io": "^1.11.5",
"xml2js": "^0.4.4"
Expand Down

0 comments on commit 2246a4a

Please sign in to comment.