@kezh/my-custom-js-converter 0.0.25 → 0.0.27
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/core/config/index.d.ts +1 -0
- package/core/config/index.js +6 -3
- package/core/decode.js +9 -6
- package/core/encode.js +19 -2
- package/package.json +1 -1
package/core/config/index.d.ts
CHANGED
package/core/config/index.js
CHANGED
|
@@ -32,6 +32,7 @@ function config() {
|
|
|
32
32
|
},
|
|
33
33
|
baseDir: "",
|
|
34
34
|
target: [""],
|
|
35
|
+
workDir: ".setting",
|
|
35
36
|
customConfig: "config.json",
|
|
36
37
|
};
|
|
37
38
|
const curDir = __dirname;
|
|
@@ -42,9 +43,11 @@ function config() {
|
|
|
42
43
|
const json = fs_1.default.readFileSync(configPath, { encoding: "utf-8" });
|
|
43
44
|
const customConfig = JSON.parse(json);
|
|
44
45
|
defConfig.baseDir = baseDir;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
Object.keys(customConfig).map(key => key).forEach((key) => {
|
|
47
|
+
if (customConfig[key]) {
|
|
48
|
+
defConfig[key] = customConfig[key];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
48
51
|
}
|
|
49
52
|
catch (err) { }
|
|
50
53
|
return defConfig;
|
package/core/decode.js
CHANGED
|
@@ -16,6 +16,7 @@ const TARGET_DIR = (0, scanf_1.scanfCodeDirs)(config_1.default.baseDir, config_1
|
|
|
16
16
|
const DECODE_FILE = config_1.default.decode.file;
|
|
17
17
|
const OUTPUT_FILE = config_1.default.decode.output;
|
|
18
18
|
const MOUNT = config_1.default.decode.mount;
|
|
19
|
+
const WORK_DIR = config_1.default.workDir;
|
|
19
20
|
const CUSTOM_CONFIG = config_1.default.customConfig;
|
|
20
21
|
(function decoding(targetDirs = TARGET_DIR) {
|
|
21
22
|
console.log("scanf dirs => ");
|
|
@@ -44,16 +45,18 @@ function decoding$0(inPath, outPath, mount = MOUNT) {
|
|
|
44
45
|
importMods(path_1.default.dirname(outPath), customConfig.mod, srcAst);
|
|
45
46
|
deleteModMethods(customConfig.mod, srcAst);
|
|
46
47
|
let { code: dist } = (0, generator_1.default)(srcAst);
|
|
47
|
-
dist = dist.replace(/},\n\n/g,
|
|
48
|
+
dist = dist.replace(/},\n\n/g, "},\n");
|
|
48
49
|
dist = prettier_1.default.format(dist, {
|
|
49
|
-
parser:
|
|
50
|
-
trailingComma:
|
|
50
|
+
parser: "babel",
|
|
51
|
+
trailingComma: "none"
|
|
51
52
|
});
|
|
52
53
|
fs_1.default.writeFileSync(outPath, dist, "utf-8");
|
|
53
54
|
}
|
|
54
55
|
function importMods(outDir, mods, srcAst) {
|
|
55
56
|
const importMods = mods.map((mod) => {
|
|
56
|
-
const requireFrom = path_1.default
|
|
57
|
+
const requireFrom = path_1.default
|
|
58
|
+
.relative(outDir, mod.path.replace(/index\.js$/, ""))
|
|
59
|
+
.replace(/[\\]+/g, "/");
|
|
57
60
|
const variableDeclarator = core_1.types.variableDeclarator(core_1.types.identifier(mod.name), core_1.types.callExpression(core_1.types.identifier("require"), [
|
|
58
61
|
core_1.types.stringLiteral(requireFrom)
|
|
59
62
|
]));
|
|
@@ -98,8 +101,8 @@ function deleteModMethods(mods, srcAst) {
|
|
|
98
101
|
}
|
|
99
102
|
});
|
|
100
103
|
}
|
|
101
|
-
function loadCustomConfig(inPath, config = CUSTOM_CONFIG) {
|
|
102
|
-
const configPath = path_1.default.join(inPath, config);
|
|
104
|
+
function loadCustomConfig(inPath, workDir = WORK_DIR, config = CUSTOM_CONFIG) {
|
|
105
|
+
const configPath = path_1.default.join(inPath, workDir, config);
|
|
103
106
|
let configObj = {
|
|
104
107
|
mod: [],
|
|
105
108
|
version: ""
|
package/core/encode.js
CHANGED
|
@@ -39,6 +39,7 @@ const ENCODE_FILE = config_1.default.encode.file;
|
|
|
39
39
|
const OUTPUT_FILE = config_1.default.encode.output;
|
|
40
40
|
const ENTRY = config_1.default.encode.entry;
|
|
41
41
|
const IGNORE_MOD = config_1.default.encode.ignoreMod;
|
|
42
|
+
const WORK_DIR = config_1.default.workDir;
|
|
42
43
|
const CUSTOM_CONFIG = config_1.default.customConfig;
|
|
43
44
|
(function encoding(targetDirs = TARGET_DIR) {
|
|
44
45
|
console.log("scanf dirs => ");
|
|
@@ -326,6 +327,12 @@ function modifyModMethods(mod, methodNames, modAst) {
|
|
|
326
327
|
if (methodNames.includes(property.name)) {
|
|
327
328
|
if (core_1.types.isIdentifier(path.node.object) ||
|
|
328
329
|
core_1.types.isThisExpression(path.node.object)) {
|
|
330
|
+
if (core_1.types.isIdentifier(path.node.object)) {
|
|
331
|
+
const object = path.node.object;
|
|
332
|
+
if (object.name !== mod) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
329
336
|
property.name = `${property.name}__${mod}`;
|
|
330
337
|
}
|
|
331
338
|
}
|
|
@@ -333,13 +340,14 @@ function modifyModMethods(mod, methodNames, modAst) {
|
|
|
333
340
|
}
|
|
334
341
|
});
|
|
335
342
|
}
|
|
336
|
-
function refreshCustomConfig(modPathByName, inPath,
|
|
337
|
-
const configPath = path_1.default.join(inPath,
|
|
343
|
+
function refreshCustomConfig(modPathByName, inPath, workDir = WORK_DIR, custConfig = CUSTOM_CONFIG) {
|
|
344
|
+
const configPath = path_1.default.join(inPath, workDir, custConfig);
|
|
338
345
|
let configObj = {
|
|
339
346
|
mod: [],
|
|
340
347
|
version: ""
|
|
341
348
|
};
|
|
342
349
|
try {
|
|
350
|
+
mkWorkDir(inPath);
|
|
343
351
|
fs_1.default.accessSync(configPath, fs_1.default.constants.F_OK);
|
|
344
352
|
const data = fs_1.default.readFileSync(configPath, { encoding: "utf-8" });
|
|
345
353
|
configObj = JSON.parse(data);
|
|
@@ -350,3 +358,12 @@ function refreshCustomConfig(modPathByName, inPath, config = CUSTOM_CONFIG) {
|
|
|
350
358
|
configObj.mod = [...modPathByName.entries()].map(([key, value]) => new config_1.Config.Mod(key, value));
|
|
351
359
|
fs_1.default.writeFileSync(configPath, JSON.stringify(configObj, null, 4), "utf-8");
|
|
352
360
|
}
|
|
361
|
+
function mkWorkDir(inPath, workDir = WORK_DIR) {
|
|
362
|
+
const workDirPath = path_1.default.join(inPath, workDir);
|
|
363
|
+
try {
|
|
364
|
+
fs_1.default.accessSync(workDirPath);
|
|
365
|
+
}
|
|
366
|
+
catch (err) {
|
|
367
|
+
fs_1.default.mkdirSync(workDirPath);
|
|
368
|
+
}
|
|
369
|
+
}
|