-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.mjs
54 lines (45 loc) · 1.44 KB
/
watch.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {watch} from 'node:fs'
import {dirname, join} from 'node:path';
import {fileURLToPath} from 'node:url';
import {exec} from 'node:child_process';
import {writeFile} from "node:fs/promises";
const __dirname = dirname(fileURLToPath(import.meta.url));
function getContent(componentFile, componentName) {
return `
import {${componentName}} from "${componentFile}";
export function App() {
return (
<>
<${componentName}/>
</>
);
}
export default App;`;
}
function firstUpperCase(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
function getFileName(path) {
return path.split('/').pop().replace('.yml', '');
}
function snakeToCamel(str) {
return `${str}`
.replace(/_([a-z])/ig, (_, letter) => letter.toUpperCase());
}
watch(join(__dirname, 'src', 'blueprints'), {recursive: true}, (event, filename) => {
if (!`${filename}`.endsWith('.yml') || `${filename}`.endsWith('~')) {
return;
}
const file = `./src/blueprints/${filename}`;
const componentFile = `./${filename}`.replace('.yml', '.jsx');
const componentName = firstUpperCase(snakeToCamel(getFileName(file)));
// console.log(file, '------')
exec(`fastui specs build ${file}`, {
cwd: __dirname
}, (error, stdout, stderr) => {
//if (!error) {
// writeFile(`./src/App.jsx`, getContent(componentFile, componentName))
// .catch(console.log);
//}
});
});