@vnejs/build 0.0.18 → 0.0.19

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/data/index.js +21 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/build",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "Build tools for @vnejs",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/data/index.js CHANGED
@@ -1,27 +1,37 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
3
  const merge = require("lodash.merge");
4
- const { runBuildData } = require("./utils");
5
-
6
- let result = {};
7
4
 
8
- module.exports = (rootDir) => (options) => {
9
- const gameDir = path.join(rootDir, "game");
10
- const distDir = path.join(rootDir, "dist");
5
+ const { runBuildData } = require("./utils");
11
6
 
12
- !options.watch && fs.rmSync(distDir, { recursive: true, force: true });
13
- !options.watch && fs.mkdirSync(distDir);
7
+ const buildDataFunc = (gameDir, distDir) => {
8
+ let result = {};
14
9
 
15
10
  fs.readdirSync(gameDir).forEach((modDir) => {
16
11
  const newData = runBuildData({ modDir: path.join(gameDir, modDir) });
12
+
17
13
  result = merge(result, newData);
18
14
 
19
15
  fs.writeFileSync(path.join(distDir, `media.${modDir}.json`), JSON.stringify(newData.data.media));
20
16
  });
21
17
 
22
- Object.keys(result.label).forEach((label) => {
23
- fs.writeFileSync(path.join(distDir, `label.${label}.json`), JSON.stringify(result.label[label]));
24
- });
18
+ Object.keys(result.label).forEach((label) => fs.writeFileSync(path.join(distDir, `label.${label}.json`), JSON.stringify(result.label[label])));
25
19
 
26
20
  fs.writeFileSync(path.join(distDir, "mods.json"), JSON.stringify(fs.readdirSync(gameDir)));
27
21
  };
22
+
23
+ const recreateDist = (distDir) => {
24
+ fs.rmSync(distDir, { recursive: true, force: true });
25
+ fs.mkdirSync(distDir);
26
+ };
27
+
28
+ module.exports = (rootDir) => (options) => {
29
+ const gameDir = path.join(rootDir, "game");
30
+ const distDir = path.join(rootDir, "dist");
31
+
32
+ recreateDist(distDir);
33
+
34
+ buildDataFunc(gameDir, distDir);
35
+
36
+ options.watch && fs.watch(gameDir, { recursive: true }, (eventType, filename) => filename && buildDataFunc(gameDir, distDir));
37
+ };