diff --git a/bin/ensure_minecraft_data.js b/bin/ensure_minecraft_data.js new file mode 100644 index 00000000..9301cdea --- /dev/null +++ b/bin/ensure_minecraft_data.js @@ -0,0 +1,28 @@ +#!/usr/bin/env node + +const fs = require('fs') +const { spawnSync } = require('child_process') + +const dataPaths = 'minecraft-data/data/dataPaths.json' +const dataRepo = 'https://github.com/mneuhaus/minecraft-data.git' +const dataBranch = 'pc_26_1_2' + +if (fs.existsSync(dataPaths)) process.exit(0) + +if (fs.existsSync('.git')) { + const result = spawnSync('git', ['submodule', 'update', '--init', '--recursive'], { stdio: 'inherit' }) + if (result.status === 0 && fs.existsSync(dataPaths)) process.exit(0) +} + +fs.rmSync('minecraft-data', { recursive: true, force: true }) + +const clone = spawnSync('git', ['clone', '--depth', '1', '--filter=blob:none', '--sparse', '--branch', dataBranch, dataRepo, 'minecraft-data'], { stdio: 'inherit' }) +if (clone.status !== 0) process.exit(clone.status || 1) + +const sparse = spawnSync('git', ['-C', 'minecraft-data', 'sparse-checkout', 'set', 'data', 'schemas'], { stdio: 'inherit' }) +if (sparse.status !== 0) process.exit(sparse.status || 1) + +if (!fs.existsSync(dataPaths)) { + console.error(`Could not load ${dataPaths}`) + process.exit(1) +} diff --git a/minecraft-data b/minecraft-data index 2dd48a4a..bc0c5957 160000 --- a/minecraft-data +++ b/minecraft-data @@ -1 +1 @@ -Subproject commit 2dd48a4adf77cd32b1d5a26dc92373be94768d06 +Subproject commit bc0c5957ff925778660f253f9d1ea51c06d14087 diff --git a/package.json b/package.json index 58de958a..045fc719 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "test:types": "tsc typings/test-typings && node typings/test-typings.js", "test": "npm run generate:types && npm run generate:data && npm run lint && npm run test:types && mocha", "lint": "standard", - "prepare": "npm run generate:data && npm run generate:types", + "prepare": "node ./bin/ensure_minecraft_data.js && npm run generate:data && npm run generate:types", "fix": "standard --fix" }, "standard": {