funkophile 0.0.4 → 0.0.6
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.d.ts +2 -1
- package/index.js +280 -247
- package/index.ts +394 -342
- package/package.json +1 -1
- package/tsconfig.json +11 -11
package/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
declare const _default: () => void;
|
|
2
|
+
export default _default;
|
package/index.js
CHANGED
|
@@ -30,271 +30,304 @@ var fs_extra_1 = require("fs-extra");
|
|
|
30
30
|
var glob_promise_1 = require("glob-promise");
|
|
31
31
|
var path_1 = require("path");
|
|
32
32
|
var bluebird_1 = require("bluebird");
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var UPSERT = 'UPSERT';
|
|
45
|
-
var REMOVE = 'REMOVE';
|
|
46
|
-
var previousState = {};
|
|
47
|
-
var outputPromise = bluebird_1.default.resolve();
|
|
48
|
-
var logger = {
|
|
49
|
-
watchError: function (p) { return console.log("\u001b[7m ! \u001b[0m" + p); },
|
|
50
|
-
watchReady: function (p) { return console.log("\u001b[7m\u001b[36m < \u001b[0m" + p); },
|
|
51
|
-
watchAdd: function (p) { return console.log("\u001b[7m\u001b[34m + \u001b[0m./" + p); },
|
|
52
|
-
watchChange: function (p) { return console.log("\u001b[7m\u001b[35m * \u001b[0m" + p); },
|
|
53
|
-
watchUnlink: function (p) { return console.log("\u001b[7m\u001b[31m - \u001b[0m./" + p); },
|
|
54
|
-
stateChange: function () { return console.log("\u001b[7m\u001b[31m --- Redux state changed --- \u001b[0m"); },
|
|
55
|
-
cleaningEmptyfolder: function (p) { return console.log("\u001b[31m\u001b[7m XXX! \u001b[0m" + p); },
|
|
56
|
-
readingFile: function (p) { return console.log("\u001b[31m <-- \u001b[0m" + p); },
|
|
57
|
-
removedFile: function (p) { return console.log("\u001b[31m\u001b[7m ??? \u001b[0m./" + p); },
|
|
58
|
-
writingString: function (p) { return console.log("\u001b[32m --> \u001b[0m" + p); },
|
|
59
|
-
writingFunction: function (p) { return console.log("\u001b[33m ... \u001b[0m" + p); },
|
|
60
|
-
writingPromise: function (p) { return console.log("\u001b[33m ... \u001b[0m" + p); },
|
|
61
|
-
writingError: function (p, message) { return console.log("\u001b[31m !!! \u001b[0m" + p + " " + message); },
|
|
62
|
-
waiting: function () { return console.log("\u001b[7m Funkophile is done for now but waiting on changes...\u001b[0m "); },
|
|
63
|
-
done: function () { return console.log("\u001b[7m Funkophile is done!\u001b[0m "); }
|
|
64
|
-
};
|
|
65
|
-
function cleanEmptyFoldersRecursively(folder) {
|
|
66
|
-
var isDir = fs_1.default.statSync(folder).isDirectory();
|
|
67
|
-
if (!isDir) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
var files = fs_1.default.readdirSync(folder);
|
|
71
|
-
if (files.length > 0) {
|
|
72
|
-
files.forEach(function (file) {
|
|
73
|
-
var fullPath = path_1.default.join(folder, file);
|
|
74
|
-
});
|
|
75
|
-
// re-evaluate files; after deleting subfolder
|
|
76
|
-
// we may have parent folder empty now
|
|
77
|
-
files = fs_1.default.readdirSync(folder);
|
|
78
|
-
}
|
|
79
|
-
if (files.length == 0) {
|
|
80
|
-
logger.cleaningEmptyfolder(folder);
|
|
81
|
-
fs_1.default.rmdirSync(folder);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
var dispatchUpsert = function (store, key, file, encodings) {
|
|
86
|
-
var fileType = file.split('.').slice(-2, -1)[0];
|
|
87
|
-
var encoding = Object.keys(encodings).find(function (e) { return encodings[e].includes(fileType); });
|
|
88
|
-
if (!fileType || !encoding) {
|
|
89
|
-
console.log("Unknown file type for ", file, "Defaulting to utf8");
|
|
90
|
-
encoding = 'utf8';
|
|
91
|
-
}
|
|
92
|
-
// console.log("dispatchUpsert", encoding, file)
|
|
93
|
-
logger.readingFile(file);
|
|
94
|
-
store.dispatch({
|
|
95
|
-
type: UPSERT,
|
|
96
|
-
payload: {
|
|
97
|
-
key: key,
|
|
98
|
-
src: file,
|
|
99
|
-
contents: fs_extra_1.default.readFileSync(file, encoding)
|
|
100
|
-
}
|
|
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,
|
|
101
44
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
var
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return
|
|
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;
|
|
114
95
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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);
|
|
122
104
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
105
|
+
if (files.length == 0) {
|
|
106
|
+
logger.cleaningEmptyfolder(folder);
|
|
107
|
+
fs_1.default.rmdirSync(folder);
|
|
108
|
+
return;
|
|
126
109
|
}
|
|
127
|
-
// return state
|
|
128
110
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
var p = path_1.default.resolve("./".concat(funkophileConfig.options.inFolder, "/").concat(funkophileConfig.inputs[inputRuleKey] || ''));
|
|
138
|
-
return new bluebird_1.default(function (fulfill, reject) {
|
|
139
|
-
if (mode_1 === "build") {
|
|
140
|
-
(0, glob_promise_1.default)(p, {}).then(function (files) {
|
|
141
|
-
files.forEach(function (file) {
|
|
142
|
-
dispatchUpsert(store, inputRuleKey, file, funkophileConfig.encodings);
|
|
143
|
-
});
|
|
144
|
-
}).then(function () {
|
|
145
|
-
fulfill();
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
else if (mode_1 === "watch") {
|
|
149
|
-
chokidar_1.default.watch(p, {})
|
|
150
|
-
.on('error', function (error) {
|
|
151
|
-
logger.watchError(p);
|
|
152
|
-
})
|
|
153
|
-
.on('ready', function () {
|
|
154
|
-
logger.watchReady(p);
|
|
155
|
-
fulfill();
|
|
156
|
-
})
|
|
157
|
-
.on('add', function (p) {
|
|
158
|
-
logger.watchAdd(p);
|
|
159
|
-
dispatchUpsert(store, inputRuleKey, './' + p, funkophileConfig.encodings);
|
|
160
|
-
})
|
|
161
|
-
.on('change', function (p) {
|
|
162
|
-
logger.watchChange(p);
|
|
163
|
-
dispatchUpsert(store, inputRuleKey, './' + p, funkophileConfig.encodings);
|
|
164
|
-
})
|
|
165
|
-
.on('unlink', function (p) {
|
|
166
|
-
logger.watchUnlink(p);
|
|
167
|
-
store.dispatch({
|
|
168
|
-
type: REMOVE,
|
|
169
|
-
payload: {
|
|
170
|
-
key: inputRuleKey,
|
|
171
|
-
file: './' + p
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
})
|
|
175
|
-
.on('unlinkDir', function (p) {
|
|
176
|
-
logger.watchUnlink(p);
|
|
177
|
-
});
|
|
178
|
-
// .on('raw', (event, p, details) => { // internal
|
|
179
|
-
// log('Raw event info:', event, p, details);
|
|
180
|
-
// })
|
|
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";
|
|
181
119
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
|
185
157
|
}
|
|
186
158
|
});
|
|
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
|
-
|
|
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("/")));
|
|
233
237
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
238
|
+
catch (ex) {
|
|
239
|
+
// console.error('inner', ex.message);
|
|
240
|
+
// throw ex;
|
|
237
241
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
242
|
+
finally {
|
|
243
|
+
// console.log('finally');
|
|
244
|
+
return;
|
|
241
245
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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);
|
|
250
258
|
logger.writingString(relativeFilePath_1);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
+
}
|
|
259
297
|
}
|
|
260
298
|
else {
|
|
261
|
-
|
|
262
|
-
fs_extra_1.default.outputFile(relativeFilePath_1, contents, fulfill);
|
|
263
|
-
logger.writingString(relativeFilePath_1);
|
|
299
|
+
fulfill();
|
|
264
300
|
}
|
|
265
301
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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);
|
|
269
314
|
}
|
|
270
315
|
});
|
|
271
|
-
})).then(function () {
|
|
272
|
-
cleanEmptyFoldersRecursively(funkophileConfig.options.outFolder);
|
|
273
|
-
if (mode_1 === "build") {
|
|
274
|
-
logger.done();
|
|
275
|
-
}
|
|
276
|
-
else if (mode_1 === "watch") {
|
|
277
|
-
logger.waiting();
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
console.error("The 3rd argument should be 'watch' or 'build', not \"".concat(mode_1, "\""));
|
|
281
|
-
process.exit(-1);
|
|
282
|
-
}
|
|
283
316
|
});
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
+
});
|
|
290
323
|
});
|
|
291
324
|
});
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
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
|
+
});
|