Created
September 24, 2017 04:53
-
-
Save damosuzuki/8454d5668a7bf5ac8fa6044c1bee9b5e to your computer and use it in GitHub Desktop.
clone-unity-projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// Usage | |
// $ npm install nodegit | |
// $ node clone-projects.js | |
const git = require("nodegit"); | |
const url = require("url"); | |
const os = require("os"); | |
const path = require("path"); | |
const { spawn } = require("child_process"); | |
const UNITY_MAC = "/Applications/Unity/Unity.app/Contents/MacOS/Unity"; | |
const UNITY_WIN = "C:\\Program Files\\Unity\\Editor\\Unity.exe"; | |
let projects = [ | |
{ url: "https://github.com/TimeWalkOrg/timewalk.git", branch: "origin/night-day-cycle" }, | |
{ url: "https://github.com/TimeWalkOrg/location-mill-valley-ca.git", branch: "origin/initial-layout" } | |
]; | |
let clonedProjects = []; | |
let processing = false; | |
function cloneProjects(){ | |
projects.forEach(proj => { | |
let path = url.parse(proj.url).pathname; | |
let repoPath = "SCRATCH-" + path.split("/").pop(); | |
console.log(`Cloning ${proj.url}#${proj.branch} to ${repoPath}`); | |
git.Clone(proj.url, repoPath) | |
.then((repo) => { | |
return repo.checkoutBranch(proj.branch); | |
}) | |
.then(() => { | |
proj.path = repoPath; | |
clonedProjects.push(proj); | |
processProjects(); | |
}) | |
.catch(function(err) { console.log(err); }); | |
}); | |
} | |
function processProjects(){ | |
if(processing) return; | |
if(clonedProjects.length === 0) { | |
console.log("Processing complete."); | |
return; | |
} | |
const project = clonedProjects.shift(); | |
const projectPath = project.path; | |
const commands = [ | |
"-quit", | |
"-batchmode", | |
"-projectPath", path.join(process.cwd(), projectPath), | |
"-executeMethod", "ExternalPackageManager.ImportAll" | |
]; | |
console.log("Processing " + projectPath); | |
processing = true; | |
const unityImport = spawn(os.platform().indexOf("win") === 0 ? UNITY_WIN : UNITY_MAC, commands); | |
unityImport.stdout.on("data", (data) => { | |
console.log(`Unity Import: ${data}`); | |
}); | |
unityImport.stderr.on("data", (data) => { | |
console.error(`Unity Import (error): ${data}`); | |
}); | |
unityImport.on("close", (code) => { | |
console.log(`Unity Import exited with code ${code}`); | |
processing = false; | |
processProjects(); | |
}); | |
} | |
if(require.main === module) { | |
cloneProjects(projects.map( project => project.url )); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment