| var fs = require('fs'); | ||
| var yauzl = require('yauzl'); | ||
| var winston = require('winston'); | ||
| var path = require('path'); | ||
| var SOURCE_FILE = 'lib/battlecode.jar'; | ||
| var MAP_FILE_REGEX = /^battlecode\/world\/resources\/(.*\.xml)$/; | ||
| var TARGET_FOLDER = 'maps'; | ||
| function copyMaps() { | ||
| yauzl.open(SOURCE_FILE, {lazyEntries: true}, function(err, zip) { | ||
| if (err) throw err; | ||
| try { | ||
| var stats = fs.statSync(TARGET_FOLDER); | ||
| if (!stats.isDirectory) { | ||
| throw TARGET_FOLDER + path.sep + " is not a directory, can't copy maps"; | ||
| } | ||
| } catch (e) { | ||
| console.log('Creating map directory'); | ||
| fs.mkdirSync(TARGET_FOLDER); | ||
| } | ||
| // Start reading entries (yauzl has a slightly odd API) | ||
| zip.readEntry(); | ||
| zip.on('entry', function(entry) { | ||
| var match = MAP_FILE_REGEX.exec(entry.fileName); | ||
| if (match !== null) { | ||
| console.log('Copying map: '+match[1]); | ||
| zip.openReadStream(entry, function(err, stream) { | ||
| stream.pipe(fs.createWriteStream(path.join(TARGET_FOLDER, match[1]))); | ||
| stream.on('end', function() { | ||
| // Read the next entry | ||
| zip.readEntry(); | ||
| }); | ||
| }); | ||
| } else { | ||
| // Read the next entry | ||
| zip.readEntry(); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
| module.exports = copyMaps; |
@@ -7,4 +7,4 @@ var fs = require('fs'); | ||
| function _getTeamsToDelete(teamDir) { | ||
| var teams = fs.readdirSync(teamDir); | ||
| function _getTeamsToDelete() { | ||
| var teams = fs.readdirSync('teams/'); | ||
| var toRemove = []; | ||
@@ -19,5 +19,5 @@ for (var i = 0; i < teams.length; i++) { | ||
| function _deletePlayer(teamDir, player, callback) { | ||
| function _deletePlayer(player, callback) { | ||
| console.log('Killing ' + player); | ||
| var remove = spawn('rm', ['-rf', path.join(teamDir, player)]); | ||
| var remove = spawn('rm', ['-rf', path.join('teams/', player)]); | ||
@@ -40,4 +40,4 @@ remove.stdout.on('data', function (data) { | ||
| function clear(teamDir, callback) { | ||
| var toRemove = _getTeamsToDelete(teamDir); | ||
| function clear(callback) { | ||
| var toRemove = _getTeamsToDelete(); | ||
@@ -51,3 +51,3 @@ function _removeNext() { | ||
| _deletePlayer(teamDir, toRemove.shift(), _removeNext); | ||
| _deletePlayer(toRemove.shift(), _removeNext); | ||
| } | ||
@@ -54,0 +54,0 @@ _removeNext(); |
+17
-4
@@ -54,2 +54,3 @@ | ||
| var spawnTeams = require('./spawnTeams'); | ||
| var copyMaps = require('./copyMaps'); | ||
@@ -65,2 +66,3 @@ var LOG_LEVEL = 'warning'; | ||
| var SPAWN = 'spawn'; | ||
| var COPY_MAPS = 'copy-maps'; | ||
@@ -109,6 +111,12 @@ // prints the help function | ||
| function _printCopyMapsHelp() { | ||
| console.log('Usage:'); | ||
| console.log(' archon copy-maps'); | ||
| console.log(' copies maps packaged into battlecode into the maps/ folder'); | ||
| } | ||
| function _printHelp() { | ||
| console.log('Usage:'); | ||
| console.log(' archon [clean/replay/match/kill/spawn]'); | ||
| console.log('See archon [clean/replay/match/kill/spawn] --help for more info'); | ||
| console.log(' archon [clean/replay/match/kill/spawn/copy-maps]'); | ||
| console.log('See archon [clean/replay/match/kill/spawn/copy-maps] --help for more info'); | ||
| } | ||
@@ -176,2 +184,3 @@ | ||
| var spawn = argv._.indexOf(SPAWN) !== -1; | ||
| var copy_maps = argv._.indexOf(COPY_MAPS) !== -1; | ||
@@ -196,2 +205,4 @@ var teamFolder = validate.getTeamsOrSrc(); | ||
| _printSpawnHelp(); | ||
| } else if (copy_maps) { | ||
| _printCopyMapsHelp(); | ||
| } else { | ||
@@ -207,3 +218,3 @@ _printHelp(); | ||
| } else if (kill) { | ||
| clearTeams.clear(teamFolder, function() { | ||
| clearTeams.clear(function() { | ||
| console.log("Successfully killed all spawned teams"); | ||
@@ -213,5 +224,7 @@ }); | ||
| spawnTeams.spawn(cleanArgs(argv._), argv.a, argv.b, argv.g); | ||
| } else if (copy_maps) { | ||
| copyMaps(); | ||
| } else { | ||
| _runMatches(); | ||
| } | ||
| }).call(this); | ||
| }).call(this); |
+3
-2
@@ -10,3 +10,3 @@ { | ||
| ], | ||
| "version": "3.0.3", | ||
| "version": "3.1.0", | ||
| "license": "MIT", | ||
@@ -23,3 +23,4 @@ "repository": { | ||
| "git": "*", | ||
| "request": "*" | ||
| "request": "*", | ||
| "yauzl": "2.4.1" | ||
| }, | ||
@@ -26,0 +27,0 @@ "devDependencies": {}, |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 2 instances
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 3 instances
51377
3.85%18
5.88%1407
3.91%5
25%+ Added
+ Added
+ Added
+ Added