@_tc/template-core 0.0.1-bate.17 → 0.0.1-bate.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.
- package/cjs/app/controller/view.js +1 -1
- package/cjs/app/extend/render-view.js +3 -1
- package/cjs/app/typings.d.ts +2 -1
- package/cjs/bundler/utils.js +13 -10
- package/esm/app/controller/view.js +1 -1
- package/esm/app/extend/render-view.js +3 -1
- package/esm/app/typings.d.ts +2 -1
- package/esm/bundler/utils.js +13 -10
- 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(),
|
|
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const paths_1 = require("../../packages/core/paths");
|
|
6
7
|
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
7
9
|
exports.default = (app) => {
|
|
8
|
-
const viewsPath =
|
|
10
|
+
const viewsPath = path_1.default.join((0, paths_1.getAppPath)(app, 'frame'), "./app/public");
|
|
9
11
|
const env = nunjucks_1.default.configure(viewsPath, {
|
|
10
12
|
autoescape: true,
|
|
11
13
|
throwOnUndefined: false,
|
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
|
@@ -108,8 +108,9 @@ function entries() {
|
|
|
108
108
|
return input;
|
|
109
109
|
}
|
|
110
110
|
function outDir() {
|
|
111
|
-
// 为了保持代码 能见性 输出地址应该为 runPath/app/public/dist
|
|
112
|
-
|
|
111
|
+
// // 为了保持代码 能见性 输出地址应该为 runPath/app/public/dist
|
|
112
|
+
// 放在框架路径比较保险
|
|
113
|
+
return path_1.default.join(frameNodePath, "./app/public/dist");
|
|
113
114
|
}
|
|
114
115
|
const watchFiles = async (callback) => {
|
|
115
116
|
const chokidar = await Promise.resolve().then(() => __importStar(require("chokidar")));
|
|
@@ -138,7 +139,7 @@ exports.watchFiles = watchFiles;
|
|
|
138
139
|
* 2. 获取输出目录下的html文件
|
|
139
140
|
* 3. 移动内部的html 至 输出目录的根节点
|
|
140
141
|
*/
|
|
141
|
-
function flattenHtmlPlugin() {
|
|
142
|
+
function flattenHtmlPlugin(suffix = ".html") {
|
|
142
143
|
return {
|
|
143
144
|
name: "flatten-html",
|
|
144
145
|
apply: "build",
|
|
@@ -150,7 +151,14 @@ function flattenHtmlPlugin() {
|
|
|
150
151
|
const htmlFiles = glob.sync("**/*.html", { cwd: feDir });
|
|
151
152
|
for (const file of htmlFiles) {
|
|
152
153
|
const src = path_1.default.join(feDir, file);
|
|
153
|
-
|
|
154
|
+
let fileOName = path_1.default.basename(file, ".html");
|
|
155
|
+
// 如果文件名没有 entry 补上后缀
|
|
156
|
+
const entrySuffix = ".entry";
|
|
157
|
+
if (fileOName.indexOf(entrySuffix) === -1) {
|
|
158
|
+
fileOName = fileOName + entrySuffix;
|
|
159
|
+
}
|
|
160
|
+
const fileName = fileOName + suffix;
|
|
161
|
+
const dest = path_1.default.join(feDir, fileName);
|
|
154
162
|
if (src !== dest) {
|
|
155
163
|
(0, fs_1.copyFileSync)(src, dest);
|
|
156
164
|
(0, fs_1.unlinkSync)(src);
|
|
@@ -186,18 +194,13 @@ const VBuildFE = async (input) => {
|
|
|
186
194
|
configFile: false,
|
|
187
195
|
plugins: [
|
|
188
196
|
(await Promise.resolve().then(() => __importStar(require("@vitejs/plugin-react")))).default(),
|
|
189
|
-
flattenHtmlPlugin(),
|
|
197
|
+
flattenHtmlPlugin(".tpl"),
|
|
190
198
|
],
|
|
191
199
|
build: {
|
|
192
200
|
outDir: outDir(),
|
|
193
201
|
emptyOutDir: true,
|
|
194
202
|
rollupOptions: {
|
|
195
203
|
input,
|
|
196
|
-
output: {
|
|
197
|
-
entryFileNames: "frontend/[name].js",
|
|
198
|
-
chunkFileNames: "frontend/[name].js",
|
|
199
|
-
assetFileNames: "frontend/[name].[ext]",
|
|
200
|
-
},
|
|
201
204
|
},
|
|
202
205
|
},
|
|
203
206
|
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(),
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { getAppPath } from "../../packages/core/paths";
|
|
1
2
|
import nunjucks from "nunjucks";
|
|
3
|
+
import path from "path";
|
|
2
4
|
export default (app) => {
|
|
3
|
-
const viewsPath = app
|
|
5
|
+
const viewsPath = path.join(getAppPath(app, 'frame'), "./app/public");
|
|
4
6
|
const env = nunjucks.configure(viewsPath, {
|
|
5
7
|
autoescape: true,
|
|
6
8
|
throwOnUndefined: false,
|
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
|
@@ -67,8 +67,9 @@ export function entries() {
|
|
|
67
67
|
return input;
|
|
68
68
|
}
|
|
69
69
|
export function outDir() {
|
|
70
|
-
// 为了保持代码 能见性 输出地址应该为 runPath/app/public/dist
|
|
71
|
-
|
|
70
|
+
// // 为了保持代码 能见性 输出地址应该为 runPath/app/public/dist
|
|
71
|
+
// 放在框架路径比较保险
|
|
72
|
+
return path.join(frameNodePath, "./app/public/dist");
|
|
72
73
|
}
|
|
73
74
|
export const watchFiles = async (callback) => {
|
|
74
75
|
const chokidar = await import("chokidar");
|
|
@@ -96,7 +97,7 @@ export const watchFiles = async (callback) => {
|
|
|
96
97
|
* 2. 获取输出目录下的html文件
|
|
97
98
|
* 3. 移动内部的html 至 输出目录的根节点
|
|
98
99
|
*/
|
|
99
|
-
function flattenHtmlPlugin() {
|
|
100
|
+
function flattenHtmlPlugin(suffix = ".html") {
|
|
100
101
|
return {
|
|
101
102
|
name: "flatten-html",
|
|
102
103
|
apply: "build",
|
|
@@ -108,7 +109,14 @@ function flattenHtmlPlugin() {
|
|
|
108
109
|
const htmlFiles = glob.sync("**/*.html", { cwd: feDir });
|
|
109
110
|
for (const file of htmlFiles) {
|
|
110
111
|
const src = path.join(feDir, file);
|
|
111
|
-
|
|
112
|
+
let fileOName = path.basename(file, ".html");
|
|
113
|
+
// 如果文件名没有 entry 补上后缀
|
|
114
|
+
const entrySuffix = ".entry";
|
|
115
|
+
if (fileOName.indexOf(entrySuffix) === -1) {
|
|
116
|
+
fileOName = fileOName + entrySuffix;
|
|
117
|
+
}
|
|
118
|
+
const fileName = fileOName + suffix;
|
|
119
|
+
const dest = path.join(feDir, fileName);
|
|
112
120
|
if (src !== dest) {
|
|
113
121
|
copyFileSync(src, dest);
|
|
114
122
|
unlinkSync(src);
|
|
@@ -144,18 +152,13 @@ export const VBuildFE = async (input) => {
|
|
|
144
152
|
configFile: false,
|
|
145
153
|
plugins: [
|
|
146
154
|
(await import("@vitejs/plugin-react")).default(),
|
|
147
|
-
flattenHtmlPlugin(),
|
|
155
|
+
flattenHtmlPlugin(".tpl"),
|
|
148
156
|
],
|
|
149
157
|
build: {
|
|
150
158
|
outDir: outDir(),
|
|
151
159
|
emptyOutDir: true,
|
|
152
160
|
rollupOptions: {
|
|
153
161
|
input,
|
|
154
|
-
output: {
|
|
155
|
-
entryFileNames: "frontend/[name].js",
|
|
156
|
-
chunkFileNames: "frontend/[name].js",
|
|
157
|
-
assetFileNames: "frontend/[name].[ext]",
|
|
158
|
-
},
|
|
159
162
|
},
|
|
160
163
|
},
|
|
161
164
|
resolve: {
|