fast-vue-multi-pages 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +63 -0
- package/dist/cjs/FastVueMultiTool.d.ts +60 -0
- package/dist/cjs/FastVueMultiTool.js +65 -0
- package/dist/cjs/http/FastVueMultiCookie.d.ts +18 -0
- package/dist/cjs/http/FastVueMultiCookie.js +30 -0
- package/dist/cjs/http/FastVueMultiHttp.d.ts +225 -0
- package/dist/cjs/http/FastVueMultiHttp.js +572 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/loader/FastTagBuilderLoader.d.ts +2 -0
- package/dist/cjs/loader/FastTagBuilderLoader.js +89 -0
- package/dist/cjs/other/FastVueMultiBoolean.d.ts +13 -0
- package/dist/cjs/other/FastVueMultiBoolean.js +56 -0
- package/dist/cjs/other/FastVueMultiClipboard.d.ts +21 -0
- package/dist/cjs/other/FastVueMultiClipboard.js +38 -0
- package/dist/cjs/other/FastVueMultiDate.d.ts +30 -0
- package/dist/cjs/other/FastVueMultiDate.js +166 -0
- package/dist/cjs/other/FastVueMultiElement.d.ts +46 -0
- package/dist/cjs/other/FastVueMultiElement.js +154 -0
- package/dist/cjs/other/FastVueMultiFunction.d.ts +19 -0
- package/dist/cjs/other/FastVueMultiFunction.js +68 -0
- package/dist/cjs/other/FastVueMultiStore.d.ts +13 -0
- package/dist/cjs/other/FastVueMultiStore.js +23 -0
- package/dist/cjs/other/FastVueMultiWindow.d.ts +21 -0
- package/dist/cjs/other/FastVueMultiWindow.js +53 -0
- package/dist/cjs/store/FastVueMultiStore.d.ts +13 -0
- package/dist/cjs/store/FastVueMultiStore.js +23 -0
- package/dist/cjs/vue/FastVueMultiConfig.d.ts +18 -0
- package/dist/cjs/vue/FastVueMultiConfig.js +43 -0
- package/dist/esm/FastVueMultiTool.d.ts +60 -0
- package/dist/esm/FastVueMultiTool.js +59 -0
- package/dist/esm/http/FastVueMultiCookie.d.ts +18 -0
- package/dist/esm/http/FastVueMultiCookie.js +34 -0
- package/dist/esm/http/FastVueMultiHttp.d.ts +225 -0
- package/dist/esm/http/FastVueMultiHttp.js +608 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/loader/FastTagBuilderLoader.d.ts +2 -0
- package/dist/esm/loader/FastTagBuilderLoader.js +89 -0
- package/dist/esm/other/FastVueMultiBoolean.d.ts +13 -0
- package/dist/esm/other/FastVueMultiBoolean.js +60 -0
- package/dist/esm/other/FastVueMultiClipboard.d.ts +21 -0
- package/dist/esm/other/FastVueMultiClipboard.js +56 -0
- package/dist/esm/other/FastVueMultiDate.d.ts +30 -0
- package/dist/esm/other/FastVueMultiDate.js +170 -0
- package/dist/esm/other/FastVueMultiElement.d.ts +46 -0
- package/dist/esm/other/FastVueMultiElement.js +158 -0
- package/dist/esm/other/FastVueMultiFunction.d.ts +19 -0
- package/dist/esm/other/FastVueMultiFunction.js +97 -0
- package/dist/esm/other/FastVueMultiStore.d.ts +13 -0
- package/dist/esm/other/FastVueMultiStore.js +27 -0
- package/dist/esm/other/FastVueMultiWindow.d.ts +21 -0
- package/dist/esm/other/FastVueMultiWindow.js +57 -0
- package/dist/esm/store/FastVueMultiStore.d.ts +13 -0
- package/dist/esm/store/FastVueMultiStore.js +27 -0
- package/dist/esm/vue/FastVueMultiConfig.d.ts +18 -0
- package/dist/esm/vue/FastVueMultiConfig.js +48 -0
- package/package.json +64 -0
- package/vue/FastBuildOption.d.ts +241 -0
- package/vue/FastBuildOption.js +249 -0
- package/vue/FastInjectJsPlugin.d.ts +11 -0
- package/vue/FastInjectJsPlugin.js +101 -0
- package/vue/FastPages.d.ts +25 -0
- package/vue/FastPages.js +173 -0
- package/vue/FastVueMultiConfig.d.ts +18 -0
- package/vue/FastVueMultiConfig.js +43 -0
- package/vue/FastVueMultiPages.d.ts +62 -0
- package/vue/FastVueMultiPages.js +294 -0
- package/vue/index.d.ts +2 -0
- package/vue/index.js +5 -0
@@ -0,0 +1,249 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.FastBuildOption = void 0;
|
4
|
+
/**
|
5
|
+
* 获取编译配置的选项配置,配置选项如下:
|
6
|
+
* <br/>
|
7
|
+
* {@link projectTitle } 项目名称
|
8
|
+
* <br/>
|
9
|
+
* {@link projectPagesDir } 项目存储页面的目录地址 默认:src/pages
|
10
|
+
* <br/>
|
11
|
+
* {@link projectOutDir } 项目默认编译输出地址 默认:dist
|
12
|
+
* <br/>
|
13
|
+
* {@link projectAssetsDir } 项目资源路径,默认:assets
|
14
|
+
* <br/>
|
15
|
+
* {@link pageTemplateFileDir } 页面的入口文件模板地址,默认:public/index.html
|
16
|
+
* <br/>
|
17
|
+
* {@link pageMainFileName }页面目录下的入口文件名,默认:index.js
|
18
|
+
* <br/>
|
19
|
+
* {@link pageConfigHtmlNamePrefix }页面生成html文件时文件命名携带的前缀
|
20
|
+
* <br/>
|
21
|
+
* {@link pageConfigFileName } 页面目录下的配置文件名,默认:config.json
|
22
|
+
* <br/>
|
23
|
+
* {@link autoCreatePageConfigFile } 是否在每个页面目录下自动创建config.json文件
|
24
|
+
* <br/>
|
25
|
+
* {@link autoCreateProjectIndexPage } 是否自动创建项目的index页面
|
26
|
+
* <br/>
|
27
|
+
* {@link nodeModulesDir } 第三方插件存放目录文件夹,默认:node_modules
|
28
|
+
* <br/>
|
29
|
+
* {@link globalConfig } 系统的全局配置
|
30
|
+
* <br/>
|
31
|
+
* {@link httpFinalParams } FastVueMultiTool.Http请求接口全局请求参数。
|
32
|
+
* <br/>
|
33
|
+
* {@link httpFinalHeaders } FastVueMultiTool.Http请求接口全局请求头参数。
|
34
|
+
* <br/>
|
35
|
+
* {@link httpBeforeRequest } FastVueMultiTool.Http请求前的拦截。
|
36
|
+
* <br/>
|
37
|
+
* {@link httpAfterRequest } FastVueMultiTool.Http请求后的拦截。
|
38
|
+
* <br/>
|
39
|
+
* {@link injectJsFiles } 所有页面全局注入的js文件
|
40
|
+
* <br/>
|
41
|
+
* {@link injectJsFilter } 所有页面全局注入js文件过滤器
|
42
|
+
* <br/>
|
43
|
+
* {@link injectVariable } 所有页面全局注入js变量
|
44
|
+
* <br/>
|
45
|
+
* {@link cacheVueLoader } 是否使用vue默认的cache-loader,默认使用
|
46
|
+
* <br/>
|
47
|
+
* {@link vConsole } 开启vConsole插件的方式,默认:auto。可选值:auto(自动根据编辑的类型追加,server模式或debug模式开启),true(强制开启),false(不开启)
|
48
|
+
* <br/>
|
49
|
+
* {@link splitChunks } 将公共js代码,进行分割,默认:true
|
50
|
+
* <br/>
|
51
|
+
* {@link buildLevel} 项目编译级别,与 标签 build-level 对应
|
52
|
+
* <br/>
|
53
|
+
* {@link buildLevelTagName} 项目编译级别标签名,默认: build-level
|
54
|
+
* <br/>
|
55
|
+
* {@link chainWebpack} 配置Webpack函数function (config){};
|
56
|
+
* <br/>
|
57
|
+
* {@link configureWebpack} 配置Webpack函数function (config){};
|
58
|
+
*/
|
59
|
+
class FastBuildOption {
|
60
|
+
/**
|
61
|
+
* 合并options
|
62
|
+
* @param options
|
63
|
+
*/
|
64
|
+
static merge(...options) {
|
65
|
+
let newObject = {};
|
66
|
+
for (let option of options) {
|
67
|
+
for (let optionsKey in option) {
|
68
|
+
if (newObject.hasOwnProperty(optionsKey)) {
|
69
|
+
continue;
|
70
|
+
}
|
71
|
+
newObject[optionsKey] = option[optionsKey];
|
72
|
+
}
|
73
|
+
}
|
74
|
+
return newObject;
|
75
|
+
}
|
76
|
+
/**
|
77
|
+
* 项目名称
|
78
|
+
*/
|
79
|
+
projectTitle = "VUE多页面项目";
|
80
|
+
/**
|
81
|
+
* 项目存储页面的目录地址,默认src/pages 或者数组:["默认src/pages","默认src/pages2"]
|
82
|
+
*/
|
83
|
+
projectPagesDir = "src/pages/";
|
84
|
+
/**
|
85
|
+
* 项目编译输出地址,默认:dist
|
86
|
+
*/
|
87
|
+
projectOutDir = "dist";
|
88
|
+
/**
|
89
|
+
* 项目资源路径,默认:assets
|
90
|
+
*/
|
91
|
+
projectAssetsDir = "assets";
|
92
|
+
/**
|
93
|
+
* 页面的入口文件模板地址,默认:public/index.html
|
94
|
+
*/
|
95
|
+
pageTemplateFileDir = "public/index.html";
|
96
|
+
/**
|
97
|
+
* 页面目录下的入口文件名,默认:index.js
|
98
|
+
*/
|
99
|
+
pageMainFileName = "index.js";
|
100
|
+
/**
|
101
|
+
* 页面目录下的配置文件名,默认:config.json
|
102
|
+
*/
|
103
|
+
pageConfigFileName = "config.json";
|
104
|
+
/**
|
105
|
+
* 页面目录下的渲染模板html,如果存在则以这个模板进行渲染,默认:index.html
|
106
|
+
*/
|
107
|
+
pageMainTemplateFileName = "index.html";
|
108
|
+
/**
|
109
|
+
* 页面生成html文件时文件命名携带的前缀
|
110
|
+
*/
|
111
|
+
pageConfigHtmlNamePrefix = "";
|
112
|
+
/**
|
113
|
+
* 是否在每个页面目录下自动创建config.json文件
|
114
|
+
*/
|
115
|
+
autoCreatePageConfigFile = false;
|
116
|
+
/**
|
117
|
+
* 是否自动创建项目的index页面
|
118
|
+
*/
|
119
|
+
autoCreateProjectIndexPage = false;
|
120
|
+
/**
|
121
|
+
* 第三方插件存放目录文件夹,默认:node_modules
|
122
|
+
*/
|
123
|
+
nodeModulesDir = "node_modules";
|
124
|
+
/**
|
125
|
+
* vue挂载的目标节点选择器
|
126
|
+
*/
|
127
|
+
mountSelector = "#app";
|
128
|
+
/**
|
129
|
+
* 系统的全局配置,
|
130
|
+
* @example
|
131
|
+
* globalConfig:{
|
132
|
+
* mainUrl:"http://192.168.0.1:8080/test"
|
133
|
+
* }
|
134
|
+
* 可通过 :FastBaseApp.Config.getGlobalConfig("mainUrl") 在任意js中获取配置
|
135
|
+
*/
|
136
|
+
globalConfig;
|
137
|
+
/**
|
138
|
+
* FastVueMultiTool.Http请求接口全局请求参数.
|
139
|
+
* @example
|
140
|
+
* httpFinalParams:{
|
141
|
+
* userId:2,
|
142
|
+
* userName:undefined //当配置undefined值时,将排除此参数属性名
|
143
|
+
* }
|
144
|
+
*/
|
145
|
+
httpFinalParams;
|
146
|
+
/**
|
147
|
+
* FastVueMultiTool.Http请求接口全局请求头参数.
|
148
|
+
* @example
|
149
|
+
* httpFinalHeaders:{
|
150
|
+
* userId:2,
|
151
|
+
* userName:undefined //当配置undefined值时,将排除此参数属性名
|
152
|
+
* }
|
153
|
+
*/
|
154
|
+
httpFinalHeaders;
|
155
|
+
/**
|
156
|
+
* FastVueMultiTool.Http请求前的拦截
|
157
|
+
* @example
|
158
|
+
* httpBeforeRequest:function(config){
|
159
|
+
* //do something
|
160
|
+
* }
|
161
|
+
*/
|
162
|
+
httpBeforeRequest;
|
163
|
+
/**
|
164
|
+
* FastVueMultiTool.Http请求后的拦截
|
165
|
+
* @example
|
166
|
+
* httpAfterRequest:function(response){
|
167
|
+
* //do something
|
168
|
+
* }
|
169
|
+
*/
|
170
|
+
httpAfterRequest;
|
171
|
+
/**
|
172
|
+
* 所有页面全局注入的js文件
|
173
|
+
* @example
|
174
|
+
* injectJsFiles:["src/js/test.js","src/js/icon.js"]
|
175
|
+
* 或
|
176
|
+
* injectJsFiles:{
|
177
|
+
* "src/js/test.js":{
|
178
|
+
* exclude:["user","set"] //排除注入页面的名称,例如:user.html,set.html
|
179
|
+
* },
|
180
|
+
* "src/js/icon.js":{
|
181
|
+
* include:["user","set"] //指定注入页面的名称,例如:user.html,set.html
|
182
|
+
* }
|
183
|
+
* }
|
184
|
+
* 或
|
185
|
+
* injectJsFiles:[
|
186
|
+
* "src/js/test.js",
|
187
|
+
* {
|
188
|
+
* "src/js/icon.js":{
|
189
|
+
* exclude:["user","set"] //排除注入页面的名称,例如:user.html,set.html
|
190
|
+
* }
|
191
|
+
* }
|
192
|
+
* ]
|
193
|
+
*/
|
194
|
+
injectJsFiles;
|
195
|
+
/**
|
196
|
+
* 所有页面全局注入js文件过滤器,当 {@link injectJsFiles} 为数组时生效!
|
197
|
+
* @example
|
198
|
+
* injectJsFilter:{
|
199
|
+
* include:["user","set"] //指定注入页面的名称,例如:user.html,set.html
|
200
|
+
* }
|
201
|
+
* 或
|
202
|
+
* injectJsFilter:{
|
203
|
+
* exclude:["user","set"] //排除注入页面的名称,例如:user.html,set.html
|
204
|
+
* }
|
205
|
+
*/
|
206
|
+
injectJsFilter;
|
207
|
+
/**
|
208
|
+
* 所有页面全局js变量注入
|
209
|
+
* @example
|
210
|
+
* injectVariable:{
|
211
|
+
* getUserId:function(){
|
212
|
+
* return 1;
|
213
|
+
* },
|
214
|
+
* server:"……"
|
215
|
+
* }
|
216
|
+
*/
|
217
|
+
injectVariable;
|
218
|
+
/**
|
219
|
+
* 是否使用vue默认的cache-loader缓存vue-loader,如果不使用,则在build版本前将删除缓存的目录.cache/vue-loader
|
220
|
+
*/
|
221
|
+
cacheVueLoader = false;
|
222
|
+
/**
|
223
|
+
* 开启vConsole插件的方式,默认:auto。可选值:auto(自动根据编辑的类型追加,server模式或debug模式开启),true(强制开启),false(不开启)
|
224
|
+
*/
|
225
|
+
vConsole = "auto";
|
226
|
+
/**
|
227
|
+
* 将公共js代码,进行分割,默认:true
|
228
|
+
*/
|
229
|
+
splitChunks = true;
|
230
|
+
/**
|
231
|
+
* 项目编译级别,与 标签 build-level 对应
|
232
|
+
*/
|
233
|
+
buildLevel = 1;
|
234
|
+
/**
|
235
|
+
* 编译级别的标签名,默认 build-level
|
236
|
+
*/
|
237
|
+
buildLevelTagName = "build-level";
|
238
|
+
/**
|
239
|
+
* 插入Webpack函数function (config){};
|
240
|
+
*/
|
241
|
+
chainWebpack = function () {
|
242
|
+
};
|
243
|
+
/**
|
244
|
+
* 配置Webpack函数function (config){};
|
245
|
+
*/
|
246
|
+
configureWebpack = function () {
|
247
|
+
};
|
248
|
+
}
|
249
|
+
exports.FastBuildOption = FastBuildOption;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* 全局注入脚本插件
|
3
|
+
*/
|
4
|
+
export declare class FastInjectJsPlugin {
|
5
|
+
private readonly options;
|
6
|
+
constructor(options: any);
|
7
|
+
filter(key: string, targetFilter: any): boolean;
|
8
|
+
injectArray(local: any, entry: any, targetInjectJsFiles: any): void;
|
9
|
+
injectObject(local: any, entry: any, targetInjectJsFiles: any): void;
|
10
|
+
apply(compiler: any): void;
|
11
|
+
}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.FastInjectJsPlugin = void 0;
|
4
|
+
/**
|
5
|
+
* 全局注入脚本插件
|
6
|
+
*/
|
7
|
+
class FastInjectJsPlugin {
|
8
|
+
options;
|
9
|
+
constructor(options) {
|
10
|
+
this.options = options;
|
11
|
+
}
|
12
|
+
filter(key, targetFilter) {
|
13
|
+
if (targetFilter) {
|
14
|
+
if (targetFilter.include) {
|
15
|
+
for (let i = 0; i < targetFilter.include.length; i++) {
|
16
|
+
if (targetFilter.include[i] === key) {
|
17
|
+
return true;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
return false;
|
21
|
+
}
|
22
|
+
if (targetFilter.exclude) {
|
23
|
+
for (let i = 0; i < targetFilter.exclude.length; i++) {
|
24
|
+
if (targetFilter.exclude[i] === key) {
|
25
|
+
return false;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
return true;
|
31
|
+
}
|
32
|
+
injectArray(local, entry, targetInjectJsFiles) {
|
33
|
+
if (Object.prototype.toString.call(targetInjectJsFiles) !== '[object Array]') {
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
const path = require('path');
|
37
|
+
const fs = require('fs');
|
38
|
+
for (let i = 0; i < targetInjectJsFiles.length; i++) {
|
39
|
+
let value = targetInjectJsFiles[i];
|
40
|
+
if (typeof value === 'string') {
|
41
|
+
const jsPath = path.join(local, value);
|
42
|
+
if (fs.existsSync(jsPath)) {
|
43
|
+
for (let entryKey in entry) {
|
44
|
+
if (!this.filter(entryKey, this.options.injectJsFilter)) {
|
45
|
+
continue;
|
46
|
+
}
|
47
|
+
let entryArray = entry[entryKey];
|
48
|
+
if (Object.prototype.toString.call(entryArray) === '[object Array]') {
|
49
|
+
entryArray.unshift(jsPath);
|
50
|
+
}
|
51
|
+
else if (entryArray.hasOwnProperty("import")
|
52
|
+
&& Object.prototype.toString.call(entryArray["import"]) === '[object Array]') {
|
53
|
+
entryArray["import"].unshift(jsPath);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
this.injectObject(local, entry, value);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
injectObject(local, entry, targetInjectJsFiles) {
|
64
|
+
if (typeof targetInjectJsFiles !== 'object') {
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
const path = require('path');
|
68
|
+
const fs = require('fs');
|
69
|
+
for (let injectJsFilesKey in targetInjectJsFiles) {
|
70
|
+
const jsPath = path.join(local, injectJsFilesKey);
|
71
|
+
if (fs.existsSync(jsPath)) {
|
72
|
+
for (let entryKey in entry) {
|
73
|
+
if (!this.filter(entryKey, targetInjectJsFiles[injectJsFilesKey])) {
|
74
|
+
continue;
|
75
|
+
}
|
76
|
+
let entryArray = entry[entryKey];
|
77
|
+
if (Object.prototype.toString.call(entryArray) === '[object Array]') {
|
78
|
+
entryArray.unshift(jsPath);
|
79
|
+
}
|
80
|
+
else if (entryArray.hasOwnProperty("import")
|
81
|
+
&& Object.prototype.toString.call(entryArray["import"]) === '[object Array]') {
|
82
|
+
entryArray["import"].unshift(jsPath);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
apply(compiler) {
|
89
|
+
if (compiler.hooks && this.options) {
|
90
|
+
compiler.hooks.entryOption.tap({ name: 'FastInjectJsPlugin' }, (local, entry) => {
|
91
|
+
if (Object.prototype.toString.call(this.options.injectJsFiles) === '[object Array]') {
|
92
|
+
this.injectArray(local, entry, this.options.injectJsFiles);
|
93
|
+
}
|
94
|
+
else if (typeof this.options.injectJsFiles === 'object') {
|
95
|
+
this.injectObject(local, entry, this.options.injectJsFiles);
|
96
|
+
}
|
97
|
+
});
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
exports.FastInjectJsPlugin = FastInjectJsPlugin;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { FastBuildOption } from "./FastBuildOption";
|
2
|
+
/**
|
3
|
+
* 页面相关操作
|
4
|
+
*/
|
5
|
+
export declare class FastPages {
|
6
|
+
/**
|
7
|
+
* 获取vue页面配置,vue.config.js 中的pages配置
|
8
|
+
* @param dirName 项目的根目录
|
9
|
+
* @param options 更多配置
|
10
|
+
*/
|
11
|
+
static getBuildPages(dirName: string, options?: FastBuildOption): any;
|
12
|
+
/**
|
13
|
+
* 获取页面下config.json配置文件
|
14
|
+
* @param pagePath
|
15
|
+
* @param options
|
16
|
+
*/
|
17
|
+
static getPageConfig(pagePath: string, options: FastBuildOption): any;
|
18
|
+
/**
|
19
|
+
* 创建默认的index索引页面
|
20
|
+
* @param pagesValue
|
21
|
+
* @param dirName
|
22
|
+
* @param options
|
23
|
+
*/
|
24
|
+
static createIndexPage(pagesValue: string, dirName: string, options?: FastBuildOption): any;
|
25
|
+
}
|
package/vue/FastPages.js
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.FastPages = void 0;
|
4
|
+
const FastBuildOption_1 = require("./FastBuildOption");
|
5
|
+
/**
|
6
|
+
* 页面相关操作
|
7
|
+
*/
|
8
|
+
class FastPages {
|
9
|
+
/**
|
10
|
+
* 获取vue页面配置,vue.config.js 中的pages配置
|
11
|
+
* @param dirName 项目的根目录
|
12
|
+
* @param options 更多配置
|
13
|
+
*/
|
14
|
+
static getBuildPages(dirName, options) {
|
15
|
+
const fs = require("fs");
|
16
|
+
const _ = require("lodash");
|
17
|
+
const path = require("path");
|
18
|
+
if (options) {
|
19
|
+
options = FastBuildOption_1.FastBuildOption.merge(options, new FastBuildOption_1.FastBuildOption());
|
20
|
+
}
|
21
|
+
else {
|
22
|
+
options = new FastBuildOption_1.FastBuildOption();
|
23
|
+
}
|
24
|
+
let projectPagesDir = options.projectPagesDir;
|
25
|
+
let pagesMap = {};
|
26
|
+
let rootPagePaths = [];
|
27
|
+
if (_.isArray(projectPagesDir)) {
|
28
|
+
for (let projectPagesDirElement of projectPagesDir) {
|
29
|
+
rootPagePaths.push(path.join(dirName, projectPagesDirElement));
|
30
|
+
}
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
rootPagePaths.push(path.join(dirName, projectPagesDir));
|
34
|
+
}
|
35
|
+
for (let rootPagePath of rootPagePaths) {
|
36
|
+
let pageFiles = fs.readdirSync(rootPagePath);
|
37
|
+
for (let i = 0; i < pageFiles.length; i++) {
|
38
|
+
let fileName = pageFiles[i];
|
39
|
+
if (fileName.indexOf(".") === 0 || fileName.indexOf("__") === 0) {
|
40
|
+
continue;
|
41
|
+
}
|
42
|
+
let vueFileName = fileName + ".vue";
|
43
|
+
let subPageDirPath = path.join(rootPagePath, fileName);
|
44
|
+
let subPageDirRelativePath = subPageDirPath.replace(dirName, "");
|
45
|
+
if (_.startsWith(subPageDirRelativePath, "/")) {
|
46
|
+
subPageDirRelativePath = subPageDirRelativePath.substring(1);
|
47
|
+
}
|
48
|
+
if (!fs.existsSync(subPageDirPath)) {
|
49
|
+
continue;
|
50
|
+
}
|
51
|
+
if (fs.statSync(subPageDirPath).isFile()) {
|
52
|
+
continue;
|
53
|
+
}
|
54
|
+
let vueFilePath = path.join(subPageDirPath, vueFileName);
|
55
|
+
if (!fs.existsSync(vueFilePath)) {
|
56
|
+
vueFileName = "index.vue";
|
57
|
+
vueFilePath = path.join(subPageDirPath, vueFileName);
|
58
|
+
}
|
59
|
+
//不存在.vue的,就默认创建一个
|
60
|
+
if (!fs.existsSync(vueFilePath)) {
|
61
|
+
let content = `<script>
|
62
|
+
import {defineComponent} from 'vue'
|
63
|
+
export default defineComponent({
|
64
|
+
name: "index"
|
65
|
+
});
|
66
|
+
</script>
|
67
|
+
<template>
|
68
|
+
<div>
|
69
|
+
默认页面
|
70
|
+
</div>
|
71
|
+
</template>
|
72
|
+
<style scoped>
|
73
|
+
</style>`;
|
74
|
+
fs.writeFileSync(vueFilePath, content, {});
|
75
|
+
}
|
76
|
+
let mainFilePath = path.join(subPageDirPath, options.pageMainFileName);
|
77
|
+
if (!fs.existsSync(mainFilePath)) {
|
78
|
+
let content = "import {createApp} from \"vue\";\n" +
|
79
|
+
"import child from \"./" + vueFileName + "\";\n" +
|
80
|
+
"createApp(child).mount(\"" + options.mountSelector + "\");";
|
81
|
+
fs.writeFileSync(mainFilePath, content, {});
|
82
|
+
}
|
83
|
+
pagesMap[fileName] = {
|
84
|
+
entry: path.join(subPageDirRelativePath, options.pageMainFileName),
|
85
|
+
title: options.projectTitle,
|
86
|
+
filename: options.pageConfigHtmlNamePrefix + fileName + ".html",
|
87
|
+
};
|
88
|
+
pagesMap[fileName]["template"] = options.pageTemplateFileDir;
|
89
|
+
let pageMainTemplateFileName = path.join(subPageDirPath, options.pageMainTemplateFileName);
|
90
|
+
if (fs.existsSync(pageMainTemplateFileName)) {
|
91
|
+
pagesMap[fileName]["template"] = path.join(subPageDirRelativePath, options.pageMainTemplateFileName);
|
92
|
+
}
|
93
|
+
let configFilePath = path.join(subPageDirPath, options.pageConfigFileName);
|
94
|
+
if (fs.existsSync(configFilePath)) {
|
95
|
+
let configContent = fs.readFileSync(configFilePath);
|
96
|
+
let configObj = JSON.parse(configContent);
|
97
|
+
for (let configObjKey in configObj) {
|
98
|
+
pagesMap[fileName][configObjKey] = configObj[configObjKey];
|
99
|
+
}
|
100
|
+
}
|
101
|
+
if (options.autoCreatePageConfigFile && Object.keys(pagesMap).length > 0) {
|
102
|
+
fs.writeFileSync(configFilePath, JSON.stringify(pagesMap[fileName], null, "\t"), {});
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
return pagesMap;
|
107
|
+
}
|
108
|
+
/**
|
109
|
+
* 获取页面下config.json配置文件
|
110
|
+
* @param pagePath
|
111
|
+
* @param options
|
112
|
+
*/
|
113
|
+
static getPageConfig(pagePath, options) {
|
114
|
+
const path = require("path");
|
115
|
+
const fs = require("fs");
|
116
|
+
let configFilePath = path.join(pagePath, options.pageConfigFileName);
|
117
|
+
if (fs.existsSync(configFilePath)) {
|
118
|
+
const fs = require("fs");
|
119
|
+
let configContent = fs.readFileSync(configFilePath);
|
120
|
+
return JSON.parse(configContent);
|
121
|
+
}
|
122
|
+
return {};
|
123
|
+
}
|
124
|
+
/**
|
125
|
+
* 创建默认的index索引页面
|
126
|
+
* @param pagesValue
|
127
|
+
* @param dirName
|
128
|
+
* @param options
|
129
|
+
*/
|
130
|
+
static createIndexPage(pagesValue, dirName, options) {
|
131
|
+
const fs = require("fs");
|
132
|
+
const path = require("path");
|
133
|
+
if (options) {
|
134
|
+
options = FastBuildOption_1.FastBuildOption.merge(options, new FastBuildOption_1.FastBuildOption());
|
135
|
+
}
|
136
|
+
else {
|
137
|
+
options = new FastBuildOption_1.FastBuildOption();
|
138
|
+
}
|
139
|
+
let projectPagesDir = options.projectPagesDir;
|
140
|
+
let baseDir = path.join(dirName, projectPagesDir, "index");
|
141
|
+
if (!fs.existsSync(baseDir)) {
|
142
|
+
fs.mkdirSync(baseDir);
|
143
|
+
}
|
144
|
+
let indexJsContent = "import {createApp} from \"vue\";\n";
|
145
|
+
indexJsContent += "import main from \"./main\";\n";
|
146
|
+
indexJsContent += "let app = createApp(main);\n";
|
147
|
+
indexJsContent += "app.config.globalProperties.pages = " + pagesValue + ";\n";
|
148
|
+
indexJsContent += "app.mount(\"" + options.mountSelector + "\");";
|
149
|
+
const indexPath = path.join(baseDir, "index.js");
|
150
|
+
fs.writeFileSync(indexPath, indexJsContent, {});
|
151
|
+
let configDiv = "<template >\n" +
|
152
|
+
" <template v-for=\"(value,name) in pages\" :key=\"name\">\n" +
|
153
|
+
" <van-cell :title=\"value.filename\" is-link :url=\"value.urlParams?value.filename+'?'+value.urlParams:value.filename\" />\n" +
|
154
|
+
" </template>\n" +
|
155
|
+
"</template>\n" +
|
156
|
+
"<script>\n" +
|
157
|
+
"/* eslint-disable vue/multi-word-component-names */" +
|
158
|
+
"import {Cell} from 'vant';\n" +
|
159
|
+
"export default {\n" +
|
160
|
+
" name: \"main\",\n" +
|
161
|
+
" components: {\n" +
|
162
|
+
" [Cell.name]: Cell\n" +
|
163
|
+
" }\n" +
|
164
|
+
"}\n" +
|
165
|
+
"</script>";
|
166
|
+
fs.writeFileSync(path.join(baseDir, "main.vue"), configDiv, {});
|
167
|
+
return {
|
168
|
+
entry: indexPath,
|
169
|
+
title: options.projectTitle + "首页"
|
170
|
+
};
|
171
|
+
}
|
172
|
+
}
|
173
|
+
exports.FastPages = FastPages;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export declare class FastVueMultiConfig {
|
2
|
+
private static getGlobalConfigObj;
|
3
|
+
/**
|
4
|
+
* 获取系统全局变量值
|
5
|
+
*/
|
6
|
+
static getGlobalConfig(configKey: string): any;
|
7
|
+
/**
|
8
|
+
* 设置系统全局变量值
|
9
|
+
* @param configKey 变量名称
|
10
|
+
* @param configValue 变量值
|
11
|
+
*/
|
12
|
+
static setGlobalConfig(configKey: string, configValue: any): void;
|
13
|
+
/**
|
14
|
+
* 判断目标级别是否在项目配置的编译级别内
|
15
|
+
* @param targetLevel
|
16
|
+
*/
|
17
|
+
static isBuildLevel(targetLevel: number): boolean;
|
18
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.FastVueMultiConfig = void 0;
|
4
|
+
class FastVueMultiConfig {
|
5
|
+
static getGlobalConfigObj() {
|
6
|
+
// @ts-ignore
|
7
|
+
if (!window["__SystemGlobalConfig"]) {
|
8
|
+
//注意:此处变量 SystemGlobalConfig 在 webpack.DefinePlugin 编译后会替换成原始值,所以需要用window对象存储一下
|
9
|
+
// @ts-ignore
|
10
|
+
window["__SystemGlobalConfig"] = SystemGlobalConfig;
|
11
|
+
}
|
12
|
+
// @ts-ignore
|
13
|
+
return window["__SystemGlobalConfig"];
|
14
|
+
}
|
15
|
+
/**
|
16
|
+
* 获取系统全局变量值
|
17
|
+
*/
|
18
|
+
static getGlobalConfig(configKey) {
|
19
|
+
try {
|
20
|
+
return this.getGlobalConfigObj()[configKey];
|
21
|
+
}
|
22
|
+
catch (e) {
|
23
|
+
console.error("获取全局变量配置异常!", e);
|
24
|
+
return null;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
/**
|
28
|
+
* 设置系统全局变量值
|
29
|
+
* @param configKey 变量名称
|
30
|
+
* @param configValue 变量值
|
31
|
+
*/
|
32
|
+
static setGlobalConfig(configKey, configValue) {
|
33
|
+
this.getGlobalConfigObj()[configKey] = configValue;
|
34
|
+
}
|
35
|
+
/**
|
36
|
+
* 判断目标级别是否在项目配置的编译级别内
|
37
|
+
* @param targetLevel
|
38
|
+
*/
|
39
|
+
static isBuildLevel(targetLevel) {
|
40
|
+
return BuildLevel >= targetLevel;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
exports.FastVueMultiConfig = FastVueMultiConfig;
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import { FastBuildOption } from "./FastBuildOption";
|
2
|
+
/**
|
3
|
+
* 项目相关操作
|
4
|
+
* @author Janesen
|
5
|
+
*/
|
6
|
+
export declare class FastVueMultiPages {
|
7
|
+
private static projectGlobalConfig;
|
8
|
+
/**
|
9
|
+
* 获取默认的vue配置文件
|
10
|
+
* @param dirName 项目根目录,建议取值 {@link __dirname}
|
11
|
+
* @param options 更多选项配置 {@link FastBuildOption}
|
12
|
+
*/
|
13
|
+
static getDefaultVueConfig(dirName: string, options: FastBuildOption): any;
|
14
|
+
/**
|
15
|
+
* 设置全局变量值
|
16
|
+
* @param key 变量名
|
17
|
+
* @param data 变量值
|
18
|
+
*/
|
19
|
+
private static setGlobalConfig;
|
20
|
+
/**
|
21
|
+
* 是否是 vue-cli-service build 命令构建模式
|
22
|
+
*/
|
23
|
+
static isVueCliServerBuild(): boolean;
|
24
|
+
/**
|
25
|
+
* 是否是 vue-cli-service server 命令构建模式
|
26
|
+
*/
|
27
|
+
static isVueCliServerServer(): boolean;
|
28
|
+
/**
|
29
|
+
* 是否是正式版本,production
|
30
|
+
*/
|
31
|
+
static isProduction(): boolean;
|
32
|
+
/**
|
33
|
+
* 是否的打包开发版本,development
|
34
|
+
*/
|
35
|
+
static isDevelopment(): boolean;
|
36
|
+
/**
|
37
|
+
* 是否的打包测试版本,test
|
38
|
+
*/
|
39
|
+
static isVueTest(): boolean;
|
40
|
+
/**
|
41
|
+
* 获取运行脚本 npm_lifecycle_script 里的参数值,例如:--model production 参数名:--model 参数值:production
|
42
|
+
* @param argument
|
43
|
+
*/
|
44
|
+
static getScriptArgumentValue(argument: string): string | null;
|
45
|
+
/**
|
46
|
+
* 获取命令参数 --src
|
47
|
+
*/
|
48
|
+
static getSrcPageDir(): string | null;
|
49
|
+
/**
|
50
|
+
* 获取命令参数 --out
|
51
|
+
*/
|
52
|
+
static getOutPageDir(): string | null;
|
53
|
+
/**
|
54
|
+
* 获取命令参数 --debug 的值
|
55
|
+
*/
|
56
|
+
static isServiceDebug(): boolean;
|
57
|
+
/**
|
58
|
+
* 彻底删除指定目录文件
|
59
|
+
* @param path
|
60
|
+
*/
|
61
|
+
private static removeFile;
|
62
|
+
}
|