@astralkit/cli 3.0.5 → 4.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.
@@ -1,145 +1,69 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const chalk = require('chalk');
4
- const inquirer = require('inquirer');
5
- const { getProjectConfig } = require('../lib/config');
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import pc from 'picocolors';
4
+ import * as p from '@clack/prompts';
5
+ import { getProjectConfig, detectFramework } from '../lib/config.js';
6
6
 
7
- /**
8
- * Remove command — cleanly uninstall a component, booster, or workflow.
9
- */
10
- async function removeCommand(slug, options) {
7
+ export async function removeCommand(name, options) {
11
8
  const config = getProjectConfig();
12
- const cwd = process.cwd();
13
-
14
- // Build a list of paths this slug might live in
15
- const candidates = [];
16
-
17
- // Component paths
9
+ const framework = config?.framework || detectFramework();
18
10
  const componentsDir = config?.componentsDir || 'src/components/ui';
19
- for (const ext of ['.tsx', '.jsx', '.html']) {
20
- const p = path.join(cwd, componentsDir, `${slug}${ext}`);
21
- if (fs.existsSync(p)) {
22
- candidates.push({ type: 'component', path: p, relative: `${componentsDir}/${slug}${ext}` });
23
- }
24
- }
25
11
 
26
- // Booster paths (core + adapter)
27
- const boosterCoreDirs = [
28
- `src/lib/${slug}`,
29
- `lib/${slug}`,
30
- ];
31
- const boosterAdapterDirs = [
32
- `src/components/${slug}`,
33
- `components/${slug}`,
34
- ];
12
+ // Find all files associated with this name
13
+ const found = [];
35
14
 
36
- for (const dir of boosterCoreDirs) {
37
- const p = path.join(cwd, dir);
38
- if (fs.existsSync(p) && fs.statSync(p).isDirectory()) {
39
- candidates.push({ type: 'booster-core', path: p, relative: `${dir}/` });
40
- }
41
- }
42
- for (const dir of boosterAdapterDirs) {
43
- const p = path.join(cwd, dir);
44
- if (fs.existsSync(p) && fs.statSync(p).isDirectory()) {
45
- candidates.push({ type: 'booster-adapter', path: p, relative: `${dir}/` });
46
- }
15
+ // Check component
16
+ for (const ext of ['.tsx', '.jsx', '.html']) {
17
+ const filePath = path.resolve(process.cwd(), componentsDir, `${name}${ext}`);
18
+ if (fs.existsSync(filePath)) found.push({ label: 'Component', path: filePath });
47
19
  }
48
20
 
49
- // Workflow paths (directory with slug name)
50
- const workflowDir = path.join(cwd, slug);
51
- if (fs.existsSync(workflowDir) && fs.statSync(workflowDir).isDirectory()) {
52
- const hasPackageJson = fs.existsSync(path.join(workflowDir, 'package.json'));
53
- if (hasPackageJson) {
54
- candidates.push({ type: 'workflow', path: workflowDir, relative: `${slug}/` });
55
- }
56
- }
21
+ // Check booster dirs
22
+ const coreDir = path.resolve(process.cwd(), `src/lib/${name}`);
23
+ const adapterDir = path.resolve(process.cwd(), `src/components/${name}`);
24
+ if (fs.existsSync(coreDir)) found.push({ label: 'Booster (core)', path: coreDir, isDir: true });
25
+ if (fs.existsSync(adapterDir)) found.push({ label: 'Booster (adapter)', path: adapterDir, isDir: true });
57
26
 
58
- if (candidates.length === 0) {
59
- console.log(chalk.yellow(`Nothing found for "${slug}" in this project.`));
60
- console.log(chalk.gray('Searched in:'));
61
- console.log(chalk.gray(` ${componentsDir}/${slug}.*`));
62
- console.log(chalk.gray(` src/lib/${slug}/`));
63
- console.log(chalk.gray(` src/components/${slug}/`));
64
- console.log(chalk.gray(` ${slug}/`));
27
+ if (found.length === 0) {
28
+ p.log.warn(`No installed files found for "${name}".`);
29
+ console.log(pc.gray('It may have been installed in a custom directory.'));
65
30
  return;
66
31
  }
67
32
 
68
- // Show what will be removed
69
- console.log(chalk.white.bold(`\nFound files for "${slug}":\n`));
70
-
71
- for (const c of candidates) {
72
- const label = c.type === 'component' ? 'Component'
73
- : c.type === 'workflow' ? 'Workflow'
74
- : c.type === 'booster-core' ? 'Booster (core)'
75
- : 'Booster (adapter)';
76
-
77
- if (fs.statSync(c.path).isDirectory()) {
78
- const files = getAllFiles(c.path);
79
- console.log(chalk.red(` ${label}: ${c.relative}`));
80
- for (const f of files.slice(0, 10)) {
81
- console.log(chalk.gray(` ${f}`));
82
- }
83
- if (files.length > 10) {
84
- console.log(chalk.gray(` ... and ${files.length - 10} more files`));
85
- }
86
- } else {
87
- console.log(chalk.red(` ${label}: ${c.relative}`));
33
+ console.log();
34
+ console.log(pc.yellow(`Found files for "${name}":`));
35
+ console.log();
36
+ for (const item of found) {
37
+ const rel = path.relative(process.cwd(), item.path);
38
+ console.log(` ${pc.cyan(item.label)}: ${pc.gray(rel)}`);
39
+ if (item.isDir && fs.existsSync(item.path)) {
40
+ const files = fs.readdirSync(item.path);
41
+ files.forEach(f => console.log(pc.gray(` ${f}`)));
88
42
  }
89
43
  }
90
-
91
44
  console.log();
92
45
 
93
- // Confirm
94
46
  if (!options.force) {
95
- const { confirm } = await inquirer.prompt([{
96
- type: 'confirm',
97
- name: 'confirm',
98
- message: `Remove ${candidates.length} item(s)?`,
99
- default: false,
100
- }]);
101
-
102
- if (!confirm) {
103
- console.log(chalk.gray('Cancelled.'));
47
+ const confirm = await p.confirm({
48
+ message: `Remove ${found.length} item(s)?`,
49
+ initialValue: false,
50
+ });
51
+ if (p.isCancel(confirm) || !confirm) {
52
+ p.cancel('Cancelled.');
104
53
  return;
105
54
  }
106
55
  }
107
56
 
108
- // Delete
109
- let removed = 0;
110
- for (const c of candidates) {
57
+ for (const item of found) {
111
58
  try {
112
- if (fs.statSync(c.path).isDirectory()) {
113
- fs.rmSync(c.path, { recursive: true, force: true });
59
+ if (item.isDir) {
60
+ fs.rmSync(item.path, { recursive: true, force: true });
114
61
  } else {
115
- fs.unlinkSync(c.path);
62
+ fs.unlinkSync(item.path);
116
63
  }
117
- console.log(chalk.green(` ✓ Removed ${c.relative}`));
118
- removed++;
64
+ console.log(pc.green(' ✓ Removed'), pc.gray(path.relative(process.cwd(), item.path)));
119
65
  } catch (err) {
120
- console.log(chalk.red(` ✖ Failed to remove ${c.relative}: ${err.message}`));
66
+ console.log(pc.red(` ✗ Failed to remove ${item.path}:`), pc.gray(err.message));
121
67
  }
122
68
  }
123
-
124
- console.log();
125
- console.log(chalk.green(`Removed ${removed} item(s) for "${slug}".`));
126
- }
127
-
128
- /**
129
- * Get all file paths (relative) in a directory recursively.
130
- */
131
- function getAllFiles(dir, base = '') {
132
- const results = [];
133
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
134
- const rel = base ? `${base}/${entry.name}` : entry.name;
135
- if (entry.name === 'node_modules' || entry.name === '.next') continue;
136
- if (entry.isDirectory()) {
137
- results.push(...getAllFiles(path.join(dir, entry.name), rel));
138
- } else {
139
- results.push(rel);
140
- }
141
- }
142
- return results;
143
69
  }
144
-
145
- module.exports = { removeCommand };
@@ -1,156 +1,58 @@
1
- const chalk = require('chalk');
2
- const ora = require('ora');
3
- const { listComponents, listBoosters, listWorkflows } = require('../lib/api');
4
- const { validateFramework } = require('../lib/validators');
5
-
6
- /**
7
- * Route to the correct search handler based on flags.
8
- */
9
- async function searchCommand(query, options) {
10
- if (options.framework && !validateFramework(options.framework)) {
11
- process.exit(1);
12
- }
13
-
14
- if (options.boosters) {
15
- return searchBoostersCommand(query, options);
16
- }
17
- if (options.workflows) {
18
- return searchWorkflowsCommand(query, options);
19
- }
20
- return searchComponentsCommand(query, options);
21
- }
22
-
23
- /**
24
- * Search UI components (existing behavior).
25
- */
26
- async function searchComponentsCommand(query, options) {
27
- const spinner = ora(`Searching for "${query}"...`).start();
28
-
29
- try {
30
- const data = await listComponents({
31
- search: query,
32
- framework: options.framework,
33
- });
34
-
35
- spinner.stop();
36
-
37
- if (!data.components || data.components.length === 0) {
38
- console.log(chalk.yellow(`No components found for "${query}".`));
39
- return;
40
- }
41
-
42
- console.log(chalk.blue.bold(`Found ${data.components.length} component(s):`));
43
- console.log();
44
-
45
- for (const comp of data.components) {
46
- const proTag = comp.is_pro ? chalk.magenta(' PRO') : '';
47
- const cat = comp.category ? chalk.gray(` (${comp.category})`) : '';
48
- console.log(` ${chalk.cyan(comp.slug)}${proTag}${cat}`);
49
- if (comp.short_description || comp.description) {
50
- const desc = comp.short_description || comp.description;
51
- console.log(` ${chalk.gray(desc.length > 80 ? desc.slice(0, 80) + '...' : desc)}`);
52
- }
53
- if (comp.supported_frameworks?.length) {
54
- console.log(` ${chalk.gray(`Frameworks: ${comp.supported_frameworks.join(', ')}`)}`);
55
- }
56
- console.log();
57
- }
58
-
59
- console.log(chalk.gray('Run'), chalk.cyan('astralkit add <component>'), chalk.gray('to install.'));
60
-
61
- } catch (err) {
62
- spinner.fail('Search failed.');
63
- console.error(chalk.red(err.message));
64
- process.exit(1);
65
- }
66
- }
67
-
68
- /**
69
- * Search boosters.
70
- */
71
- async function searchBoostersCommand(query, options) {
72
- const spinner = ora(`Searching boosters for "${query}"...`).start();
73
-
74
- try {
75
- const data = await listBoosters({
76
- search: query,
77
- framework: options.framework,
78
- });
79
-
80
- spinner.stop();
81
-
82
- if (!data.boosters || data.boosters.length === 0) {
83
- console.log(chalk.yellow(`No boosters found for "${query}".`));
84
- return;
85
- }
86
-
87
- console.log(chalk.blue.bold(`Found ${data.boosters.length} booster(s):`));
88
- console.log();
89
-
90
- for (const b of data.boosters) {
91
- const proTag = b.is_pro ? chalk.magenta(' PRO') : '';
92
- const cat = b.category ? chalk.gray(` (${b.category})`) : '';
93
- console.log(` ${chalk.cyan(b.slug)}${proTag}${cat}`);
94
- if (b.description) {
95
- console.log(` ${chalk.gray(b.description.length > 80 ? b.description.slice(0, 80) + '...' : b.description)}`);
96
- }
97
- if (b.frameworks?.length) {
98
- console.log(` ${chalk.gray(`Frameworks: ${b.frameworks.join(', ')}`)}`);
99
- }
100
- console.log();
101
- }
102
-
103
- console.log(chalk.gray('Run'), chalk.cyan('astralkit add --booster <name>'), chalk.gray('to install.'));
104
-
105
- } catch (err) {
106
- spinner.fail('Search failed.');
107
- console.error(chalk.red(err.message));
108
- process.exit(1);
109
- }
110
- }
111
-
112
- /**
113
- * Search workflows.
114
- */
115
- async function searchWorkflowsCommand(query, options) {
116
- const spinner = ora(`Searching workflows for "${query}"...`).start();
117
-
118
- try {
119
- const data = await listWorkflows({
120
- search: query,
121
- framework: options.framework,
122
- });
123
-
124
- spinner.stop();
125
-
126
- if (!data.workflows || data.workflows.length === 0) {
127
- console.log(chalk.yellow(`No workflows found for "${query}".`));
128
- return;
129
- }
130
-
131
- console.log(chalk.blue.bold(`Found ${data.workflows.length} workflow(s):`));
132
- console.log();
133
-
134
- for (const w of data.workflows) {
135
- const proTag = w.is_pro ? chalk.magenta(' PRO') : '';
136
- const cat = w.category ? chalk.gray(` (${w.category})`) : '';
137
- console.log(` ${chalk.cyan(w.slug)}${proTag}${cat}`);
138
- if (w.description) {
139
- console.log(` ${chalk.gray(w.description.length > 80 ? w.description.slice(0, 80) + '...' : w.description)}`);
140
- }
141
- if (w.frameworks?.length) {
142
- console.log(` ${chalk.gray(`Frameworks: ${w.frameworks.join(', ')}`)}`);
143
- }
144
- console.log();
145
- }
146
-
147
- console.log(chalk.gray('Run'), chalk.cyan('astralkit add --workflow <name>'), chalk.gray('to scaffold.'));
148
-
149
- } catch (err) {
150
- spinner.fail('Search failed.');
151
- console.error(chalk.red(err.message));
152
- process.exit(1);
153
- }
154
- }
155
-
156
- module.exports = { searchCommand };
1
+ import pc from 'picocolors';
2
+ import * as p from '@clack/prompts';
3
+ import { listComponents, listBoosters, listWorkflows } from '../lib/api.js';
4
+
5
+ const FRAMEWORK_LABELS = { nextjs: 'Next.js', react: 'React', html: 'HTML' };
6
+
7
+ export async function searchCommand(query, options) {
8
+ const ora = (await import('ora')).default;
9
+ const spinner = ora(`Searching for "${pc.cyan(query)}"...`).start();
10
+
11
+ try {
12
+ const filters = { search: query, framework: options.framework };
13
+ let results = [];
14
+
15
+ if (options.boosters) {
16
+ results = await listBoosters(filters);
17
+ } else if (options.workflows) {
18
+ results = await listWorkflows(filters);
19
+ } else {
20
+ // Search all three in parallel
21
+ const [components, boosters, workflows] = await Promise.allSettled([
22
+ listComponents(filters),
23
+ listBoosters(filters),
24
+ listWorkflows(filters),
25
+ ]);
26
+ if (components.status === 'fulfilled') results.push(...(components.value || []).map(i => ({ ...i, _type: 'component' })));
27
+ if (boosters.status === 'fulfilled') results.push(...(boosters.value || []).map(i => ({ ...i, _type: 'booster' })));
28
+ if (workflows.status === 'fulfilled') results.push(...(workflows.value || []).map(i => ({ ...i, _type: 'workflow' })));
29
+ }
30
+
31
+ spinner.stop();
32
+
33
+ if (!results.length) {
34
+ p.log.info(`No results for "${query}".`);
35
+ return;
36
+ }
37
+
38
+ console.log();
39
+ console.log(pc.bold(` ${results.length} result(s) for "${query}"\n`));
40
+
41
+ for (const item of results) {
42
+ const typeLabel = item._type ? pc.gray(` [${item._type}]`) : '';
43
+ const proTag = item.is_pro ? pc.magenta(' [PRO]') : pc.green(' [FREE]');
44
+ const fw = item.frameworks?.map(f => FRAMEWORK_LABELS[f] || f).join(', ') || '';
45
+ console.log(` ${pc.cyan(item.slug || item.name)}${typeLabel}${proTag}`);
46
+ if (item.description) console.log(pc.gray(` ${item.description}`));
47
+ if (fw) console.log(pc.gray(` Frameworks: ${fw}`));
48
+ console.log();
49
+ }
50
+
51
+ console.log(pc.gray(` astralkit add <slug> to install`));
52
+ } catch (err) {
53
+ spinner.fail('Search failed.');
54
+ if (err.code === 'AUTH_REQUIRED') p.log.warn(err.message);
55
+ else console.error(pc.red(err.message));
56
+ process.exit(1);
57
+ }
58
+ }
@@ -1,120 +1,90 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const chalk = require('chalk');
4
- const ora = require('ora');
5
- const inquirer = require('inquirer');
6
- const { getComponent } = require('../lib/api');
7
- const { getProjectConfig, detectFramework } = require('../lib/config');
8
- const { validateSlug, validateFramework, isSafePath } = require('../lib/validators');
9
-
10
- async function updateCommand(componentSlug, options) {
11
- // Validate inputs
12
- if (!validateSlug(componentSlug)) process.exit(1);
13
- if (!validateFramework(options.framework)) process.exit(1);
14
-
15
- const config = getProjectConfig();
16
- const framework = options.framework || config?.framework || detectFramework();
17
- const componentsDir = options.dir || config?.componentsDir || 'src/components/ui';
18
- const targetDir = path.resolve(process.cwd(), componentsDir, componentSlug);
19
-
20
- // Check if component exists locally
21
- if (!fs.existsSync(targetDir)) {
22
- console.log(chalk.yellow(`Component "${componentSlug}" not found locally.`));
23
- console.log(chalk.gray(`Run ${chalk.cyan(`astralkit add ${componentSlug}`)} to install it first.`));
24
- return;
25
- }
26
-
27
- const spinner = ora(`Fetching latest ${componentSlug} (${framework})...`).start();
28
-
29
- try {
30
- const data = await getComponent(componentSlug, framework);
31
-
32
- if (!data.files || data.files.length === 0) {
33
- spinner.fail(`No ${framework} code available for "${componentSlug}".`);
34
- return;
35
- }
36
-
37
- spinner.stop();
38
-
39
- // Check which files have changes
40
- const changedFiles = [];
41
- const newFiles = [];
42
-
43
- for (const remoteFile of data.files) {
44
- const localPath = path.join(targetDir, remoteFile.path);
45
-
46
- if (!fs.existsSync(localPath)) {
47
- newFiles.push(remoteFile);
48
- continue;
49
- }
50
-
51
- const localContent = fs.readFileSync(localPath, 'utf8');
52
- if (localContent !== remoteFile.content) {
53
- changedFiles.push(remoteFile);
54
- }
55
- }
56
-
57
- if (changedFiles.length === 0 && newFiles.length === 0) {
58
- console.log(chalk.green('Already up to date.'));
59
- return;
60
- }
61
-
62
- // Show what will change
63
- console.log(chalk.blue.bold(`Update: ${data.name || componentSlug}`));
64
- console.log();
65
-
66
- if (changedFiles.length > 0) {
67
- console.log(chalk.yellow('Modified files:'));
68
- for (const f of changedFiles) {
69
- console.log(chalk.yellow(` ~ ${f.path}`));
70
- }
71
- }
72
- if (newFiles.length > 0) {
73
- console.log(chalk.green('New files:'));
74
- for (const f of newFiles) {
75
- console.log(chalk.green(` + ${f.path}`));
76
- }
77
- }
78
- console.log();
79
-
80
- // Confirm unless --force
81
- if (!options.force) {
82
- const { confirm } = await inquirer.prompt([{
83
- type: 'confirm',
84
- name: 'confirm',
85
- message: `Update ${changedFiles.length + newFiles.length} file(s)? This will overwrite local changes.`,
86
- default: false,
87
- }]);
88
-
89
- if (!confirm) {
90
- console.log(chalk.gray('Aborted.'));
91
- return;
92
- }
93
- }
94
-
95
- // Write updated files (with path traversal protection)
96
- const updateSpinner = ora('Updating files...').start();
97
-
98
- for (const file of [...changedFiles, ...newFiles]) {
99
- if (!isSafePath(targetDir, file.path)) {
100
- console.log(chalk.red(` Skipping suspicious file path: ${file.path}`));
101
- continue;
102
- }
103
- const filePath = path.resolve(targetDir, file.path);
104
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
105
- fs.writeFileSync(filePath, file.content);
106
- }
107
-
108
- updateSpinner.succeed(`Updated ${chalk.cyan(data.name || componentSlug)}`);
109
-
110
- for (const file of [...changedFiles, ...newFiles]) {
111
- console.log(chalk.gray(` ${file.path}`));
112
- }
113
- } catch (err) {
114
- spinner.fail('Update failed.');
115
- console.error(chalk.red(err.message));
116
- process.exit(1);
117
- }
118
- }
119
-
120
- module.exports = { updateCommand };
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import pc from 'picocolors';
4
+ import * as p from '@clack/prompts';
5
+ import { getComponent } from '../lib/api.js';
6
+ import { getProjectConfig, detectFramework } from '../lib/config.js';
7
+ import { isSafePath } from '../lib/validators.js';
8
+
9
+ export async function updateCommand(componentSlug, options) {
10
+ const ora = (await import('ora')).default;
11
+ const config = getProjectConfig();
12
+ const framework = options.framework || config?.framework || detectFramework();
13
+ const componentsDir = options.dir || config?.componentsDir || 'src/components/ui';
14
+
15
+ const spinner = ora(`Fetching latest ${pc.cyan(componentSlug)}...`).start();
16
+
17
+ try {
18
+ const data = await getComponent(componentSlug, framework);
19
+ spinner.stop();
20
+
21
+ if (!data.files?.length) {
22
+ p.log.warn(`No ${framework} version available for "${componentSlug}".`);
23
+ return;
24
+ }
25
+
26
+ const dir = path.resolve(process.cwd(), componentsDir);
27
+
28
+ // Check what's actually changing
29
+ const toUpdate = [];
30
+ const toCreate = [];
31
+
32
+ for (const file of data.files) {
33
+ const filePath = path.resolve(dir, file.path);
34
+ if (!fs.existsSync(filePath)) {
35
+ toCreate.push(file);
36
+ } else {
37
+ const localContent = fs.readFileSync(filePath, 'utf8');
38
+ if (localContent !== file.content) toUpdate.push(file);
39
+ }
40
+ }
41
+
42
+ if (toUpdate.length === 0 && toCreate.length === 0) {
43
+ p.log.success(`${pc.cyan(componentSlug)} is already up to date.`);
44
+ return;
45
+ }
46
+
47
+ // Show what will change
48
+ console.log();
49
+ if (toCreate.length > 0) {
50
+ console.log(pc.gray(' New files:'));
51
+ toCreate.forEach(f => console.log(pc.green(` + ${f.path}`)));
52
+ }
53
+ if (toUpdate.length > 0) {
54
+ console.log(pc.gray(' Updated files:'));
55
+ toUpdate.forEach(f => console.log(pc.yellow(` ~ ${f.path}`)));
56
+ }
57
+ console.log();
58
+
59
+ if (!options.force) {
60
+ const confirm = await p.confirm({
61
+ message: `Update ${pc.cyan(componentSlug)}?`,
62
+ initialValue: true,
63
+ });
64
+ if (p.isCancel(confirm) || !confirm) {
65
+ p.cancel('Cancelled.');
66
+ return;
67
+ }
68
+ }
69
+
70
+ fs.mkdirSync(dir, { recursive: true });
71
+
72
+ for (const file of [...toCreate, ...toUpdate]) {
73
+ if (!isSafePath(dir, file.path)) {
74
+ console.log(pc.red(` Skipping suspicious path: ${file.path}`));
75
+ continue;
76
+ }
77
+ const filePath = path.resolve(dir, file.path);
78
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
79
+ fs.writeFileSync(filePath, file.content);
80
+ }
81
+
82
+ p.outro(pc.green(`✅ ${data.name || componentSlug} updated`));
83
+
84
+ } catch (err) {
85
+ spinner.fail('Failed to update component.');
86
+ if (err.code === 'AUTH_REQUIRED' || err.code === 'PRO_REQUIRED') p.log.warn(err.message);
87
+ else console.error(pc.red(err.message));
88
+ process.exit(1);
89
+ }
90
+ }