funkophile 0.0.1 → 0.0.2
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.js +1 -1
- package/index.js +42 -35
- package/package.json +1 -1
package/funkophileHelpers.js
CHANGED
|
@@ -13,7 +13,7 @@ module.exports = {
|
|
|
13
13
|
try{
|
|
14
14
|
return selected[Object.keys(selected)[0]]
|
|
15
15
|
} catch (e) {
|
|
16
|
-
console.error("error", e)
|
|
16
|
+
console.error("error in contentOfFile", e)
|
|
17
17
|
console.error("selected", selected)
|
|
18
18
|
console.error("selector", selector)
|
|
19
19
|
process.exit(-1)
|
package/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const chokidar = require('chokidar');
|
|
4
4
|
const createSelector = require('reselect').createSelector;
|
|
5
5
|
const createStore = require('redux').createStore;
|
|
6
|
+
const fs = require("fs")
|
|
6
7
|
const fse = require("fs-extra")
|
|
7
8
|
const glob = require("glob-promise");
|
|
8
9
|
const path = require("path")
|
|
@@ -12,7 +13,8 @@ Promise.config({
|
|
|
12
13
|
cancellation: true
|
|
13
14
|
});
|
|
14
15
|
|
|
15
|
-
const
|
|
16
|
+
const configFile = path.resolve(process.argv[2]);
|
|
17
|
+
const funkophileConfig = require(configFile)
|
|
16
18
|
const mode = process.argv[3]
|
|
17
19
|
const keyToWatch = process.argv[4]
|
|
18
20
|
|
|
@@ -24,23 +26,23 @@ const previousState = {}
|
|
|
24
26
|
let outputPromise = Promise.resolve();
|
|
25
27
|
|
|
26
28
|
const logger = {
|
|
27
|
-
watchError: (
|
|
28
|
-
watchReady: (
|
|
29
|
-
watchAdd: (
|
|
30
|
-
watchChange: (
|
|
31
|
-
watchUnlink: (
|
|
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),
|
|
32
34
|
|
|
33
35
|
stateChange: () => console.log("\u001b[7m\u001b[31m --- Redux state changed --- \u001b[0m"),
|
|
34
36
|
|
|
35
|
-
cleaningEmptyfolder: (
|
|
37
|
+
cleaningEmptyfolder: (p) => console.log("\u001b[31m\u001b[7m XXX! \u001b[0m" + p),
|
|
36
38
|
|
|
37
|
-
readingFile: (
|
|
38
|
-
removedFile: (
|
|
39
|
+
readingFile: (p) => console.log("\u001b[31m <-- \u001b[0m" + p),
|
|
40
|
+
removedFile: (p) => console.log("\u001b[31m\u001b[7m ??? \u001b[0m./" + p),
|
|
39
41
|
|
|
40
|
-
writingString: (
|
|
41
|
-
writingFunction: (
|
|
42
|
-
writingPromise: (
|
|
43
|
-
writingError: (
|
|
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),
|
|
44
46
|
|
|
45
47
|
waiting: () => console.log("\u001b[7m Funkophile is done for now but waiting on changes...\u001b[0m "),
|
|
46
48
|
done: () => console.log("\u001b[7m Funkophile is done!\u001b[0m ")
|
|
@@ -78,7 +80,7 @@ const dispatchUpsert = (store, key, file, encodings) => {
|
|
|
78
80
|
payload: {
|
|
79
81
|
key: key,
|
|
80
82
|
src: file,
|
|
81
|
-
contents: fse.readFileSync(file, Object.keys(encodings).find((e) => encodings[e].includes(file.split('.')[
|
|
83
|
+
contents: fse.readFileSync(file, Object.keys(encodings).find((e) => encodings[e].includes(file.split('.')[1])))
|
|
82
84
|
}
|
|
83
85
|
});
|
|
84
86
|
|
|
@@ -159,10 +161,13 @@ Promise.all(
|
|
|
159
161
|
Object.keys(funkophileConfig.inputs)
|
|
160
162
|
// ['FUNKYBUNDLE']
|
|
161
163
|
.map((inputRuleKey) => {
|
|
162
|
-
const
|
|
164
|
+
const p = path.resolve(`./${funkophileConfig.options.inFolder}/${funkophileConfig.inputs[inputRuleKey] || ''}`)
|
|
165
|
+
|
|
166
|
+
// console.log("mark3", p)
|
|
167
|
+
|
|
163
168
|
return new Promise((fulfill, reject) => {
|
|
164
169
|
if (mode === "build") {
|
|
165
|
-
glob(
|
|
170
|
+
glob(p, {}).then((files) => {
|
|
166
171
|
files.forEach((file) => {
|
|
167
172
|
dispatchUpsert(store, inputRuleKey, file, funkophileConfig.encodings);
|
|
168
173
|
})
|
|
@@ -171,37 +176,37 @@ Promise.all(
|
|
|
171
176
|
})
|
|
172
177
|
} else if (mode === "watch") {
|
|
173
178
|
|
|
174
|
-
chokidar.watch(
|
|
179
|
+
chokidar.watch(p, {})
|
|
175
180
|
.on('error', error => {
|
|
176
|
-
logger.watchError(
|
|
181
|
+
logger.watchError(p)
|
|
177
182
|
})
|
|
178
183
|
.on('ready', () => {
|
|
179
|
-
logger.watchReady(
|
|
184
|
+
logger.watchReady(p)
|
|
180
185
|
fulfill()
|
|
181
186
|
})
|
|
182
|
-
.on('add',
|
|
183
|
-
logger.watchAdd(
|
|
184
|
-
dispatchUpsert(store, inputRuleKey, './' +
|
|
187
|
+
.on('add', p => {
|
|
188
|
+
logger.watchAdd(p)
|
|
189
|
+
dispatchUpsert(store, inputRuleKey, './' + p, funkophileConfig.encodings);
|
|
185
190
|
})
|
|
186
|
-
.on('change',
|
|
187
|
-
logger.watchChange(
|
|
188
|
-
dispatchUpsert(store, inputRuleKey, './' +
|
|
191
|
+
.on('change', p => {
|
|
192
|
+
logger.watchChange(p)
|
|
193
|
+
dispatchUpsert(store, inputRuleKey, './' + p, funkophileConfig.encodings);
|
|
189
194
|
})
|
|
190
|
-
.on('unlink',
|
|
191
|
-
logger.watchUnlink(
|
|
195
|
+
.on('unlink', p => {
|
|
196
|
+
logger.watchUnlink(p)
|
|
192
197
|
store.dispatch({
|
|
193
198
|
type: REMOVE,
|
|
194
199
|
payload: {
|
|
195
200
|
key: inputRuleKey,
|
|
196
|
-
file: './' +
|
|
201
|
+
file: './' + p
|
|
197
202
|
}
|
|
198
203
|
})
|
|
199
204
|
})
|
|
200
|
-
.on('unlinkDir',
|
|
201
|
-
logger.watchUnlink(
|
|
205
|
+
.on('unlinkDir', p => {
|
|
206
|
+
logger.watchUnlink(p)
|
|
202
207
|
})
|
|
203
|
-
// .on('raw', (event,
|
|
204
|
-
// log('Raw event info:', event,
|
|
208
|
+
// .on('raw', (event, p, details) => { // internal
|
|
209
|
+
// log('Raw event info:', event, p, details);
|
|
205
210
|
// })
|
|
206
211
|
|
|
207
212
|
} else {
|
|
@@ -214,8 +219,10 @@ Promise.all(
|
|
|
214
219
|
|
|
215
220
|
// listen for changes to the store
|
|
216
221
|
store.subscribe(() => {
|
|
222
|
+
const s = store.getState()
|
|
223
|
+
|
|
217
224
|
logger.stateChange()
|
|
218
|
-
const outputs = finalSelector(
|
|
225
|
+
const outputs = finalSelector(s)
|
|
219
226
|
|
|
220
227
|
if (outputPromise.isPending()) {
|
|
221
228
|
console.log('cancelling previous write!')
|
|
@@ -286,8 +293,8 @@ Promise.all(
|
|
|
286
293
|
});
|
|
287
294
|
|
|
288
295
|
} else {
|
|
289
|
-
console.log(
|
|
290
|
-
fse.outputFile(relativeFilePath, contents,
|
|
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);
|
|
291
298
|
logger.writingString(relativeFilePath);
|
|
292
299
|
}
|
|
293
300
|
} else {
|