bc-minecraft-project 1.21.1-4 → 1.21.44-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/src/Lib/mcattributes.js +11 -11
- package/lib/src/Lib/mcdefinitions.js +13 -13
- package/lib/src/Lib/mcignore.js +13 -17
- package/lib/src/Lib/project.js +6 -12
- package/package.json +12 -8
|
@@ -17,23 +17,23 @@ var MCAttributes;
|
|
|
17
17
|
* @param content The content that one would get as in a file
|
|
18
18
|
* @returns A parsed version based on the contents, or an empty object*/
|
|
19
19
|
function parse(content) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const parts = content.split(/(\r\n|\n)/);
|
|
21
|
+
const result = {};
|
|
22
22
|
parts.forEach((property) => {
|
|
23
|
-
|
|
23
|
+
const cindex = property.indexOf("#");
|
|
24
24
|
if (cindex >= 0) {
|
|
25
25
|
property = property.substring(0, cindex).trim();
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
const index = property.indexOf("=");
|
|
28
28
|
if (index >= 0) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const name = property.substring(0, index);
|
|
30
|
+
const value = property.substring(index + 1, property.length);
|
|
31
31
|
//Write value
|
|
32
32
|
if (name !== "")
|
|
33
|
-
|
|
33
|
+
result[name] = value;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
return
|
|
36
|
+
return result;
|
|
37
37
|
}
|
|
38
38
|
MCAttributes.parse = parse;
|
|
39
39
|
/**Converts the given MCAttributes to file content
|
|
@@ -53,7 +53,7 @@ var MCAttributes;
|
|
|
53
53
|
* @param items The first data set
|
|
54
54
|
* @returns A new object with the combined attributes*/
|
|
55
55
|
function merge(...items) {
|
|
56
|
-
|
|
56
|
+
const Out = createEmpty();
|
|
57
57
|
for (const item of items) {
|
|
58
58
|
for (const Key in item) {
|
|
59
59
|
const value = item[Key];
|
|
@@ -81,7 +81,7 @@ var MCAttributes;
|
|
|
81
81
|
* @returns A filled MCAttributes*/
|
|
82
82
|
function loadSync(filepath) {
|
|
83
83
|
if (fs.existsSync(filepath)) {
|
|
84
|
-
|
|
84
|
+
const buffer = fs.readFileSync(filepath);
|
|
85
85
|
return parse(buffer.toString());
|
|
86
86
|
}
|
|
87
87
|
return {};
|
|
@@ -91,7 +91,7 @@ var MCAttributes;
|
|
|
91
91
|
* @param filepath The path to the file to load
|
|
92
92
|
* @returns A filled promise that returns a MCAttributes*/
|
|
93
93
|
async function load(filepath) {
|
|
94
|
-
|
|
94
|
+
const P = fs.promises.readFile(filepath);
|
|
95
95
|
return P.then((buffer) => parse(buffer.toString()));
|
|
96
96
|
}
|
|
97
97
|
MCAttributes.load = load;
|
|
@@ -22,16 +22,16 @@ var Definition;
|
|
|
22
22
|
* @param key The key each item will be receiving
|
|
23
23
|
* @returns A text rep of the object for files*/
|
|
24
24
|
function toString(container, key) {
|
|
25
|
-
let
|
|
26
|
-
|
|
25
|
+
let result = "";
|
|
26
|
+
result += `## ${key}\n`;
|
|
27
27
|
for (let I = 0; I < container.defined.length; I++) {
|
|
28
|
-
|
|
28
|
+
result += `${key}=${container.defined[I]}\n`;
|
|
29
29
|
}
|
|
30
30
|
for (let I = 0; I < container.excluded.length; I++) {
|
|
31
|
-
|
|
31
|
+
result += `${key}=!${container.excluded[I]}\n`;
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
return
|
|
33
|
+
result += "\n";
|
|
34
|
+
return result;
|
|
35
35
|
}
|
|
36
36
|
Definition.toString = toString;
|
|
37
37
|
/**Creates an empty version of the interface Definition
|
|
@@ -66,8 +66,8 @@ var MCDefinition;
|
|
|
66
66
|
/**Converts the given contents as if its file contents and returns a MCDefinition object
|
|
67
67
|
* @param content The contents of the given files*/
|
|
68
68
|
function parse(content) {
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
const parts = content.split(/(\r\n|\n)/);
|
|
70
|
+
const Out = MCDefinition.createEmpty();
|
|
71
71
|
parts.forEach((property) => {
|
|
72
72
|
//Remove comment
|
|
73
73
|
const cindex = property.indexOf("#");
|
|
@@ -78,7 +78,7 @@ var MCDefinition;
|
|
|
78
78
|
if (index >= 0) {
|
|
79
79
|
const name = property.substring(0, index).toLowerCase();
|
|
80
80
|
const value = property.substring(index + 1, property.length);
|
|
81
|
-
|
|
81
|
+
const container = getOrAdd(Out, name);
|
|
82
82
|
Definition.add(container, value);
|
|
83
83
|
}
|
|
84
84
|
});
|
|
@@ -103,8 +103,8 @@ var MCDefinition;
|
|
|
103
103
|
* @returns A text rep of the object*/
|
|
104
104
|
function toString(data) {
|
|
105
105
|
let Out = "";
|
|
106
|
-
for (
|
|
107
|
-
|
|
106
|
+
for (const key in data) {
|
|
107
|
+
const item = data[key];
|
|
108
108
|
if (Definition.is(item)) {
|
|
109
109
|
Out += Definition.toString(item, key);
|
|
110
110
|
}
|
|
@@ -144,7 +144,7 @@ var MCDefinition;
|
|
|
144
144
|
* @returns A filled MCDefinition*/
|
|
145
145
|
function loadSync(filepath) {
|
|
146
146
|
if (fs.existsSync(filepath)) {
|
|
147
|
-
|
|
147
|
+
const buffer = fs.readFileSync(filepath);
|
|
148
148
|
return parse(buffer.toString());
|
|
149
149
|
}
|
|
150
150
|
return createEmpty();
|
|
@@ -154,7 +154,7 @@ var MCDefinition;
|
|
|
154
154
|
* @param filepath The path to the file to load
|
|
155
155
|
* @returns A filled promise that returns a MCDefinition*/
|
|
156
156
|
async function load(filepath) {
|
|
157
|
-
|
|
157
|
+
const P = fs.promises.readFile(filepath);
|
|
158
158
|
return P.then((buffer) => parse(buffer.toString()));
|
|
159
159
|
}
|
|
160
160
|
MCDefinition.load = load;
|
package/lib/src/Lib/mcignore.js
CHANGED
|
@@ -18,12 +18,12 @@ var MCIgnore;
|
|
|
18
18
|
* @param B The second data set
|
|
19
19
|
* @returns A new object with the combined patterns*/
|
|
20
20
|
function merge(A, B) {
|
|
21
|
-
|
|
21
|
+
const result = MCIgnore.createEmpty();
|
|
22
22
|
if (A)
|
|
23
|
-
|
|
23
|
+
result.patterns.push(...A.patterns);
|
|
24
24
|
if (B)
|
|
25
|
-
|
|
26
|
-
return
|
|
25
|
+
result.patterns.push(...B.patterns);
|
|
26
|
+
return result;
|
|
27
27
|
}
|
|
28
28
|
MCIgnore.merge = merge;
|
|
29
29
|
/** Checks wheter or not the given object implements MCIgnore
|
|
@@ -40,22 +40,19 @@ var MCIgnore;
|
|
|
40
40
|
* @param content The content that one would get as in a file
|
|
41
41
|
* @returns A parsed version based on the contents, or an empty object*/
|
|
42
42
|
function parse(content) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
return Out;
|
|
43
|
+
return {
|
|
44
|
+
patterns: content
|
|
45
|
+
.split(/(\r\n|\n)/)
|
|
46
|
+
.map((item) => item.trim())
|
|
47
|
+
.filter((item) => item !== ""),
|
|
48
|
+
};
|
|
51
49
|
}
|
|
52
50
|
MCIgnore.parse = parse;
|
|
53
51
|
/**Converts the given MCIgnore to file content
|
|
54
52
|
* @param data The MCIgnore data to convert
|
|
55
53
|
* @returns A string represerntation of the contents of a MCIgnore*/
|
|
56
54
|
function toString(data) {
|
|
57
|
-
|
|
58
|
-
return Out;
|
|
55
|
+
return data.patterns.join("\n");
|
|
59
56
|
}
|
|
60
57
|
MCIgnore.toString = toString;
|
|
61
58
|
/** Loads the content of the given file into a MCIgnore
|
|
@@ -63,7 +60,7 @@ var MCIgnore;
|
|
|
63
60
|
* @returns A filled MCIgnore*/
|
|
64
61
|
function loadSync(filepath) {
|
|
65
62
|
if (fs.existsSync(filepath)) {
|
|
66
|
-
|
|
63
|
+
const buffer = fs.readFileSync(filepath);
|
|
67
64
|
return parse(buffer.toString());
|
|
68
65
|
}
|
|
69
66
|
return createEmpty();
|
|
@@ -73,8 +70,7 @@ var MCIgnore;
|
|
|
73
70
|
* @param filepath The path to the file to load
|
|
74
71
|
* @returns A filled promise that returns a MCIgnore*/
|
|
75
72
|
async function load(filepath) {
|
|
76
|
-
|
|
77
|
-
return P.then((buffer) => parse(buffer.toString()));
|
|
73
|
+
return fs.promises.readFile(filepath).then((buffer) => parse(buffer.toString()));
|
|
78
74
|
}
|
|
79
75
|
MCIgnore.load = load;
|
|
80
76
|
/** Saves the given MCIgnore into the specified file
|
package/lib/src/Lib/project.js
CHANGED
|
@@ -38,22 +38,16 @@ var MCProject;
|
|
|
38
38
|
* @param Source The root folder to retrieve files from
|
|
39
39
|
* @returns*/
|
|
40
40
|
function loadSync(Source) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
attributes: Attributes,
|
|
46
|
-
definitions: Definitions,
|
|
47
|
-
ignores: Ignores,
|
|
48
|
-
};
|
|
41
|
+
const attributes = mcattributes_1.MCAttributes.loadSync(path.join(Source, mcattributes_1.MCAttributes.filename));
|
|
42
|
+
const definitions = mcdefinitions_1.MCDefinition.loadSync(path.join(Source, mcdefinitions_1.MCDefinition.filename));
|
|
43
|
+
const ignores = mcignore_1.MCIgnore.loadSync(path.join(Source, mcignore_1.MCIgnore.filename));
|
|
44
|
+
return { attributes, definitions, ignores };
|
|
49
45
|
}
|
|
50
46
|
MCProject.loadSync = loadSync;
|
|
51
47
|
/**Loads from the given root folder the necessary project files
|
|
52
48
|
* @param Source The root folder to retrieve files from*/
|
|
53
49
|
function load(Source) {
|
|
54
|
-
return new Promise((resolve
|
|
55
|
-
resolve(loadSync(Source));
|
|
56
|
-
});
|
|
50
|
+
return new Promise((resolve) => resolve(loadSync(Source)));
|
|
57
51
|
}
|
|
58
52
|
MCProject.load = load;
|
|
59
53
|
/**Saves the gives project into the specified folder
|
|
@@ -70,7 +64,7 @@ var MCProject;
|
|
|
70
64
|
* @param project The data to save
|
|
71
65
|
* @returns A promise that is done wheter the data has been written*/
|
|
72
66
|
async function save(Folder, project) {
|
|
73
|
-
|
|
67
|
+
const P = [
|
|
74
68
|
mcattributes_1.MCAttributes.save(project.attributes, path.join(Folder, mcattributes_1.MCAttributes.filename)),
|
|
75
69
|
mcignore_1.MCIgnore.save(project.ignores, path.join(Folder, mcignore_1.MCIgnore.filename)),
|
|
76
70
|
mcdefinitions_1.MCDefinition.save(project.definitions, path.join(Folder, mcdefinitions_1.MCDefinition.filename)),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bc-minecraft-project",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.44-0",
|
|
4
4
|
"description": "A library that provides object and handling for minecraft projects",
|
|
5
5
|
"main": "./lib/src/main.js",
|
|
6
6
|
"types": "./lib/src/main.d.ts",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"compile": "tsc -b",
|
|
9
9
|
"build": "npm run clean && npm run compile",
|
|
10
10
|
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
11
|
-
"test": "
|
|
11
|
+
"test": "jest",
|
|
12
|
+
"lint": "eslint",
|
|
12
13
|
"clean": "rimraf lib",
|
|
13
14
|
"pretest": "npm run compile",
|
|
14
15
|
"prepublishOnly": "npm test",
|
|
@@ -38,13 +39,16 @@
|
|
|
38
39
|
"lib/src/**/*"
|
|
39
40
|
],
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@types/
|
|
43
|
-
"@types/
|
|
44
|
-
"
|
|
45
|
-
"
|
|
42
|
+
"@eslint/js": "^9.9.1",
|
|
43
|
+
"@types/eslint__js": "^8.42.3",
|
|
44
|
+
"@types/jest": "^29.5.12",
|
|
45
|
+
"@types/node": "^22.5.4",
|
|
46
|
+
"eslint": "^9.9.1",
|
|
47
|
+
"eslint-plugin-jest": "^28.8.3",
|
|
46
48
|
"rimraf": "^6.0.1",
|
|
49
|
+
"ts-jest": "^29.2.5",
|
|
47
50
|
"ts-node": "^10.9.1",
|
|
48
|
-
"typescript": "^5.2.2"
|
|
51
|
+
"typescript": "^5.2.2",
|
|
52
|
+
"typescript-eslint": "^8.4.0"
|
|
49
53
|
}
|
|
50
54
|
}
|