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