dcntui 0.1.9 → 0.1.11
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/dist/commands/add.d.ts +1 -1
- package/dist/commands/add.d.ts.map +1 -1
- package/dist/commands/add.js +24 -95
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +30 -7
- package/dist/commands/init.js.map +1 -1
- package/dist/constants.d.ts +1 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -2
- package/dist/constants.js.map +1 -1
- package/dist/index.js +9 -24
- package/dist/index.js.map +1 -1
- package/dist/utils/banner.d.ts.map +1 -1
- package/dist/utils/banner.js +7 -10
- package/dist/utils/banner.js.map +1 -1
- package/dist/utils/config.d.ts +0 -4
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +22 -21
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/detect-css.d.ts +2 -3
- package/dist/utils/detect-css.d.ts.map +1 -1
- package/dist/utils/detect-css.js +5 -114
- package/dist/utils/detect-css.js.map +1 -1
- package/dist/utils/detect-framework.d.ts.map +1 -1
- package/dist/utils/detect-framework.js +2 -9
- package/dist/utils/detect-framework.js.map +1 -1
- package/dist/utils/detect-package-manager.d.ts.map +1 -1
- package/dist/utils/detect-package-manager.js +15 -25
- package/dist/utils/detect-package-manager.js.map +1 -1
- package/dist/utils/detect-typescript.d.ts.map +1 -1
- package/dist/utils/detect-typescript.js +1 -7
- package/dist/utils/detect-typescript.js.map +1 -1
- package/dist/utils/helpers.d.ts +5 -3
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +3 -3
- package/dist/utils/helpers.js.map +1 -1
- package/dist/utils/registry.d.ts +3 -35
- package/dist/utils/registry.d.ts.map +1 -1
- package/dist/utils/registry.js +58 -120
- package/dist/utils/registry.js.map +1 -1
- package/dist/utils/wizard.d.ts +0 -1
- package/dist/utils/wizard.d.ts.map +1 -1
- package/dist/utils/wizard.js +73 -135
- package/dist/utils/wizard.js.map +1 -1
- package/dist/utils/write-component.d.ts +0 -9
- package/dist/utils/write-component.d.ts.map +1 -1
- package/dist/utils/write-component.js +2 -121
- package/dist/utils/write-component.js.map +1 -1
- package/package.json +8 -7
- package/dist/commands/config.d.ts +0 -2
- package/dist/commands/config.d.ts.map +0 -1
- package/dist/commands/config.js +0 -68
- package/dist/commands/config.js.map +0 -1
- package/dist/commands/doctor.d.ts +0 -2
- package/dist/commands/doctor.d.ts.map +0 -1
- package/dist/commands/doctor.js +0 -348
- package/dist/commands/doctor.js.map +0 -1
- package/dist/commands/list.d.ts +0 -6
- package/dist/commands/list.d.ts.map +0 -1
- package/dist/commands/list.js +0 -104
- package/dist/commands/list.js.map +0 -1
- package/dist/commands/remove.d.ts +0 -2
- package/dist/commands/remove.d.ts.map +0 -1
- package/dist/commands/remove.js +0 -87
- package/dist/commands/remove.js.map +0 -1
- package/dist/commands/search.d.ts +0 -2
- package/dist/commands/search.d.ts.map +0 -1
- package/dist/commands/search.js +0 -124
- package/dist/commands/search.js.map +0 -1
- package/dist/commands/update.d.ts +0 -6
- package/dist/commands/update.d.ts.map +0 -1
- package/dist/commands/update.js +0 -247
- package/dist/commands/update.js.map +0 -1
- package/dist/utils/lock.d.ts +0 -6
- package/dist/utils/lock.d.ts.map +0 -1
- package/dist/utils/lock.js +0 -30
- package/dist/utils/lock.js.map +0 -1
- package/dist/utils/search.d.ts +0 -21
- package/dist/utils/search.d.ts.map +0 -1
- package/dist/utils/search.js +0 -104
- package/dist/utils/search.js.map +0 -1
package/dist/utils/detect-css.js
CHANGED
|
@@ -1,126 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { fileExists, hasDep, readPackageJson } from './helpers.js';
|
|
1
|
+
import { hasDep, readPackageJson } from './helpers.js';
|
|
5
2
|
export const CSS_OPTIONS = [
|
|
6
|
-
{ value: 'tailwind
|
|
7
|
-
{ value: 'tailwind-v3', label: 'Tailwind CSS v3' },
|
|
3
|
+
{ value: 'tailwind', label: 'Tailwind CSS' },
|
|
8
4
|
{ value: 'scss', label: 'SASS / SCSS' },
|
|
9
5
|
{ value: 'css', label: 'Plain CSS' }
|
|
10
6
|
];
|
|
11
|
-
const IGNORE = ['**/node_modules/**', '**/.git/**', '**/dist/**', '**/.next/**', '**/.svelte-kit/**', '**/build/**'];
|
|
12
|
-
function hasTailwindV4Import(cwd) {
|
|
13
|
-
const cssFiles = fg.sync('**/*.css', { cwd, ignore: IGNORE, deep: 4, absolute: true });
|
|
14
|
-
const pattern = /@import\s+['"]tailwindcss['"]/;
|
|
15
|
-
for (const file of cssFiles) {
|
|
16
|
-
try {
|
|
17
|
-
if (pattern.test(fs.readFileSync(file, 'utf-8')))
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
catch { }
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
function hasScssFiles(cwd) {
|
|
25
|
-
return fg.sync('**/*.scss', { cwd, ignore: IGNORE, deep: 4 }).length > 0;
|
|
26
|
-
}
|
|
27
|
-
function tailwindMajorVersion(pkg) {
|
|
28
|
-
const deps = {
|
|
29
|
-
...pkg['dependencies'],
|
|
30
|
-
...pkg['devDependencies']
|
|
31
|
-
};
|
|
32
|
-
const raw = deps['tailwindcss'];
|
|
33
|
-
if (!raw)
|
|
34
|
-
return null;
|
|
35
|
-
const match = raw.match(/(\d+)\./);
|
|
36
|
-
return match ? parseInt(match[1], 10) : null;
|
|
37
|
-
}
|
|
38
|
-
const BASE_STYLE_CANDIDATES = [
|
|
39
|
-
'src/app/globals.css',
|
|
40
|
-
'app/globals.css',
|
|
41
|
-
'src/styles/globals.css',
|
|
42
|
-
'styles/globals.css',
|
|
43
|
-
'src/index.css',
|
|
44
|
-
'src/main.css',
|
|
45
|
-
'src/styles.css',
|
|
46
|
-
'src/styles/index.css',
|
|
47
|
-
'src/app.css',
|
|
48
|
-
'index.css'
|
|
49
|
-
];
|
|
50
|
-
const BASE_STYLE_CANDIDATES_SCSS = [
|
|
51
|
-
'src/app/globals.scss',
|
|
52
|
-
'app/globals.scss',
|
|
53
|
-
'src/styles/globals.scss',
|
|
54
|
-
'styles/globals.scss',
|
|
55
|
-
'src/index.scss',
|
|
56
|
-
'src/main.scss',
|
|
57
|
-
'src/styles.scss',
|
|
58
|
-
'src/styles/globals.scss',
|
|
59
|
-
'src/styles/index.scss',
|
|
60
|
-
'src/styles/main.scss',
|
|
61
|
-
'src/app.scss',
|
|
62
|
-
'src/lib/styles.scss',
|
|
63
|
-
'index.scss'
|
|
64
|
-
];
|
|
65
|
-
export function detectBaseStylesFile(cwd, css) {
|
|
66
|
-
switch (css) {
|
|
67
|
-
case 'tailwind-v4': {
|
|
68
|
-
const cssFiles = fg.sync('**/*.css', { cwd, ignore: IGNORE, deep: 4, absolute: true });
|
|
69
|
-
const pattern = /@import\s+['"]tailwindcss['"]/;
|
|
70
|
-
for (const file of cssFiles) {
|
|
71
|
-
try {
|
|
72
|
-
if (pattern.test(fs.readFileSync(file, 'utf-8'))) {
|
|
73
|
-
return path.relative(cwd, file);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch { }
|
|
77
|
-
}
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
case 'tailwind-v3':
|
|
81
|
-
case 'css': {
|
|
82
|
-
for (const candidate of BASE_STYLE_CANDIDATES) {
|
|
83
|
-
if (fs.existsSync(path.join(cwd, candidate)))
|
|
84
|
-
return candidate;
|
|
85
|
-
}
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
case 'scss': {
|
|
89
|
-
for (const candidate of BASE_STYLE_CANDIDATES_SCSS) {
|
|
90
|
-
if (fs.existsSync(path.join(cwd, candidate)))
|
|
91
|
-
return candidate;
|
|
92
|
-
}
|
|
93
|
-
const found = fg.sync('**/*.scss', { cwd, ignore: IGNORE, deep: 4 });
|
|
94
|
-
return found[0] ? path.normalize(found[0]) : null;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
7
|
export function detectCss(cwd) {
|
|
99
|
-
const pkg = readPackageJson(cwd);
|
|
100
|
-
if (
|
|
101
|
-
return
|
|
102
|
-
const hasConfigJs = fileExists(cwd, 'tailwind.config.js');
|
|
103
|
-
const hasConfigTs = fileExists(cwd, 'tailwind.config.ts');
|
|
104
|
-
const hasTailwindConfig = hasConfigJs || hasConfigTs;
|
|
105
|
-
if (!hasTailwindConfig && hasTailwindV4Import(cwd)) {
|
|
106
|
-
return 'tailwind-v4';
|
|
107
|
-
}
|
|
108
|
-
const twMajor = tailwindMajorVersion(pkg);
|
|
109
|
-
if (!hasTailwindConfig && twMajor !== null && twMajor >= 4) {
|
|
110
|
-
return 'tailwind-v4';
|
|
111
|
-
}
|
|
112
|
-
if (hasTailwindConfig) {
|
|
113
|
-
return 'tailwind-v3';
|
|
114
|
-
}
|
|
115
|
-
if (twMajor !== null && twMajor === 3) {
|
|
116
|
-
return 'tailwind-v3';
|
|
8
|
+
const pkg = readPackageJson(cwd) ?? {};
|
|
9
|
+
if (hasDep(pkg, 'tailwindcss')) {
|
|
10
|
+
return 'tailwind';
|
|
117
11
|
}
|
|
118
12
|
if (hasDep(pkg, 'sass') || hasDep(pkg, 'sass-embedded')) {
|
|
119
13
|
return 'scss';
|
|
120
14
|
}
|
|
121
|
-
if (hasScssFiles(cwd)) {
|
|
122
|
-
return 'scss';
|
|
123
|
-
}
|
|
124
15
|
return 'css';
|
|
125
16
|
}
|
|
126
17
|
//# sourceMappingURL=detect-css.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect-css.js","sourceRoot":"","sources":["../../src/utils/detect-css.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"detect-css.js","sourceRoot":"","sources":["../../src/utils/detect-css.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AASvD,MAAM,CAAC,MAAM,WAAW,GAAgB;IACtC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,cAAc,EAAE;IAC5C,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE;IACvC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE;CACrC,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,MAAM,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAEvC,IAAI,MAAM,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE,CAAC;QAC/B,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,eAAe,CAAC,EAAE,CAAC;QACxD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect-framework.d.ts","sourceRoot":"","sources":["../../src/utils/detect-framework.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,YAAY,GAAG,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAE/F,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,iBAAiB,EAAE,eAAe,EAO9C,CAAC;AAEF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"detect-framework.d.ts","sourceRoot":"","sources":["../../src/utils/detect-framework.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,YAAY,GAAG,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAE/F,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,iBAAiB,EAAE,eAAe,EAO9C,CAAC;AAEF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAkBtD"}
|
|
@@ -16,15 +16,8 @@ export function detectFramework(cwd) {
|
|
|
16
16
|
if (hasDep(pkg, 'svelte'))
|
|
17
17
|
return 'svelte';
|
|
18
18
|
if (hasDep(pkg, 'next')) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
if (hasAppDir && !hasPagesDir)
|
|
22
|
-
return 'next-app';
|
|
23
|
-
if (hasPagesDir && !hasAppDir)
|
|
24
|
-
return 'next-pages';
|
|
25
|
-
if (hasAppDir && hasPagesDir)
|
|
26
|
-
return 'next-app';
|
|
27
|
-
return 'next-app';
|
|
19
|
+
const hasPagesOnly = (dirExists(cwd, 'pages') || dirExists(cwd, 'src/pages')) && !dirExists(cwd, 'app') && !dirExists(cwd, 'src/app');
|
|
20
|
+
return hasPagesOnly ? 'next-pages' : 'next-app';
|
|
28
21
|
}
|
|
29
22
|
if (hasDep(pkg, 'react'))
|
|
30
23
|
return 'react';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect-framework.js","sourceRoot":"","sources":["../../src/utils/detect-framework.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAUlE,MAAM,CAAC,MAAM,iBAAiB,GAAsB;IAClD,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,oBAAoB,EAAE;IAClD,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,sBAAsB,EAAE;IACtD,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE;IAC3C,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;IACpC,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;IAClC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,EAAE;CAC7D,CAAC;AAEF,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,MAAM,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,CAAC,GAAG;QAAE,OAAO,MAAM,CAAC;IAExB,IAAI,MAAM,CAAC,GAAG,EAAE,eAAe,CAAC;QAAE,OAAO,YAAY,CAAC;IAEtD,IAAI,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAE3C,IAAI,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC;QACxB,MAAM,
|
|
1
|
+
{"version":3,"file":"detect-framework.js","sourceRoot":"","sources":["../../src/utils/detect-framework.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAUlE,MAAM,CAAC,MAAM,iBAAiB,GAAsB;IAClD,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,oBAAoB,EAAE;IAClD,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,sBAAsB,EAAE;IACtD,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE;IAC3C,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;IACpC,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;IAClC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,EAAE;CAC7D,CAAC;AAEF,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,MAAM,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,CAAC,GAAG;QAAE,OAAO,MAAM,CAAC;IAExB,IAAI,MAAM,CAAC,GAAG,EAAE,eAAe,CAAC;QAAE,OAAO,YAAY,CAAC;IAEtD,IAAI,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAE3C,IAAI,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC;QACxB,MAAM,YAAY,GAChB,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,SAAS,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAEnH,OAAO,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC;IAClD,CAAC;IAED,IAAI,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IAEzC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect-package-manager.d.ts","sourceRoot":"","sources":["../../src/utils/detect-package-manager.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"detect-package-manager.d.ts","sourceRoot":"","sources":["../../src/utils/detect-package-manager.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAuB7D,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAEhE;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,cAAc,GAAG,MAAM,CAE3D;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAEjF"}
|
|
@@ -6,35 +6,25 @@ const LOCKFILES = [
|
|
|
6
6
|
{ file: 'bun.lockb', pm: 'bun' },
|
|
7
7
|
{ file: 'package-lock.json', pm: 'npm' }
|
|
8
8
|
];
|
|
9
|
+
const PACKAGE_RUNNERS = {
|
|
10
|
+
bun: 'bunx',
|
|
11
|
+
pnpm: 'pnpm dlx',
|
|
12
|
+
yarn: 'yarn dlx',
|
|
13
|
+
npm: 'npx'
|
|
14
|
+
};
|
|
15
|
+
const INSTALL_COMMANDS = {
|
|
16
|
+
pnpm: 'pnpm add',
|
|
17
|
+
yarn: 'yarn add',
|
|
18
|
+
bun: 'bun add',
|
|
19
|
+
npm: 'npm install'
|
|
20
|
+
};
|
|
9
21
|
export function detectPackageManager(cwd) {
|
|
10
|
-
|
|
11
|
-
if (fs.existsSync(path.join(cwd, file)))
|
|
12
|
-
return pm;
|
|
13
|
-
}
|
|
14
|
-
return 'npm';
|
|
22
|
+
return LOCKFILES.find(({ file }) => fs.existsSync(path.join(cwd, file)))?.pm ?? 'npm';
|
|
15
23
|
}
|
|
16
24
|
export function getPackageRunner(pm) {
|
|
17
|
-
|
|
18
|
-
case 'bun':
|
|
19
|
-
return 'bunx';
|
|
20
|
-
case 'pnpm':
|
|
21
|
-
return 'pnpm dlx';
|
|
22
|
-
case 'yarn':
|
|
23
|
-
return 'yarn dlx';
|
|
24
|
-
default:
|
|
25
|
-
return 'npx';
|
|
26
|
-
}
|
|
25
|
+
return PACKAGE_RUNNERS[pm];
|
|
27
26
|
}
|
|
28
27
|
export function buildInstallArgs(pm, packages) {
|
|
29
|
-
|
|
30
|
-
case 'pnpm':
|
|
31
|
-
return ['pnpm', 'add', ...packages];
|
|
32
|
-
case 'yarn':
|
|
33
|
-
return ['yarn', 'add', ...packages];
|
|
34
|
-
case 'bun':
|
|
35
|
-
return ['bun', 'add', ...packages];
|
|
36
|
-
case 'npm':
|
|
37
|
-
return ['npm', 'install', ...packages];
|
|
38
|
-
}
|
|
28
|
+
return [...INSTALL_COMMANDS[pm].split(' '), ...packages];
|
|
39
29
|
}
|
|
40
30
|
//# sourceMappingURL=detect-package-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect-package-manager.js","sourceRoot":"","sources":["../../src/utils/detect-package-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,MAAM,SAAS,GAAgD;IAC7D,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,EAAE;IACtC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE;IACjC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,KAAK,EAAE;IAChC,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,EAAE,KAAK,EAAE;CACzC,CAAC;AAEF,MAAM,
|
|
1
|
+
{"version":3,"file":"detect-package-manager.js","sourceRoot":"","sources":["../../src/utils/detect-package-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,MAAM,SAAS,GAAgD;IAC7D,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,EAAE;IACtC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE;IACjC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,KAAK,EAAE;IAChC,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,EAAE,KAAK,EAAE;CACzC,CAAC;AAEF,MAAM,eAAe,GAAmC;IACtD,GAAG,EAAE,MAAM;IACX,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IAChB,GAAG,EAAE,KAAK;CACX,CAAC;AAEF,MAAM,gBAAgB,GAAmC;IACvD,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IAChB,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,aAAa;CACnB,CAAC;AAEF,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC9C,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,KAAK,CAAC;AACxF,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAkB;IACjD,OAAO,eAAe,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAkB,EAAE,QAAkB;IACrE,OAAO,CAAC,GAAG,gBAAgB,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect-typescript.d.ts","sourceRoot":"","sources":["../../src/utils/detect-typescript.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"detect-typescript.d.ts","sourceRoot":"","sources":["../../src/utils/detect-typescript.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAGrD"}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
1
|
import { hasDep, readPackageJson } from './helpers.js';
|
|
4
2
|
export function detectTypeScript(cwd) {
|
|
5
|
-
if (fs.existsSync(path.join(cwd, 'tsconfig.json')))
|
|
6
|
-
return true;
|
|
7
3
|
const pkg = readPackageJson(cwd);
|
|
8
|
-
|
|
9
|
-
return true;
|
|
10
|
-
return false;
|
|
4
|
+
return pkg !== null && hasDep(pkg, 'typescript');
|
|
11
5
|
}
|
|
12
6
|
//# sourceMappingURL=detect-typescript.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect-typescript.js","sourceRoot":"","sources":["../../src/utils/detect-typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"detect-typescript.js","sourceRoot":"","sources":["../../src/utils/detect-typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,MAAM,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,GAAG,KAAK,IAAI,IAAI,MAAM,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;AACnD,CAAC"}
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
1
|
+
type PackageJson = Record<string, unknown>;
|
|
2
|
+
export declare function isProjectRoot(cwd: string): boolean;
|
|
3
|
+
export declare function readPackageJson(cwd: string): PackageJson | null;
|
|
4
|
+
export declare function hasDep(pkg: PackageJson, name: string): boolean;
|
|
4
5
|
export declare function dirExists(cwd: string, dir: string): boolean;
|
|
6
|
+
export {};
|
|
5
7
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAGA,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAGA,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAG3C,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAM/D;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAI9D;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3D"}
|
package/dist/utils/helpers.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
export function isProjectRoot(cwd) {
|
|
4
|
+
return fs.existsSync(path.join(cwd, 'package.json'));
|
|
5
|
+
}
|
|
3
6
|
export function readPackageJson(cwd) {
|
|
4
7
|
try {
|
|
5
8
|
return JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf-8'));
|
|
@@ -13,9 +16,6 @@ export function hasDep(pkg, name) {
|
|
|
13
16
|
const dev = (pkg['devDependencies'] ?? {});
|
|
14
17
|
return name in deps || name in dev;
|
|
15
18
|
}
|
|
16
|
-
export function fileExists(cwd, ...segments) {
|
|
17
|
-
return fs.existsSync(path.join(cwd, ...segments));
|
|
18
|
-
}
|
|
19
19
|
export function dirExists(cwd, dir) {
|
|
20
20
|
return fs.existsSync(path.join(cwd, dir));
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAK7B,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,CAAgB,CAAC;IAC7F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,GAAgB,EAAE,IAAY;IACnD,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAe,CAAC;IACvD,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAe,CAAC;IACzD,OAAO,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,GAAG,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,GAAW;IAChD,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAC5C,CAAC"}
|
package/dist/utils/registry.d.ts
CHANGED
|
@@ -3,12 +3,7 @@ export interface ComponentFile {
|
|
|
3
3
|
path: string;
|
|
4
4
|
content: string;
|
|
5
5
|
}
|
|
6
|
-
export interface TailwindPatch {
|
|
7
|
-
v4?: string;
|
|
8
|
-
v3?: string;
|
|
9
|
-
}
|
|
10
6
|
export interface ComponentMetadata {
|
|
11
|
-
type?: 'component';
|
|
12
7
|
name: string;
|
|
13
8
|
version: string;
|
|
14
9
|
framework: string;
|
|
@@ -17,41 +12,14 @@ export interface ComponentMetadata {
|
|
|
17
12
|
premium: boolean;
|
|
18
13
|
dependencies: string[];
|
|
19
14
|
files: ComponentFile[];
|
|
20
|
-
tailwind: TailwindPatch;
|
|
21
15
|
postInstall: string[];
|
|
22
16
|
}
|
|
23
|
-
export interface CollectionMetadata {
|
|
24
|
-
type: 'collection';
|
|
25
|
-
name: string;
|
|
26
|
-
version: string;
|
|
27
|
-
description: string;
|
|
28
|
-
premium: boolean;
|
|
29
|
-
components: string[];
|
|
30
|
-
postInstall: string[];
|
|
31
|
-
}
|
|
32
|
-
export type AnyMetadata = ComponentMetadata | CollectionMetadata;
|
|
33
|
-
export declare function isCollection(meta: AnyMetadata): meta is CollectionMetadata;
|
|
34
|
-
export declare function resolveVariantSlug(config: DCNTUIConfig): string;
|
|
35
|
-
export declare function resolveRegistryUrl(config: DCNTUIConfig, componentName: string): string;
|
|
36
|
-
export declare function resolveCollectionUrl(config: DCNTUIConfig, collectionName: string): string;
|
|
37
|
-
export declare function fetchAny(config: DCNTUIConfig, name: string, token?: string): Promise<AnyMetadata>;
|
|
38
17
|
export declare class RegistryError extends Error {
|
|
39
18
|
readonly statusCode?: number | undefined;
|
|
40
19
|
constructor(message: string, statusCode?: number | undefined);
|
|
41
20
|
}
|
|
42
|
-
export declare function
|
|
21
|
+
export declare function resolveVariantSlug(config: DCNTUIConfig): string;
|
|
22
|
+
export declare function resolveComponentUrl(config: DCNTUIConfig, name: string): string;
|
|
23
|
+
export declare function fetchComponent(config: DCNTUIConfig, name: string, token?: string): Promise<ComponentMetadata>;
|
|
43
24
|
export declare function verifyPremiumToken(registry: string, token: string): Promise<boolean>;
|
|
44
|
-
export interface CatalogEntry {
|
|
45
|
-
name: string;
|
|
46
|
-
description: string;
|
|
47
|
-
premium: boolean;
|
|
48
|
-
}
|
|
49
|
-
export interface CatalogCategory {
|
|
50
|
-
name: string;
|
|
51
|
-
components: CatalogEntry[];
|
|
52
|
-
}
|
|
53
|
-
export interface Catalog {
|
|
54
|
-
categories: CatalogCategory[];
|
|
55
|
-
}
|
|
56
|
-
export declare function fetchCatalog(registry: string): Promise<Catalog>;
|
|
57
25
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/utils/registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/utils/registry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAuBhD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,qBAAa,aAAc,SAAQ,KAAK;aAGpB,UAAU,CAAC,EAAE,MAAM;gBADnC,OAAO,EAAE,MAAM,EACC,UAAU,CAAC,EAAE,MAAM,YAAA;CAKtC;AA4CD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAG/D;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9E;AAED,wBAAsB,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAiBnH;AAED,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAY1F"}
|
package/dist/utils/registry.js
CHANGED
|
@@ -1,130 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createHmac } from 'node:crypto';
|
|
2
|
+
import { REGISTRY_BASE } from '../constants.js';
|
|
3
|
+
const SIGNATURE_HEADER = 'x-dcntui-signature';
|
|
4
|
+
const TIMESTAMP_HEADER = 'x-dcntui-timestamp';
|
|
5
|
+
const BASE = REGISTRY_BASE.replace(/\/$/, '');
|
|
6
|
+
function signRequest(secret, method, path, timestamp) {
|
|
7
|
+
return createHmac('sha256', secret).update(`${timestamp}:${method.toUpperCase()}:${path}`).digest('hex');
|
|
3
8
|
}
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
function signingHeaders(method, url) {
|
|
10
|
+
const secret = process.env['DCNTUI_SIGNING_SECRET'];
|
|
11
|
+
if (!secret)
|
|
12
|
+
return {};
|
|
13
|
+
const { pathname, search } = new URL(url);
|
|
14
|
+
const timestamp = Date.now().toString();
|
|
15
|
+
return {
|
|
16
|
+
[SIGNATURE_HEADER]: signRequest(secret, method, pathname + search, timestamp),
|
|
17
|
+
[TIMESTAMP_HEADER]: timestamp
|
|
18
|
+
};
|
|
12
19
|
}
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
export class RegistryError extends Error {
|
|
21
|
+
statusCode;
|
|
22
|
+
constructor(message, statusCode) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.statusCode = statusCode;
|
|
25
|
+
this.name = 'RegistryError';
|
|
26
|
+
}
|
|
17
27
|
}
|
|
18
|
-
|
|
19
|
-
const componentUrl = resolveRegistryUrl(config, name);
|
|
20
|
-
const collectionUrl = resolveCollectionUrl(config, name);
|
|
28
|
+
function buildHeaders(method, url, token) {
|
|
21
29
|
const headers = {
|
|
22
30
|
Accept: 'application/json',
|
|
23
|
-
'User-Agent': 'dcntui-cli'
|
|
31
|
+
'User-Agent': 'dcntui-cli',
|
|
32
|
+
...signingHeaders(method, url)
|
|
24
33
|
};
|
|
25
34
|
if (token)
|
|
26
35
|
headers['Authorization'] = `Bearer ${token}`;
|
|
36
|
+
return headers;
|
|
37
|
+
}
|
|
38
|
+
async function fetchJson(url, options) {
|
|
27
39
|
let res;
|
|
28
40
|
try {
|
|
29
|
-
res = await fetch(
|
|
41
|
+
res = await fetch(url, options);
|
|
30
42
|
}
|
|
31
43
|
catch {
|
|
32
|
-
throw new RegistryError(`Could not reach the DCNT UI registry.\n\nCheck your internet connection.\nRegistry: ${
|
|
33
|
-
}
|
|
34
|
-
if (res.ok) {
|
|
35
|
-
try {
|
|
36
|
-
return (await res.json());
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
throw new RegistryError(`Registry response could not be parsed as JSON.\nURL: ${componentUrl}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (res.status === 404) {
|
|
43
|
-
let colRes;
|
|
44
|
-
try {
|
|
45
|
-
colRes = await fetch(collectionUrl, { headers });
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
throw new RegistryError(`Could not reach the DCNT UI registry.\n\nCheck your internet connection.\nRegistry: ${collectionUrl}`);
|
|
49
|
-
}
|
|
50
|
-
if (colRes.ok) {
|
|
51
|
-
try {
|
|
52
|
-
return (await colRes.json());
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
throw new RegistryError(`Registry response could not be parsed as JSON.\nURL: ${collectionUrl}`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (colRes.status === 404) {
|
|
59
|
-
throw new RegistryError(`"${name}" was not found as a component or collection.\n\n` +
|
|
60
|
-
`Run ${`npx dcntui list`} to browse available components and collections.`, 404);
|
|
61
|
-
}
|
|
62
|
-
if (colRes.status === 401 || colRes.status === 403) {
|
|
63
|
-
throw new RegistryError(`Access denied. "${name}" requires a valid premium token.\n` +
|
|
64
|
-
`Set DCNTUI_TOKEN or add premiumToken to dcntui.config.json.`, colRes.status);
|
|
65
|
-
}
|
|
66
|
-
throw new RegistryError(`Registry returned an unexpected error (HTTP ${colRes.status}).`, colRes.status);
|
|
44
|
+
throw new RegistryError(`Could not reach the DCNT UI registry.\n\nCheck your internet connection.\nRegistry: ${url}`);
|
|
67
45
|
}
|
|
68
46
|
if (res.status === 401 || res.status === 403) {
|
|
69
|
-
throw new RegistryError(`Access denied.
|
|
70
|
-
`Set DCNTUI_TOKEN
|
|
47
|
+
throw new RegistryError(`Access denied. This component requires a valid premium token.\n` +
|
|
48
|
+
`Set DCNTUI_TOKEN in your environment variables.`, res.status);
|
|
71
49
|
}
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
export class RegistryError extends Error {
|
|
75
|
-
constructor(message, statusCode) {
|
|
76
|
-
super(message);
|
|
77
|
-
this.statusCode = statusCode;
|
|
78
|
-
this.name = 'RegistryError';
|
|
50
|
+
if (!res.ok) {
|
|
51
|
+
throw new RegistryError(`Registry returned an unexpected error (HTTP ${res.status}).`, res.status);
|
|
79
52
|
}
|
|
80
|
-
}
|
|
81
|
-
export async function fetchComponent(url, token) {
|
|
82
|
-
const headers = {
|
|
83
|
-
Accept: 'application/json',
|
|
84
|
-
'User-Agent': 'dcntui-cli'
|
|
85
|
-
};
|
|
86
|
-
if (token) {
|
|
87
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
88
|
-
}
|
|
89
|
-
let response;
|
|
90
53
|
try {
|
|
91
|
-
|
|
54
|
+
return (await res.json());
|
|
92
55
|
}
|
|
93
56
|
catch {
|
|
94
|
-
throw new RegistryError(`
|
|
95
|
-
`Check your internet connection or try again later.\n` +
|
|
96
|
-
`Registry: ${url}`);
|
|
57
|
+
throw new RegistryError(`Registry response could not be parsed as JSON.\nURL: ${url}`);
|
|
97
58
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
59
|
+
}
|
|
60
|
+
export function resolveVariantSlug(config) {
|
|
61
|
+
const lang = config.typescript ? 'ts' : 'js';
|
|
62
|
+
return `${config.framework}-${config.css}-${lang}`;
|
|
63
|
+
}
|
|
64
|
+
export function resolveComponentUrl(config, name) {
|
|
65
|
+
return `${BASE}/components/${name}/${resolveVariantSlug(config)}.json`;
|
|
66
|
+
}
|
|
67
|
+
export async function fetchComponent(config, name, token) {
|
|
68
|
+
const url = resolveComponentUrl(config, name);
|
|
69
|
+
try {
|
|
70
|
+
return await fetchJson(url, { headers: buildHeaders('GET', url, token) });
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
if (err instanceof RegistryError && err.statusCode === 404) {
|
|
74
|
+
throw new RegistryError(`Component "${name}" was not found in the registry.\n\n` +
|
|
101
75
|
`URL: ${url}\n\n` +
|
|
102
76
|
`This may mean the component doesn't support your current\n` +
|
|
103
77
|
`framework / CSS / language combination yet.`, 404);
|
|
104
78
|
}
|
|
105
|
-
|
|
106
|
-
throw new RegistryError(`Access denied by the registry.\n\n` +
|
|
107
|
-
`This component requires a valid premium token.\n` +
|
|
108
|
-
`Set DCNTUI_TOKEN in your environment or add premiumToken to dcntui.config.json.`, response.status);
|
|
109
|
-
}
|
|
110
|
-
throw new RegistryError(`Registry returned an unexpected error (HTTP ${response.status}).`, response.status);
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
return (await response.json());
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
throw new RegistryError(`Registry response could not be parsed as JSON.\nURL: ${url}`);
|
|
79
|
+
throw err;
|
|
117
80
|
}
|
|
118
81
|
}
|
|
119
82
|
export async function verifyPremiumToken(registry, token) {
|
|
120
|
-
const
|
|
83
|
+
const url = `${registry.replace(/\/$/, '')}/api/verify-token`;
|
|
121
84
|
try {
|
|
122
|
-
const res = await fetch(
|
|
85
|
+
const res = await fetch(url, {
|
|
123
86
|
method: 'POST',
|
|
124
|
-
headers: {
|
|
125
|
-
'Content-Type': 'application/json',
|
|
126
|
-
'User-Agent': 'dcntui-cli'
|
|
127
|
-
},
|
|
87
|
+
headers: { 'Content-Type': 'application/json', ...buildHeaders('POST', url) },
|
|
128
88
|
body: JSON.stringify({ token })
|
|
129
89
|
});
|
|
130
90
|
return res.ok;
|
|
@@ -133,26 +93,4 @@ export async function verifyPremiumToken(registry, token) {
|
|
|
133
93
|
return false;
|
|
134
94
|
}
|
|
135
95
|
}
|
|
136
|
-
export async function fetchCatalog(registry) {
|
|
137
|
-
const base = registry.replace(/\/$/, '');
|
|
138
|
-
const url = `${base}/catalog.json`;
|
|
139
|
-
let response;
|
|
140
|
-
try {
|
|
141
|
-
response = await fetch(url, {
|
|
142
|
-
headers: { Accept: 'application/json', 'User-Agent': 'dcntui-cli' }
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
catch {
|
|
146
|
-
throw new RegistryError(`Could not reach the DCNT UI registry.\n\nCheck your internet connection or try again later.\nRegistry: ${url}`);
|
|
147
|
-
}
|
|
148
|
-
if (!response.ok) {
|
|
149
|
-
throw new RegistryError(`Registry returned an unexpected error (HTTP ${response.status}).`, response.status);
|
|
150
|
-
}
|
|
151
|
-
try {
|
|
152
|
-
return (await response.json());
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
throw new RegistryError(`Catalog response could not be parsed as JSON.\nURL: ${url}`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
96
|
//# sourceMappingURL=registry.js.map
|