-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathextract_datafolder.js
More file actions
84 lines (72 loc) · 1.99 KB
/
Copy pathextract_datafolder.js
File metadata and controls
84 lines (72 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict'
const fs = require('fs-extra')
const path = require('path')
const getMinecraftFiles = require('./get_minecraft_files')
if (process.argv.length !== 5) {
console.log(
'Usage : node extract_datafolder.js <version1,version2,...> <output_dir> <temporary_dir>'
)
process.exit(1)
}
const minecraftVersions = process.argv[2].split(',')
const outputDir = path.resolve(process.argv[3])
const temporaryDir = path.resolve(process.argv[4])
minecraftVersions.forEach(minecraftVersion => {
extract(
minecraftVersion,
outputDir + '/' + minecraftVersion,
temporaryDir,
function (err) {
if (err) {
console.log(err.stack)
return
}
console.log('done ' + minecraftVersion + '!')
}
)
})
function copyFileSync (source, target) {
let targetFile = target
if (fs.existsSync(target)) {
if (fs.lstatSync(target).isDirectory()) {
targetFile = path.join(target, path.basename(source))
}
}
fs.writeFileSync(targetFile, fs.readFileSync(source))
}
function copyFolderRecursiveSync (source, target) {
let files = []
const targetFolder = path.join(target, path.basename(source))
if (!fs.existsSync(targetFolder)) {
fs.mkdirSync(targetFolder)
}
if (fs.lstatSync(source).isDirectory()) {
files = fs.readdirSync(source)
files.forEach(function (file) {
const curSource = path.join(source, file)
if (fs.lstatSync(curSource).isDirectory()) {
copyFolderRecursiveSync(curSource, targetFolder)
} else {
copyFileSync(curSource, targetFolder)
}
})
}
}
function extract (minecraftVersion, outputDir, temporaryDir, cb) {
getMinecraftFiles(minecraftVersion, temporaryDir, function (
err,
unzippedFilesDir
) {
if (err) {
cb(err)
return
}
fs.mkdirpSync(outputDir)
copyFolderRecursiveSync(
path.join(unzippedFilesDir, 'data', 'minecraft'),
outputDir
)
fs.rename(path.join(outputDir, 'minecraft'), path.join(outputDir, 'data'))
cb()
})
}