@kezh/my-custom-js-converter 0.0.26 → 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.
@@ -6,6 +6,7 @@ export declare namespace Config {
6
6
  decode: DecodeConfig;
7
7
  baseDir: string;
8
8
  target: string[];
9
+ workDir: string;
9
10
  customConfig: string;
10
11
  }
11
12
  interface SubConfig {
@@ -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
- defConfig.target = customConfig.target;
46
- defConfig.encode = customConfig.encode;
47
- defConfig.decode = customConfig.decode;
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, '},\n');
48
+ dist = dist.replace(/},\n\n/g, "},\n");
48
49
  dist = prettier_1.default.format(dist, {
49
- parser: 'babel',
50
- trailingComma: 'none'
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.relative(outDir, mod.path.replace(/index\.js$/, '')).replace(/[\\]+/g, '/');
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 => ");
@@ -339,13 +340,14 @@ function modifyModMethods(mod, methodNames, modAst) {
339
340
  }
340
341
  });
341
342
  }
342
- function refreshCustomConfig(modPathByName, inPath, config = CUSTOM_CONFIG) {
343
- const configPath = path_1.default.join(inPath, config);
343
+ function refreshCustomConfig(modPathByName, inPath, workDir = WORK_DIR, custConfig = CUSTOM_CONFIG) {
344
+ const configPath = path_1.default.join(inPath, workDir, custConfig);
344
345
  let configObj = {
345
346
  mod: [],
346
347
  version: ""
347
348
  };
348
349
  try {
350
+ mkWorkDir(inPath);
349
351
  fs_1.default.accessSync(configPath, fs_1.default.constants.F_OK);
350
352
  const data = fs_1.default.readFileSync(configPath, { encoding: "utf-8" });
351
353
  configObj = JSON.parse(data);
@@ -356,3 +358,12 @@ function refreshCustomConfig(modPathByName, inPath, config = CUSTOM_CONFIG) {
356
358
  configObj.mod = [...modPathByName.entries()].map(([key, value]) => new config_1.Config.Mod(key, value));
357
359
  fs_1.default.writeFileSync(configPath, JSON.stringify(configObj, null, 4), "utf-8");
358
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kezh/my-custom-js-converter",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
4
4
  "description": "自定义代码转换器",
5
5
  "main": "index.js",
6
6
  "bin": {