@kezh/my-custom-js-converter 0.0.26 → 0.0.28
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 +17 -3
- 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 => ");
|
|
@@ -62,10 +63,13 @@ function encoding$0(inPath, outPath) {
|
|
|
62
63
|
});
|
|
63
64
|
const srcAst = (0, parser_1.parse)(src);
|
|
64
65
|
const methods = [];
|
|
66
|
+
const customMethodNames = getSrcMethodNames(ENTRY, srcAst);
|
|
67
|
+
if (!customMethodNames.length) {
|
|
68
|
+
console.log(`not found entry => ${ENTRY}`);
|
|
69
|
+
}
|
|
65
70
|
const importModPathByName = getImportModPaths(path_1.default.dirname(inPath), srcAst);
|
|
66
71
|
const importMethodNamesByMod = getImportMethodNames([...importModPathByName.keys()], srcAst);
|
|
67
72
|
const importMethods = getImportMethods(importModPathByName, importMethodNamesByMod);
|
|
68
|
-
const customMethodNames = getSrcMethodNames(ENTRY, srcAst);
|
|
69
73
|
modifyCallObjectAndMethodNames(customMethodNames, [...importModPathByName.keys()], srcAst);
|
|
70
74
|
const customMethods = getMethods(ENTRY, srcAst);
|
|
71
75
|
methods.push(...customMethods, ...importMethods);
|
|
@@ -339,13 +343,14 @@ function modifyModMethods(mod, methodNames, modAst) {
|
|
|
339
343
|
}
|
|
340
344
|
});
|
|
341
345
|
}
|
|
342
|
-
function refreshCustomConfig(modPathByName, inPath,
|
|
343
|
-
const configPath = path_1.default.join(inPath,
|
|
346
|
+
function refreshCustomConfig(modPathByName, inPath, workDir = WORK_DIR, custConfig = CUSTOM_CONFIG) {
|
|
347
|
+
const configPath = path_1.default.join(inPath, workDir, custConfig);
|
|
344
348
|
let configObj = {
|
|
345
349
|
mod: [],
|
|
346
350
|
version: ""
|
|
347
351
|
};
|
|
348
352
|
try {
|
|
353
|
+
mkWorkDir(inPath);
|
|
349
354
|
fs_1.default.accessSync(configPath, fs_1.default.constants.F_OK);
|
|
350
355
|
const data = fs_1.default.readFileSync(configPath, { encoding: "utf-8" });
|
|
351
356
|
configObj = JSON.parse(data);
|
|
@@ -356,3 +361,12 @@ function refreshCustomConfig(modPathByName, inPath, config = CUSTOM_CONFIG) {
|
|
|
356
361
|
configObj.mod = [...modPathByName.entries()].map(([key, value]) => new config_1.Config.Mod(key, value));
|
|
357
362
|
fs_1.default.writeFileSync(configPath, JSON.stringify(configObj, null, 4), "utf-8");
|
|
358
363
|
}
|
|
364
|
+
function mkWorkDir(inPath, workDir = WORK_DIR) {
|
|
365
|
+
const workDirPath = path_1.default.join(inPath, workDir);
|
|
366
|
+
try {
|
|
367
|
+
fs_1.default.accessSync(workDirPath);
|
|
368
|
+
}
|
|
369
|
+
catch (err) {
|
|
370
|
+
fs_1.default.mkdirSync(workDirPath);
|
|
371
|
+
}
|
|
372
|
+
}
|