@astralkit/cli 4.2.1 → 4.2.3
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/CHANGELOG.md +46 -0
- package/README.md +16 -4
- package/package.json +3 -2
- package/src/commands/init.js +199 -190
- package/src/lib/config.js +183 -163
- package/src/lib/pkg-manager.js +18 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the `@astralkit/cli` package.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [4.2.3] — 2026-04-19
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- **v4 init writes the explicit theme path.** Previously `init` wrote `@import "astralkit/theme";` for Tailwind v4 projects, which relied on the SDK's `./theme` default pointing at the v4 file. After the SDK revert in `astralkit@0.3.2` (where `./theme` correctly resolves to the v3 `:root` file), v4 projects need the explicit `@import "astralkit/theme-v4";` import instead. `init` now writes that for v4 projects. v3 projects continue to register tokens via the `astralkit/tailwind.cjs` plugin with no theme CSS import.
|
|
12
|
+
- **README** updated to reflect the v3-default + v4-opt-in model, with distinct `globals.css` examples for each Tailwind major version.
|
|
13
|
+
|
|
14
|
+
### Compatibility
|
|
15
|
+
- Works with `astralkit >= 0.3.2`. Earlier astralkit versions (0.3.0 / 0.3.1) are not recommended — see the `astralkit` CHANGELOG for the theme-export revert.
|
|
16
|
+
|
|
17
|
+
## [4.2.2] — 2026-04-18
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- **CSS import ordering.** When `init` ran against a project with an existing `@import "tailwindcss";` line, it was prepending the astralkit imports *before* tailwindcss — the opposite of the recommended order (Tailwind v4 docs + our own main app put tailwindcss first, then `@theme` customizations). Now the astralkit imports are inserted on the line after the last tailwind-related line, matching the canonical order.
|
|
21
|
+
- **Tailwind version parsing** handles more real-world `package.json` version specifiers. Previous logic used `.replace(/[^0-9]/, '')` (no `g` flag, strips only first non-digit), which produced misleading numbers for values like `"^4.0.0-beta"`. New logic strips all leading non-digits before parsing and returns `null` for non-parseable values like `"latest"` or `"file:..."` instead of guessing.
|
|
22
|
+
- **Tailwind v3 plugin registration regex** now matches more formatting variants of the `plugins: [...]` array — including no-space (`plugins:[`) and newline-before-bracket formats. Previously only matched `plugins: [` (one space).
|
|
23
|
+
- **Package manager detection** now walks up parent directories looking for a lockfile, instead of checking only `cwd`. This correctly picks up pnpm/yarn/bun in monorepo subpackages where the lockfile lives at the workspace root.
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
- No user-facing API changes. All three fixes improve detection robustness during `init`.
|
|
27
|
+
|
|
28
|
+
## [4.2.1] — 2026-04-18
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
- **README example slugs.** Replaced three non-existent slugs (`pricing-table`, `sidebar-light`, `auth-system`) with real catalog slugs (`button-variants`, `sidebar-expanded-light`, `authentication-system`). Copy-pasting from the README now produces working commands.
|
|
32
|
+
- **`init` success message** no longer points at `pricing-table`. Now shows `astralkit add button-variants`.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
- **Plans table in README** rewritten to reflect the actual four tiers (Free, Pro, Plus, Lifetime) documented on the pricing page. Previous table only showed Free/Pro and incorrectly claimed Free tier gets React/Next.js output (it's HTML-only via the website).
|
|
36
|
+
- **Environment variable documentation** expanded. Added `ASTRALKIT_TOKEN` (session JWT from browser login), tightened descriptions for `ASTRALKIT_API_KEY`, `ASTRALKIT_API_URL` (https-only-except-localhost note), and `ASTRALKIT_LOGIN_PORT` (valid range).
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
- **"Discover what's available" section** in README. Points users at `astralkit list` and the showcase URLs rather than a hardcoded catalog list that would go stale.
|
|
40
|
+
- **Boosters / workflows roadmap note.** Makes clear they're rolling out through 2026 and that components (156 of them) are available now.
|
|
41
|
+
|
|
42
|
+
## [4.2.0] — 2026-04-02
|
|
43
|
+
|
|
44
|
+
### Previous public release.
|
|
45
|
+
|
|
46
|
+
Commands available: `init`, `add`, `remove`, `login`, `logout`, `whoami`, `list`, `search`, `diff`, `update`. Smart content detection across components/boosters/workflows registries. Framework detection (Next.js/React), Tailwind version detection (v3/v4), TypeScript detection, package manager detection (npm/pnpm/yarn/bun).
|
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ npx @astralkit/cli init --api-key ak_YOUR_KEY
|
|
|
32
32
|
2. **Detects your framework** — Next.js or React (auto-detected from project files)
|
|
33
33
|
3. **Detects Tailwind version** — v3 or v4, writes the correct CSS imports
|
|
34
34
|
4. **Detects TypeScript** — serves `.tsx` or `.jsx` accordingly
|
|
35
|
-
5. **Updates your CSS** — adds `@import "astralkit/theme"
|
|
35
|
+
5. **Updates your CSS** — adds the correct AstralKit imports for your Tailwind version: on v3 it adds `@import "astralkit/theme";` + `@import "astralkit/utilities";` and also registers `astralkit/tailwind.cjs` in your `tailwind.config.js`; on v4 it adds `@import "astralkit/theme-v4";` + `@import "astralkit/utilities";` to your globals.css
|
|
36
36
|
6. **Creates `astralkit-ai-rules.md`** — paste into Cursor, CLAUDE.md, etc.
|
|
37
37
|
|
|
38
38
|
No config file is created. Everything is auto-detected on every command.
|
|
@@ -216,8 +216,10 @@ After `astralkit init`, your project has:
|
|
|
216
216
|
|
|
217
217
|
```
|
|
218
218
|
node_modules/astralkit/ ← real npm dependency
|
|
219
|
-
├── astralkit-theme.css ← design tokens
|
|
219
|
+
├── astralkit-theme.css ← design tokens (v3 :root — default)
|
|
220
|
+
├── astralkit-theme-v4.css ← design tokens (v4 @theme — opt-in)
|
|
220
221
|
├── astralkit-utilities.css ← utility classes
|
|
222
|
+
├── tailwind.cjs ← v3 plugin (registers ak-* tokens)
|
|
221
223
|
├── lib/utils.js ← cn() function
|
|
222
224
|
└── package.json
|
|
223
225
|
|
|
@@ -225,12 +227,22 @@ src/components/ui/ ← components go here
|
|
|
225
227
|
astralkit-ai-rules.md ← AI coding rules
|
|
226
228
|
```
|
|
227
229
|
|
|
228
|
-
Your `globals.css
|
|
230
|
+
Your `globals.css` — **Tailwind v3 (the default):**
|
|
229
231
|
```css
|
|
230
|
-
@
|
|
232
|
+
@tailwind base;
|
|
233
|
+
@tailwind components;
|
|
234
|
+
@tailwind utilities;
|
|
231
235
|
@import "astralkit/theme";
|
|
232
236
|
@import "astralkit/utilities";
|
|
233
237
|
```
|
|
238
|
+
`tailwind.config.js` plugins array gets `require('astralkit/tailwind.cjs')` added automatically. The plugin teaches Tailwind about the `ak-*` token names so utilities like `bg-ak-bg` know which CSS variable to output; the theme CSS file provides the `:root { --color-ak-*: ... }` declarations.
|
|
239
|
+
|
|
240
|
+
Your `globals.css` — **Tailwind v4:**
|
|
241
|
+
```css
|
|
242
|
+
@import "tailwindcss";
|
|
243
|
+
@import "astralkit/theme-v4";
|
|
244
|
+
@import "astralkit/utilities";
|
|
245
|
+
```
|
|
234
246
|
|
|
235
247
|
Teammates clone and run `npm install` — everything works. No `astralkit init` needed in CI.
|
|
236
248
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astralkit/cli",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.3",
|
|
4
4
|
"description": "AstralKit CLI — Install and manage UI components in your project",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"bin",
|
|
11
11
|
"src",
|
|
12
|
-
"LICENSE"
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"CHANGELOG.md"
|
|
13
14
|
],
|
|
14
15
|
"engines": {
|
|
15
16
|
"node": ">=18.0.0"
|
package/src/commands/init.js
CHANGED
|
@@ -1,190 +1,199 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import pc from 'picocolors';
|
|
4
|
-
import * as p from '@clack/prompts';
|
|
5
|
-
import {
|
|
6
|
-
detectFramework,
|
|
7
|
-
detectTailwindVersion,
|
|
8
|
-
detectTypeScript,
|
|
9
|
-
isAstralkitInstalled,
|
|
10
|
-
findCssEntryFile,
|
|
11
|
-
getMissingCssImports,
|
|
12
|
-
addCssImports,
|
|
13
|
-
getRequiredCssImports,
|
|
14
|
-
} from '../lib/config.js';
|
|
15
|
-
import { getAiRulesContent } from '../lib/ai-rules.js';
|
|
16
|
-
import { saveApiKey, getApiKey } from '../lib/auth.js';
|
|
17
|
-
import { detectPackageManager, runInstall } from '../lib/pkg-manager.js';
|
|
18
|
-
|
|
19
|
-
const FRAMEWORK_LABELS = { nextjs: 'Next.js', react: 'React' };
|
|
20
|
-
|
|
21
|
-
export async function initCommand(options) {
|
|
22
|
-
p.intro(pc.bgBlue(pc.white(' AstralKit Setup ')));
|
|
23
|
-
|
|
24
|
-
// ─── Step 1: API Key ─────────────────────────────────
|
|
25
|
-
let apiKey = options.apiKey || getApiKey();
|
|
26
|
-
|
|
27
|
-
if (options.apiKey) {
|
|
28
|
-
if (!options.apiKey.startsWith('ak_')) {
|
|
29
|
-
p.cancel(pc.red('Invalid API key format. Keys start with ak_'));
|
|
30
|
-
console.log(pc.gray('Get your key at ') + pc.cyan('https://astralkit.com/account'));
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
saveApiKey(options.apiKey);
|
|
34
|
-
p.log.success('API key saved');
|
|
35
|
-
} else if (!apiKey) {
|
|
36
|
-
p.log.warn('No API key found.');
|
|
37
|
-
console.log();
|
|
38
|
-
console.log(pc.gray(' Get your free API key at: ') + pc.cyan('https://astralkit.com/account'));
|
|
39
|
-
console.log();
|
|
40
|
-
|
|
41
|
-
const keyInput = await p.text({
|
|
42
|
-
message: 'Paste your API key (or press Enter to skip for now):',
|
|
43
|
-
placeholder: 'ak_...',
|
|
44
|
-
validate(val) {
|
|
45
|
-
if (!val) return;
|
|
46
|
-
if (!val.startsWith('ak_')) return 'Keys start with ak_ — check astralkit.com/account';
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
if (p.isCancel(keyInput)) {
|
|
51
|
-
p.cancel('Setup cancelled.');
|
|
52
|
-
process.exit(0);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (keyInput) {
|
|
56
|
-
saveApiKey(keyInput);
|
|
57
|
-
apiKey = keyInput;
|
|
58
|
-
p.log.success('API key saved');
|
|
59
|
-
} else {
|
|
60
|
-
p.log.warn('Skipping API key — some features will be unavailable.');
|
|
61
|
-
p.log.info('Run ' + pc.cyan('astralkit init --api-key <key>') + ' later to add it.');
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
p.log.success('API key found');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// ─── Step 2: Detect project ────────────────────────────
|
|
68
|
-
const framework = options.framework || detectFramework();
|
|
69
|
-
const tailwindVersion = detectTailwindVersion();
|
|
70
|
-
const isTS = detectTypeScript();
|
|
71
|
-
const pm = detectPackageManager();
|
|
72
|
-
|
|
73
|
-
if (framework !== 'react' && framework !== 'nextjs') {
|
|
74
|
-
p.log.warn('AstralKit CLI is for React and Next.js projects.');
|
|
75
|
-
p.log.info('For HTML, copy components from ' + pc.cyan('https://astralkit.com'));
|
|
76
|
-
p.outro('');
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
p.log.step(`Framework: ${pc.cyan(FRAMEWORK_LABELS[framework])}`);
|
|
81
|
-
if (tailwindVersion) p.log.step(`Tailwind: ${pc.cyan('v' + tailwindVersion)}`);
|
|
82
|
-
p.log.step(`TypeScript: ${pc.cyan(isTS ? 'Yes' : 'No')}`);
|
|
83
|
-
p.log.step(`Package manager: ${pc.cyan(pm)}`);
|
|
84
|
-
|
|
85
|
-
// ─── Step 3: Install astralkit (real npm dependency) ────
|
|
86
|
-
//
|
|
87
|
-
// `npm install astralkit` — a proper package on the public registry.
|
|
88
|
-
// Contains: design tokens (CSS), cn() utility, AI rules.
|
|
89
|
-
// Listed in package.json. Survives npm ci. Works for teammates and CI/CD.
|
|
90
|
-
|
|
91
|
-
if (!isAstralkitInstalled()) {
|
|
92
|
-
const ora = (await import('ora')).default;
|
|
93
|
-
const spinner = ora('Installing astralkit...').start();
|
|
94
|
-
try {
|
|
95
|
-
const result = await runInstall(pm, process.cwd(), ['astralkit']);
|
|
96
|
-
if (result.success) {
|
|
97
|
-
spinner.succeed('Installed astralkit');
|
|
98
|
-
} else {
|
|
99
|
-
spinner.fail('Failed to install astralkit.');
|
|
100
|
-
console.log(pc.gray(' ' + (result.hint || result.error)));
|
|
101
|
-
console.log(pc.gray(` Retry manually: ${pm === 'npm' ? 'npm install' : pm + ' add'} astralkit`));
|
|
102
|
-
}
|
|
103
|
-
} catch (err) {
|
|
104
|
-
spinner.fail('Failed to install astralkit.');
|
|
105
|
-
console.log(pc.gray(' ' + err.message));
|
|
106
|
-
}
|
|
107
|
-
} else {
|
|
108
|
-
p.log.step('astralkit already installed');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// ─── Step 4: CSS imports ─────────────────────────────
|
|
112
|
-
const cssEntry = findCssEntryFile();
|
|
113
|
-
|
|
114
|
-
if (cssEntry) {
|
|
115
|
-
const missing = getMissingCssImports(cssEntry.path, tailwindVersion);
|
|
116
|
-
if (missing.length > 0) {
|
|
117
|
-
addCssImports(cssEntry.path, missing);
|
|
118
|
-
p.log.success(`Updated ${pc.cyan(cssEntry.relative)}`);
|
|
119
|
-
} else {
|
|
120
|
-
p.log.step('CSS imports already present');
|
|
121
|
-
}
|
|
122
|
-
} else {
|
|
123
|
-
// Create a default CSS file
|
|
124
|
-
const defaultCssPath = path.join(process.cwd(), 'src', 'app', 'globals.css');
|
|
125
|
-
const defaultCssRelative = path.relative(process.cwd(), defaultCssPath);
|
|
126
|
-
const cssDir = path.dirname(defaultCssPath);
|
|
127
|
-
if (!fs.existsSync(cssDir)) fs.mkdirSync(cssDir, { recursive: true });
|
|
128
|
-
const imports = getRequiredCssImports(tailwindVersion);
|
|
129
|
-
fs.writeFileSync(defaultCssPath, imports.join('\n') + '\n', 'utf-8');
|
|
130
|
-
p.log.success(`Created ${pc.cyan(defaultCssRelative)}`);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// ─── Step 4b: Tailwind v3 plugin registration ─────────
|
|
134
|
-
//
|
|
135
|
-
// In v3, the @theme directive doesn't exist, so ak-* utility classes
|
|
136
|
-
// (bg-ak-bg, text-ak-text, p-ak-2, etc.) only work if the Tailwind
|
|
137
|
-
// config extends the theme. The astralkit/tailwind plugin does this.
|
|
138
|
-
//
|
|
139
|
-
if (tailwindVersion === 3) {
|
|
140
|
-
const configPath = path.join(process.cwd(), 'tailwind.config.js');
|
|
141
|
-
const configPathTs = path.join(process.cwd(), 'tailwind.config.ts');
|
|
142
|
-
const configFile = fs.existsSync(configPathTs) ? configPathTs : (fs.existsSync(configPath) ? configPath : null);
|
|
143
|
-
|
|
144
|
-
if (configFile) {
|
|
145
|
-
const configContent = fs.readFileSync(configFile, 'utf8');
|
|
146
|
-
if (!configContent.includes('astralkit/tailwind')) {
|
|
147
|
-
// Insert the plugin require into the plugins array
|
|
148
|
-
const pluginLine = "require('astralkit/tailwind.cjs')";
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
// plugins exists
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import pc from 'picocolors';
|
|
4
|
+
import * as p from '@clack/prompts';
|
|
5
|
+
import {
|
|
6
|
+
detectFramework,
|
|
7
|
+
detectTailwindVersion,
|
|
8
|
+
detectTypeScript,
|
|
9
|
+
isAstralkitInstalled,
|
|
10
|
+
findCssEntryFile,
|
|
11
|
+
getMissingCssImports,
|
|
12
|
+
addCssImports,
|
|
13
|
+
getRequiredCssImports,
|
|
14
|
+
} from '../lib/config.js';
|
|
15
|
+
import { getAiRulesContent } from '../lib/ai-rules.js';
|
|
16
|
+
import { saveApiKey, getApiKey } from '../lib/auth.js';
|
|
17
|
+
import { detectPackageManager, runInstall } from '../lib/pkg-manager.js';
|
|
18
|
+
|
|
19
|
+
const FRAMEWORK_LABELS = { nextjs: 'Next.js', react: 'React' };
|
|
20
|
+
|
|
21
|
+
export async function initCommand(options) {
|
|
22
|
+
p.intro(pc.bgBlue(pc.white(' AstralKit Setup ')));
|
|
23
|
+
|
|
24
|
+
// ─── Step 1: API Key ─────────────────────────────────
|
|
25
|
+
let apiKey = options.apiKey || getApiKey();
|
|
26
|
+
|
|
27
|
+
if (options.apiKey) {
|
|
28
|
+
if (!options.apiKey.startsWith('ak_')) {
|
|
29
|
+
p.cancel(pc.red('Invalid API key format. Keys start with ak_'));
|
|
30
|
+
console.log(pc.gray('Get your key at ') + pc.cyan('https://astralkit.com/account'));
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
saveApiKey(options.apiKey);
|
|
34
|
+
p.log.success('API key saved');
|
|
35
|
+
} else if (!apiKey) {
|
|
36
|
+
p.log.warn('No API key found.');
|
|
37
|
+
console.log();
|
|
38
|
+
console.log(pc.gray(' Get your free API key at: ') + pc.cyan('https://astralkit.com/account'));
|
|
39
|
+
console.log();
|
|
40
|
+
|
|
41
|
+
const keyInput = await p.text({
|
|
42
|
+
message: 'Paste your API key (or press Enter to skip for now):',
|
|
43
|
+
placeholder: 'ak_...',
|
|
44
|
+
validate(val) {
|
|
45
|
+
if (!val) return;
|
|
46
|
+
if (!val.startsWith('ak_')) return 'Keys start with ak_ — check astralkit.com/account';
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (p.isCancel(keyInput)) {
|
|
51
|
+
p.cancel('Setup cancelled.');
|
|
52
|
+
process.exit(0);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (keyInput) {
|
|
56
|
+
saveApiKey(keyInput);
|
|
57
|
+
apiKey = keyInput;
|
|
58
|
+
p.log.success('API key saved');
|
|
59
|
+
} else {
|
|
60
|
+
p.log.warn('Skipping API key — some features will be unavailable.');
|
|
61
|
+
p.log.info('Run ' + pc.cyan('astralkit init --api-key <key>') + ' later to add it.');
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
p.log.success('API key found');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ─── Step 2: Detect project ────────────────────────────
|
|
68
|
+
const framework = options.framework || detectFramework();
|
|
69
|
+
const tailwindVersion = detectTailwindVersion();
|
|
70
|
+
const isTS = detectTypeScript();
|
|
71
|
+
const pm = detectPackageManager();
|
|
72
|
+
|
|
73
|
+
if (framework !== 'react' && framework !== 'nextjs') {
|
|
74
|
+
p.log.warn('AstralKit CLI is for React and Next.js projects.');
|
|
75
|
+
p.log.info('For HTML, copy components from ' + pc.cyan('https://astralkit.com'));
|
|
76
|
+
p.outro('');
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
p.log.step(`Framework: ${pc.cyan(FRAMEWORK_LABELS[framework])}`);
|
|
81
|
+
if (tailwindVersion) p.log.step(`Tailwind: ${pc.cyan('v' + tailwindVersion)}`);
|
|
82
|
+
p.log.step(`TypeScript: ${pc.cyan(isTS ? 'Yes' : 'No')}`);
|
|
83
|
+
p.log.step(`Package manager: ${pc.cyan(pm)}`);
|
|
84
|
+
|
|
85
|
+
// ─── Step 3: Install astralkit (real npm dependency) ────
|
|
86
|
+
//
|
|
87
|
+
// `npm install astralkit` — a proper package on the public registry.
|
|
88
|
+
// Contains: design tokens (CSS), cn() utility, AI rules.
|
|
89
|
+
// Listed in package.json. Survives npm ci. Works for teammates and CI/CD.
|
|
90
|
+
|
|
91
|
+
if (!isAstralkitInstalled()) {
|
|
92
|
+
const ora = (await import('ora')).default;
|
|
93
|
+
const spinner = ora('Installing astralkit...').start();
|
|
94
|
+
try {
|
|
95
|
+
const result = await runInstall(pm, process.cwd(), ['astralkit']);
|
|
96
|
+
if (result.success) {
|
|
97
|
+
spinner.succeed('Installed astralkit');
|
|
98
|
+
} else {
|
|
99
|
+
spinner.fail('Failed to install astralkit.');
|
|
100
|
+
console.log(pc.gray(' ' + (result.hint || result.error)));
|
|
101
|
+
console.log(pc.gray(` Retry manually: ${pm === 'npm' ? 'npm install' : pm + ' add'} astralkit`));
|
|
102
|
+
}
|
|
103
|
+
} catch (err) {
|
|
104
|
+
spinner.fail('Failed to install astralkit.');
|
|
105
|
+
console.log(pc.gray(' ' + err.message));
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
p.log.step('astralkit already installed');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ─── Step 4: CSS imports ─────────────────────────────
|
|
112
|
+
const cssEntry = findCssEntryFile();
|
|
113
|
+
|
|
114
|
+
if (cssEntry) {
|
|
115
|
+
const missing = getMissingCssImports(cssEntry.path, tailwindVersion);
|
|
116
|
+
if (missing.length > 0) {
|
|
117
|
+
addCssImports(cssEntry.path, missing);
|
|
118
|
+
p.log.success(`Updated ${pc.cyan(cssEntry.relative)}`);
|
|
119
|
+
} else {
|
|
120
|
+
p.log.step('CSS imports already present');
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
// Create a default CSS file
|
|
124
|
+
const defaultCssPath = path.join(process.cwd(), 'src', 'app', 'globals.css');
|
|
125
|
+
const defaultCssRelative = path.relative(process.cwd(), defaultCssPath);
|
|
126
|
+
const cssDir = path.dirname(defaultCssPath);
|
|
127
|
+
if (!fs.existsSync(cssDir)) fs.mkdirSync(cssDir, { recursive: true });
|
|
128
|
+
const imports = getRequiredCssImports(tailwindVersion);
|
|
129
|
+
fs.writeFileSync(defaultCssPath, imports.join('\n') + '\n', 'utf-8');
|
|
130
|
+
p.log.success(`Created ${pc.cyan(defaultCssRelative)}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ─── Step 4b: Tailwind v3 plugin registration ─────────
|
|
134
|
+
//
|
|
135
|
+
// In v3, the @theme directive doesn't exist, so ak-* utility classes
|
|
136
|
+
// (bg-ak-bg, text-ak-text, p-ak-2, etc.) only work if the Tailwind
|
|
137
|
+
// config extends the theme. The astralkit/tailwind plugin does this.
|
|
138
|
+
//
|
|
139
|
+
if (tailwindVersion === 3) {
|
|
140
|
+
const configPath = path.join(process.cwd(), 'tailwind.config.js');
|
|
141
|
+
const configPathTs = path.join(process.cwd(), 'tailwind.config.ts');
|
|
142
|
+
const configFile = fs.existsSync(configPathTs) ? configPathTs : (fs.existsSync(configPath) ? configPath : null);
|
|
143
|
+
|
|
144
|
+
if (configFile) {
|
|
145
|
+
const configContent = fs.readFileSync(configFile, 'utf8');
|
|
146
|
+
if (!configContent.includes('astralkit/tailwind')) {
|
|
147
|
+
// Insert the plugin require into the plugins array
|
|
148
|
+
const pluginLine = "require('astralkit/tailwind.cjs')";
|
|
149
|
+
|
|
150
|
+
// Match `plugins` followed by optional whitespace/newlines and an
|
|
151
|
+
// opening bracket. Covers:
|
|
152
|
+
// plugins: [ (current format)
|
|
153
|
+
// plugins:[ (no space)
|
|
154
|
+
// plugins: \n [ (newline before bracket)
|
|
155
|
+
// plugins = [ (variable assignment style, rare)
|
|
156
|
+
const arrayOpenRe = /plugins\s*[:=]\s*\[/;
|
|
157
|
+
|
|
158
|
+
if (arrayOpenRe.test(configContent)) {
|
|
159
|
+
// plugins array exists — inject after the opening bracket, preserving
|
|
160
|
+
// the user's indentation style as best we can
|
|
161
|
+
const updated = configContent.replace(
|
|
162
|
+
arrayOpenRe,
|
|
163
|
+
(match) => `${match}\n ${pluginLine},`
|
|
164
|
+
);
|
|
165
|
+
fs.writeFileSync(configFile, updated, 'utf8');
|
|
166
|
+
p.log.success(`Added AstralKit plugin to ${pc.cyan(path.relative(process.cwd(), configFile))}`);
|
|
167
|
+
} else if (/plugins\s*[:=]/.test(configContent)) {
|
|
168
|
+
// plugins key exists but not as an array — warn
|
|
169
|
+
p.log.warn('Could not auto-add plugin to tailwind config (plugins is not an array literal).');
|
|
170
|
+
p.log.info(`Add manually: ${pc.cyan(pluginLine)} to your plugins array.`);
|
|
171
|
+
} else {
|
|
172
|
+
p.log.warn('No plugins array found in tailwind config.');
|
|
173
|
+
p.log.info(`Add manually: ${pc.cyan(`plugins: [${pluginLine}]`)}`);
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
p.log.step('AstralKit Tailwind plugin already registered');
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
p.log.warn('No tailwind.config found. AstralKit Tailwind v3 plugin not registered.');
|
|
180
|
+
p.log.info(`Create one and add: ${pc.cyan("plugins: [require('astralkit/tailwind.cjs')]")}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// ─── Step 5: AI rules file ───────────────────────────
|
|
185
|
+
const rulesFile = 'astralkit-ai-rules.md';
|
|
186
|
+
const rulesPath = path.join(process.cwd(), rulesFile);
|
|
187
|
+
if (!fs.existsSync(rulesPath)) {
|
|
188
|
+
fs.writeFileSync(rulesPath, getAiRulesContent());
|
|
189
|
+
p.log.success(`Created ${pc.cyan(rulesFile)}`);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// ─── Done ────────────────────────────────────────────
|
|
193
|
+
p.outro(pc.green('AstralKit is ready!'));
|
|
194
|
+
|
|
195
|
+
console.log();
|
|
196
|
+
console.log(pc.gray(' Add a component:'), pc.cyan('astralkit add button-variants'));
|
|
197
|
+
console.log(pc.gray(' Browse all: '), pc.cyan('astralkit list'));
|
|
198
|
+
console.log();
|
|
199
|
+
}
|
package/src/lib/config.js
CHANGED
|
@@ -1,163 +1,183 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
// ─── CSS entry file candidates (searched in order) ────────
|
|
5
|
-
export const CSS_ENTRY_CANDIDATES = [
|
|
6
|
-
'src/app/globals.css',
|
|
7
|
-
'src/index.css',
|
|
8
|
-
'src/styles/globals.css',
|
|
9
|
-
'src/styles/index.css',
|
|
10
|
-
'app/globals.css',
|
|
11
|
-
'styles/globals.css',
|
|
12
|
-
'index.css',
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
// ─── Framework detection ──────────────────────────────────
|
|
16
|
-
|
|
17
|
-
export function detectFramework(dir = process.cwd()) {
|
|
18
|
-
// Next.js
|
|
19
|
-
if (
|
|
20
|
-
fs.existsSync(path.join(dir, 'next.config.js')) ||
|
|
21
|
-
fs.existsSync(path.join(dir, 'next.config.mjs')) ||
|
|
22
|
-
fs.existsSync(path.join(dir, 'next.config.ts'))
|
|
23
|
-
) return 'nextjs';
|
|
24
|
-
|
|
25
|
-
// React (Vite, CRA, etc.)
|
|
26
|
-
const pkgPath = path.join(dir, 'package.json');
|
|
27
|
-
if (fs.existsSync(pkgPath)) {
|
|
28
|
-
try {
|
|
29
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
30
|
-
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
31
|
-
if (allDeps['react']) return 'react';
|
|
32
|
-
} catch { /* ignore */ }
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return 'html';
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// ─── Tailwind version detection ───────────────────────────
|
|
39
|
-
|
|
40
|
-
export function detectTailwindVersion(dir = process.cwd()) {
|
|
41
|
-
const pkgPath = path.join(dir, 'package.json');
|
|
42
|
-
if (!fs.existsSync(pkgPath)) return null;
|
|
43
|
-
try {
|
|
44
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
45
|
-
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
46
|
-
const ver = allDeps['tailwindcss'];
|
|
47
|
-
if (!ver) return null;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
// ─── CSS entry file candidates (searched in order) ────────
|
|
5
|
+
export const CSS_ENTRY_CANDIDATES = [
|
|
6
|
+
'src/app/globals.css',
|
|
7
|
+
'src/index.css',
|
|
8
|
+
'src/styles/globals.css',
|
|
9
|
+
'src/styles/index.css',
|
|
10
|
+
'app/globals.css',
|
|
11
|
+
'styles/globals.css',
|
|
12
|
+
'index.css',
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
// ─── Framework detection ──────────────────────────────────
|
|
16
|
+
|
|
17
|
+
export function detectFramework(dir = process.cwd()) {
|
|
18
|
+
// Next.js
|
|
19
|
+
if (
|
|
20
|
+
fs.existsSync(path.join(dir, 'next.config.js')) ||
|
|
21
|
+
fs.existsSync(path.join(dir, 'next.config.mjs')) ||
|
|
22
|
+
fs.existsSync(path.join(dir, 'next.config.ts'))
|
|
23
|
+
) return 'nextjs';
|
|
24
|
+
|
|
25
|
+
// React (Vite, CRA, etc.)
|
|
26
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
27
|
+
if (fs.existsSync(pkgPath)) {
|
|
28
|
+
try {
|
|
29
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
30
|
+
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
31
|
+
if (allDeps['react']) return 'react';
|
|
32
|
+
} catch { /* ignore */ }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return 'html';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ─── Tailwind version detection ───────────────────────────
|
|
39
|
+
|
|
40
|
+
export function detectTailwindVersion(dir = process.cwd()) {
|
|
41
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
42
|
+
if (!fs.existsSync(pkgPath)) return null;
|
|
43
|
+
try {
|
|
44
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
45
|
+
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
46
|
+
const ver = allDeps['tailwindcss'];
|
|
47
|
+
if (!ver) return null;
|
|
48
|
+
// Handle: "^4.0.0", "~4.1.2", "4.0.0-beta.1", ">=3.4.0", "file:...", "latest", "next".
|
|
49
|
+
// Strip only the leading non-digits (^ ~ >= etc.) then parse. Anything
|
|
50
|
+
// that doesn't start with a digit after stripping (file:..., latest, next,
|
|
51
|
+
// workspace:*) returns NaN from parseInt and falls through to null —
|
|
52
|
+
// better to return null than guess wrong.
|
|
53
|
+
const match = ver.match(/^\D*(\d+)/);
|
|
54
|
+
if (!match) return null;
|
|
55
|
+
const major = parseInt(match[1], 10);
|
|
56
|
+
if (Number.isNaN(major)) return null;
|
|
57
|
+
if (major >= 4) return 4;
|
|
58
|
+
if (major >= 3) return 3;
|
|
59
|
+
return null;
|
|
60
|
+
} catch { return null; }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ─── TypeScript detection ─────────────────────────────────
|
|
64
|
+
|
|
65
|
+
export function detectTypeScript(dir = process.cwd()) {
|
|
66
|
+
return fs.existsSync(path.join(dir, 'tsconfig.json'));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ─── astralkit installed check ────────────────────────────
|
|
70
|
+
|
|
71
|
+
export function isAstralkitInstalled(dir = process.cwd()) {
|
|
72
|
+
return fs.existsSync(path.join(dir, 'node_modules', 'astralkit', 'package.json'));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ─── CSS entry file search ────────────────────────────────
|
|
76
|
+
|
|
77
|
+
export function findCssEntryFile(dir = process.cwd()) {
|
|
78
|
+
for (const candidate of CSS_ENTRY_CANDIDATES) {
|
|
79
|
+
const filePath = path.join(dir, candidate);
|
|
80
|
+
if (fs.existsSync(filePath)) return { path: filePath, relative: candidate };
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ─── CSS imports (Tailwind v3 vs v4 aware) ────────────────
|
|
86
|
+
|
|
87
|
+
export function getRequiredCssImports(tailwindVersion) {
|
|
88
|
+
if (tailwindVersion === 3) {
|
|
89
|
+
// v3: :root CSS variable declarations come from astralkit/theme (which
|
|
90
|
+
// resolves to astralkit-theme.css — the :root variant). The plugin in
|
|
91
|
+
// tailwind.config.js teaches Tailwind about the token names so utilities
|
|
92
|
+
// like bg-ak-bg know which var() to emit. Utilities CSS is Tailwind-agnostic.
|
|
93
|
+
return [
|
|
94
|
+
'@tailwind base;',
|
|
95
|
+
'@tailwind components;',
|
|
96
|
+
'@tailwind utilities;',
|
|
97
|
+
'@import "astralkit/theme";',
|
|
98
|
+
'@import "astralkit/utilities";',
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
// v4 or unknown — v4 projects explicitly import the @theme-directive file
|
|
102
|
+
// at `astralkit/theme-v4`. The default `astralkit/theme` export resolves
|
|
103
|
+
// to the v3 :root file (v3 is the default customer base); v4 users must
|
|
104
|
+
// opt in via the explicit path.
|
|
105
|
+
return [
|
|
106
|
+
'@import "tailwindcss";',
|
|
107
|
+
'@import "astralkit/theme-v4";',
|
|
108
|
+
'@import "astralkit/utilities";',
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function getMissingCssImports(cssFilePath, tailwindVersion) {
|
|
113
|
+
try {
|
|
114
|
+
const content = fs.readFileSync(cssFilePath, 'utf8');
|
|
115
|
+
const required = getRequiredCssImports(tailwindVersion);
|
|
116
|
+
|
|
117
|
+
return required.filter(imp => {
|
|
118
|
+
// For tailwind directives, check if either v3 or v4 syntax is present
|
|
119
|
+
if (imp === '@import "tailwindcss";') {
|
|
120
|
+
return !content.includes('@import "tailwindcss"') && !content.includes('@tailwind base');
|
|
121
|
+
}
|
|
122
|
+
if (imp === '@tailwind base;') {
|
|
123
|
+
return !content.includes('@tailwind base') && !content.includes('@import "tailwindcss"');
|
|
124
|
+
}
|
|
125
|
+
if (imp === '@tailwind components;') {
|
|
126
|
+
return !content.includes('@tailwind components');
|
|
127
|
+
}
|
|
128
|
+
if (imp === '@tailwind utilities;') {
|
|
129
|
+
return !content.includes('@tailwind utilities');
|
|
130
|
+
}
|
|
131
|
+
// AstralKit imports — check directly
|
|
132
|
+
return !content.includes(imp);
|
|
133
|
+
});
|
|
134
|
+
} catch {
|
|
135
|
+
return getRequiredCssImports(tailwindVersion);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function addCssImports(cssFilePath, imports) {
|
|
140
|
+
const existing = fs.existsSync(cssFilePath) ? fs.readFileSync(cssFilePath, 'utf8') : '';
|
|
141
|
+
const astralkitImports = imports.filter(i => i.includes('astralkit'));
|
|
142
|
+
|
|
143
|
+
// If Tailwind is already imported/directive'd in the file (v3 @tailwind
|
|
144
|
+
// directives OR v4 @import "tailwindcss"), insert astralkit imports AFTER
|
|
145
|
+
// the last Tailwind-related line. This preserves the recommended ordering
|
|
146
|
+
// (tailwindcss first, astralkit after) instead of prepending astralkit
|
|
147
|
+
// imports before tailwindcss in the file.
|
|
148
|
+
const tailwindImportRe = /^@import\s+["']tailwindcss["']/;
|
|
149
|
+
const hasTailwind = existing.includes('@tailwind utilities') || tailwindImportRe.test(existing);
|
|
150
|
+
|
|
151
|
+
if (hasTailwind && astralkitImports.length > 0) {
|
|
152
|
+
const lines = existing.split('\n');
|
|
153
|
+
let lastTailwindIdx = -1;
|
|
154
|
+
for (let i = 0; i < lines.length; i++) {
|
|
155
|
+
const trimmed = lines[i].trim();
|
|
156
|
+
if (trimmed.startsWith('@tailwind') || tailwindImportRe.test(trimmed)) {
|
|
157
|
+
lastTailwindIdx = i;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (lastTailwindIdx >= 0) {
|
|
161
|
+
lines.splice(lastTailwindIdx + 1, 0, '', ...astralkitImports);
|
|
162
|
+
fs.writeFileSync(cssFilePath, lines.join('\n'));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Default: prepend everything (fresh file with no Tailwind yet)
|
|
168
|
+
fs.writeFileSync(cssFilePath, imports.join('\n') + '\n\n' + existing);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ─── Legacy config file support ───────────────────────────
|
|
172
|
+
// Reads astralkit.config.json if it exists (from older init versions).
|
|
173
|
+
// New installs don't create this file.
|
|
174
|
+
|
|
175
|
+
export const CONFIG_FILENAME = 'astralkit.config.json';
|
|
176
|
+
|
|
177
|
+
export function getProjectConfig(dir = process.cwd()) {
|
|
178
|
+
const configPath = path.join(dir, CONFIG_FILENAME);
|
|
179
|
+
if (!fs.existsSync(configPath)) return null;
|
|
180
|
+
try {
|
|
181
|
+
return JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
182
|
+
} catch { return null; }
|
|
183
|
+
}
|
package/src/lib/pkg-manager.js
CHANGED
|
@@ -3,9 +3,24 @@ import path from 'path';
|
|
|
3
3
|
import { execa } from 'execa';
|
|
4
4
|
|
|
5
5
|
export function detectPackageManager(dir = process.cwd()) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
// Walk up from `dir` to the filesystem root, stopping at the first lockfile
|
|
7
|
+
// found. Handles monorepos where the lockfile lives at the workspace root
|
|
8
|
+
// (e.g., running `astralkit init` inside `packages/my-app/` of a pnpm repo).
|
|
9
|
+
let current = path.resolve(dir);
|
|
10
|
+
const { root } = path.parse(current);
|
|
11
|
+
|
|
12
|
+
while (true) {
|
|
13
|
+
if (fs.existsSync(path.join(current, 'bun.lockb')) || fs.existsSync(path.join(current, 'bun.lock'))) return 'bun';
|
|
14
|
+
if (fs.existsSync(path.join(current, 'pnpm-lock.yaml'))) return 'pnpm';
|
|
15
|
+
if (fs.existsSync(path.join(current, 'yarn.lock'))) return 'yarn';
|
|
16
|
+
if (fs.existsSync(path.join(current, 'package-lock.json'))) return 'npm';
|
|
17
|
+
|
|
18
|
+
if (current === root) break;
|
|
19
|
+
const parent = path.dirname(current);
|
|
20
|
+
if (parent === current) break; // belt-and-suspenders against infinite loops
|
|
21
|
+
current = parent;
|
|
22
|
+
}
|
|
23
|
+
|
|
9
24
|
return 'npm';
|
|
10
25
|
}
|
|
11
26
|
|