1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const path = require("path");
|
4 | const _ = require("lodash");
|
5 | const util_1 = require("../util");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | class WxSFM {
|
13 | |
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | constructor(source, request, options) {
|
21 | this.request = request;
|
22 | this.source = (source || '').trim();
|
23 | this.destExt = options.destExt;
|
24 | this.initDest();
|
25 | }
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | get isWxa() {
|
33 | return this.request.isWxa;
|
34 | }
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | get isWxp() {
|
42 | return this.request.isWxp;
|
43 | }
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | get isWxc() {
|
51 | return this.request.isWxc;
|
52 | }
|
53 | |
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | get isSFC() {
|
60 | return this.request.isSFC;
|
61 | }
|
62 | |
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | getDester(ext) {
|
70 | let ppath = path.parse(this.request.dest);
|
71 | ppath.base = ppath.name + ext;
|
72 | ppath.ext = ext;
|
73 | let dest = path.format(ppath);
|
74 | let destRelative = path.relative(util_1.config.cwd, dest);
|
75 | return {
|
76 | dest,
|
77 | destRelative
|
78 | };
|
79 | }
|
80 |
|
81 | generator() {
|
82 | util_1.log.fatal('WxSFM.generator Method not implemented.');
|
83 | return '';
|
84 | }
|
85 |
|
86 | beforeSave() {
|
87 |
|
88 | }
|
89 |
|
90 | save() {
|
91 | this.beforeSave();
|
92 | let code = this.generator();
|
93 | if (_.isString(code)) {
|
94 | this.write(code);
|
95 | }
|
96 | else {
|
97 | code.then(this.write.bind(this));
|
98 | }
|
99 | this.afterSave();
|
100 | }
|
101 |
|
102 | afterSave() {
|
103 |
|
104 | }
|
105 |
|
106 | beforeRemove() {
|
107 |
|
108 | }
|
109 |
|
110 | remove() {
|
111 | this.beforeRemove();
|
112 | util_1.log.msg(util_1.LogType.DELETE, this.destRelative);
|
113 | util_1.default.unlink(this.dest);
|
114 | this.afterRemove();
|
115 | }
|
116 |
|
117 | afterRemove() {
|
118 |
|
119 | }
|
120 |
|
121 | getDepends() {
|
122 | util_1.log.fatal('WxSFM.getDepends Method not implemented.');
|
123 | return [];
|
124 | }
|
125 |
|
126 | updateDepends(uses) {
|
127 | util_1.log.fatal('WxSFM.updateRequest Method not implemented.');
|
128 | }
|
129 | |
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | initDest() {
|
136 | let dester = this.getDester(this.destExt);
|
137 | this.dest = dester.dest;
|
138 | this.destRelative = dester.destRelative;
|
139 | }
|
140 | |
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | write(code) {
|
148 | util_1.log.msg(util_1.LogType.WRITE, this.destRelative);
|
149 | util_1.default.writeFile(this.dest, code);
|
150 | }
|
151 | }
|
152 | exports.WxSFM = WxSFM;
|