-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (55 loc) · 1.88 KB
/
index.js
File metadata and controls
69 lines (55 loc) · 1.88 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { Command } = require('commander');
const { version } = require('./package.json');
const { exec } = require('child_process');
const fs = require('fs');
const program = new Command();
function createDirectory(path) {
try {
fs.mkdirSync(path, { recursive: true });
console.log(`Directory created: ${path}`);
} catch (err) {
console.error(`Error creating directory: ${path}\n${err.message}`);
}
}
function writeToFile(filePath, content) {
try {
fs.writeFileSync(filePath, content);
console.log(`File written: ${filePath}`);
} catch (err) {
console.error(`Error writing to file: ${filePath}\n${err.message}`);
}
}
function SupabaseGen(projectId) {
const outputPath = './transpile/supabase_transpile.ts';
createDirectory('./transpile');
writeToFile(outputPath, '');
return `npx supabase gen types typescript --project-id ${projectId} --schema public > ${outputPath}`;
}
function DartGen() {
const inputPath = './transpile/supabase_transpile.ts';
fs.readFile(inputPath, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading file: ${inputPath}\n${err.message}`);
return;
}
exec(`npx ts2dart ${inputPath}`, (error) => {
if (error) {
console.error(`Error transpiling to Dart: ${error.message}`);
return;
}
console.log('Transpiling Supabase Types to Dart Models...');
});
});
}
program
.version(version)
.description('A tool for generating Supabase types and transpiling them to Dart models');
program
.command('supabase-gen <projectId>')
.description('Generate Supabase typescript types')
.action(SupabaseGen);
program
.command('dart-gen')
.description('Transpile Supabase types to Dart models')
.action(DartGen);
program.parse(process.argv);