juas.dev 1.0.0
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/index.js +123 -0
- package/package.json +17 -0
package/index.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import prompts from 'prompts';
|
|
5
|
+
import pc from 'picocolors';
|
|
6
|
+
import ora from 'ora';
|
|
7
|
+
import fs from 'fs/promises';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { createClient } from '@supabase/supabase-js';
|
|
10
|
+
|
|
11
|
+
// Hardcoded for CLI public access
|
|
12
|
+
const SUPABASE_URL = "https://jznmqsiueeauoulgvzww.supabase.co";
|
|
13
|
+
const SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imp6bm1xc2l1ZWVhdW91bGd2end3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3ODE1MTA0MjIsImV4cCI6MjA5NzA4NjQyMn0.KG54rFl_jT0ofhQ9KuYGEQYNC8_kZD0KxoCpmXWz1pU";
|
|
14
|
+
|
|
15
|
+
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
|
|
16
|
+
const program = new Command();
|
|
17
|
+
|
|
18
|
+
program
|
|
19
|
+
.name('dhil-ui')
|
|
20
|
+
.description('Add ultra-premium React components to your project')
|
|
21
|
+
.version('1.0.0');
|
|
22
|
+
|
|
23
|
+
// --- INIT COMMAND ---
|
|
24
|
+
program
|
|
25
|
+
.command('init')
|
|
26
|
+
.description('Initialize your project and choose your components directory')
|
|
27
|
+
.action(async () => {
|
|
28
|
+
console.log(pc.bold(pc.red('Welcome to dhil.dev CLI\n')));
|
|
29
|
+
|
|
30
|
+
const response = await prompts({
|
|
31
|
+
type: 'text',
|
|
32
|
+
name: 'componentsDir',
|
|
33
|
+
message: 'Where is your components directory?',
|
|
34
|
+
initial: 'components/ui'
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (!response.componentsDir) {
|
|
38
|
+
console.log(pc.red('Operation cancelled.'));
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const config = {
|
|
43
|
+
componentsDir: response.componentsDir
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
await fs.writeFile(
|
|
47
|
+
path.join(process.cwd(), 'components.json'),
|
|
48
|
+
JSON.stringify(config, null, 2)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
console.log(pc.green(`\n✔ Configuration saved to components.json`));
|
|
52
|
+
console.log(`\nYou can now run ${pc.cyan('npx dhil-ui add <component>')} to start building.`);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// --- ADD COMMAND ---
|
|
56
|
+
program
|
|
57
|
+
.command('add <componentId>')
|
|
58
|
+
.description('Add a component to your project')
|
|
59
|
+
.action(async (componentId) => {
|
|
60
|
+
const spinner = ora(`Fetching ${componentId}...`).start();
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
// 1. Fetch from Supabase
|
|
64
|
+
const { data: component, error } = await supabase
|
|
65
|
+
.from('components')
|
|
66
|
+
.select(`
|
|
67
|
+
id, name, tech_stack,
|
|
68
|
+
component_versions (
|
|
69
|
+
code_tsx, dependencies
|
|
70
|
+
)
|
|
71
|
+
`)
|
|
72
|
+
.eq('id', componentId)
|
|
73
|
+
.single();
|
|
74
|
+
|
|
75
|
+
if (error || !component) {
|
|
76
|
+
throw new Error(`Component not found or API error: ${error?.message || ''}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const version = component.component_versions[0];
|
|
80
|
+
if (!version || !version.code_tsx) {
|
|
81
|
+
throw new Error('No source code available for this component.');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
spinner.text = `Installing ${component.name}...`;
|
|
85
|
+
|
|
86
|
+
// 2. Determine target directory
|
|
87
|
+
let targetDir = 'components/ui';
|
|
88
|
+
try {
|
|
89
|
+
const configRaw = await fs.readFile(path.join(process.cwd(), 'components.json'), 'utf-8');
|
|
90
|
+
const config = JSON.parse(configRaw);
|
|
91
|
+
if (config.componentsDir) {
|
|
92
|
+
targetDir = config.componentsDir;
|
|
93
|
+
}
|
|
94
|
+
} catch (err) {
|
|
95
|
+
// Default to components/ui if no config
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Ensure directory exists
|
|
99
|
+
const absoluteTargetDir = path.join(process.cwd(), targetDir);
|
|
100
|
+
await fs.mkdir(absoluteTargetDir, { recursive: true });
|
|
101
|
+
|
|
102
|
+
// 3. Write File
|
|
103
|
+
// Format filename (e.g. "Colorful 3D Text" -> "Colorful3DText.tsx")
|
|
104
|
+
const fileName = component.name.replace(/[^a-zA-Z0-9]/g, '') + '.tsx';
|
|
105
|
+
const filePath = path.join(absoluteTargetDir, fileName);
|
|
106
|
+
|
|
107
|
+
await fs.writeFile(filePath, version.code_tsx);
|
|
108
|
+
|
|
109
|
+
spinner.succeed(pc.green(`Added ${pc.bold(component.name)} to ${targetDir}/${fileName}`));
|
|
110
|
+
|
|
111
|
+
// 4. Check dependencies
|
|
112
|
+
if (version.dependencies && version.dependencies.length > 0) {
|
|
113
|
+
console.log(pc.yellow(`\n⚠ Please ensure you have the following dependencies installed:`));
|
|
114
|
+
console.log(pc.cyan(` npm install ${version.dependencies.join(' ')}`));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
} catch (err) {
|
|
118
|
+
spinner.fail(pc.red(err.message));
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "juas.dev",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLI for juas.dev components",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"dhil-ui": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"commander": "^11.0.0",
|
|
12
|
+
"prompts": "^2.4.2",
|
|
13
|
+
"picocolors": "^1.0.0",
|
|
14
|
+
"ora": "^7.0.1",
|
|
15
|
+
"@supabase/supabase-js": "^2.39.0"
|
|
16
|
+
}
|
|
17
|
+
}
|