@astralkit/cli 2.1.0 → 2.2.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/README.md +7 -4
- package/bin/index.js +1 -1
- package/package.json +2 -4
- package/src/commands/add.js +85 -115
- package/src/commands/diff.js +1 -1
- package/src/commands/init.js +82 -11
- package/src/commands/update.js +1 -4
- package/src/lib/config.js +70 -23
- package/src/lib/validators.js +29 -6
package/README.md
CHANGED
|
@@ -35,7 +35,11 @@ AstralKit distributes three types of content:
|
|
|
35
35
|
|
|
36
36
|
### `astralkit init`
|
|
37
37
|
|
|
38
|
-
Initialize AstralKit in your project.
|
|
38
|
+
Initialize AstralKit in your project. This command:
|
|
39
|
+
|
|
40
|
+
1. Installs the `astralkit` npm package (design tokens, utilities, and `cn()` helper)
|
|
41
|
+
2. Adds required CSS imports to your stylesheet (`@import "tailwindcss"`, `@import "astralkit/theme"`, `@import "astralkit/utilities"`)
|
|
42
|
+
3. Creates `astralkit.config.json` with your framework and component directory
|
|
39
43
|
|
|
40
44
|
```bash
|
|
41
45
|
astralkit init
|
|
@@ -85,7 +89,7 @@ astralkit add saas-starter --workflow --overlay --overwrite
|
|
|
85
89
|
|
|
86
90
|
#### Options
|
|
87
91
|
|
|
88
|
-
- `-f, --framework` — Framework version (html, react,
|
|
92
|
+
- `-f, --framework` — Framework version (html, react, nextjs)
|
|
89
93
|
- `--dir` — Override output directory
|
|
90
94
|
- `--overwrite` — Overwrite existing files
|
|
91
95
|
- `--booster` — Install a booster (feature module)
|
|
@@ -196,8 +200,7 @@ Created by `astralkit init` in your project root:
|
|
|
196
200
|
{
|
|
197
201
|
"$schema": "https://astralkit.com/schema/config.json",
|
|
198
202
|
"framework": "nextjs",
|
|
199
|
-
"componentsDir": "src/components/ui"
|
|
200
|
-
"tokensImport": "@astralkit/tokens/css"
|
|
203
|
+
"componentsDir": "src/components/ui"
|
|
201
204
|
}
|
|
202
205
|
```
|
|
203
206
|
|
package/bin/index.js
CHANGED
|
@@ -33,7 +33,7 @@ program
|
|
|
33
33
|
program
|
|
34
34
|
.command('add <name>')
|
|
35
35
|
.description('Add a component, booster, or workflow to your project')
|
|
36
|
-
.option('-f, --framework <framework>', 'Framework version (html, react,
|
|
36
|
+
.option('-f, --framework <framework>', 'Framework version (html, react, nextjs)')
|
|
37
37
|
.option('--dir <directory>', 'Override output directory')
|
|
38
38
|
.option('--overwrite', 'Overwrite existing files', false)
|
|
39
39
|
.option('--booster', 'Install a booster (feature module)')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astralkit/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "AstralKit CLI — Install and manage UI components in your project",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -28,9 +28,7 @@
|
|
|
28
28
|
"tailwind",
|
|
29
29
|
"cli",
|
|
30
30
|
"react",
|
|
31
|
-
"nextjs"
|
|
32
|
-
"vue",
|
|
33
|
-
"svelte"
|
|
31
|
+
"nextjs"
|
|
34
32
|
],
|
|
35
33
|
"homepage": "https://astralkit.com",
|
|
36
34
|
"repository": {
|
package/src/commands/add.js
CHANGED
|
@@ -3,8 +3,16 @@ const path = require('path');
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
4
|
const ora = require('ora');
|
|
5
5
|
const { getComponent, getBooster, getWorkflow } = require('../lib/api');
|
|
6
|
-
const {
|
|
7
|
-
|
|
6
|
+
const {
|
|
7
|
+
getProjectConfig,
|
|
8
|
+
detectFramework,
|
|
9
|
+
isAstralkitInstalled,
|
|
10
|
+
findCssEntryFile,
|
|
11
|
+
getMissingCssImports,
|
|
12
|
+
addCssImports,
|
|
13
|
+
REQUIRED_CSS_IMPORTS,
|
|
14
|
+
} = require('../lib/config');
|
|
15
|
+
const { validateSlug, validateFramework, isSafePath, writeFiles } = require('../lib/validators');
|
|
8
16
|
|
|
9
17
|
/**
|
|
10
18
|
* Route to the correct add handler based on flags.
|
|
@@ -20,7 +28,9 @@ async function addCommand(nameOrSlug, options) {
|
|
|
20
28
|
}
|
|
21
29
|
|
|
22
30
|
/**
|
|
23
|
-
* Add a single UI component
|
|
31
|
+
* Add a single UI component.
|
|
32
|
+
* Drops a single file (.html, .jsx, or .tsx) into src/components/ui/.
|
|
33
|
+
* Verifies astralkit npm package is installed and CSS imports are present.
|
|
24
34
|
*/
|
|
25
35
|
async function addComponent(componentSlug, options) {
|
|
26
36
|
if (!validateSlug(componentSlug)) process.exit(1);
|
|
@@ -29,11 +39,15 @@ async function addComponent(componentSlug, options) {
|
|
|
29
39
|
const config = getProjectConfig();
|
|
30
40
|
const framework = options.framework || config?.framework || detectFramework();
|
|
31
41
|
const componentsDir = options.dir || config?.componentsDir || 'src/components/ui';
|
|
32
|
-
const targetDir = path.resolve(process.cwd(), componentsDir, componentSlug);
|
|
33
42
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
// For react/nextjs, the API returns a single file — write it directly into componentsDir
|
|
44
|
+
// For html, also a single file
|
|
45
|
+
const ext = framework === 'nextjs' ? '.tsx' : framework === 'react' ? '.jsx' : '.html';
|
|
46
|
+
const targetFile = path.resolve(process.cwd(), componentsDir, `${componentSlug}${ext}`);
|
|
47
|
+
|
|
48
|
+
if (fs.existsSync(targetFile) && !options.overwrite) {
|
|
49
|
+
console.log(chalk.yellow(`Component already exists: ${componentsDir}/${componentSlug}${ext}`));
|
|
50
|
+
console.log(chalk.gray('Use --overwrite to replace.'));
|
|
37
51
|
return;
|
|
38
52
|
}
|
|
39
53
|
|
|
@@ -50,32 +64,54 @@ async function addComponent(componentSlug, options) {
|
|
|
50
64
|
return;
|
|
51
65
|
}
|
|
52
66
|
|
|
53
|
-
|
|
67
|
+
// Write the component file(s)
|
|
68
|
+
const dir = path.resolve(process.cwd(), componentsDir);
|
|
69
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
54
70
|
|
|
55
71
|
for (const file of data.files) {
|
|
56
|
-
if (!isSafePath(
|
|
72
|
+
if (!isSafePath(dir, file.path)) {
|
|
57
73
|
console.log(chalk.red(` Skipping suspicious file path: ${file.path}`));
|
|
58
74
|
continue;
|
|
59
75
|
}
|
|
60
|
-
const filePath = path.resolve(
|
|
61
|
-
|
|
62
|
-
if (!fs.existsSync(fileDir)) {
|
|
63
|
-
fs.mkdirSync(fileDir, { recursive: true });
|
|
64
|
-
}
|
|
76
|
+
const filePath = path.resolve(dir, file.path);
|
|
77
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
65
78
|
fs.writeFileSync(filePath, file.content);
|
|
66
79
|
}
|
|
67
80
|
|
|
68
81
|
spinner.succeed(`Added ${chalk.cyan(data.name || componentSlug)} (${framework})`);
|
|
69
82
|
|
|
70
|
-
console.log(chalk.gray(` ${componentsDir}
|
|
83
|
+
console.log(chalk.gray(` ${componentsDir}/`));
|
|
71
84
|
for (const file of data.files) {
|
|
72
85
|
console.log(chalk.gray(` ${file.path}`));
|
|
73
86
|
}
|
|
74
87
|
|
|
75
|
-
|
|
88
|
+
// ─── Post-install checks for react/nextjs ──────────────
|
|
89
|
+
if (framework !== 'html') {
|
|
76
90
|
console.log();
|
|
77
|
-
|
|
78
|
-
|
|
91
|
+
|
|
92
|
+
// Check astralkit npm package
|
|
93
|
+
if (!isAstralkitInstalled()) {
|
|
94
|
+
console.log(chalk.yellow('astralkit package not found.'));
|
|
95
|
+
console.log(chalk.cyan(' npm install astralkit'));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Check CSS imports
|
|
99
|
+
const cssEntry = findCssEntryFile();
|
|
100
|
+
if (cssEntry) {
|
|
101
|
+
const missing = getMissingCssImports(cssEntry.path);
|
|
102
|
+
if (missing.length > 0) {
|
|
103
|
+
console.log(chalk.yellow(`Missing CSS imports in ${cssEntry.relative}:`));
|
|
104
|
+
for (const imp of missing) {
|
|
105
|
+
console.log(chalk.cyan(` ${imp}`));
|
|
106
|
+
}
|
|
107
|
+
console.log(chalk.gray('Run `astralkit init` to set up automatically.'));
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
console.log(chalk.yellow('No CSS entry file found. Add these to your main CSS:'));
|
|
111
|
+
for (const imp of REQUIRED_CSS_IMPORTS) {
|
|
112
|
+
console.log(chalk.cyan(` ${imp}`));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
79
115
|
}
|
|
80
116
|
|
|
81
117
|
if (data.is_pro) {
|
|
@@ -93,7 +129,7 @@ async function addComponent(componentSlug, options) {
|
|
|
93
129
|
* Add a booster (multi-file feature module with core + adapter).
|
|
94
130
|
*/
|
|
95
131
|
async function addBooster(slug, options) {
|
|
96
|
-
if (!validateSlug(slug)) process.exit(1);
|
|
132
|
+
if (!validateSlug(slug, 'booster name')) process.exit(1);
|
|
97
133
|
if (options.framework && !validateFramework(options.framework)) process.exit(1);
|
|
98
134
|
|
|
99
135
|
const config = getProjectConfig();
|
|
@@ -143,37 +179,9 @@ async function addBooster(slug, options) {
|
|
|
143
179
|
}
|
|
144
180
|
}
|
|
145
181
|
|
|
146
|
-
// Write core files
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (!isSafePath(coreDir, file.path)) {
|
|
150
|
-
console.log(chalk.red(` Skipping suspicious file path: ${file.path}`));
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
const filePath = path.resolve(coreDir, file.path);
|
|
154
|
-
const fileDir = path.dirname(filePath);
|
|
155
|
-
if (!fs.existsSync(fileDir)) {
|
|
156
|
-
fs.mkdirSync(fileDir, { recursive: true });
|
|
157
|
-
}
|
|
158
|
-
fs.writeFileSync(filePath, file.content);
|
|
159
|
-
coreCount++;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Write adapter files
|
|
163
|
-
let adapterCount = 0;
|
|
164
|
-
for (const file of adapterFiles) {
|
|
165
|
-
if (!isSafePath(adapterDir, file.path)) {
|
|
166
|
-
console.log(chalk.red(` Skipping suspicious file path: ${file.path}`));
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
const filePath = path.resolve(adapterDir, file.path);
|
|
170
|
-
const fileDir = path.dirname(filePath);
|
|
171
|
-
if (!fs.existsSync(fileDir)) {
|
|
172
|
-
fs.mkdirSync(fileDir, { recursive: true });
|
|
173
|
-
}
|
|
174
|
-
fs.writeFileSync(filePath, file.content);
|
|
175
|
-
adapterCount++;
|
|
176
|
-
}
|
|
182
|
+
// Write core + adapter files
|
|
183
|
+
const coreCount = writeFiles(coreDir, coreFiles);
|
|
184
|
+
const adapterCount = writeFiles(adapterDir, adapterFiles);
|
|
177
185
|
|
|
178
186
|
spinner.succeed(`Added booster ${chalk.cyan(data.name || slug)} (${framework})`);
|
|
179
187
|
|
|
@@ -191,28 +199,7 @@ async function addBooster(slug, options) {
|
|
|
191
199
|
}
|
|
192
200
|
}
|
|
193
201
|
|
|
194
|
-
|
|
195
|
-
if (data.dependencies?.npm?.length) {
|
|
196
|
-
console.log();
|
|
197
|
-
console.log(chalk.yellow('Install required dependencies:'));
|
|
198
|
-
console.log(chalk.cyan(` npm install ${data.dependencies.npm.join(' ')}`));
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Environment variables
|
|
202
|
-
if (data.dependencies?.env?.length) {
|
|
203
|
-
console.log();
|
|
204
|
-
console.log(chalk.yellow('Add these environment variables to your .env:'));
|
|
205
|
-
for (const envVar of data.dependencies.env) {
|
|
206
|
-
console.log(chalk.gray(` ${envVar}=`));
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Post-install instructions
|
|
211
|
-
if (data.post_install) {
|
|
212
|
-
console.log();
|
|
213
|
-
console.log(chalk.white.bold('Setup instructions:'));
|
|
214
|
-
console.log(chalk.gray(data.post_install));
|
|
215
|
-
}
|
|
202
|
+
printPostInstallInfo(data);
|
|
216
203
|
|
|
217
204
|
if (data.is_pro) {
|
|
218
205
|
console.log();
|
|
@@ -229,7 +216,7 @@ async function addBooster(slug, options) {
|
|
|
229
216
|
* Add a workflow (complete application scaffold).
|
|
230
217
|
*/
|
|
231
218
|
async function addWorkflow(slug, options) {
|
|
232
|
-
if (!validateSlug(slug)) process.exit(1);
|
|
219
|
+
if (!validateSlug(slug, 'workflow name')) process.exit(1);
|
|
233
220
|
if (options.framework && !validateFramework(options.framework)) process.exit(1);
|
|
234
221
|
|
|
235
222
|
const config = getProjectConfig();
|
|
@@ -251,10 +238,8 @@ async function addWorkflow(slug, options) {
|
|
|
251
238
|
// Determine target directory
|
|
252
239
|
let targetDir;
|
|
253
240
|
if (options.overlay) {
|
|
254
|
-
// Overlay mode: write into current project
|
|
255
241
|
targetDir = path.resolve(process.cwd());
|
|
256
242
|
} else {
|
|
257
|
-
// Default: create a new subdirectory
|
|
258
243
|
const dirName = options.dir || slug;
|
|
259
244
|
targetDir = path.resolve(process.cwd(), dirName);
|
|
260
245
|
}
|
|
@@ -288,52 +273,14 @@ async function addWorkflow(slug, options) {
|
|
|
288
273
|
}
|
|
289
274
|
|
|
290
275
|
// Write files
|
|
291
|
-
|
|
292
|
-
for (const file of data.files) {
|
|
293
|
-
if (!isSafePath(targetDir, file.path)) {
|
|
294
|
-
console.log(chalk.red(` Skipping suspicious file path: ${file.path}`));
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
const filePath = path.resolve(targetDir, file.path);
|
|
298
|
-
const fileDir = path.dirname(filePath);
|
|
299
|
-
if (!fs.existsSync(fileDir)) {
|
|
300
|
-
fs.mkdirSync(fileDir, { recursive: true });
|
|
301
|
-
}
|
|
302
|
-
fs.writeFileSync(filePath, file.content);
|
|
303
|
-
fileCount++;
|
|
304
|
-
}
|
|
276
|
+
const fileCount = writeFiles(targetDir, data.files);
|
|
305
277
|
|
|
306
278
|
const targetLabel = options.overlay ? './' : `${slug}/`;
|
|
307
279
|
spinner.succeed(`Scaffolded workflow ${chalk.cyan(data.name || slug)} (${framework}) → ${targetLabel}`);
|
|
308
280
|
|
|
309
281
|
console.log(chalk.gray(` ${fileCount} files written to ${targetLabel}`));
|
|
310
282
|
|
|
311
|
-
|
|
312
|
-
if (data.dependencies?.npm?.length) {
|
|
313
|
-
console.log();
|
|
314
|
-
console.log(chalk.yellow('Install dependencies:'));
|
|
315
|
-
if (options.overlay) {
|
|
316
|
-
console.log(chalk.cyan(` npm install ${data.dependencies.npm.join(' ')}`));
|
|
317
|
-
} else {
|
|
318
|
-
console.log(chalk.cyan(` cd ${slug} && npm install`));
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// Environment variables
|
|
323
|
-
if (data.dependencies?.env?.length) {
|
|
324
|
-
console.log();
|
|
325
|
-
console.log(chalk.yellow('Add these environment variables to your .env:'));
|
|
326
|
-
for (const envVar of data.dependencies.env) {
|
|
327
|
-
console.log(chalk.gray(` ${envVar}=`));
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// Post-install instructions
|
|
332
|
-
if (data.post_install) {
|
|
333
|
-
console.log();
|
|
334
|
-
console.log(chalk.white.bold('Setup instructions:'));
|
|
335
|
-
console.log(chalk.gray(data.post_install));
|
|
336
|
-
}
|
|
283
|
+
printPostInstallInfo(data, { npmPrefix: options.overlay ? '' : `cd ${slug} && ` });
|
|
337
284
|
|
|
338
285
|
if (data.is_pro) {
|
|
339
286
|
console.log();
|
|
@@ -346,6 +293,29 @@ async function addWorkflow(slug, options) {
|
|
|
346
293
|
}
|
|
347
294
|
}
|
|
348
295
|
|
|
296
|
+
/**
|
|
297
|
+
* Print post-install info (deps, env vars, setup instructions).
|
|
298
|
+
*/
|
|
299
|
+
function printPostInstallInfo(data, { npmPrefix = '' } = {}) {
|
|
300
|
+
if (data.dependencies?.npm?.length) {
|
|
301
|
+
console.log();
|
|
302
|
+
console.log(chalk.yellow('Install required dependencies:'));
|
|
303
|
+
console.log(chalk.cyan(` ${npmPrefix}npm install ${data.dependencies.npm.join(' ')}`));
|
|
304
|
+
}
|
|
305
|
+
if (data.dependencies?.env?.length) {
|
|
306
|
+
console.log();
|
|
307
|
+
console.log(chalk.yellow('Add these environment variables to your .env:'));
|
|
308
|
+
for (const envVar of data.dependencies.env) {
|
|
309
|
+
console.log(chalk.gray(` ${envVar}=`));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (data.post_install) {
|
|
313
|
+
console.log();
|
|
314
|
+
console.log(chalk.white.bold('Setup instructions:'));
|
|
315
|
+
console.log(chalk.gray(data.post_install));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
349
319
|
/**
|
|
350
320
|
* Shared error handler for add commands.
|
|
351
321
|
*/
|
package/src/commands/diff.js
CHANGED
|
@@ -79,7 +79,7 @@ async function diffCommand(componentSlug, options) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
// Check for local files not on remote
|
|
82
|
-
|
|
82
|
+
{
|
|
83
83
|
const localFiles = fs.readdirSync(targetDir);
|
|
84
84
|
const remoteFilenames = new Set(data.files.map(f => f.path));
|
|
85
85
|
for (const localFile of localFiles) {
|
package/src/commands/init.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
1
3
|
const chalk = require('chalk');
|
|
2
4
|
const inquirer = require('inquirer');
|
|
3
|
-
const
|
|
5
|
+
const ora = require('ora');
|
|
6
|
+
const { execSync } = require('child_process');
|
|
7
|
+
const {
|
|
8
|
+
detectFramework,
|
|
9
|
+
defaultConfig,
|
|
10
|
+
writeProjectConfig,
|
|
11
|
+
getProjectConfig,
|
|
12
|
+
CONFIG_FILENAME,
|
|
13
|
+
isAstralkitInstalled,
|
|
14
|
+
findCssEntryFile,
|
|
15
|
+
getMissingCssImports,
|
|
16
|
+
addCssImports,
|
|
17
|
+
REQUIRED_CSS_IMPORTS,
|
|
18
|
+
} = require('../lib/config');
|
|
4
19
|
const { validateFramework } = require('../lib/validators');
|
|
5
20
|
|
|
6
21
|
async function initCommand(options) {
|
|
@@ -42,12 +57,8 @@ async function initCommand(options) {
|
|
|
42
57
|
{ name: `${detected} (detected)`, value: detected },
|
|
43
58
|
{ name: 'HTML + Tailwind', value: 'html' },
|
|
44
59
|
{ name: 'React', value: 'react' },
|
|
45
|
-
{ name: 'Vue', value: 'vue' },
|
|
46
60
|
{ name: 'Next.js', value: 'nextjs' },
|
|
47
|
-
|
|
48
|
-
{ name: 'Svelte', value: 'svelte' },
|
|
49
|
-
{ name: 'Astro', value: 'astro' },
|
|
50
|
-
].filter((c, i, arr) => {
|
|
61
|
+
].filter((c, i) => {
|
|
51
62
|
// Remove duplicate if detected matches a named option
|
|
52
63
|
if (i === 0) return true;
|
|
53
64
|
return c.value !== detected;
|
|
@@ -60,10 +71,60 @@ async function initCommand(options) {
|
|
|
60
71
|
// Component directory
|
|
61
72
|
const componentDir = options.dir || 'src/components/ui';
|
|
62
73
|
|
|
63
|
-
//
|
|
74
|
+
// ─── Step 1: Install astralkit npm package ──────────────
|
|
75
|
+
if (framework !== 'html') {
|
|
76
|
+
if (!isAstralkitInstalled()) {
|
|
77
|
+
const spinner = ora('Installing astralkit...').start();
|
|
78
|
+
try {
|
|
79
|
+
const pm = detectPackageManager();
|
|
80
|
+
const installCmd = pm === 'yarn' ? 'yarn add astralkit'
|
|
81
|
+
: pm === 'pnpm' ? 'pnpm add astralkit'
|
|
82
|
+
: pm === 'bun' ? 'bun add astralkit'
|
|
83
|
+
: 'npm install astralkit';
|
|
84
|
+
execSync(installCmd, { stdio: 'pipe', cwd: process.cwd() });
|
|
85
|
+
spinner.succeed('Installed astralkit');
|
|
86
|
+
} catch (err) {
|
|
87
|
+
spinner.fail('Failed to install astralkit');
|
|
88
|
+
console.log(chalk.yellow('Run manually: npm install astralkit'));
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
console.log(chalk.gray(' astralkit already installed'));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ─── Step 2: Add CSS imports ────────────────────────────
|
|
96
|
+
const cssEntry = findCssEntryFile();
|
|
97
|
+
if (cssEntry) {
|
|
98
|
+
const missing = getMissingCssImports(cssEntry.path);
|
|
99
|
+
if (missing.length > 0) {
|
|
100
|
+
console.log();
|
|
101
|
+
console.log(chalk.gray(`Found CSS entry: ${cssEntry.relative}`));
|
|
102
|
+
const { addImports } = await inquirer.prompt([{
|
|
103
|
+
type: 'confirm',
|
|
104
|
+
name: 'addImports',
|
|
105
|
+
message: `Add AstralKit imports to ${cssEntry.relative}?`,
|
|
106
|
+
default: true,
|
|
107
|
+
}]);
|
|
108
|
+
if (addImports) {
|
|
109
|
+
addCssImports(cssEntry.path, missing);
|
|
110
|
+
console.log(chalk.green(' Added CSS imports'));
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
console.log(chalk.gray(' CSS imports already present'));
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
console.log();
|
|
117
|
+
console.log(chalk.yellow('No CSS entry file found.'));
|
|
118
|
+
console.log(chalk.gray('Add these imports to your main CSS file:'));
|
|
119
|
+
for (const imp of REQUIRED_CSS_IMPORTS) {
|
|
120
|
+
console.log(chalk.cyan(` ${imp}`));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ─── Step 3: Write config ──────────────────────────────
|
|
64
125
|
const config = defaultConfig(framework);
|
|
65
126
|
config.componentsDir = componentDir;
|
|
66
|
-
|
|
127
|
+
writeProjectConfig(config);
|
|
67
128
|
|
|
68
129
|
console.log();
|
|
69
130
|
console.log(chalk.green('Created'), chalk.cyan(CONFIG_FILENAME));
|
|
@@ -71,9 +132,19 @@ async function initCommand(options) {
|
|
|
71
132
|
console.log(chalk.gray(` Components: ${componentDir}/`));
|
|
72
133
|
console.log();
|
|
73
134
|
console.log(chalk.green('Next steps:'));
|
|
74
|
-
console.log(chalk.gray(' astralkit add
|
|
75
|
-
console.log(chalk.gray(' astralkit list
|
|
76
|
-
console.log(chalk.gray(' astralkit login
|
|
135
|
+
console.log(chalk.gray(' astralkit add sidebar-expanded-light Add a component'));
|
|
136
|
+
console.log(chalk.gray(' astralkit list Browse components'));
|
|
137
|
+
console.log(chalk.gray(' astralkit login Unlock pro components'));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Detect which package manager the project uses.
|
|
142
|
+
*/
|
|
143
|
+
function detectPackageManager(dir = process.cwd()) {
|
|
144
|
+
if (fs.existsSync(path.join(dir, 'bun.lockb')) || fs.existsSync(path.join(dir, 'bun.lock'))) return 'bun';
|
|
145
|
+
if (fs.existsSync(path.join(dir, 'pnpm-lock.yaml'))) return 'pnpm';
|
|
146
|
+
if (fs.existsSync(path.join(dir, 'yarn.lock'))) return 'yarn';
|
|
147
|
+
return 'npm';
|
|
77
148
|
}
|
|
78
149
|
|
|
79
150
|
module.exports = { initCommand };
|
package/src/commands/update.js
CHANGED
|
@@ -101,10 +101,7 @@ async function updateCommand(componentSlug, options) {
|
|
|
101
101
|
continue;
|
|
102
102
|
}
|
|
103
103
|
const filePath = path.resolve(targetDir, file.path);
|
|
104
|
-
|
|
105
|
-
if (!fs.existsSync(fileDir)) {
|
|
106
|
-
fs.mkdirSync(fileDir, { recursive: true });
|
|
107
|
-
}
|
|
104
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
108
105
|
fs.writeFileSync(filePath, file.content);
|
|
109
106
|
}
|
|
110
107
|
|
package/src/lib/config.js
CHANGED
|
@@ -11,7 +11,6 @@ function defaultConfig(framework = 'html') {
|
|
|
11
11
|
$schema: 'https://astralkit.com/schema/config.json',
|
|
12
12
|
framework,
|
|
13
13
|
componentsDir: 'src/components/ui',
|
|
14
|
-
tokensImport: '@astralkit/tokens/css',
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
16
|
|
|
@@ -70,33 +69,12 @@ function detectFramework(dir = process.cwd()) {
|
|
|
70
69
|
return 'nextjs';
|
|
71
70
|
}
|
|
72
71
|
|
|
73
|
-
// Check for
|
|
74
|
-
if (fs.existsSync(path.join(dir, 'nuxt.config.ts')) || fs.existsSync(path.join(dir, 'nuxt.config.js'))) {
|
|
75
|
-
return 'vue';
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Check for Svelte
|
|
79
|
-
if (fs.existsSync(path.join(dir, 'svelte.config.js')) || fs.existsSync(path.join(dir, 'svelte.config.ts'))) {
|
|
80
|
-
return 'svelte';
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Check for Astro
|
|
84
|
-
if (fs.existsSync(path.join(dir, 'astro.config.mjs')) || fs.existsSync(path.join(dir, 'astro.config.ts'))) {
|
|
85
|
-
return 'astro';
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Check for Angular
|
|
89
|
-
if (fs.existsSync(path.join(dir, 'angular.json'))) {
|
|
90
|
-
return 'angular';
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Check package.json for Vue/React
|
|
72
|
+
// Check package.json for React
|
|
94
73
|
const pkgPath = path.join(dir, 'package.json');
|
|
95
74
|
if (fs.existsSync(pkgPath)) {
|
|
96
75
|
try {
|
|
97
76
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
98
77
|
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
99
|
-
if (allDeps['vue']) return 'vue';
|
|
100
78
|
if (allDeps['react']) return 'react';
|
|
101
79
|
} catch {
|
|
102
80
|
// Ignore
|
|
@@ -106,6 +84,69 @@ function detectFramework(dir = process.cwd()) {
|
|
|
106
84
|
return 'html';
|
|
107
85
|
}
|
|
108
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Check if the astralkit npm package is installed in the project.
|
|
89
|
+
*/
|
|
90
|
+
function isAstralkitInstalled(dir = process.cwd()) {
|
|
91
|
+
return fs.existsSync(path.join(dir, 'node_modules', 'astralkit', 'package.json'));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Common CSS file locations to search for when adding imports.
|
|
96
|
+
*/
|
|
97
|
+
const CSS_ENTRY_CANDIDATES = [
|
|
98
|
+
'src/index.css',
|
|
99
|
+
'src/app/globals.css',
|
|
100
|
+
'src/styles/globals.css',
|
|
101
|
+
'src/styles/index.css',
|
|
102
|
+
'app/globals.css',
|
|
103
|
+
'styles/globals.css',
|
|
104
|
+
'index.css',
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
const REQUIRED_CSS_IMPORTS = [
|
|
108
|
+
'@import "tailwindcss";',
|
|
109
|
+
'@import "astralkit/theme";',
|
|
110
|
+
'@import "astralkit/utilities";',
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Find the project's CSS entry file.
|
|
115
|
+
*/
|
|
116
|
+
function findCssEntryFile(dir = process.cwd()) {
|
|
117
|
+
for (const candidate of CSS_ENTRY_CANDIDATES) {
|
|
118
|
+
const filePath = path.join(dir, candidate);
|
|
119
|
+
if (fs.existsSync(filePath)) {
|
|
120
|
+
return { path: filePath, relative: candidate };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Check which of the 3 required CSS imports are missing from a file.
|
|
128
|
+
* Returns array of missing import lines.
|
|
129
|
+
*/
|
|
130
|
+
function getMissingCssImports(cssFilePath) {
|
|
131
|
+
try {
|
|
132
|
+
const content = fs.readFileSync(cssFilePath, 'utf8');
|
|
133
|
+
return REQUIRED_CSS_IMPORTS.filter(imp => !content.includes(imp));
|
|
134
|
+
} catch {
|
|
135
|
+
return REQUIRED_CSS_IMPORTS;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Add missing CSS imports to the top of a file.
|
|
141
|
+
*/
|
|
142
|
+
function addCssImports(cssFilePath, imports) {
|
|
143
|
+
const existing = fs.existsSync(cssFilePath)
|
|
144
|
+
? fs.readFileSync(cssFilePath, 'utf8')
|
|
145
|
+
: '';
|
|
146
|
+
const newContent = imports.join('\n') + '\n\n' + existing;
|
|
147
|
+
fs.writeFileSync(cssFilePath, newContent);
|
|
148
|
+
}
|
|
149
|
+
|
|
109
150
|
module.exports = {
|
|
110
151
|
CONFIG_FILENAME,
|
|
111
152
|
defaultConfig,
|
|
@@ -113,4 +154,10 @@ module.exports = {
|
|
|
113
154
|
getProjectConfig,
|
|
114
155
|
writeProjectConfig,
|
|
115
156
|
detectFramework,
|
|
157
|
+
isAstralkitInstalled,
|
|
158
|
+
CSS_ENTRY_CANDIDATES,
|
|
159
|
+
REQUIRED_CSS_IMPORTS,
|
|
160
|
+
findCssEntryFile,
|
|
161
|
+
getMissingCssImports,
|
|
162
|
+
addCssImports,
|
|
116
163
|
};
|
package/src/lib/validators.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
1
2
|
const path = require('path');
|
|
2
3
|
const chalk = require('chalk');
|
|
3
4
|
|
|
4
|
-
const VALID_FRAMEWORKS = ['html', 'react', '
|
|
5
|
+
const VALID_FRAMEWORKS = ['html', 'react', 'nextjs'];
|
|
5
6
|
const SLUG_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -20,23 +21,25 @@ function validateFramework(framework) {
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
|
-
* Validate a
|
|
24
|
+
* Validate a slug format.
|
|
25
|
+
* @param {string} slug
|
|
26
|
+
* @param {string} [label='name'] - Content type label for error messages.
|
|
24
27
|
* Returns true if valid, false if invalid (and logs an error).
|
|
25
28
|
*/
|
|
26
|
-
function validateSlug(slug) {
|
|
29
|
+
function validateSlug(slug, label = 'name') {
|
|
27
30
|
if (!slug || typeof slug !== 'string') {
|
|
28
|
-
console.error(chalk.red(
|
|
31
|
+
console.error(chalk.red(`${label.charAt(0).toUpperCase() + label.slice(1)} is required.`));
|
|
29
32
|
return false;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
if (slug.length > 128) {
|
|
33
|
-
console.error(chalk.red(
|
|
36
|
+
console.error(chalk.red(`${label.charAt(0).toUpperCase() + label.slice(1)} is too long (max 128 characters).`));
|
|
34
37
|
return false;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
if (!SLUG_PATTERN.test(slug)) {
|
|
38
41
|
console.error(
|
|
39
|
-
chalk.red(`Invalid
|
|
42
|
+
chalk.red(`Invalid ${label} "${slug}".`),
|
|
40
43
|
chalk.gray('Use lowercase letters, numbers, and hyphens only (e.g., "button-sizes").')
|
|
41
44
|
);
|
|
42
45
|
return false;
|
|
@@ -55,10 +58,30 @@ function isSafePath(basedir, filepath) {
|
|
|
55
58
|
return !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
56
59
|
}
|
|
57
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Write files to a base directory with path-traversal protection.
|
|
63
|
+
* Returns the number of files successfully written.
|
|
64
|
+
*/
|
|
65
|
+
function writeFiles(baseDir, files) {
|
|
66
|
+
let count = 0;
|
|
67
|
+
for (const file of files) {
|
|
68
|
+
if (!isSafePath(baseDir, file.path)) {
|
|
69
|
+
console.log(chalk.red(` Skipping suspicious file path: ${file.path}`));
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const filePath = path.resolve(baseDir, file.path);
|
|
73
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
74
|
+
fs.writeFileSync(filePath, file.content);
|
|
75
|
+
count++;
|
|
76
|
+
}
|
|
77
|
+
return count;
|
|
78
|
+
}
|
|
79
|
+
|
|
58
80
|
module.exports = {
|
|
59
81
|
VALID_FRAMEWORKS,
|
|
60
82
|
SLUG_PATTERN,
|
|
61
83
|
validateFramework,
|
|
62
84
|
validateSlug,
|
|
63
85
|
isSafePath,
|
|
86
|
+
writeFiles,
|
|
64
87
|
};
|