@_tc/template-core 0.0.1-bate.13 → 0.0.1-bate.14

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.
@@ -1,43 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.dev = dev;
40
- const path_1 = __importDefault(require("path"));
41
4
  const utils_1 = require("./utils");
42
5
  async function dev() {
43
6
  // 获取入口
@@ -48,21 +11,5 @@ async function dev() {
48
11
  }
49
12
  await (0, utils_1.VBuildFE)(input);
50
13
  // 监听文件变化
51
- const chokidar = await Promise.resolve().then(() => __importStar(require("chokidar")));
52
- const watcher = chokidar.watch(path_1.default.resolve("src"), {
53
- ignored: /(^|[\/\\])\../,
54
- persistent: true,
55
- ignoreInitial: true,
56
- });
57
- let building = false;
58
- watcher.on("change", async (filePath) => {
59
- if (building)
60
- return;
61
- building = true;
62
- console.log(`changed: ${filePath}`);
63
- await (0, utils_1.VBuildFE)(input);
64
- console.log("rebuild done");
65
- building = false;
66
- });
67
- console.log("watching src/...");
14
+ (0, utils_1.watchFiles)(async () => (0, utils_1.VBuildFE)(input));
68
15
  }
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  *
3
3
  * 寻找 frontend\/**\/*.entry.[j|t]s(x)?
4
+ * 生成入口
4
5
  */
5
- export declare function entries(root?: string): Record<string, string>;
6
+ export declare function entries(): Record<string, string>;
6
7
  export declare function outDir(): string;
8
+ export declare const watchFiles: (callback?: () => Promise<any>) => Promise<void>;
7
9
  export declare const VBuildFE: (input: Record<string, string>) => Promise<void>;
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.VBuildFE = void 0;
39
+ exports.VBuildFE = exports.watchFiles = void 0;
40
40
  exports.entries = entries;
41
41
  exports.outDir = outDir;
42
42
  const path_1 = __importDefault(require("path"));
@@ -44,17 +44,19 @@ const glob = __importStar(require("glob"));
44
44
  const vite_1 = require("vite");
45
45
  const utils_1 = require("../packages/utils");
46
46
  const fs_1 = require("fs");
47
+ const base = process.cwd();
48
+ // 瞄准输出后的产物路径
49
+ const framePath = path_1.default.resolve(__dirname, "../../");
50
+ const frameNodePath = path_1.default.resolve(__dirname, "../");
51
+ const frameFEPath = path_1.default.resolve(framePath, "./fe/frontend");
52
+ const runPath = path_1.default.resolve(base, ".");
53
+ const runFEPath = path_1.default.resolve(runPath, "./frontend");
47
54
  /**
48
55
  *
49
56
  * 寻找 frontend\/**\/*.entry.[j|t]s(x)?
57
+ * 生成入口
50
58
  */
51
- function entries(root) {
52
- const base = root ? path_1.default.resolve(root) : process.cwd();
53
- // 瞄准输出后的产物路径
54
- const framePath = path_1.default.resolve(__dirname, "../../");
55
- const frameNodePath = path_1.default.resolve(__dirname, "../");
56
- const frameFEPath = path_1.default.resolve(framePath, "./fe/frontend");
57
- const runFEPath = path_1.default.resolve(base, "./frontend");
59
+ function entries() {
58
60
  console.log("frameFEPath: ", frameFEPath);
59
61
  console.log("runFEPath: ", runFEPath);
60
62
  /**
@@ -68,7 +70,6 @@ function entries(root) {
68
70
  .filter((fileName) => !fileName.includes(".d.ts"));
69
71
  return [...o, ...files];
70
72
  }, []);
71
- console.log(files);
72
73
  const input = {};
73
74
  if (!files.length)
74
75
  return input;
@@ -80,9 +81,7 @@ function entries(root) {
80
81
  for (let index = 0; index < files.length; index++) {
81
82
  const filePath = files[index];
82
83
  const fileDIr = path_1.default.resolve(filePath, "../");
83
- console.log(fileDIr);
84
84
  const fileHtml = glob.sync((0, utils_1.resolve)(fileDIr, "*.html"))[0];
85
- console.log(fileHtml);
86
85
  if (!fileHtml) {
87
86
  if (!templateHtml) {
88
87
  templateHtml = (0, fs_1.readFileSync)(path_1.default.resolve(frameNodePath, "./app/view/entry.tpl"), "utf-8");
@@ -90,7 +89,6 @@ function entries(root) {
90
89
  //
91
90
  const scriptStr = filePath.split(path_1.default.sep).at(-1);
92
91
  const content = templateHtml.replace(`<!-- {{InsertScript}} -->`, `<script type="module" src="./${scriptStr}"></script>`);
93
- console.log(content);
94
92
  const htmlName = fileDIr.split(path_1.default.sep).at(-1);
95
93
  const htmlPath = path_1.default.join(fileDIr, htmlName + ".html");
96
94
  (0, fs_1.writeFileSync)(htmlPath, content);
@@ -110,8 +108,30 @@ function entries(root) {
110
108
  return input;
111
109
  }
112
110
  function outDir() {
113
- return "dist";
111
+ // 为了保持代码 能见性 输出地址应该为 runPath/app/publish/dist
112
+ return path_1.default.join(runPath, "./app/publish/dist");
114
113
  }
114
+ const watchFiles = async (callback) => {
115
+ const chokidar = await Promise.resolve().then(() => __importStar(require("chokidar")));
116
+ // 在实际使用时 只有使用方的文件会变化
117
+ const watcher = chokidar.watch(runFEPath, {
118
+ ignored: /(^|[\/\\])\../,
119
+ persistent: true,
120
+ ignoreInitial: true,
121
+ });
122
+ let building = false;
123
+ watcher.on("change", async (filePath) => {
124
+ if (building)
125
+ return;
126
+ building = true;
127
+ console.log(`changed: ${filePath}`);
128
+ await callback?.();
129
+ console.log("rebuild done");
130
+ building = false;
131
+ });
132
+ console.log(`watching ${runFEPath}/...`);
133
+ };
134
+ exports.watchFiles = watchFiles;
115
135
  const VBuildFE = async (input) => {
116
136
  // 根据入口构建
117
137
  await (0, vite_1.build)({
@@ -1,5 +1,4 @@
1
- import path from "path";
2
- import { entries, VBuildFE } from "./utils";
1
+ import { entries, VBuildFE, watchFiles } from "./utils";
3
2
  export async function dev() {
4
3
  // 获取入口
5
4
  const input = entries();
@@ -9,21 +8,5 @@ export async function dev() {
9
8
  }
10
9
  await VBuildFE(input);
11
10
  // 监听文件变化
12
- const chokidar = await import("chokidar");
13
- const watcher = chokidar.watch(path.resolve("src"), {
14
- ignored: /(^|[\/\\])\../,
15
- persistent: true,
16
- ignoreInitial: true,
17
- });
18
- let building = false;
19
- watcher.on("change", async (filePath) => {
20
- if (building)
21
- return;
22
- building = true;
23
- console.log(`changed: ${filePath}`);
24
- await VBuildFE(input);
25
- console.log("rebuild done");
26
- building = false;
27
- });
28
- console.log("watching src/...");
11
+ watchFiles(async () => VBuildFE(input));
29
12
  }
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  *
3
3
  * 寻找 frontend\/**\/*.entry.[j|t]s(x)?
4
+ * 生成入口
4
5
  */
5
- export declare function entries(root?: string): Record<string, string>;
6
+ export declare function entries(): Record<string, string>;
6
7
  export declare function outDir(): string;
8
+ export declare const watchFiles: (callback?: () => Promise<any>) => Promise<void>;
7
9
  export declare const VBuildFE: (input: Record<string, string>) => Promise<void>;
8
10
  //# sourceMappingURL=utils.d.ts.map
@@ -3,17 +3,19 @@ import * as glob from "glob";
3
3
  import { build } from "vite";
4
4
  import { resolve } from "../packages/utils";
5
5
  import { readFileSync, writeFileSync } from "fs";
6
+ const base = process.cwd();
7
+ // 瞄准输出后的产物路径
8
+ const framePath = path.resolve(__dirname, "../../");
9
+ const frameNodePath = path.resolve(__dirname, "../");
10
+ const frameFEPath = path.resolve(framePath, "./fe/frontend");
11
+ const runPath = path.resolve(base, ".");
12
+ const runFEPath = path.resolve(runPath, "./frontend");
6
13
  /**
7
14
  *
8
15
  * 寻找 frontend\/**\/*.entry.[j|t]s(x)?
16
+ * 生成入口
9
17
  */
10
- export function entries(root) {
11
- const base = root ? path.resolve(root) : process.cwd();
12
- // 瞄准输出后的产物路径
13
- const framePath = path.resolve(__dirname, "../../");
14
- const frameNodePath = path.resolve(__dirname, "../");
15
- const frameFEPath = path.resolve(framePath, "./fe/frontend");
16
- const runFEPath = path.resolve(base, "./frontend");
18
+ export function entries() {
17
19
  console.log("frameFEPath: ", frameFEPath);
18
20
  console.log("runFEPath: ", runFEPath);
19
21
  /**
@@ -27,7 +29,6 @@ export function entries(root) {
27
29
  .filter((fileName) => !fileName.includes(".d.ts"));
28
30
  return [...o, ...files];
29
31
  }, []);
30
- console.log(files);
31
32
  const input = {};
32
33
  if (!files.length)
33
34
  return input;
@@ -39,9 +40,7 @@ export function entries(root) {
39
40
  for (let index = 0; index < files.length; index++) {
40
41
  const filePath = files[index];
41
42
  const fileDIr = path.resolve(filePath, "../");
42
- console.log(fileDIr);
43
43
  const fileHtml = glob.sync(resolve(fileDIr, "*.html"))[0];
44
- console.log(fileHtml);
45
44
  if (!fileHtml) {
46
45
  if (!templateHtml) {
47
46
  templateHtml = readFileSync(path.resolve(frameNodePath, "./app/view/entry.tpl"), "utf-8");
@@ -49,7 +48,6 @@ export function entries(root) {
49
48
  //
50
49
  const scriptStr = filePath.split(path.sep).at(-1);
51
50
  const content = templateHtml.replace(`<!-- {{InsertScript}} -->`, `<script type="module" src="./${scriptStr}"></script>`);
52
- console.log(content);
53
51
  const htmlName = fileDIr.split(path.sep).at(-1);
54
52
  const htmlPath = path.join(fileDIr, htmlName + ".html");
55
53
  writeFileSync(htmlPath, content);
@@ -69,8 +67,29 @@ export function entries(root) {
69
67
  return input;
70
68
  }
71
69
  export function outDir() {
72
- return "dist";
70
+ // 为了保持代码 能见性 输出地址应该为 runPath/app/publish/dist
71
+ return path.join(runPath, "./app/publish/dist");
73
72
  }
73
+ export const watchFiles = async (callback) => {
74
+ const chokidar = await import("chokidar");
75
+ // 在实际使用时 只有使用方的文件会变化
76
+ const watcher = chokidar.watch(runFEPath, {
77
+ ignored: /(^|[\/\\])\../,
78
+ persistent: true,
79
+ ignoreInitial: true,
80
+ });
81
+ let building = false;
82
+ watcher.on("change", async (filePath) => {
83
+ if (building)
84
+ return;
85
+ building = true;
86
+ console.log(`changed: ${filePath}`);
87
+ await callback?.();
88
+ console.log("rebuild done");
89
+ building = false;
90
+ });
91
+ console.log(`watching ${runFEPath}/...`);
92
+ };
74
93
  export const VBuildFE = async (input) => {
75
94
  // 根据入口构建
76
95
  await build({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@_tc/template-core",
3
- "version": "0.0.1-bate.13",
3
+ "version": "0.0.1-bate.14",
4
4
  "description": "A TypeScript Koa framework template - Monorepo root",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -45,6 +45,7 @@
45
45
  "@types/node": ">=18.0.0",
46
46
  "@vitejs/plugin-react": "^4.3.4",
47
47
  "vite-plugin-html": "^3.2.2",
48
+ "chokidar": "^4.0.3",
48
49
  "koa": "^2.15.0",
49
50
  "koa-nunjucks-2": "^3.0.2",
50
51
  "koa-router": "^12.0.1",