@astralkit/cli 3.0.2 → 3.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astralkit/cli",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": "AstralKit CLI — Install and manage UI components in your project",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "bin": {
@@ -138,7 +138,9 @@ async function tryFetch(type, slug, options) {
138
138
  await getWorkflow(slug, framework);
139
139
  }
140
140
  return true;
141
- } catch {
141
+ } catch (err) {
142
+ // 403 = exists but user doesn't have access — still counts as "found"
143
+ if (err.code === 'PRO_REQUIRED') return true;
142
144
  return false;
143
145
  }
144
146
  }
@@ -233,7 +235,27 @@ async function addComponent(componentSlug, options) {
233
235
  const spinner = ora(`Fetching ${componentSlug} (${FRAMEWORK_LABELS[framework] || framework})...`).start();
234
236
 
235
237
  try {
236
- const data = await getComponent(componentSlug, framework);
238
+ let data;
239
+ try {
240
+ data = await getComponent(componentSlug, framework);
241
+ } catch (fetchErr) {
242
+ // Pro required for React/Next.js — fall back to HTML for free users
243
+ if (fetchErr.code === 'PRO_REQUIRED' && framework !== 'html') {
244
+ spinner.warn(`${FRAMEWORK_LABELS[framework] || framework} requires a Pro subscription.`);
245
+ console.log(chalk.gray(' Fetching HTML version instead (free tier).'));
246
+ const htmlSpinner = ora(`Fetching ${componentSlug} (HTML)...`).start();
247
+ try {
248
+ data = await getComponent(componentSlug, 'html');
249
+ htmlSpinner.succeed(`Fetched ${componentSlug} (HTML)`);
250
+ } catch (htmlErr) {
251
+ htmlSpinner.fail(`Failed to add component.`);
252
+ console.log(chalk.yellow(htmlErr.message));
253
+ return;
254
+ }
255
+ } else {
256
+ throw fetchErr;
257
+ }
258
+ }
237
259
 
238
260
  if (!data.files || data.files.length === 0) {
239
261
  spinner.fail(`No ${framework} code available for "${componentSlug}".`);
@@ -85,28 +85,37 @@ async function initCommand(options) {
85
85
  const response = await apiRequest('/api/cli/sdk');
86
86
  const data = await response.json();
87
87
 
88
- // Create node_modules/astralkit/ directory structure
88
+ // Install runtime dependencies FIRST (clsx + tailwind-merge)
89
+ // Must happen before writing astralkit files, because npm prunes
90
+ // extraneous folders from node_modules during install.
91
+ const pm = detectPackageManager();
92
+ const depsCmd = pm === 'yarn' ? 'yarn add clsx tailwind-merge'
93
+ : pm === 'pnpm' ? 'pnpm add clsx tailwind-merge'
94
+ : pm === 'bun' ? 'bun add clsx tailwind-merge'
95
+ : 'npm install clsx tailwind-merge';
96
+ execSync(depsCmd, { stdio: 'pipe', cwd: process.cwd() });
97
+
98
+ // Now write astralkit token files to node_modules/astralkit/
99
+ // (after npm install so they don't get pruned)
89
100
  const sdkDir = path.join(process.cwd(), 'node_modules', 'astralkit');
90
101
  const libDir = path.join(sdkDir, 'lib');
91
102
  fs.mkdirSync(libDir, { recursive: true });
92
103
 
93
- // Write all files
94
- for (const [filePath, content] of Object.entries(data.files)) {
104
+ let filesWritten = 0;
105
+ for (const [filePath, content] of Object.entries(data.files || {})) {
95
106
  const fullPath = path.join(sdkDir, filePath);
96
107
  const dir = path.dirname(fullPath);
97
108
  if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
98
109
  fs.writeFileSync(fullPath, content, 'utf-8');
110
+ filesWritten++;
99
111
  }
100
112
 
101
- // Also install the runtime dependencies (clsx + tailwind-merge)
102
- const pm = detectPackageManager();
103
- const depsCmd = pm === 'yarn' ? 'yarn add clsx tailwind-merge'
104
- : pm === 'pnpm' ? 'pnpm add clsx tailwind-merge'
105
- : pm === 'bun' ? 'bun add clsx tailwind-merge'
106
- : 'npm install clsx tailwind-merge';
107
- execSync(depsCmd, { stdio: 'pipe', cwd: process.cwd() });
108
-
109
- spinner.succeed('Installed astralkit design tokens');
113
+ if (filesWritten === 0) {
114
+ spinner.fail('No token files received from API');
115
+ console.log(chalk.yellow('Try again — the API may be updating.'));
116
+ } else {
117
+ spinner.succeed(`Installed astralkit design tokens (${filesWritten} files)`);
118
+ }
110
119
  } catch (err) {
111
120
  spinner.fail('Failed to install astralkit');
112
121
  if (err.message?.includes('Authentication')) {
@@ -141,12 +150,18 @@ async function initCommand(options) {
141
150
  console.log(chalk.gray(' CSS imports already present'));
142
151
  }
143
152
  } else {
153
+ // No CSS entry found — create one with AstralKit imports
154
+ const defaultCssPath = framework === 'html'
155
+ ? path.join(process.cwd(), 'styles.css')
156
+ : path.join(process.cwd(), 'src', 'app', 'globals.css');
157
+ const defaultCssRelative = path.relative(process.cwd(), defaultCssPath);
158
+
144
159
  console.log();
145
- console.log(chalk.yellow('No CSS entry file found.'));
146
- console.log(chalk.gray('Add these imports to your main CSS file:'));
147
- for (const imp of REQUIRED_CSS_IMPORTS) {
148
- console.log(chalk.cyan(` ${imp}`));
149
- }
160
+ const cssContent = REQUIRED_CSS_IMPORTS.join('\n') + '\n';
161
+ const cssDir = path.dirname(defaultCssPath);
162
+ if (!fs.existsSync(cssDir)) fs.mkdirSync(cssDir, { recursive: true });
163
+ fs.writeFileSync(defaultCssPath, cssContent, 'utf-8');
164
+ console.log(chalk.green(' Created'), chalk.cyan(defaultCssRelative), chalk.green('with AstralKit imports'));
150
165
  }
151
166
 
152
167
  // ─── Step 3: Write config ──────────────────────────────