funkophile 0.0.2 → 0.0.5
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/funkophileHelpers.d.ts +108 -0
- package/funkophileHelpers.js +45 -44
- package/funkophileHelpers.ts +41 -0
- package/index.d.ts +2 -0
- package/index.js +332 -328
- package/index.ts +395 -0
- package/package.json +27 -3
- package/tsconfig.json +11 -0
package/index.js
CHANGED
|
@@ -1,329 +1,333 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const REMOVE = 'REMOVE';
|
|
24
|
-
|
|
25
|
-
const previousState = {}
|
|
26
|
-
let outputPromise = Promise.resolve();
|
|
27
|
-
|
|
28
|
-
const logger = {
|
|
29
|
-
watchError: (p) => console.log("\u001b[7m ! \u001b[0m" + p),
|
|
30
|
-
watchReady: (p) => console.log("\u001b[7m\u001b[36m < \u001b[0m" + p),
|
|
31
|
-
watchAdd: (p) => console.log("\u001b[7m\u001b[34m + \u001b[0m./" + p),
|
|
32
|
-
watchChange: (p) => console.log("\u001b[7m\u001b[35m * \u001b[0m" + p),
|
|
33
|
-
watchUnlink: (p) => console.log("\u001b[7m\u001b[31m - \u001b[0m./" + p),
|
|
34
|
-
|
|
35
|
-
stateChange: () => console.log("\u001b[7m\u001b[31m --- Redux state changed --- \u001b[0m"),
|
|
36
|
-
|
|
37
|
-
cleaningEmptyfolder: (p) => console.log("\u001b[31m\u001b[7m XXX! \u001b[0m" + p),
|
|
38
|
-
|
|
39
|
-
readingFile: (p) => console.log("\u001b[31m <-- \u001b[0m" + p),
|
|
40
|
-
removedFile: (p) => console.log("\u001b[31m\u001b[7m ??? \u001b[0m./" + p),
|
|
41
|
-
|
|
42
|
-
writingString: (p) => console.log("\u001b[32m --> \u001b[0m" + p),
|
|
43
|
-
writingFunction: (p) => console.log("\u001b[33m ... \u001b[0m" + p),
|
|
44
|
-
writingPromise: (p) => console.log("\u001b[33m ... \u001b[0m" + p),
|
|
45
|
-
writingError: (p, message) => console.log("\u001b[31m !!! \u001b[0m" + p + " " + message),
|
|
46
|
-
|
|
47
|
-
waiting: () => console.log("\u001b[7m Funkophile is done for now but waiting on changes...\u001b[0m "),
|
|
48
|
-
done: () => console.log("\u001b[7m Funkophile is done!\u001b[0m ")
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function cleanEmptyFoldersRecursively(folder) {
|
|
53
|
-
var isDir = fs.statSync(folder).isDirectory();
|
|
54
|
-
if (!isDir) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
var files = fs.readdirSync(folder);
|
|
58
|
-
if (files.length > 0) {
|
|
59
|
-
files.forEach(function(file) {
|
|
60
|
-
var fullPath = path.join(folder, file);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// re-evaluate files; after deleting subfolder
|
|
64
|
-
// we may have parent folder empty now
|
|
65
|
-
files = fs.readdirSync(folder);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (files.length == 0) {
|
|
69
|
-
logger.cleaningEmptyfolder(folder)
|
|
70
|
-
|
|
71
|
-
fs.rmdirSync(folder);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const dispatchUpsert = (store, key, file, encodings) => {
|
|
77
|
-
logger.readingFile(file)
|
|
78
|
-
store.dispatch({
|
|
79
|
-
type: UPSERT,
|
|
80
|
-
payload: {
|
|
81
|
-
key: key,
|
|
82
|
-
src: file,
|
|
83
|
-
contents: fse.readFileSync(file, Object.keys(encodings).find((e) => encodings[e].includes(file.split('.')[1])))
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// const filetype = file.split('.')[2]
|
|
88
|
-
// const encoding = Object.keys(encodings).find((e) => encodings[e].includes(filetype))
|
|
89
|
-
// const relativeFilePath = './' + file;
|
|
90
|
-
// console.log("\u001b[31m <-- \u001b[0m" + file)
|
|
91
|
-
// fse.readFile(file, encoding).then((contents) => {
|
|
92
|
-
// store.dispatch({
|
|
93
|
-
// type: UPSERT,
|
|
94
|
-
// payload: {
|
|
95
|
-
// key: key,
|
|
96
|
-
// src: file,
|
|
97
|
-
// contents: contents
|
|
98
|
-
// }
|
|
99
|
-
// });
|
|
100
|
-
// });
|
|
101
|
-
|
|
102
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
103
23
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
var chokidar_1 = require("chokidar");
|
|
26
|
+
var reselect_1 = require("reselect");
|
|
27
|
+
var redux_1 = require("redux");
|
|
28
|
+
var fs_1 = require("fs");
|
|
29
|
+
var fs_extra_1 = require("fs-extra");
|
|
30
|
+
var glob_promise_1 = require("glob-promise");
|
|
31
|
+
var path_1 = require("path");
|
|
32
|
+
var bluebird_1 = require("bluebird");
|
|
33
|
+
exports.default = (function () {
|
|
34
|
+
if (process.argv[2] &&
|
|
35
|
+
(process.argv[3] === "watch" || process.argv[3] === "build")) {
|
|
36
|
+
var configFile = path_1.default.resolve(process.argv[2]);
|
|
37
|
+
var mode_1 = process.argv[3];
|
|
38
|
+
// console.log("configfile", configFile);
|
|
39
|
+
Promise.resolve("".concat(configFile)).then(function (s) { return require(s); }).then(function (funkophileConfigModule) {
|
|
40
|
+
var funkophileConfig = funkophileConfigModule.default;
|
|
41
|
+
// console.log("funkophileConfig", (funkophileConfig));
|
|
42
|
+
bluebird_1.default.config({
|
|
43
|
+
cancellation: true,
|
|
44
|
+
});
|
|
45
|
+
var INITIALIZE = "INITIALIZE";
|
|
46
|
+
var UPSERT = "UPSERT";
|
|
47
|
+
var REMOVE = "REMOVE";
|
|
48
|
+
var previousState = {};
|
|
49
|
+
var outputPromise = bluebird_1.default.resolve();
|
|
50
|
+
var logger = {
|
|
51
|
+
watchError: function (p) { return console.log("\u001b[7m ! \u001b[0m" + p); },
|
|
52
|
+
watchReady: function (p) {
|
|
53
|
+
return console.log("\u001b[7m\u001b[36m < \u001b[0m" + p);
|
|
54
|
+
},
|
|
55
|
+
watchAdd: function (p) {
|
|
56
|
+
return console.log("\u001b[7m\u001b[34m + \u001b[0m./" + p);
|
|
57
|
+
},
|
|
58
|
+
watchChange: function (p) {
|
|
59
|
+
return console.log("\u001b[7m\u001b[35m * \u001b[0m" + p);
|
|
60
|
+
},
|
|
61
|
+
watchUnlink: function (p) {
|
|
62
|
+
return console.log("\u001b[7m\u001b[31m - \u001b[0m./" + p);
|
|
63
|
+
},
|
|
64
|
+
stateChange: function () {
|
|
65
|
+
return console.log("\u001b[7m\u001b[31m --- Redux state changed --- \u001b[0m");
|
|
66
|
+
},
|
|
67
|
+
cleaningEmptyfolder: function (p) {
|
|
68
|
+
return console.log("\u001b[31m\u001b[7m XXX! \u001b[0m" + p);
|
|
69
|
+
},
|
|
70
|
+
readingFile: function (p) { return console.log("\u001b[31m <-- \u001b[0m" + p); },
|
|
71
|
+
removedFile: function (p) {
|
|
72
|
+
return console.log("\u001b[31m\u001b[7m ??? \u001b[0m./" + p);
|
|
73
|
+
},
|
|
74
|
+
writingString: function (p) {
|
|
75
|
+
return console.log("\u001b[32m --> \u001b[0m" + p);
|
|
76
|
+
},
|
|
77
|
+
writingFunction: function (p) {
|
|
78
|
+
return console.log("\u001b[33m ... \u001b[0m" + p);
|
|
79
|
+
},
|
|
80
|
+
writingPromise: function (p) {
|
|
81
|
+
return console.log("\u001b[33m ... \u001b[0m" + p);
|
|
82
|
+
},
|
|
83
|
+
writingError: function (p, message) {
|
|
84
|
+
return console.log("\u001b[31m !!! \u001b[0m" + p + " " + message);
|
|
85
|
+
},
|
|
86
|
+
waiting: function () {
|
|
87
|
+
return console.log("\u001b[7m Funkophile is done for now but waiting on changes...\u001b[0m ");
|
|
88
|
+
},
|
|
89
|
+
done: function () { return console.log("\u001b[7m Funkophile is done!\u001b[0m "); },
|
|
90
|
+
};
|
|
91
|
+
function cleanEmptyFoldersRecursively(folder) {
|
|
92
|
+
var isDir = fs_1.default.statSync(folder).isDirectory();
|
|
93
|
+
if (!isDir) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
var files = fs_1.default.readdirSync(folder);
|
|
97
|
+
if (files.length > 0) {
|
|
98
|
+
files.forEach(function (file) {
|
|
99
|
+
var fullPath = path_1.default.join(folder, file);
|
|
100
|
+
});
|
|
101
|
+
// re-evaluate files; after deleting subfolder
|
|
102
|
+
// we may have parent folder empty now
|
|
103
|
+
files = fs_1.default.readdirSync(folder);
|
|
104
|
+
}
|
|
105
|
+
if (files.length == 0) {
|
|
106
|
+
logger.cleaningEmptyfolder(folder);
|
|
107
|
+
fs_1.default.rmdirSync(folder);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
var dispatchUpsert = function (store, key, file, encodings) {
|
|
112
|
+
var fileType = file.split(".").slice(-2, -1)[0];
|
|
113
|
+
var encoding = Object.keys(encodings).find(function (e) {
|
|
114
|
+
return encodings[e].includes(fileType);
|
|
115
|
+
});
|
|
116
|
+
if (!fileType || !encoding) {
|
|
117
|
+
console.log("Unknown file type for ", file, "Defaulting to utf8");
|
|
118
|
+
encoding = "utf8";
|
|
119
|
+
}
|
|
120
|
+
// console.log("dispatchUpsert", encoding, file)
|
|
121
|
+
logger.readingFile(file);
|
|
122
|
+
store.dispatch({
|
|
123
|
+
type: UPSERT,
|
|
124
|
+
payload: {
|
|
125
|
+
key: key,
|
|
126
|
+
src: file,
|
|
127
|
+
contents: fs_extra_1.default.readFileSync(file, encoding),
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
function omit(key, obj) {
|
|
132
|
+
var _a = obj, _b = key, omitted = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
133
|
+
return rest;
|
|
134
|
+
}
|
|
135
|
+
var store = (0, redux_1.createStore)(function (state, action) {
|
|
136
|
+
var _a, _b, _c;
|
|
137
|
+
if (state === void 0) { state = __assign(__assign({ initialLoad: true }, funkophileConfig.initialState), { timestamp: Date.now() }); }
|
|
138
|
+
// console.log("\u001b[7m\u001b[35m ||| Redux recieved action \u001b[0m", action.type)
|
|
139
|
+
if (!action.type.includes("@@redux")) {
|
|
140
|
+
if (action.type === INITIALIZE) {
|
|
141
|
+
return __assign(__assign({}, state), { initialLoad: false, timestamp: Date.now() });
|
|
142
|
+
}
|
|
143
|
+
else if (action.type === UPSERT) {
|
|
144
|
+
return __assign(__assign({}, state), (_a = {}, _a[action["payload"].key] = __assign(__assign({}, state[action.payload.key]), (_b = {},
|
|
145
|
+
_b[action["payload"].src] = action["payload"].contents,
|
|
146
|
+
_b)), _a.timestamp = Date.now(), _a));
|
|
147
|
+
}
|
|
148
|
+
else if (action.type === REMOVE) {
|
|
149
|
+
return __assign(__assign({}, state), (_c = {}, _c[action["payload"].key] = omit(action["payload"].file, state[action["payload"].key]), _c.timestamp = Date.now(), _c));
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
console.error("Redux was asked to handle an unknown action type: " +
|
|
153
|
+
action.type);
|
|
154
|
+
process.exit(-1);
|
|
155
|
+
}
|
|
156
|
+
// return state
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
var finalSelector = funkophileConfig.outputs(Object.keys(funkophileConfig.inputs).reduce(function (mm, inputKey) {
|
|
160
|
+
var _a;
|
|
161
|
+
return __assign(__assign({}, mm), (_a = {}, _a[inputKey] = (0, reselect_1.createSelector)([function (x) { return x; }], function (root) { return root[inputKey]; }), _a));
|
|
162
|
+
}, {}));
|
|
163
|
+
// Wait for all the file watchers to check in
|
|
164
|
+
bluebird_1.default.all(Object.keys(funkophileConfig.inputs)
|
|
165
|
+
.map(function (inputRuleKey) {
|
|
166
|
+
var p = path_1.default.resolve("./".concat(funkophileConfig.options.inFolder, "/").concat(funkophileConfig.inputs[inputRuleKey] || ""));
|
|
167
|
+
return new bluebird_1.default(function (fulfill, reject) {
|
|
168
|
+
if (mode_1 === "build") {
|
|
169
|
+
(0, glob_promise_1.default)(p, {})
|
|
170
|
+
.then(function (files) {
|
|
171
|
+
files.forEach(function (file) {
|
|
172
|
+
dispatchUpsert(store, inputRuleKey, file, funkophileConfig.encodings);
|
|
173
|
+
});
|
|
174
|
+
})
|
|
175
|
+
.then(function () {
|
|
176
|
+
fulfill();
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
else if (mode_1 === "watch") {
|
|
180
|
+
chokidar_1.default
|
|
181
|
+
.watch(p, {})
|
|
182
|
+
.on("error", function (error) {
|
|
183
|
+
logger.watchError(p);
|
|
184
|
+
})
|
|
185
|
+
.on("ready", function () {
|
|
186
|
+
logger.watchReady(p);
|
|
187
|
+
fulfill();
|
|
188
|
+
})
|
|
189
|
+
.on("add", function (p) {
|
|
190
|
+
logger.watchAdd(p);
|
|
191
|
+
dispatchUpsert(store, inputRuleKey, "./" + p, funkophileConfig.encodings);
|
|
192
|
+
})
|
|
193
|
+
.on("change", function (p) {
|
|
194
|
+
logger.watchChange(p);
|
|
195
|
+
dispatchUpsert(store, inputRuleKey, "./" + p, funkophileConfig.encodings);
|
|
196
|
+
})
|
|
197
|
+
.on("unlink", function (p) {
|
|
198
|
+
logger.watchUnlink(p);
|
|
199
|
+
store.dispatch({
|
|
200
|
+
type: REMOVE,
|
|
201
|
+
payload: {
|
|
202
|
+
key: inputRuleKey,
|
|
203
|
+
file: "./" + p,
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
})
|
|
207
|
+
.on("unlinkDir", function (p) {
|
|
208
|
+
logger.watchUnlink(p);
|
|
209
|
+
});
|
|
210
|
+
// .on('raw', (event, p, details) => { // internal
|
|
211
|
+
// log('Raw event info:', event, p, details);
|
|
212
|
+
// })
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
console.error("The 3rd argument should be 'watch' or 'build', not \"".concat(mode_1, "\""));
|
|
216
|
+
process.exit(-1);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
})).then(function () {
|
|
220
|
+
// listen for changes to the store
|
|
221
|
+
store.subscribe(function () {
|
|
222
|
+
var s = store.getState();
|
|
223
|
+
logger.stateChange();
|
|
224
|
+
var outputs = finalSelector(s);
|
|
225
|
+
if (outputPromise.isPending()) {
|
|
226
|
+
console.log("cancelling previous write!");
|
|
227
|
+
outputPromise.cancel();
|
|
228
|
+
}
|
|
229
|
+
outputPromise = bluebird_1.default.all(Array.from(new Set(Object.keys(previousState).concat(Object.keys(outputs)))).map(function (key) {
|
|
230
|
+
return new bluebird_1.default(function (fulfill, reject) {
|
|
231
|
+
if (!outputs[key]) {
|
|
232
|
+
var file = funkophileConfig.options.outFolder + "/" + key;
|
|
233
|
+
logger.removedFile(file);
|
|
234
|
+
try {
|
|
235
|
+
fs_extra_1.default.unlinkSync("./" + file);
|
|
236
|
+
cleanEmptyFoldersRecursively("./" + file.substring(0, file.lastIndexOf("/")));
|
|
237
|
+
}
|
|
238
|
+
catch (ex) {
|
|
239
|
+
// console.error('inner', ex.message);
|
|
240
|
+
// throw ex;
|
|
241
|
+
}
|
|
242
|
+
finally {
|
|
243
|
+
// console.log('finally');
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
// delete previousState[key]
|
|
247
|
+
// fulfill()
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
if (outputs[key] !== previousState[key]) {
|
|
251
|
+
previousState[key] = outputs[key];
|
|
252
|
+
var relativeFilePath_1 = "./" + funkophileConfig.options.outFolder + "/" + key;
|
|
253
|
+
var contents = outputs[key];
|
|
254
|
+
if (typeof contents === "function") {
|
|
255
|
+
logger.writingFunction(relativeFilePath_1);
|
|
256
|
+
contents(function (err, res) {
|
|
257
|
+
fs_extra_1.default.outputFile(relativeFilePath_1, res, fulfill);
|
|
258
|
+
logger.writingString(relativeFilePath_1);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
else if (typeof contents === "string") {
|
|
262
|
+
fs_extra_1.default.outputFile(relativeFilePath_1, contents, fulfill);
|
|
263
|
+
logger.writingString(relativeFilePath_1);
|
|
264
|
+
}
|
|
265
|
+
else if (Buffer.isBuffer(contents)) {
|
|
266
|
+
fs_extra_1.default.outputFile(relativeFilePath_1, contents, fulfill);
|
|
267
|
+
logger.writingString(relativeFilePath_1);
|
|
268
|
+
}
|
|
269
|
+
else if (Array.isArray(contents)) {
|
|
270
|
+
fs_extra_1.default.outputFile(relativeFilePath_1, JSON.stringify(contents), fulfill);
|
|
271
|
+
logger.writingString(relativeFilePath_1);
|
|
272
|
+
}
|
|
273
|
+
else if (typeof contents.then === "function") {
|
|
274
|
+
logger.writingPromise(relativeFilePath_1);
|
|
275
|
+
bluebird_1.default.resolve(contents).then(function (value) {
|
|
276
|
+
if (value instanceof Error) {
|
|
277
|
+
logger.writingError(relativeFilePath_1, value.message);
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
fs_extra_1.default.outputFile(relativeFilePath_1, value, fulfill);
|
|
281
|
+
logger.writingString(relativeFilePath_1);
|
|
282
|
+
}
|
|
283
|
+
}, function (value) {
|
|
284
|
+
// not called
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
else if (typeof contents === "object") {
|
|
288
|
+
fs_extra_1.default.outputFile(relativeFilePath_1, JSON.stringify(contents), fulfill);
|
|
289
|
+
logger.writingString(relativeFilePath_1);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
console.log("I don't recognize what this is but I will try to write it to a file: " +
|
|
293
|
+
relativeFilePath_1, typeof contents, contents);
|
|
294
|
+
fs_extra_1.default.outputFile(relativeFilePath_1, contents, fulfill);
|
|
295
|
+
logger.writingString(relativeFilePath_1);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
fulfill();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
})).then(function () {
|
|
304
|
+
cleanEmptyFoldersRecursively(funkophileConfig.options.outFolder);
|
|
305
|
+
if (mode_1 === "build") {
|
|
306
|
+
logger.done();
|
|
307
|
+
}
|
|
308
|
+
else if (mode_1 === "watch") {
|
|
309
|
+
logger.waiting();
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
console.error("The 3rd argument should be 'watch' or 'build', not \"".concat(mode_1, "\""));
|
|
313
|
+
process.exit(-1);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
// lastly, turn the store `on`.
|
|
318
|
+
// This is to prevent unecessary recomputations when initialy adding files to redux
|
|
319
|
+
store.dispatch({
|
|
320
|
+
type: INITIALIZE,
|
|
321
|
+
payload: true,
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
console.error("command line arguments do not make sense");
|
|
328
|
+
console.error("first argument should be a funkophile config file");
|
|
329
|
+
console.error("second argument should be a 'build' or 'watch'");
|
|
330
|
+
console.error("You passed", process.argv);
|
|
331
|
+
process.exit(-1);
|
|
332
|
+
}
|
|
333
|
+
});
|