UNPKG

3.14 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const _ = require("lodash");
4const changeCase = require("change-case");
5const util_1 = require("../util");
6/**
7 * 请求核心类
8 *
9 * @export
10 * @class RequestCore
11 * @implements {Request.Core}
12 */
13class RequestCore {
14 /**
15 * Creates an instance of RequestCore.
16 * @param {Request.Options} options
17 * @memberof RequestCore
18 */
19 constructor(options) {
20 // 通过resolveDep的请求依赖分析方法,将结果合并到RequestCore实例
21 _.merge(this, util_1.resolveDep(options));
22 }
23}
24exports.RequestCore = RequestCore;
25/**
26 * 请求扩展类
27 *
28 * @export
29 * @class RequestExtend
30 * @extends {RequestCore}
31 * @implements {Request.Extend}
32 */
33class RequestExtend extends RequestCore {
34 /**
35 * 是否单文件类型
36 *
37 * @readonly
38 * @memberof RequestExtend
39 */
40 get isSFC() {
41 return this.isWxa || this.isWxp || this.isWxc;
42 }
43 /**
44 * 是否原生文件类型
45 *
46 * @readonly
47 * @memberof RequestExtend
48 */
49 get isNFC() {
50 return this.isTemplate || this.isScript || this.isStyle;
51 }
52 /**
53 * 是否模板文件类型
54 *
55 * @readonly
56 * @memberof RequestExtend
57 */
58 get isTemplate() {
59 return this.isWxml;
60 }
61 /**
62 * 是否脚本文件类型
63 *
64 * @readonly
65 * @memberof RequestExtend
66 */
67 get isScript() {
68 return this.isJs || this.isTs || this.isCs || this.isWxs;
69 }
70 /**
71 * 是否样式文件类型
72 *
73 * @readonly
74 * @memberof RequestExtend
75 */
76 get isStyle() {
77 return this.isCss || this.isWxss || this.isLess || this.isPcss || this.isSass || this.isStylus;
78 }
79 /**
80 * 是否为静态文件(无依赖、无编译)
81 *
82 * @readonly
83 * @memberof RequestExtend
84 */
85 get isStatic() {
86 return this.isJson || this.isImage || this.isIconFont;
87 }
88 /**
89 * 是否为图标字体文件
90 *
91 * @readonly
92 * @memberof RequestExtend
93 */
94 get isIconFont() {
95 return this.isEot || this.isSvg || this.isTtf || this.isWoff;
96 }
97 /**
98 * 是否为图片文件
99 *
100 * @readonly
101 * @memberof RequestExtend
102 */
103 get isImage() {
104 return this.isPng || this.isJpg || this.isJpeg || this.isGif || this.isBmp || this.isWebp;
105 }
106 /**
107 * Creates an instance of RequestExtend.
108 * @param {Request.Options} options
109 * @memberof RequestExtend
110 */
111 constructor(options) {
112 super(options);
113 // 通过扩展名,取得key值
114 let key = _.findKey(util_1.config.ext, value => value === this.ext);
115 if (key) {
116 // 通过 key 值,设置实例中对应字段的真值,其余都为假值
117 this[`is${changeCase.pascalCase(key)}`] = true;
118 }
119 }
120}
121exports.RequestExtend = RequestExtend;
122/**
123 * 请求类
124 *
125 * @export
126 * @class Request
127 * @extends {RequestExtend}
128 */
129class Request extends RequestExtend {
130 constructor(options) {
131 super(options);
132 }
133}
134exports.Request = Request;