funkophile 0.2.4 → 0.2.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/dev.js +59 -0
- package/dist/esm/funkophileHelpers.js +62 -22
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +311 -67
- package/funkophileHelpers.ts +55 -5
- package/index.ts +336 -81
- package/package.json +6 -2
- package/tsconfig.json +2 -1
package/dev.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import chokidar from 'chokidar';
|
|
2
|
+
import { exec } from 'child_process';
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { dirname } from 'path';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
|
|
10
|
+
const execAsync = promisify(exec);
|
|
11
|
+
|
|
12
|
+
console.log('Watching for file changes...');
|
|
13
|
+
|
|
14
|
+
const watcher = chokidar.watch('**/*.ts', {
|
|
15
|
+
ignored: /node_modules/,
|
|
16
|
+
persistent: true,
|
|
17
|
+
ignoreInitial: true
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
let buildInProgress = false;
|
|
21
|
+
|
|
22
|
+
const runBuild = async () => {
|
|
23
|
+
if (buildInProgress) {
|
|
24
|
+
console.log('Build already in progress, skipping...');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
buildInProgress = true;
|
|
29
|
+
console.log('File changes detected. Rebuilding...');
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const { stdout, stderr } = await execAsync('yarn transpile');
|
|
33
|
+
if (stdout) console.log(stdout);
|
|
34
|
+
if (stderr) console.error(stderr);
|
|
35
|
+
console.log('Rebuild completed successfully!');
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error('Build failed:', error);
|
|
38
|
+
} finally {
|
|
39
|
+
buildInProgress = false;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
watcher.on('change', runBuild);
|
|
44
|
+
watcher.on('add', runBuild);
|
|
45
|
+
watcher.on('unlink', runBuild);
|
|
46
|
+
|
|
47
|
+
// Initial build
|
|
48
|
+
console.log('Performing initial build...');
|
|
49
|
+
execAsync('yarn transpile')
|
|
50
|
+
.then(({ stdout, stderr }) => {
|
|
51
|
+
if (stdout) console.log(stdout);
|
|
52
|
+
if (stderr) console.error(stderr);
|
|
53
|
+
console.log('Initial build completed!');
|
|
54
|
+
console.log('Watching for changes...');
|
|
55
|
+
})
|
|
56
|
+
.catch(error => {
|
|
57
|
+
console.error('Initial build failed:', error);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
});
|
|
@@ -1,48 +1,88 @@
|
|
|
1
1
|
import { createSelector } from "reselect";
|
|
2
|
+
import path from "path";
|
|
2
3
|
export const contentsOfFiles = (selector) => {
|
|
3
4
|
return createSelector([selector], (selected) => {
|
|
4
|
-
if (
|
|
5
|
-
|
|
5
|
+
if (selected === undefined || selected === null) {
|
|
6
|
+
throw new Error(`contentsOfFiles: selected is ${selected}. Make sure the selector is pointing to valid state.`);
|
|
7
|
+
}
|
|
6
8
|
return Object.keys(selected).reduce((mm, k) => mm + (selected[k] || ""), "");
|
|
7
9
|
});
|
|
8
10
|
};
|
|
9
11
|
export const contentOfFile = (selector) => {
|
|
10
12
|
return createSelector([selector], (selected) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return selected[keys[0]] || "";
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
console.error("error", e);
|
|
21
|
-
console.error("selected", selected);
|
|
22
|
-
console.error("selector", selector);
|
|
23
|
-
process.exit(-1);
|
|
13
|
+
if (selected === undefined || selected === null) {
|
|
14
|
+
throw new Error(`contentOfFile: selected is ${selected}. Make sure the selector is pointing to valid state.`);
|
|
15
|
+
}
|
|
16
|
+
const keys = Object.keys(selected);
|
|
17
|
+
if (keys.length === 0) {
|
|
18
|
+
throw new Error(`contentOfFile: selected object is empty. No files found. This may be because the input pattern didn't match any files.`);
|
|
24
19
|
}
|
|
20
|
+
return selected[keys[0]] || "";
|
|
25
21
|
});
|
|
26
22
|
};
|
|
27
23
|
export const srcAndContentOfFile = (selector, key) => {
|
|
28
24
|
return createSelector([selector], (selected) => {
|
|
29
|
-
if (
|
|
30
|
-
|
|
25
|
+
if (selected === undefined || selected === null) {
|
|
26
|
+
throw new Error(`srcAndContentOfFile: selected is ${selected}. Make sure the selector is pointing to valid state.`);
|
|
27
|
+
}
|
|
28
|
+
const keys = Object.keys(selected);
|
|
29
|
+
if (keys.length === 0) {
|
|
30
|
+
throw new Error(`srcAndContentOfFile: selected object is empty. No files found. This may be because the input pattern didn't match any files.`);
|
|
31
|
+
}
|
|
32
|
+
// Try exact match first
|
|
33
|
+
let matchingKey = keys.find(k => k === key);
|
|
34
|
+
// If exact match not found, try to find by resolving to absolute path
|
|
35
|
+
if (!matchingKey) {
|
|
36
|
+
// Try to resolve the key to an absolute path
|
|
37
|
+
const resolvedKey = path.resolve(process.cwd(), key);
|
|
38
|
+
matchingKey = keys.find(k => k === resolvedKey);
|
|
39
|
+
}
|
|
40
|
+
// If still not found, try to find by basename
|
|
41
|
+
if (!matchingKey) {
|
|
42
|
+
const keyBasename = path.basename(key);
|
|
43
|
+
matchingKey = keys.find(k => path.basename(k) === keyBasename);
|
|
44
|
+
}
|
|
45
|
+
// If still not found, try to find by relative path
|
|
46
|
+
if (!matchingKey) {
|
|
47
|
+
const relativeKey = path.relative(process.cwd(), key);
|
|
48
|
+
matchingKey = keys.find(k => {
|
|
49
|
+
const kRelative = path.relative(process.cwd(), k);
|
|
50
|
+
return kRelative === relativeKey;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// If still not found, try to find by ending with the key
|
|
54
|
+
if (!matchingKey) {
|
|
55
|
+
matchingKey = keys.find(k => k.endsWith(key));
|
|
56
|
+
}
|
|
57
|
+
// If still not found, try to find by the key ending with the path
|
|
58
|
+
if (!matchingKey) {
|
|
59
|
+
matchingKey = keys.find(k => k.endsWith(key.replace('./', '')));
|
|
60
|
+
}
|
|
61
|
+
// If still not found, try to find by the key being a relative path that matches
|
|
62
|
+
if (!matchingKey) {
|
|
63
|
+
// Remove leading './' if present
|
|
64
|
+
const cleanKey = key.startsWith('./') ? key.slice(2) : key;
|
|
65
|
+
matchingKey = keys.find(k => k.endsWith(cleanKey));
|
|
66
|
+
}
|
|
67
|
+
if (!matchingKey) {
|
|
68
|
+
throw new Error(`srcAndContentOfFile: key "${key}" not found in selected object. Available keys: ${keys.join(', ')}`);
|
|
69
|
+
}
|
|
31
70
|
return {
|
|
32
|
-
src:
|
|
33
|
-
content: selected[
|
|
71
|
+
src: matchingKey,
|
|
72
|
+
content: selected[matchingKey],
|
|
34
73
|
};
|
|
35
74
|
});
|
|
36
75
|
};
|
|
37
76
|
export const srcAndContentOfFiles = (selector) => {
|
|
38
77
|
return createSelector([selector], (selected) => {
|
|
39
|
-
if (
|
|
40
|
-
|
|
78
|
+
if (selected === undefined || selected === null) {
|
|
79
|
+
throw new Error(`srcAndContentOfFiles: selected is ${selected}. Make sure the selector is pointing to valid state.`);
|
|
80
|
+
}
|
|
41
81
|
const keys = Object.keys(selected);
|
|
42
82
|
return keys.map((key) => {
|
|
43
83
|
return {
|
|
44
84
|
src: key,
|
|
45
|
-
content: selected[key]
|
|
85
|
+
content: selected[key],
|
|
46
86
|
};
|
|
47
87
|
});
|
|
48
88
|
});
|