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/index.js CHANGED
@@ -1,329 +1,333 @@
1
- // funkophile/index.js
2
-
3
- const chokidar = require('chokidar');
4
- const createSelector = require('reselect').createSelector;
5
- const createStore = require('redux').createStore;
6
- const fs = require("fs")
7
- const fse = require("fs-extra")
8
- const glob = require("glob-promise");
9
- const path = require("path")
10
- const Promise = require("bluebird")
11
-
12
- Promise.config({
13
- cancellation: true
14
- });
15
-
16
- const configFile = path.resolve(process.argv[2]);
17
- const funkophileConfig = require(configFile)
18
- const mode = process.argv[3]
19
- const keyToWatch = process.argv[4]
20
-
21
- const INITIALIZE = 'INITIALIZE';
22
- const UPSERT = 'UPSERT';
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
- function omit(key, obj) {
106
- const {
107
- [key]: omitted, ...rest
108
- } = obj;
109
- return rest;
110
- }
111
-
112
- const store = createStore((state = {
113
- initialLoad: true,
114
- ...funkophileConfig.initialState,
115
- timestamp: Date.now()
116
- }, action) => {
117
- // console.log("\u001b[7m\u001b[35m ||| Redux recieved action \u001b[0m", action.type)
118
- if (!action.type.includes('@@redux')) {
119
-
120
- if (action.type === INITIALIZE) {
121
- return {
122
- ...state,
123
- initialLoad: false,
124
- timestamp: Date.now()
125
- }
126
- } else if (action.type === UPSERT) {
127
- return {
128
- ...state,
129
- [action.payload.key]: {
130
- ...state[action.payload.key],
131
- ...{
132
- [action.payload.src]: action.payload.contents
133
- }
134
- },
135
- timestamp: Date.now()
136
- }
137
- } else if (action.type === REMOVE) {
138
- return {
139
- ...state,
140
- [action.payload.key]: omit(action.payload.file, state[action.payload.key]),
141
- timestamp: Date.now()
142
- }
143
- } else {
144
- console.error("Redux was asked to handle an unknown action type: " + action.type)
145
- process.exit(-1)
146
- }
147
- return state
148
- }
149
- })
150
-
151
- const finalSelector = funkophileConfig.outputs(Object.keys(funkophileConfig.inputs).reduce((mm, inputKey) => {
152
- return {
153
- ...mm,
154
- [inputKey]: createSelector([(x) => x], (root) => root[inputKey])
155
- }
156
- }, {}))
157
-
158
-
159
- // Wait for all the file watchers to check in
160
- Promise.all(
161
- Object.keys(funkophileConfig.inputs)
162
- // ['FUNKYBUNDLE']
163
- .map((inputRuleKey) => {
164
- const p = path.resolve(`./${funkophileConfig.options.inFolder}/${funkophileConfig.inputs[inputRuleKey] || ''}`)
165
-
166
- // console.log("mark3", p)
167
-
168
- return new Promise((fulfill, reject) => {
169
- if (mode === "build") {
170
- glob(p, {}).then((files) => {
171
- files.forEach((file) => {
172
- dispatchUpsert(store, inputRuleKey, file, funkophileConfig.encodings);
173
- })
174
- }).then(() => {
175
- fulfill()
176
- })
177
- } else if (mode === "watch") {
178
-
179
- chokidar.watch(p, {})
180
- .on('error', error => {
181
- logger.watchError(p)
182
- })
183
- .on('ready', () => {
184
- logger.watchReady(p)
185
- fulfill()
186
- })
187
- .on('add', p => {
188
- logger.watchAdd(p)
189
- dispatchUpsert(store, inputRuleKey, './' + p, funkophileConfig.encodings);
190
- })
191
- .on('change', p => {
192
- logger.watchChange(p)
193
- dispatchUpsert(store, inputRuleKey, './' + p, funkophileConfig.encodings);
194
- })
195
- .on('unlink', p => {
196
- logger.watchUnlink(p)
197
- store.dispatch({
198
- type: REMOVE,
199
- payload: {
200
- key: inputRuleKey,
201
- file: './' + p
202
- }
203
- })
204
- })
205
- .on('unlinkDir', p => {
206
- logger.watchUnlink(p)
207
- })
208
- // .on('raw', (event, p, details) => { // internal
209
- // log('Raw event info:', event, p, details);
210
- // })
211
-
212
- } else {
213
- console.error(`The 3rd argument should be 'watch' or 'build', not "${mode}"`)
214
- process.exit(-1)
215
- }
216
-
217
- });
218
- })).then(function() {
219
-
220
- // listen for changes to the store
221
- store.subscribe(() => {
222
- const s = store.getState()
223
-
224
- logger.stateChange()
225
- const outputs = finalSelector(s)
226
-
227
- if (outputPromise.isPending()) {
228
- console.log('cancelling previous write!')
229
- outputPromise.cancel()
230
- }
231
-
232
- outputPromise = Promise.all(
233
- Array.from(new Set(Object.keys(previousState).concat(Object.keys(outputs))))
234
- .map((key) => {
235
-
236
- return new Promise((fulfill, reject) => {
237
- if (!outputs[key]) {
238
-
239
- const file = funkophileConfig.options.outFolder + "/" + key
240
- logger.removedFile(file)
241
-
242
- try {
243
- fse.unlinkSync('./' + file)
244
- cleanEmptyFoldersRecursively('./' + file.substring(0, file.lastIndexOf("/")))
245
- } catch (ex) {
246
- // console.error('inner', ex.message);
247
- // throw ex;
248
- } finally {
249
- // console.log('finally');
250
- return;
251
- }
252
- delete previousState[key]
253
- fulfill()
254
- } else {
255
- if (outputs[key] !== previousState[key]) {
256
- previousState[key] = outputs[key]
257
-
258
- const relativeFilePath = './' + funkophileConfig.options.outFolder + "/" + key;
259
- const contents = outputs[key];
260
-
261
- if (typeof contents === "function") {
262
- logger.writingFunction(relativeFilePath)
263
- contents((err, res) => {
264
- fse.outputFile(relativeFilePath, res, fulfill);
265
- logger.writingString(relativeFilePath);
266
- })
267
-
268
- } else if (typeof contents === 'string') {
269
- fse.outputFile(relativeFilePath, contents, fulfill);
270
- logger.writingString(relativeFilePath);
271
-
272
- } else if (Buffer.isBuffer(contents)) {
273
- fse.outputFile(relativeFilePath, contents, fulfill);
274
- logger.writingString(relativeFilePath);
275
-
276
- } else if (Array.isArray(contents)) {
277
- fse.outputFile(relativeFilePath, JSON.stringify(contents), fulfill);
278
- logger.writingString(relativeFilePath);
279
-
280
- } else if (typeof contents.then === 'function') {
281
- logger.writingPromise(relativeFilePath)
282
- Promise.resolve(contents).then(function(value) {
283
-
284
- if (value instanceof Error) {
285
- logger.writingError(relativeFilePath, value.message)
286
- } else {
287
- fse.outputFile(relativeFilePath, value, fulfill);
288
- logger.writingString(relativeFilePath);
289
- }
290
-
291
- }, function(value) {
292
- // not called
293
- });
294
-
295
- } else {
296
- console.log(`I don't recognize what this is but I will try to write it to a file: ` + relativeFilePath, contents)
297
- fse.outputFile(relativeFilePath, JSON.stringify(contents, null, 2), fulfill);
298
- logger.writingString(relativeFilePath);
299
- }
300
- } else {
301
- fulfill()
302
- }
303
- }
304
- });
305
-
306
- })
307
- ).then(() => {
308
- cleanEmptyFoldersRecursively(funkophileConfig.options.outFolder);
309
-
310
- if (mode === "build") {
311
- logger.done()
312
- } else if (mode === "watch") {
313
- logger.waiting()
314
- } else {
315
- console.error(`The 3rd argument should be 'watch' or 'build', not "${mode}"`)
316
- process.exit(-1)
317
- }
318
-
319
- })
320
- })
321
-
322
- // lastly, turn the store `on`.
323
- // This is to prevent unecessary recomputations when initialy adding files to redux
324
- store.dispatch({
325
- type: INITIALIZE,
326
- payload: true
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
+ });