@_tc/template-core 0.0.1-bate.16 → 0.0.1-bate.18
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/cjs/app/controller/view.js +1 -1
- package/cjs/app/typings.d.ts +2 -1
- package/cjs/bundler/utils.js +51 -21
- package/esm/app/controller/view.js +1 -1
- package/esm/app/typings.d.ts +2 -1
- package/esm/bundler/utils.js +52 -22
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const getViewController = (app) => class ViewController {
|
|
4
4
|
async renderPage(ctx) {
|
|
5
|
-
app.extends.renderView(`dist
|
|
5
|
+
app.extends.renderView(`dist/${ctx.params.page}.entry`, ctx, {
|
|
6
6
|
projKey: ctx.query.proj_key,
|
|
7
7
|
name: app.options?.name,
|
|
8
8
|
env: app.envs.get(),
|
package/cjs/app/typings.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type getDB from "./extend/db";
|
|
|
6
6
|
import type getLogger from "./extend/logger";
|
|
7
7
|
import type generateErrorMessage from "./extend/generateErrorMessage";
|
|
8
8
|
import type parsingParamsOnUrl from "./extend/parsingParamsOnUrl";
|
|
9
|
+
import renderView from "./extend/render-view";
|
|
9
10
|
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
|
|
10
11
|
type GetInstance<T extends (...args: never[]) => unknown> = T extends (...args: never[]) => infer R ? R extends new () => infer C ? C : R extends Promise<infer P> ? P extends new () => infer C2 ? C2 : never : never : never;
|
|
11
12
|
declare module "../packages/core/index.js" {
|
|
@@ -23,7 +24,7 @@ declare module "../packages/core/index.js" {
|
|
|
23
24
|
generateErrorMessage: ReturnType<typeof generateErrorMessage>;
|
|
24
25
|
parsingParamsOnUrl: ReturnType<typeof parsingParamsOnUrl>;
|
|
25
26
|
nunjucksEnv: import("nunjucks").Environment;
|
|
26
|
-
renderView:
|
|
27
|
+
renderView: ReturnType<typeof renderView>;
|
|
27
28
|
}
|
|
28
29
|
interface IMiddlewaresAugmented {
|
|
29
30
|
errorHandle: import("koa").Middleware;
|
package/cjs/bundler/utils.js
CHANGED
|
@@ -100,7 +100,7 @@ function entries() {
|
|
|
100
100
|
input[key] = path_1.default.resolve(base, fileHtml);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
// for (const file of
|
|
103
|
+
// for (const file of readdirSync(base)) {
|
|
104
104
|
// if (!file.endsWith(".html")) continue;
|
|
105
105
|
// const key = path.basename(file, ".html");
|
|
106
106
|
// input[key] = path.resolve(base, file);
|
|
@@ -132,38 +132,68 @@ const watchFiles = async (callback) => {
|
|
|
132
132
|
console.log(`watching ${runFEPath}/...`);
|
|
133
133
|
};
|
|
134
134
|
exports.watchFiles = watchFiles;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
135
|
+
/**
|
|
136
|
+
*
|
|
137
|
+
* 1. 在 build 结束后
|
|
138
|
+
* 2. 获取输出目录下的html文件
|
|
139
|
+
* 3. 移动内部的html 至 输出目录的根节点
|
|
140
|
+
*/
|
|
141
|
+
function flattenHtmlPlugin(suffix = ".html") {
|
|
142
|
+
return {
|
|
143
|
+
name: "flatten-html",
|
|
144
|
+
apply: "build",
|
|
145
|
+
closeBundle() {
|
|
146
|
+
const feDir = outDir();
|
|
147
|
+
if (!(0, fs_1.existsSync)(feDir))
|
|
148
|
+
return;
|
|
149
|
+
// 移动文件
|
|
150
|
+
const htmlFiles = glob.sync("**/*.html", { cwd: feDir });
|
|
151
|
+
for (const file of htmlFiles) {
|
|
152
|
+
const src = path_1.default.join(feDir, file);
|
|
153
|
+
const fileName = path_1.default.basename(file, ".html") + suffix;
|
|
154
|
+
const dest = path_1.default.join(feDir, fileName);
|
|
155
|
+
if (src !== dest) {
|
|
156
|
+
(0, fs_1.copyFileSync)(src, dest);
|
|
157
|
+
(0, fs_1.unlinkSync)(src);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const parents = [...new Set(htmlFiles.map((f) => path_1.default.dirname(f)))]
|
|
161
|
+
.sort()
|
|
162
|
+
.reverse();
|
|
163
|
+
/**
|
|
164
|
+
*
|
|
165
|
+
* 删除空的目录
|
|
166
|
+
*/
|
|
167
|
+
const delEmptyDir = (pathStr) => {
|
|
168
|
+
const currentDir = (0, fs_1.existsSync)(pathStr) ? (0, fs_1.readdirSync)(pathStr) : [1];
|
|
169
|
+
if (!currentDir.length) {
|
|
170
|
+
(0, fs_1.rmdirSync)(pathStr);
|
|
171
|
+
const pa = pathStr.split(path_1.default.sep).slice(0, -1);
|
|
172
|
+
pa.length && delEmptyDir(pa.join(path_1.default.sep));
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
for (const dir of parents) {
|
|
176
|
+
if (dir && dir !== ".") {
|
|
177
|
+
const fullPath = path_1.default.join(feDir, dir);
|
|
178
|
+
delEmptyDir(fullPath);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
149
184
|
const VBuildFE = async (input) => {
|
|
150
185
|
// 根据入口构建
|
|
151
186
|
await (0, vite_1.build)({
|
|
152
187
|
configFile: false,
|
|
153
188
|
plugins: [
|
|
154
189
|
(await Promise.resolve().then(() => __importStar(require("@vitejs/plugin-react")))).default(),
|
|
155
|
-
|
|
190
|
+
flattenHtmlPlugin('.tpl'),
|
|
156
191
|
],
|
|
157
192
|
build: {
|
|
158
193
|
outDir: outDir(),
|
|
159
194
|
emptyOutDir: true,
|
|
160
195
|
rollupOptions: {
|
|
161
196
|
input,
|
|
162
|
-
output: {
|
|
163
|
-
entryFileNames: "frontend/[name].js",
|
|
164
|
-
chunkFileNames: "frontend/[name].js",
|
|
165
|
-
assetFileNames: "frontend/[name].[ext]",
|
|
166
|
-
},
|
|
167
197
|
},
|
|
168
198
|
},
|
|
169
199
|
resolve: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const getViewController = (app) => class ViewController {
|
|
2
2
|
async renderPage(ctx) {
|
|
3
|
-
app.extends.renderView(`dist
|
|
3
|
+
app.extends.renderView(`dist/${ctx.params.page}.entry`, ctx, {
|
|
4
4
|
projKey: ctx.query.proj_key,
|
|
5
5
|
name: app.options?.name,
|
|
6
6
|
env: app.envs.get(),
|
package/esm/app/typings.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type getDB from "./extend/db";
|
|
|
6
6
|
import type getLogger from "./extend/logger";
|
|
7
7
|
import type generateErrorMessage from "./extend/generateErrorMessage";
|
|
8
8
|
import type parsingParamsOnUrl from "./extend/parsingParamsOnUrl";
|
|
9
|
+
import renderView from "./extend/render-view";
|
|
9
10
|
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
|
|
10
11
|
type GetInstance<T extends (...args: never[]) => unknown> = T extends (...args: never[]) => infer R ? R extends new () => infer C ? C : R extends Promise<infer P> ? P extends new () => infer C2 ? C2 : never : never : never;
|
|
11
12
|
declare module "../packages/core/index.js" {
|
|
@@ -23,7 +24,7 @@ declare module "../packages/core/index.js" {
|
|
|
23
24
|
generateErrorMessage: ReturnType<typeof generateErrorMessage>;
|
|
24
25
|
parsingParamsOnUrl: ReturnType<typeof parsingParamsOnUrl>;
|
|
25
26
|
nunjucksEnv: import("nunjucks").Environment;
|
|
26
|
-
renderView:
|
|
27
|
+
renderView: ReturnType<typeof renderView>;
|
|
27
28
|
}
|
|
28
29
|
interface IMiddlewaresAugmented {
|
|
29
30
|
errorHandle: import("koa").Middleware;
|
package/esm/bundler/utils.js
CHANGED
|
@@ -2,7 +2,7 @@ import path from "path";
|
|
|
2
2
|
import * as glob from "glob";
|
|
3
3
|
import { build } from "vite";
|
|
4
4
|
import { resolve } from "../packages/utils";
|
|
5
|
-
import { readFileSync, writeFileSync } from "fs";
|
|
5
|
+
import { copyFileSync, existsSync, readdirSync, readFileSync, rmdirSync, unlinkSync, writeFileSync, } from "fs";
|
|
6
6
|
const base = process.cwd();
|
|
7
7
|
// 瞄准输出后的产物路径
|
|
8
8
|
const framePath = path.resolve(__dirname, "../../");
|
|
@@ -59,7 +59,7 @@ export function entries() {
|
|
|
59
59
|
input[key] = path.resolve(base, fileHtml);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
// for (const file of
|
|
62
|
+
// for (const file of readdirSync(base)) {
|
|
63
63
|
// if (!file.endsWith(".html")) continue;
|
|
64
64
|
// const key = path.basename(file, ".html");
|
|
65
65
|
// input[key] = path.resolve(base, file);
|
|
@@ -90,38 +90,68 @@ export const watchFiles = async (callback) => {
|
|
|
90
90
|
});
|
|
91
91
|
console.log(`watching ${runFEPath}/...`);
|
|
92
92
|
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
93
|
+
/**
|
|
94
|
+
*
|
|
95
|
+
* 1. 在 build 结束后
|
|
96
|
+
* 2. 获取输出目录下的html文件
|
|
97
|
+
* 3. 移动内部的html 至 输出目录的根节点
|
|
98
|
+
*/
|
|
99
|
+
function flattenHtmlPlugin(suffix = ".html") {
|
|
100
|
+
return {
|
|
101
|
+
name: "flatten-html",
|
|
102
|
+
apply: "build",
|
|
103
|
+
closeBundle() {
|
|
104
|
+
const feDir = outDir();
|
|
105
|
+
if (!existsSync(feDir))
|
|
106
|
+
return;
|
|
107
|
+
// 移动文件
|
|
108
|
+
const htmlFiles = glob.sync("**/*.html", { cwd: feDir });
|
|
109
|
+
for (const file of htmlFiles) {
|
|
110
|
+
const src = path.join(feDir, file);
|
|
111
|
+
const fileName = path.basename(file, ".html") + suffix;
|
|
112
|
+
const dest = path.join(feDir, fileName);
|
|
113
|
+
if (src !== dest) {
|
|
114
|
+
copyFileSync(src, dest);
|
|
115
|
+
unlinkSync(src);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const parents = [...new Set(htmlFiles.map((f) => path.dirname(f)))]
|
|
119
|
+
.sort()
|
|
120
|
+
.reverse();
|
|
121
|
+
/**
|
|
122
|
+
*
|
|
123
|
+
* 删除空的目录
|
|
124
|
+
*/
|
|
125
|
+
const delEmptyDir = (pathStr) => {
|
|
126
|
+
const currentDir = existsSync(pathStr) ? readdirSync(pathStr) : [1];
|
|
127
|
+
if (!currentDir.length) {
|
|
128
|
+
rmdirSync(pathStr);
|
|
129
|
+
const pa = pathStr.split(path.sep).slice(0, -1);
|
|
130
|
+
pa.length && delEmptyDir(pa.join(path.sep));
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
for (const dir of parents) {
|
|
134
|
+
if (dir && dir !== ".") {
|
|
135
|
+
const fullPath = path.join(feDir, dir);
|
|
136
|
+
delEmptyDir(fullPath);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
107
142
|
export const VBuildFE = async (input) => {
|
|
108
143
|
// 根据入口构建
|
|
109
144
|
await build({
|
|
110
145
|
configFile: false,
|
|
111
146
|
plugins: [
|
|
112
147
|
(await import("@vitejs/plugin-react")).default(),
|
|
113
|
-
|
|
148
|
+
flattenHtmlPlugin('.tpl'),
|
|
114
149
|
],
|
|
115
150
|
build: {
|
|
116
151
|
outDir: outDir(),
|
|
117
152
|
emptyOutDir: true,
|
|
118
153
|
rollupOptions: {
|
|
119
154
|
input,
|
|
120
|
-
output: {
|
|
121
|
-
entryFileNames: "frontend/[name].js",
|
|
122
|
-
chunkFileNames: "frontend/[name].js",
|
|
123
|
-
assetFileNames: "frontend/[name].[ext]",
|
|
124
|
-
},
|
|
125
155
|
},
|
|
126
156
|
},
|
|
127
157
|
resolve: {
|