提交 11411f92 编写于 作者: M Mugen87

Utils: Clean up

上级 77eabf47
...@@ -144,4 +144,4 @@ function convert( path, ignoreList ) { ...@@ -144,4 +144,4 @@ function convert( path, ignoreList ) {
fs.writeFileSync( dstFolder + path, output, 'utf-8' ); fs.writeFileSync( dstFolder + path, output, 'utf-8' );
}; }
...@@ -26,8 +26,10 @@ var fs = require( 'fs' ); ...@@ -26,8 +26,10 @@ var fs = require( 'fs' );
var path = require( 'path' ); var path = require( 'path' );
if ( process.argv.length !== 3 ) { if ( process.argv.length !== 3 ) {
console.log( "Usage: node packLDrawModel <modelFilePath>" ); console.log( "Usage: node packLDrawModel <modelFilePath>" );
exit ( 0 ); exit( 0 );
} }
var fileName = process.argv[ 2 ]; var fileName = process.argv[ 2 ];
...@@ -61,14 +63,18 @@ for ( var i = 0; i < listOfNotFound.length; i ++ ) { ...@@ -61,14 +63,18 @@ for ( var i = 0; i < listOfNotFound.length; i ++ ) {
} }
if ( someNotFound ) { if ( someNotFound ) {
console.log( "Some files were not found, aborting." ); console.log( "Some files were not found, aborting." );
process.exit( -1 ); process.exit( - 1 );
} }
// Obtain packed content // Obtain packed content
var packedContent = materialsContent + "\n"; var packedContent = materialsContent + "\n";
for ( var i = objectsPaths.length - 1; i >= 0; i -- ) { for ( var i = objectsPaths.length - 1; i >= 0; i -- ) {
packedContent += objectsContents[ i ]; packedContent += objectsContents[ i ];
} }
packedContent += "\n"; packedContent += "\n";
...@@ -106,8 +112,7 @@ function parseObject( fileName, isRoot ) { ...@@ -106,8 +112,7 @@ function parseObject( fileName, isRoot ) {
prefix = "p/"; prefix = "p/";
} } else if ( fileName.startsWith( 's/' ) ) {
else if ( fileName.startsWith( 's/' ) ) {
prefix = "parts/"; prefix = "parts/";
...@@ -120,8 +125,7 @@ function parseObject( fileName, isRoot ) { ...@@ -120,8 +125,7 @@ function parseObject( fileName, isRoot ) {
objectContent = fs.readFileSync( absoluteObjectPath, { encoding: "utf8" } ); objectContent = fs.readFileSync( absoluteObjectPath, { encoding: "utf8" } );
break; break;
} } catch ( e ) {
catch ( e ) {
prefix = "parts/"; prefix = "parts/";
absoluteObjectPath = path.join( ldrawPath, prefix, fileName ); absoluteObjectPath = path.join( ldrawPath, prefix, fileName );
...@@ -131,8 +135,7 @@ function parseObject( fileName, isRoot ) { ...@@ -131,8 +135,7 @@ function parseObject( fileName, isRoot ) {
objectContent = fs.readFileSync( absoluteObjectPath, { encoding: "utf8" } ); objectContent = fs.readFileSync( absoluteObjectPath, { encoding: "utf8" } );
break; break;
} } catch ( e ) {
catch ( e ) {
prefix = "p/"; prefix = "p/";
absoluteObjectPath = path.join( ldrawPath, prefix, fileName ); absoluteObjectPath = path.join( ldrawPath, prefix, fileName );
...@@ -142,8 +145,7 @@ function parseObject( fileName, isRoot ) { ...@@ -142,8 +145,7 @@ function parseObject( fileName, isRoot ) {
objectContent = fs.readFileSync( absoluteObjectPath, { encoding: "utf8" } ); objectContent = fs.readFileSync( absoluteObjectPath, { encoding: "utf8" } );
break; break;
} } catch ( e ) {
catch ( e ) {
try { try {
...@@ -153,8 +155,8 @@ function parseObject( fileName, isRoot ) { ...@@ -153,8 +155,8 @@ function parseObject( fileName, isRoot ) {
objectContent = fs.readFileSync( absoluteObjectPath, { encoding: "utf8" } ); objectContent = fs.readFileSync( absoluteObjectPath, { encoding: "utf8" } );
break; break;
} } catch ( e ) {
catch ( e ) {
if ( attempt === 1 ) { if ( attempt === 1 ) {
// The file has not been found, add to list of not found // The file has not been found, add to list of not found
...@@ -184,7 +186,7 @@ function parseObject( fileName, isRoot ) { ...@@ -184,7 +186,7 @@ function parseObject( fileName, isRoot ) {
if ( objectContent.indexOf( '\r\n' ) !== - 1 ) { if ( objectContent.indexOf( '\r\n' ) !== - 1 ) {
// This is faster than String.split with regex that splits on both // This is faster than String.split with regex that splits on both
objectContent= objectContent.replace( /\r\n/g, '\n' ); objectContent = objectContent.replace( /\r\n/g, '\n' );
} }
...@@ -201,7 +203,7 @@ function parseObject( fileName, isRoot ) { ...@@ -201,7 +203,7 @@ function parseObject( fileName, isRoot ) {
var charIndex = 0; var charIndex = 0;
while ( ( line.charAt( charIndex ) === ' ' || line.charAt( charIndex ) === '\t' ) && charIndex < lineLength ) { while ( ( line.charAt( charIndex ) === ' ' || line.charAt( charIndex ) === '\t' ) && charIndex < lineLength ) {
charIndex++; charIndex ++;
} }
line = line.substring( charIndex ); line = line.substring( charIndex );
...@@ -209,7 +211,7 @@ function parseObject( fileName, isRoot ) { ...@@ -209,7 +211,7 @@ function parseObject( fileName, isRoot ) {
charIndex = 0; charIndex = 0;
if ( line.startsWith( '0 FILE ') ) { if ( line.startsWith( '0 FILE ' ) ) {
if ( i === 0 ) { if ( i === 0 ) {
...@@ -238,6 +240,7 @@ function parseObject( fileName, isRoot ) { ...@@ -238,6 +240,7 @@ function parseObject( fileName, isRoot ) {
} }
if ( line.startsWith( '1 ' ) ) { if ( line.startsWith( '1 ' ) ) {
// Subobject, add it // Subobject, add it
charIndex = 2; charIndex = 2;
...@@ -247,14 +250,14 @@ function parseObject( fileName, isRoot ) { ...@@ -247,14 +250,14 @@ function parseObject( fileName, isRoot ) {
// Skip token // Skip token
while ( line.charAt( charIndex ) !== ' ' && line.charAt( charIndex ) !== '\t' && charIndex < lineLength ) { while ( line.charAt( charIndex ) !== ' ' && line.charAt( charIndex ) !== '\t' && charIndex < lineLength ) {
charIndex++; charIndex ++;
} }
// Skip spaces/tabs // Skip spaces/tabs
while ( ( line.charAt( charIndex ) === ' ' || line.charAt( charIndex ) === '\t' ) && charIndex < lineLength ) { while ( ( line.charAt( charIndex ) === ' ' || line.charAt( charIndex ) === '\t' ) && charIndex < lineLength ) {
charIndex++; charIndex ++;
} }
...@@ -280,8 +283,7 @@ function parseObject( fileName, isRoot ) { ...@@ -280,8 +283,7 @@ function parseObject( fileName, isRoot ) {
} }
} } else {
else {
processedObjectContent += line + "\n"; processedObjectContent += line + "\n";
...@@ -297,4 +299,5 @@ function parseObject( fileName, isRoot ) { ...@@ -297,4 +299,5 @@ function parseObject( fileName, isRoot ) {
} }
return objectPath; return objectPath;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册