kigumi 0.2.2 → 0.4.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 +220 -64
- package/dist/chunk-Z74ULW6C.js +178 -0
- package/dist/index.js +328 -208
- package/dist/templates/react/ButtonGroup/ButtonGroup.css.hbs +15 -0
- package/dist/templates/react/ButtonGroup/ButtonGroup.jsx.hbs +48 -0
- package/dist/templates/react/ButtonGroup/ButtonGroup.test.jsx.hbs +44 -0
- package/dist/templates/react/ButtonGroup/ButtonGroup.test.tsx.hbs +32 -0
- package/dist/templates/react/ButtonGroup/ButtonGroup.tsx.hbs +50 -0
- package/dist/templates/react/Callout/Callout.css.hbs +17 -0
- package/dist/templates/react/Callout/Callout.jsx.hbs +29 -0
- package/dist/templates/react/Callout/Callout.test.jsx.hbs +27 -0
- package/dist/templates/react/Callout/Callout.test.tsx.hbs +27 -0
- package/dist/templates/react/Callout/Callout.tsx.hbs +32 -0
- package/dist/templates/react/Page/Page.css.hbs +79 -0
- package/dist/templates/react/Page/Page.jsx.hbs +117 -0
- package/dist/templates/react/Page/Page.test.jsx.hbs +51 -0
- package/dist/templates/react/Page/Page.test.tsx.hbs +57 -0
- package/dist/templates/react/Page/Page.tsx.hbs +122 -0
- package/dist/{tier-2ZEZT6E3.js → tier-6FHJQIUG.js} +1 -1
- package/package.json +2 -1
- package/templates/react/ButtonGroup/ButtonGroup.css.hbs +15 -0
- package/templates/react/ButtonGroup/ButtonGroup.jsx.hbs +48 -0
- package/templates/react/ButtonGroup/ButtonGroup.test.jsx.hbs +44 -0
- package/templates/react/ButtonGroup/ButtonGroup.test.tsx.hbs +32 -0
- package/templates/react/ButtonGroup/ButtonGroup.tsx.hbs +50 -0
- package/templates/react/Callout/Callout.css.hbs +17 -0
- package/templates/react/Callout/Callout.jsx.hbs +29 -0
- package/templates/react/Callout/Callout.test.jsx.hbs +27 -0
- package/templates/react/Callout/Callout.test.tsx.hbs +27 -0
- package/templates/react/Callout/Callout.tsx.hbs +32 -0
- package/templates/react/Page/Page.css.hbs +79 -0
- package/templates/react/Page/Page.jsx.hbs +117 -0
- package/templates/react/Page/Page.test.jsx.hbs +51 -0
- package/templates/react/Page/Page.test.tsx.hbs +57 -0
- package/templates/react/Page/Page.tsx.hbs +122 -0
- package/dist/chunk-FG4CIVPT.js +0 -52
- package/dist/chunk-IRCCX2A2.js +0 -72
- package/dist/path-aliases-3OJ2RKTE.js +0 -95
- package/dist/path-aliases-44XMTAAA.js +0 -89
- package/dist/path-aliases-CNBMGBKE.js +0 -98
- package/dist/path-aliases-L6USUZ4R.js +0 -91
- package/dist/path-aliases-NX2TDEHO.js +0 -92
- package/dist/path-aliases-ZRNAAXX2.js +0 -94
- package/dist/project-config-3XEQHIUM.js +0 -115
- package/dist/project-config-YLUSQM7U.js +0 -108
- package/dist/templates/react/KIGUMI_SETUP.md.hbs +0 -52
- package/dist/tier-GFXZQZUI.js +0 -12
package/README.md
CHANGED
|
@@ -1,126 +1,282 @@
|
|
|
1
1
|
# Kigumi
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
> **Note:** Currently React-only. Vue, Angular, and Svelte support coming soon.
|
|
3
|
+
> Build framework-agnostic UIs with ready-made components. Kigumi wraps Web Components for React (Vue, Angular, Svelte soon). Same components, any stack.
|
|
6
4
|
|
|
7
5
|
## Quick Start
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
8
|
npx kigumi init
|
|
11
|
-
npx kigumi add button
|
|
9
|
+
npx kigumi add button input
|
|
12
10
|
```
|
|
13
11
|
|
|
14
|
-
Import
|
|
12
|
+
Import in your entry file (e.g. `src/main.tsx`):
|
|
15
13
|
|
|
16
14
|
```tsx
|
|
17
|
-
// src/main.tsx
|
|
18
15
|
import '@/lib/webawesome';
|
|
19
16
|
```
|
|
20
17
|
|
|
21
|
-
Use
|
|
18
|
+
Use components:
|
|
22
19
|
|
|
23
20
|
```tsx
|
|
24
|
-
import { Button,
|
|
21
|
+
import { Button, Input } from '@/components/ui';
|
|
22
|
+
|
|
23
|
+
export default function LoginForm() {
|
|
24
|
+
const [email, setEmail] = useState('');
|
|
25
25
|
|
|
26
|
-
function App() {
|
|
27
26
|
return (
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
<form
|
|
28
|
+
onSubmit={(e) => {
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
console.log('Email:', email);
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
<Input
|
|
34
|
+
type="email"
|
|
35
|
+
label="Email"
|
|
36
|
+
value={email}
|
|
37
|
+
onInput={(e) => setEmail(e.target.value)}
|
|
38
|
+
required
|
|
39
|
+
/>
|
|
40
|
+
<Button type="submit" variant="brand">
|
|
41
|
+
Sign In
|
|
42
|
+
</Button>
|
|
43
|
+
</form>
|
|
31
44
|
);
|
|
32
45
|
}
|
|
33
46
|
```
|
|
34
47
|
|
|
35
|
-
##
|
|
48
|
+
## Why Kigumi
|
|
49
|
+
|
|
50
|
+
**Framework-agnostic by design**
|
|
51
|
+
Build your UI once. Web Components work in React, Vue, Angular, Svelte, or vanilla JS.
|
|
36
52
|
|
|
37
|
-
|
|
53
|
+
**You own the code**
|
|
54
|
+
Components are copied to your project. Modify, extend, or remove whatever you need.
|
|
38
55
|
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
- **Ref forwarding** - Access the underlying Web Component when needed
|
|
42
|
-
- **Copied to your project** - No external dependencies, customize as needed
|
|
56
|
+
**Production-ready**
|
|
57
|
+
50+ components (including Pro-only advanced components) with TypeScript support, accessibility built-in, and 11 themes included.
|
|
43
58
|
|
|
44
59
|
## Commands
|
|
45
60
|
|
|
61
|
+
### `init`
|
|
62
|
+
|
|
63
|
+
Initialize Kigumi in your project. Sets up theming and installs dependencies.
|
|
64
|
+
|
|
46
65
|
```bash
|
|
47
|
-
npx kigumi init
|
|
48
|
-
npx kigumi add <component> # Add component(s)
|
|
49
|
-
npx kigumi add # Interactive component selection
|
|
50
|
-
npx kigumi add --all # Add all components
|
|
51
|
-
npx kigumi list # List available components
|
|
52
|
-
npx kigumi status # Show current configuration
|
|
53
|
-
npx kigumi theme set <name> # Change theme
|
|
54
|
-
npx kigumi palette <name> # Change color palette
|
|
55
|
-
npx kigumi brand <color> # Change brand color
|
|
66
|
+
npx kigumi init
|
|
56
67
|
```
|
|
57
68
|
|
|
58
|
-
**
|
|
69
|
+
**Web Awesome Pro:** To unlock premium themes and Pro-only components:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Configure your token globally (once per machine)
|
|
73
|
+
npm config set //npm.cloudsmith.io/fortawesome/webawesome-pro/:_authToken YOUR_TOKEN
|
|
74
|
+
|
|
75
|
+
# Then just run init - Pro tier is auto-detected
|
|
76
|
+
npx kigumi init
|
|
77
|
+
```
|
|
59
78
|
|
|
60
|
-
|
|
79
|
+
Get your token at [webawesome.com](https://https://webawesome.com/login)
|
|
80
|
+
|
|
81
|
+
<details>
|
|
82
|
+
<summary>CI/CD Setup</summary>
|
|
83
|
+
|
|
84
|
+
For CI/CD environments, set the `WEBAWESOME_NPM_TOKEN` environment variable:
|
|
85
|
+
|
|
86
|
+
```yaml
|
|
87
|
+
# GitHub Actions example
|
|
88
|
+
env:
|
|
89
|
+
WEBAWESOME_NPM_TOKEN: ${{ secrets.WEBAWESOME_NPM_TOKEN }}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
</details>
|
|
93
|
+
|
|
94
|
+
### `add`
|
|
95
|
+
|
|
96
|
+
Add components to your project:
|
|
61
97
|
|
|
62
98
|
```bash
|
|
63
|
-
npx kigumi
|
|
64
|
-
npx kigumi add
|
|
99
|
+
npx kigumi add <components> # Add specific components (e.g., button input card)
|
|
100
|
+
npx kigumi add # Interactive component selector
|
|
101
|
+
npx kigumi add --all # Add all 80+ components at once
|
|
65
102
|
```
|
|
66
103
|
|
|
67
|
-
|
|
104
|
+
### `list`
|
|
68
105
|
|
|
69
|
-
|
|
106
|
+
View all available components:
|
|
70
107
|
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
"framework": "react",
|
|
74
|
-
"typescript": true,
|
|
75
|
-
"componentsDir": "src/components/ui",
|
|
76
|
-
"stylesDir": "src/styles",
|
|
77
|
-
"theme": {
|
|
78
|
-
"selected": "default",
|
|
79
|
-
"palette": "default",
|
|
80
|
-
"brandColor": "blue"
|
|
81
|
-
}
|
|
82
|
-
}
|
|
108
|
+
```bash
|
|
109
|
+
npx kigumi list
|
|
83
110
|
```
|
|
84
111
|
|
|
85
|
-
|
|
112
|
+
Shows component name, description, and Pro badge for Pro-only components.
|
|
113
|
+
|
|
114
|
+
### `theme`
|
|
115
|
+
|
|
116
|
+
Change theme, palette, or brand color:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npx kigumi theme [name] # Change theme (shows selector if name omitted)
|
|
120
|
+
npx kigumi palette [name] # Change color palette
|
|
121
|
+
npx kigumi brand [color] # Change brand color
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Free themes:** `default`, `awesome`, `shoelace`
|
|
125
|
+
**Pro themes:** `brutalist`, `glossy`, `matter`, `mellow`, `playful`, `premium`, `tailspin`, `active`
|
|
126
|
+
**Color palettes:** `default`, `bright`, `shoelace`, `rudimentary`, `elegant`, `mild`, `natural`, `anodized`, `vogue`
|
|
127
|
+
**Brand colors:** `blue`, `purple`, `green`, `red`, `orange`, `yellow`, `cyan`, `indigo`, `pink`, `gray`
|
|
128
|
+
|
|
129
|
+
## Utility Classes
|
|
86
130
|
|
|
87
|
-
|
|
131
|
+
With the included [style](https://webawesome.com/docs/utilities) and [layout](https://webawesome.com/docs/layout/) utility classes you can quickly build your UI:
|
|
88
132
|
|
|
89
|
-
|
|
133
|
+
```tsx
|
|
134
|
+
<div className="wa-stack wa-gap-md">
|
|
135
|
+
<h1 className="wa-heading-2xl">Welcome</h1>
|
|
136
|
+
<p className="wa-text-muted">Get started below</p>
|
|
137
|
+
</div>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Customization
|
|
141
|
+
|
|
142
|
+
Add your custom CSS overrides in `src/styles/theme.css`:
|
|
90
143
|
|
|
91
144
|
```css
|
|
92
145
|
:root {
|
|
93
|
-
/* Brand color */
|
|
94
146
|
--wa-color-brand-600: #6366f1;
|
|
95
|
-
|
|
96
|
-
/* Typography */
|
|
97
147
|
--wa-font-family-sans: 'Inter', system-ui, sans-serif;
|
|
98
|
-
|
|
99
|
-
/* Border radius */
|
|
100
148
|
--wa-border-radius-medium: 0.5rem;
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Note:** Theme selection is handled via `kigumi theme` command, which updates `src/lib/webawesome.ts`. The `theme.css` file is for your custom CSS only.
|
|
101
153
|
|
|
102
|
-
|
|
103
|
-
|
|
154
|
+
[Design Tokens Reference](https://webawesome.com/docs/tokens)
|
|
155
|
+
[Theming Guide](https://webawesome.com/docs/themes)
|
|
156
|
+
|
|
157
|
+
## CSS Architecture
|
|
158
|
+
|
|
159
|
+
Kigumi uses CSS cascade layers (`@layer`) for predictable style precedence:
|
|
160
|
+
|
|
161
|
+
**Layer hierarchy:**
|
|
162
|
+
|
|
163
|
+
1. **base** - Web Awesome foundation + theme styles (lowest priority)
|
|
164
|
+
2. **theme** - Your custom CSS overrides in `src/styles/theme.css` (higher priority)
|
|
165
|
+
|
|
166
|
+
Later layers always override earlier layers, regardless of specificity. This means your custom styles in `theme.css` will reliably override Web Awesome defaults without needing `!important`.
|
|
167
|
+
|
|
168
|
+
**How it works:**
|
|
169
|
+
|
|
170
|
+
- `src/styles/layers.css` (auto-generated) wraps Web Awesome imports in layers
|
|
171
|
+
- `src/lib/webawesome.ts` (auto-generated) imports layers.css
|
|
172
|
+
- Your custom styles in `theme.css` are imported into the `theme` layer
|
|
173
|
+
|
|
174
|
+
[Learn more about CSS cascade layers](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer)
|
|
175
|
+
|
|
176
|
+
## Troubleshooting
|
|
177
|
+
|
|
178
|
+
### Import errors with @ alias
|
|
179
|
+
|
|
180
|
+
If you see errors like `Cannot find module '@/lib/webawesome'`, configure path aliases:
|
|
181
|
+
|
|
182
|
+
**Vite (vite.config.ts):**
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
export default defineConfig({
|
|
186
|
+
resolve: {
|
|
187
|
+
alias: {
|
|
188
|
+
'@': path.resolve(__dirname, './src'),
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**TypeScript (tsconfig.json):**
|
|
195
|
+
|
|
196
|
+
```json
|
|
197
|
+
{
|
|
198
|
+
"compilerOptions": {
|
|
199
|
+
"paths": {
|
|
200
|
+
"@/*": ["./src/*"]
|
|
201
|
+
}
|
|
202
|
+
}
|
|
104
203
|
}
|
|
105
204
|
```
|
|
106
205
|
|
|
107
|
-
|
|
206
|
+
### Pro token authentication fails
|
|
207
|
+
|
|
208
|
+
If `npm install` fails with 401 errors:
|
|
108
209
|
|
|
109
|
-
|
|
210
|
+
1. Configure your token globally:
|
|
110
211
|
|
|
111
|
-
|
|
212
|
+
```bash
|
|
213
|
+
npm config set //npm.cloudsmith.io/fortawesome/webawesome-pro/:_authToken YOUR_TOKEN
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
2. Verify it's configured:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
npm config get //npm.cloudsmith.io/fortawesome/webawesome-pro/:_authToken
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
3. Check your token is valid at [https://webawesome.com/login](https://https://webawesome.com/login)
|
|
223
|
+
|
|
224
|
+
### Component styles not loading
|
|
225
|
+
|
|
226
|
+
Make sure you've imported the Web Awesome setup in your app entry point:
|
|
227
|
+
|
|
228
|
+
```tsx
|
|
229
|
+
import '@/lib/webawesome'; // Must be imported before components
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Need more help?
|
|
233
|
+
|
|
234
|
+
- [Web Awesome Documentation](https://webawesome.com/docs)
|
|
235
|
+
- [GitHub Issues](https://github.com/giregar/kigumi-cli/issues)
|
|
236
|
+
- Run `npx kigumi --help` for command reference
|
|
237
|
+
|
|
238
|
+
## Deploying to Vercel
|
|
239
|
+
|
|
240
|
+
The docs website (`/docs`) can be deployed to Vercel:
|
|
241
|
+
|
|
242
|
+
### Prerequisites
|
|
243
|
+
|
|
244
|
+
1. Web Awesome Pro token from [https://webawesome.com/login](https://https://webawesome.com/login)
|
|
245
|
+
2. Vercel account and project created
|
|
246
|
+
|
|
247
|
+
### Setup
|
|
248
|
+
|
|
249
|
+
1. **Import the repository** to Vercel
|
|
250
|
+
- Framework Preset: Vite
|
|
251
|
+
- Root Directory: `docs`
|
|
252
|
+
- Build Command: `pnpm build`
|
|
253
|
+
- Output Directory: `dist`
|
|
254
|
+
|
|
255
|
+
2. **Configure Environment Variables** in Vercel Dashboard:
|
|
256
|
+
- Go to Project Settings → Environment Variables
|
|
257
|
+
- Add `WEBAWESOME_NPM_TOKEN` with your Pro token
|
|
258
|
+
- Select all environments (Production, Preview, Development)
|
|
259
|
+
|
|
260
|
+
3. **Deploy**
|
|
261
|
+
- Push to `main` branch to trigger deployment
|
|
262
|
+
- Vercel will automatically build and deploy
|
|
263
|
+
|
|
264
|
+
### Local Development
|
|
112
265
|
|
|
113
266
|
```bash
|
|
114
|
-
|
|
267
|
+
cd docs
|
|
268
|
+
pnpm install
|
|
269
|
+
pnpm dev
|
|
115
270
|
```
|
|
116
271
|
|
|
117
|
-
|
|
272
|
+
The dev server will run at http://localhost:5173
|
|
118
273
|
|
|
119
|
-
|
|
120
|
-
Ensure `import '@/lib/webawesome'` is in your entry file.
|
|
274
|
+
## Resources
|
|
121
275
|
|
|
122
|
-
|
|
123
|
-
|
|
276
|
+
- [Web Awesome Documentation](https://webawesome.com/docs)
|
|
277
|
+
- [Component Gallery](https://webawesome.com/docs/components)
|
|
278
|
+
- [GitHub Repository](https://github.com/giregar/kigumi-cli)
|
|
279
|
+
- [Report Issues](https://github.com/giregar/kigumi-cli/issues)
|
|
124
280
|
|
|
125
281
|
## License
|
|
126
282
|
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var WEB_AWESOME_FREE_PACKAGE = "@awesome.me/webawesome";
|
|
3
|
+
var WEB_AWESOME_PRO_PACKAGE = "@awesome.me/webawesome-pro";
|
|
4
|
+
var WEB_AWESOME_SCOPE = "@awesome.me";
|
|
5
|
+
var ENV_TOKEN_KEY = "WEBAWESOME_NPM_TOKEN";
|
|
6
|
+
var MIN_TOKEN_LENGTH = 10;
|
|
7
|
+
var ENV_FILE_NAME = ".env";
|
|
8
|
+
var NPM_PUBLIC_REGISTRY = "https://registry.npmjs.org/";
|
|
9
|
+
var NPM_PRO_REGISTRY = "https://npm.cloudsmith.io/fortawesome/webawesome-pro";
|
|
10
|
+
var FREE_PACKAGE_REGEX = /@awesome\.me\/webawesome(?!-pro)/g;
|
|
11
|
+
var PRO_PACKAGE_REGEX = /@awesome\.me\/webawesome-pro/g;
|
|
12
|
+
var ENV_TOKEN_REGEX = /^\s*WEBAWESOME_NPM_TOKEN\s*=\s*(.+?)\s*$/m;
|
|
13
|
+
|
|
14
|
+
// src/utils/token.ts
|
|
15
|
+
import fs from "fs-extra";
|
|
16
|
+
import os from "os";
|
|
17
|
+
import path from "path";
|
|
18
|
+
async function detectProToken(cwd) {
|
|
19
|
+
const result = await detectProTokenWithSource(cwd);
|
|
20
|
+
return result.token;
|
|
21
|
+
}
|
|
22
|
+
function detectProTokenSync(cwd) {
|
|
23
|
+
const result = detectProTokenWithSourceSync(cwd);
|
|
24
|
+
return result.token;
|
|
25
|
+
}
|
|
26
|
+
function getTokenSourceSync(cwd) {
|
|
27
|
+
const result = detectProTokenWithSourceSync(cwd);
|
|
28
|
+
return result.source;
|
|
29
|
+
}
|
|
30
|
+
async function detectProTokenWithSource(cwd) {
|
|
31
|
+
const envToken = getTokenFromEnvVar();
|
|
32
|
+
if (envToken) {
|
|
33
|
+
return { token: envToken, source: "env" };
|
|
34
|
+
}
|
|
35
|
+
if (!process.env.KIGUMI_SKIP_GLOBAL_NPMRC) {
|
|
36
|
+
const npmrcToken = await getTokenFromGlobalNpmrc();
|
|
37
|
+
if (npmrcToken) {
|
|
38
|
+
return { token: npmrcToken, source: "npmrc" };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const dotenvToken = await getTokenFromDotenv(cwd);
|
|
42
|
+
if (dotenvToken) {
|
|
43
|
+
return { token: dotenvToken, source: "dotenv" };
|
|
44
|
+
}
|
|
45
|
+
return { token: null, source: null };
|
|
46
|
+
}
|
|
47
|
+
function detectProTokenWithSourceSync(cwd) {
|
|
48
|
+
const envToken = getTokenFromEnvVar();
|
|
49
|
+
if (envToken) {
|
|
50
|
+
return { token: envToken, source: "env" };
|
|
51
|
+
}
|
|
52
|
+
if (!process.env.KIGUMI_SKIP_GLOBAL_NPMRC) {
|
|
53
|
+
const npmrcToken = getTokenFromGlobalNpmrcSync();
|
|
54
|
+
if (npmrcToken) {
|
|
55
|
+
return { token: npmrcToken, source: "npmrc" };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const dotenvToken = getTokenFromDotenvSync(cwd);
|
|
59
|
+
if (dotenvToken) {
|
|
60
|
+
return { token: dotenvToken, source: "dotenv" };
|
|
61
|
+
}
|
|
62
|
+
return { token: null, source: null };
|
|
63
|
+
}
|
|
64
|
+
function getTokenFromEnvVar() {
|
|
65
|
+
const token = process.env[ENV_TOKEN_KEY];
|
|
66
|
+
if (token && token.length >= MIN_TOKEN_LENGTH) {
|
|
67
|
+
return token.trim();
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
async function getTokenFromGlobalNpmrc() {
|
|
72
|
+
const npmrcPath = path.join(os.homedir(), ".npmrc");
|
|
73
|
+
if (!await fs.pathExists(npmrcPath)) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const content = await fs.readFile(npmrcPath, "utf-8");
|
|
77
|
+
return extractTokenFromNpmrc(content);
|
|
78
|
+
}
|
|
79
|
+
function getTokenFromGlobalNpmrcSync() {
|
|
80
|
+
const npmrcPath = path.join(os.homedir(), ".npmrc");
|
|
81
|
+
if (!fs.existsSync(npmrcPath)) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const content = fs.readFileSync(npmrcPath, "utf-8");
|
|
85
|
+
return extractTokenFromNpmrc(content);
|
|
86
|
+
}
|
|
87
|
+
function extractTokenFromNpmrc(content) {
|
|
88
|
+
const registryHost = NPM_PRO_REGISTRY.replace("https://", "");
|
|
89
|
+
const patterns = [
|
|
90
|
+
new RegExp(`//${registryHost}/?:_authToken=(.+)`, "m"),
|
|
91
|
+
new RegExp(`${registryHost}/?:_authToken=(.+)`, "m")
|
|
92
|
+
];
|
|
93
|
+
for (const pattern of patterns) {
|
|
94
|
+
const match = content.match(pattern);
|
|
95
|
+
if (match && match[1]) {
|
|
96
|
+
const token = match[1].trim();
|
|
97
|
+
if (token.length >= MIN_TOKEN_LENGTH) {
|
|
98
|
+
return token;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
async function getTokenFromDotenv(cwd) {
|
|
105
|
+
const envPath = path.join(cwd, ENV_FILE_NAME);
|
|
106
|
+
if (!await fs.pathExists(envPath)) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
const content = await fs.readFile(envPath, "utf-8");
|
|
110
|
+
return extractTokenFromDotenv(content);
|
|
111
|
+
}
|
|
112
|
+
function getTokenFromDotenvSync(cwd) {
|
|
113
|
+
const envPath = path.join(cwd, ENV_FILE_NAME);
|
|
114
|
+
if (!fs.existsSync(envPath)) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
const content = fs.readFileSync(envPath, "utf-8");
|
|
118
|
+
return extractTokenFromDotenv(content);
|
|
119
|
+
}
|
|
120
|
+
function extractTokenFromDotenv(content) {
|
|
121
|
+
const match = content.match(ENV_TOKEN_REGEX);
|
|
122
|
+
if (match && match[1]) {
|
|
123
|
+
const token = match[1].trim();
|
|
124
|
+
if (token.length >= MIN_TOKEN_LENGTH) {
|
|
125
|
+
return token;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
function describeTokenSource(source) {
|
|
131
|
+
switch (source) {
|
|
132
|
+
case "env":
|
|
133
|
+
return `environment variable ($${ENV_TOKEN_KEY})`;
|
|
134
|
+
case "npmrc":
|
|
135
|
+
return "global ~/.npmrc";
|
|
136
|
+
case "dotenv":
|
|
137
|
+
return "project .env file";
|
|
138
|
+
default:
|
|
139
|
+
return "unknown";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/utils/tier.ts
|
|
144
|
+
async function detectTier(cwd) {
|
|
145
|
+
const token = await detectProToken(cwd);
|
|
146
|
+
return token ? "pro" : "free";
|
|
147
|
+
}
|
|
148
|
+
function detectTierSync(cwd) {
|
|
149
|
+
const token = detectProTokenSync(cwd);
|
|
150
|
+
return token ? "pro" : "free";
|
|
151
|
+
}
|
|
152
|
+
async function getProToken(cwd) {
|
|
153
|
+
return detectProToken(cwd);
|
|
154
|
+
}
|
|
155
|
+
function getWebAwesomePackage(tier) {
|
|
156
|
+
return tier === "pro" ? WEB_AWESOME_PRO_PACKAGE : WEB_AWESOME_FREE_PACKAGE;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export {
|
|
160
|
+
WEB_AWESOME_FREE_PACKAGE,
|
|
161
|
+
WEB_AWESOME_PRO_PACKAGE,
|
|
162
|
+
WEB_AWESOME_SCOPE,
|
|
163
|
+
ENV_TOKEN_KEY,
|
|
164
|
+
MIN_TOKEN_LENGTH,
|
|
165
|
+
ENV_FILE_NAME,
|
|
166
|
+
NPM_PUBLIC_REGISTRY,
|
|
167
|
+
NPM_PRO_REGISTRY,
|
|
168
|
+
FREE_PACKAGE_REGEX,
|
|
169
|
+
PRO_PACKAGE_REGEX,
|
|
170
|
+
ENV_TOKEN_REGEX,
|
|
171
|
+
detectProTokenSync,
|
|
172
|
+
getTokenSourceSync,
|
|
173
|
+
describeTokenSource,
|
|
174
|
+
detectTier,
|
|
175
|
+
detectTierSync,
|
|
176
|
+
getProToken,
|
|
177
|
+
getWebAwesomePackage
|
|
178
|
+
};
|