zard-cli 1.0.0-beta.13 → 1.0.0-beta.130
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 +39 -167
- package/commands/add/component-installer.d.ts +5 -1
- package/commands/add/component-installer.d.ts.map +1 -1
- package/commands/add/component-installer.js +34 -5
- package/commands/add/component-installer.js.map +1 -1
- package/commands/add/component-selector.d.ts +6 -0
- package/commands/add/component-selector.d.ts.map +1 -1
- package/commands/add/component-selector.js +9 -27
- package/commands/add/component-selector.js.map +1 -1
- package/commands/add/dark-mode-setup.d.ts +2 -0
- package/commands/add/dark-mode-setup.d.ts.map +1 -1
- package/commands/add/dark-mode-setup.js +5 -11
- package/commands/add/dark-mode-setup.js.map +1 -1
- package/commands/add/dependency-resolver.d.ts +9 -2
- package/commands/add/dependency-resolver.d.ts.map +1 -1
- package/commands/add/dependency-resolver.js +91 -21
- package/commands/add/dependency-resolver.js.map +1 -1
- package/commands/add/index.d.ts.map +1 -1
- package/commands/add/index.js +140 -86
- package/commands/add/index.js.map +1 -1
- package/commands/add/stylesheet-setup.d.ts +3 -0
- package/commands/add/stylesheet-setup.d.ts.map +1 -0
- package/commands/add/stylesheet-setup.js +92 -0
- package/commands/add/stylesheet-setup.js.map +1 -0
- package/commands/add/wizard.d.ts +35 -0
- package/commands/add/wizard.d.ts.map +1 -0
- package/commands/add/wizard.js +299 -0
- package/commands/add/wizard.js.map +1 -0
- package/commands/init/config-prompter.d.ts +67 -56
- package/commands/init/config-prompter.d.ts.map +1 -1
- package/commands/init/config-prompter.js +92 -74
- package/commands/init/config-prompter.js.map +1 -1
- package/commands/init/dependencies.d.ts +1 -8
- package/commands/init/dependencies.d.ts.map +1 -1
- package/commands/init/dependencies.js +51 -23
- package/commands/init/dependencies.js.map +1 -1
- package/commands/init/index.d.ts.map +1 -1
- package/commands/init/index.js +150 -86
- package/commands/init/index.js.map +1 -1
- package/commands/init/project-kind.d.ts +82 -0
- package/commands/init/project-kind.d.ts.map +1 -0
- package/commands/init/project-kind.js +166 -0
- package/commands/init/project-kind.js.map +1 -0
- package/commands/init/steps.d.ts +15 -0
- package/commands/init/steps.d.ts.map +1 -0
- package/commands/init/steps.js +154 -0
- package/commands/init/steps.js.map +1 -0
- package/commands/init/tailwind-setup.d.ts +9 -2
- package/commands/init/tailwind-setup.d.ts.map +1 -1
- package/commands/init/tailwind-setup.js +33 -9
- package/commands/init/tailwind-setup.js.map +1 -1
- package/commands/init/theme-loader.d.ts.map +1 -1
- package/commands/init/theme-loader.js +1 -3
- package/commands/init/theme-loader.js.map +1 -1
- package/commands/init/tsconfig-updater.d.ts +8 -1
- package/commands/init/tsconfig-updater.d.ts.map +1 -1
- package/commands/init/tsconfig-updater.js +30 -11
- package/commands/init/tsconfig-updater.js.map +1 -1
- package/commands/init/update-angular-config.d.ts.map +1 -1
- package/commands/init/update-angular-config.js +28 -47
- package/commands/init/update-angular-config.js.map +1 -1
- package/commands/init/vite-setup.d.ts +11 -0
- package/commands/init/vite-setup.d.ts.map +1 -0
- package/commands/init/vite-setup.js +61 -0
- package/commands/init/vite-setup.js.map +1 -0
- package/commands/init/wizard.d.ts +30 -0
- package/commands/init/wizard.d.ts.map +1 -0
- package/commands/init/wizard.js +560 -0
- package/commands/init/wizard.js.map +1 -0
- package/constants/app.constants.d.ts +17 -0
- package/constants/app.constants.d.ts.map +1 -1
- package/constants/app.constants.js +39 -16
- package/constants/app.constants.js.map +1 -1
- package/core/icons/families.d.ts +38 -0
- package/core/icons/families.d.ts.map +1 -0
- package/core/icons/families.js +26 -0
- package/core/icons/families.js.map +1 -0
- package/core/icons/icon-map.d.ts +24 -0
- package/core/icons/icon-map.d.ts.map +1 -0
- package/core/icons/icon-map.js +141 -0
- package/core/icons/icon-map.js.map +1 -0
- package/core/icons/index.d.ts +107 -0
- package/core/icons/index.d.ts.map +1 -0
- package/core/icons/index.js +183 -0
- package/core/icons/index.js.map +1 -0
- package/core/registry/registry-data.d.ts.map +1 -1
- package/core/registry/registry-data.js +861 -108
- package/core/registry/registry-data.js.map +1 -1
- package/core/themes/theme-definitions.d.ts +5 -5
- package/core/themes/theme-definitions.d.ts.map +1 -1
- package/core/themes/theme-definitions.js +75 -82
- package/core/themes/theme-definitions.js.map +1 -1
- package/index.js +41 -4
- package/index.js.map +1 -1
- package/package.json +9 -14
- package/ui/blocks.d.ts +71 -0
- package/ui/blocks.d.ts.map +1 -0
- package/ui/blocks.js +116 -0
- package/ui/blocks.js.map +1 -0
- package/ui/brand.d.ts +14 -0
- package/ui/brand.d.ts.map +1 -0
- package/ui/brand.js +35 -0
- package/ui/brand.js.map +1 -0
- package/ui/engine/animation/index.d.ts +38 -0
- package/ui/engine/animation/index.d.ts.map +1 -0
- package/ui/engine/animation/index.js +102 -0
- package/ui/engine/animation/index.js.map +1 -0
- package/ui/engine/ansi/index.d.ts +51 -0
- package/ui/engine/ansi/index.d.ts.map +1 -0
- package/ui/engine/ansi/index.js +116 -0
- package/ui/engine/ansi/index.js.map +1 -0
- package/ui/engine/components/index.d.ts +211 -0
- package/ui/engine/components/index.d.ts.map +1 -0
- package/ui/engine/components/index.js +109 -0
- package/ui/engine/components/index.js.map +1 -0
- package/ui/engine/cursor/index.d.ts +16 -0
- package/ui/engine/cursor/index.d.ts.map +1 -0
- package/ui/engine/cursor/index.js +40 -0
- package/ui/engine/cursor/index.js.map +1 -0
- package/ui/engine/diff/index.d.ts +26 -0
- package/ui/engine/diff/index.d.ts.map +1 -0
- package/ui/engine/diff/index.js +56 -0
- package/ui/engine/diff/index.js.map +1 -0
- package/ui/engine/events/index.d.ts +24 -0
- package/ui/engine/events/index.d.ts.map +1 -0
- package/ui/engine/events/index.js +60 -0
- package/ui/engine/events/index.js.map +1 -0
- package/ui/engine/focus/index.d.ts +25 -0
- package/ui/engine/focus/index.d.ts.map +1 -0
- package/ui/engine/focus/index.js +77 -0
- package/ui/engine/focus/index.js.map +1 -0
- package/ui/engine/frame/index.d.ts +48 -0
- package/ui/engine/frame/index.d.ts.map +1 -0
- package/ui/engine/frame/index.js +0 -0
- package/ui/engine/frame/index.js.map +1 -0
- package/ui/engine/index.d.ts +28 -0
- package/ui/engine/index.d.ts.map +1 -0
- package/ui/engine/index.js +28 -0
- package/ui/engine/index.js.map +1 -0
- package/ui/engine/input/index.d.ts +36 -0
- package/ui/engine/input/index.d.ts.map +1 -0
- package/ui/engine/input/index.js +224 -0
- package/ui/engine/input/index.js.map +1 -0
- package/ui/engine/layout/index.d.ts +42 -0
- package/ui/engine/layout/index.d.ts.map +1 -0
- package/ui/engine/layout/index.js +241 -0
- package/ui/engine/layout/index.js.map +1 -0
- package/ui/engine/renderer/index.d.ts +43 -0
- package/ui/engine/renderer/index.d.ts.map +1 -0
- package/ui/engine/renderer/index.js +619 -0
- package/ui/engine/renderer/index.js.map +1 -0
- package/ui/engine/scheduler/index.d.ts +22 -0
- package/ui/engine/scheduler/index.d.ts.map +1 -0
- package/ui/engine/scheduler/index.js +77 -0
- package/ui/engine/scheduler/index.js.map +1 -0
- package/ui/engine/screen/index.d.ts +39 -0
- package/ui/engine/screen/index.d.ts.map +1 -0
- package/ui/engine/screen/index.js +255 -0
- package/ui/engine/screen/index.js.map +1 -0
- package/ui/engine/terminal/index.d.ts +84 -0
- package/ui/engine/terminal/index.d.ts.map +1 -0
- package/ui/engine/terminal/index.js +235 -0
- package/ui/engine/terminal/index.js.map +1 -0
- package/ui/engine/testing/index.d.ts +27 -0
- package/ui/engine/testing/index.d.ts.map +1 -0
- package/ui/engine/testing/index.js +63 -0
- package/ui/engine/testing/index.js.map +1 -0
- package/ui/engine/theme/index.d.ts +26 -0
- package/ui/engine/theme/index.d.ts.map +1 -0
- package/ui/engine/theme/index.js +128 -0
- package/ui/engine/theme/index.js.map +1 -0
- package/ui/engine/utils/index.d.ts +12 -0
- package/ui/engine/utils/index.d.ts.map +1 -0
- package/ui/engine/utils/index.js +143 -0
- package/ui/engine/utils/index.js.map +1 -0
- package/ui/gate.d.ts +19 -0
- package/ui/gate.d.ts.map +1 -0
- package/ui/gate.js +36 -0
- package/ui/gate.js.map +1 -0
- package/ui/index.d.ts +18 -0
- package/ui/index.d.ts.map +1 -0
- package/ui/index.js +18 -0
- package/ui/index.js.map +1 -0
- package/ui/log-sink.d.ts +24 -0
- package/ui/log-sink.d.ts.map +1 -0
- package/ui/log-sink.js +35 -0
- package/ui/log-sink.js.map +1 -0
- package/ui/output.d.ts +14 -0
- package/ui/output.d.ts.map +1 -0
- package/ui/output.js +28 -0
- package/ui/output.js.map +1 -0
- package/ui/report.d.ts +30 -0
- package/ui/report.d.ts.map +1 -0
- package/ui/report.js +45 -0
- package/ui/report.js.map +1 -0
- package/ui/runner.d.ts +66 -0
- package/ui/runner.d.ts.map +1 -0
- package/ui/runner.js +135 -0
- package/ui/runner.js.map +1 -0
- package/ui/style.d.ts +24 -0
- package/ui/style.d.ts.map +1 -0
- package/ui/style.js +44 -0
- package/ui/style.js.map +1 -0
- package/ui/testing/fake-tty.d.ts +26 -0
- package/ui/testing/fake-tty.d.ts.map +1 -0
- package/ui/testing/fake-tty.js +61 -0
- package/ui/testing/fake-tty.js.map +1 -0
- package/ui/text-input.d.ts +31 -0
- package/ui/text-input.d.ts.map +1 -0
- package/ui/text-input.js +89 -0
- package/ui/text-input.js.map +1 -0
- package/ui/theme.d.ts +10 -0
- package/ui/theme.d.ts.map +1 -0
- package/ui/theme.js +20 -0
- package/ui/theme.js.map +1 -0
- package/utils/angular-compat.d.ts +21 -0
- package/utils/angular-compat.d.ts.map +1 -0
- package/utils/angular-compat.js +52 -0
- package/utils/angular-compat.js.map +1 -0
- package/utils/config.d.ts +55 -69
- package/utils/config.d.ts.map +1 -1
- package/utils/config.js +66 -9
- package/utils/config.js.map +1 -1
- package/utils/errors.d.ts +27 -0
- package/utils/errors.d.ts.map +1 -0
- package/utils/errors.js +45 -0
- package/utils/errors.js.map +1 -0
- package/utils/get-package-info.js +4 -4
- package/utils/get-package-info.js.map +1 -1
- package/utils/get-project-info.d.ts +30 -0
- package/utils/get-project-info.d.ts.map +1 -1
- package/utils/get-project-info.js +195 -6
- package/utils/get-project-info.js.map +1 -1
- package/utils/http-client.d.ts +8 -0
- package/utils/http-client.d.ts.map +1 -0
- package/utils/http-client.js +83 -0
- package/utils/http-client.js.map +1 -0
- package/utils/icon-catalog.d.ts +34 -0
- package/utils/icon-catalog.d.ts.map +1 -0
- package/utils/icon-catalog.js +63 -0
- package/utils/icon-catalog.js.map +1 -0
- package/utils/logger.d.ts +16 -1
- package/utils/logger.d.ts.map +1 -1
- package/utils/logger.js +104 -12
- package/utils/logger.js.map +1 -1
- package/utils/package-manager.d.ts +44 -1
- package/utils/package-manager.d.ts.map +1 -1
- package/utils/package-manager.js +210 -14
- package/utils/package-manager.js.map +1 -1
- package/utils/registry.d.ts +86 -2
- package/utils/registry.d.ts.map +1 -1
- package/utils/registry.js +147 -31
- package/utils/registry.js.map +1 -1
- package/utils/schema-version.d.ts +21 -0
- package/utils/schema-version.d.ts.map +1 -0
- package/utils/schema-version.js +28 -0
- package/utils/schema-version.js.map +1 -0
- package/utils/source-file.d.ts +40 -0
- package/utils/source-file.d.ts.map +1 -0
- package/utils/source-file.js +104 -0
- package/utils/source-file.js.map +1 -0
- package/utils/theme-selector.d.ts +1 -1
- package/utils/theme-selector.d.ts.map +1 -1
- package/utils/theme-selector.js +6 -6
- package/utils/theme-selector.js.map +1 -1
- package/utils/fetch-component.d.ts +0 -3
- package/utils/fetch-component.d.ts.map +0 -1
- package/utils/fetch-component.js +0 -75
- package/utils/fetch-component.js.map +0 -1
package/utils/registry.js
CHANGED
|
@@ -1,68 +1,184 @@
|
|
|
1
1
|
import { DEFAULT_REGISTRY_URL as BUILD_REGISTRY_URL } from '../config/registry-config.js';
|
|
2
|
-
import {
|
|
2
|
+
import { isIconFamily, retargetIcons, SOURCE_ICON_FAMILY } from '../core/icons/index.js';
|
|
3
|
+
import { ConfigError } from '../utils/errors.js';
|
|
4
|
+
import { fetchJson } from '../utils/http-client.js';
|
|
5
|
+
import { iconCatalog } from '../utils/icon-catalog.js';
|
|
6
|
+
import { logger } from '../utils/logger.js';
|
|
7
|
+
import { assertSupportedSchema } from '../utils/schema-version.js';
|
|
3
8
|
export const DEFAULT_REGISTRY_URL = process.env['ZARD_REGISTRY_URL'] ||
|
|
4
9
|
(BUILD_REGISTRY_URL !== '__REGISTRY_URL__' ? BUILD_REGISTRY_URL : 'https://zardui.com/r');
|
|
10
|
+
/**
|
|
11
|
+
* The family the item's files are written in.
|
|
12
|
+
*
|
|
13
|
+
* An item with no `icons` — published before the property existed — is in
|
|
14
|
+
* lucide, which was the only possibility. So is an unknown value: better the
|
|
15
|
+
* right guess than refusing to install over an unfamiliar field.
|
|
16
|
+
*/
|
|
17
|
+
export function sourceFamilyOf(item) {
|
|
18
|
+
const family = item.icons?.family;
|
|
19
|
+
return family !== undefined && isIconFamily(family, iconCatalog()) ? family : SOURCE_ICON_FAMILY;
|
|
20
|
+
}
|
|
5
21
|
export function getRegistryUrl(config) {
|
|
6
22
|
return config?.registryUrl || DEFAULT_REGISTRY_URL;
|
|
7
23
|
}
|
|
8
|
-
|
|
24
|
+
export function validateRegistryUrl(url) {
|
|
9
25
|
try {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
'
|
|
15
|
-
'User-Agent: ngzard-cli',
|
|
16
|
-
'--max-time',
|
|
17
|
-
'30',
|
|
18
|
-
url,
|
|
19
|
-
]);
|
|
20
|
-
if (!stdout || stdout.includes('<!DOCTYPE') || stdout.includes('<html')) {
|
|
21
|
-
throw new Error(`Invalid response from registry: ${url}`);
|
|
26
|
+
const parsed = new URL(url);
|
|
27
|
+
const isHttps = parsed.protocol === 'https:';
|
|
28
|
+
const isLocalhost = parsed.hostname === 'localhost' || parsed.hostname === '127.0.0.1';
|
|
29
|
+
if (!isHttps && !isLocalhost) {
|
|
30
|
+
throw new ConfigError('Registry URL must use HTTPS (or localhost for development)');
|
|
22
31
|
}
|
|
23
|
-
return JSON.parse(stdout);
|
|
24
32
|
}
|
|
25
33
|
catch (error) {
|
|
26
|
-
if (error instanceof
|
|
27
|
-
throw
|
|
28
|
-
}
|
|
29
|
-
throw new Error(`Failed to fetch from registry: ${url} - ${error}`);
|
|
34
|
+
if (error instanceof ConfigError)
|
|
35
|
+
throw error;
|
|
36
|
+
throw new ConfigError(`Invalid registry URL: ${url}`);
|
|
30
37
|
}
|
|
31
38
|
}
|
|
39
|
+
const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
|
40
|
+
/**
|
|
41
|
+
* Keyed by registry URL, not global.
|
|
42
|
+
*
|
|
43
|
+
* `registryUrl` is a `components.json` field, so two registries can be read in one
|
|
44
|
+
* run — and a single cache entry handed the second call the first registry's index.
|
|
45
|
+
*/
|
|
46
|
+
const registryIndexCache = new Map();
|
|
32
47
|
export async function fetchRegistryIndex(registryUrl) {
|
|
33
48
|
const baseUrl = registryUrl || DEFAULT_REGISTRY_URL;
|
|
49
|
+
const cached = registryIndexCache.get(baseUrl);
|
|
50
|
+
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
|
|
51
|
+
return cached.data;
|
|
52
|
+
}
|
|
34
53
|
const url = `${baseUrl}/registry.json`;
|
|
35
|
-
|
|
54
|
+
const data = await fetchJson(url);
|
|
55
|
+
assertSupportedSchema(data.schemaVersion, 'registry.json');
|
|
56
|
+
registryIndexCache.set(baseUrl, { data, timestamp: Date.now() });
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
export function invalidateRegistryCache() {
|
|
60
|
+
registryIndexCache.clear();
|
|
61
|
+
blocksIndexCache.clear();
|
|
36
62
|
}
|
|
37
63
|
export async function fetchComponentFromRegistry(componentName, registryUrl) {
|
|
38
64
|
const baseUrl = registryUrl || DEFAULT_REGISTRY_URL;
|
|
39
65
|
const url = `${baseUrl}/${componentName}.json`;
|
|
40
66
|
return fetchJson(url);
|
|
41
67
|
}
|
|
68
|
+
const blocksIndexCache = new Map();
|
|
69
|
+
/**
|
|
70
|
+
* The block index, cached like the component one.
|
|
71
|
+
*
|
|
72
|
+
* A registry that predates blocks has no `blocks-registry.json`; that is not an
|
|
73
|
+
* error, it just means this registry publishes none.
|
|
74
|
+
*/
|
|
75
|
+
export async function fetchBlocksIndex(registryUrl) {
|
|
76
|
+
const baseUrl = registryUrl || DEFAULT_REGISTRY_URL;
|
|
77
|
+
const cached = blocksIndexCache.get(baseUrl);
|
|
78
|
+
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
|
|
79
|
+
return cached.data;
|
|
80
|
+
}
|
|
81
|
+
let data;
|
|
82
|
+
try {
|
|
83
|
+
data = await fetchJson(`${baseUrl}/blocks-registry.json`);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
data = { blocks: [] };
|
|
87
|
+
}
|
|
88
|
+
blocksIndexCache.set(baseUrl, { data, timestamp: Date.now() });
|
|
89
|
+
return data;
|
|
90
|
+
}
|
|
91
|
+
export async function fetchBlockFromRegistry(blockId, registryUrl) {
|
|
92
|
+
const baseUrl = registryUrl || DEFAULT_REGISTRY_URL;
|
|
93
|
+
return fetchJson(`${baseUrl}/blocks/${blockId}.json`);
|
|
94
|
+
}
|
|
95
|
+
export async function getAvailableBlocks(registryUrl) {
|
|
96
|
+
const index = await fetchBlocksIndex(registryUrl);
|
|
97
|
+
return index.blocks.map(block => block.id);
|
|
98
|
+
}
|
|
42
99
|
export async function getAvailableComponents(registryUrl) {
|
|
43
100
|
const index = await fetchRegistryIndex(registryUrl);
|
|
44
101
|
return index.items.map(item => item.name);
|
|
45
102
|
}
|
|
46
|
-
|
|
103
|
+
/** Sem isto, um alias digitado como `@/ui/components/` produz `@/ui/components//button`. */
|
|
104
|
+
function trimSlashes(alias) {
|
|
105
|
+
return alias.replace(/\/+$/, '');
|
|
106
|
+
}
|
|
107
|
+
export function transformContent(content, config, options = {}) {
|
|
47
108
|
let transformed = content;
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
109
|
+
const aliases = {
|
|
110
|
+
components: options.siblingComponents ? '..' : trimSlashes(config.aliases.components),
|
|
111
|
+
utils: trimSlashes(config.aliases.utils),
|
|
112
|
+
core: trimSlashes(config.aliases.core),
|
|
113
|
+
services: trimSlashes(config.aliases.services),
|
|
114
|
+
};
|
|
115
|
+
/*
|
|
116
|
+
* Blocks are authored inside the monorepo, so their sources import the library
|
|
117
|
+
* by its workspace alias (`@zard/components/card/card.imports`). Nothing maps
|
|
118
|
+
* that name in the installing project — left alone, every block would arrive
|
|
119
|
+
* with imports that do not resolve.
|
|
120
|
+
*/
|
|
121
|
+
transformed = transformed.replace(/(['"])@zard\/components\/([\w\-/.]+)\1/g, (_match, quote, subpath) => `${quote}${aliases.components}/${subpath}${quote}`);
|
|
52
122
|
// Replace relative component imports with aliased imports
|
|
53
123
|
const componentImportRegex = /from ['"]\.\.\/([\w-/.]+)['"]/g;
|
|
54
124
|
transformed = transformed.replace(componentImportRegex, `from '${aliases.components}/$1'`);
|
|
55
125
|
// Replace ClassValue imports
|
|
56
126
|
transformed = transformed.replace(/import \{ ClassValue \} from ['"]class-variance-authority\/dist\/types['"]/g, `import { ClassValue } from 'clsx'`);
|
|
57
127
|
transformed = transformed.replace(/import \{ ClassValue \} from ['"]class-variance-authority['"]/g, `import { ClassValue } from 'clsx'`);
|
|
128
|
+
// Transform default @/shared/* to match aliases
|
|
129
|
+
for (const [key, value] of Object.entries(aliases)) {
|
|
130
|
+
if (!value) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
// The subpath is optional: `card.component.ts` imports the barrel directly
|
|
134
|
+
// (`from '@/shared/core'`). Requiring `/something` after the key let that
|
|
135
|
+
// import escape the substitution, and the installed component kept pointing
|
|
136
|
+
// at `@/shared/core` — a folder that does not exist under a custom alias.
|
|
137
|
+
const regex = new RegExp(`(['"])@\\/shared\\/${key}(\\/[\\w\\-\\/.]+)?\\1`, 'g');
|
|
138
|
+
transformed = transformed.replace(regex, (_match, quote, subpath) => {
|
|
139
|
+
return `${quote}${value}${subpath ?? ''}${quote}`;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
58
142
|
return transformed;
|
|
59
143
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
144
|
+
/**
|
|
145
|
+
* A block in the shape the installer already understands.
|
|
146
|
+
*
|
|
147
|
+
* The two differ only in what the registry carries: a block entry adds `path`
|
|
148
|
+
* and `language` per file, neither of which affects how the files are written.
|
|
149
|
+
*/
|
|
150
|
+
function blockAsRegistryItem(block) {
|
|
151
|
+
return {
|
|
152
|
+
name: block.id,
|
|
153
|
+
type: 'registry:component',
|
|
154
|
+
basePath: 'blocks',
|
|
155
|
+
dependencies: block.dependencies,
|
|
156
|
+
registryDependencies: block.registryDependencies,
|
|
157
|
+
files: block.files.map(file => ({ name: file.name, content: file.content })),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
export async function fetchComponent(componentName, config, registryUrl, options = {}) {
|
|
161
|
+
const item = options.isBlock
|
|
162
|
+
? blockAsRegistryItem(await fetchBlockFromRegistry(componentName, registryUrl))
|
|
163
|
+
: await fetchComponentFromRegistry(componentName, registryUrl);
|
|
164
|
+
if (!item.files || !Array.isArray(item.files)) {
|
|
165
|
+
throw new ConfigError(`Component "${componentName}" has no files in the registry`);
|
|
166
|
+
}
|
|
167
|
+
const sourceFamily = sourceFamilyOf(item);
|
|
168
|
+
const missing = new Set();
|
|
169
|
+
const transformedFiles = item.files.map(file => {
|
|
170
|
+
const retargeted = retargetIcons(transformContent(file.content, config, options), sourceFamily, config.icons, iconCatalog());
|
|
171
|
+
for (const symbol of retargeted.missing)
|
|
172
|
+
missing.add(symbol);
|
|
173
|
+
return { name: file.name, content: retargeted.content };
|
|
174
|
+
});
|
|
175
|
+
// An icon with no equivalent in the chosen family keeps its original symbol,
|
|
176
|
+
// and its import no longer resolves. Failing the whole install over that would
|
|
177
|
+
// be worse: the rest of the component is correct and the fix is one line.
|
|
178
|
+
if (missing.size > 0) {
|
|
179
|
+
logger.warn(`"${componentName}" uses icons that ${config.icons} does not provide: ${[...missing].sort().join(', ')}. ` +
|
|
180
|
+
'They were left untouched — replace them by hand.');
|
|
181
|
+
}
|
|
66
182
|
return {
|
|
67
183
|
...item,
|
|
68
184
|
files: transformedFiles,
|
package/utils/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/utils/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,IAAI,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/utils/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,IAAI,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAmB,MAAM,0BAA0B,CAAC;AAE5G,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,MAAM,CAAC,MAAM,oBAAoB,GAC/B,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;IAChC,CAAC,kBAAkB,KAAK,kBAAkB,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC;AAmF5F;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,IAAiC;IAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC;IAClC,OAAO,MAAM,KAAK,SAAS,IAAI,YAAY,CAAC,MAAM,EAAE,WA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MAAM,EAAE,OAAO,CAAC,EAC/C,YAAY,EACZ,MAAM,CAAC,KAAK,EACZ,WAAW,EAAE,CACd,CAAC;QACF,KAAK,MAAM,MAAM,IAAI,UAAU,CAAC,OAAO;YAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAE7D,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,6EAA6E;IAC7E,+EAA+E;IAC/E,0EAA0E;IAC1E,IAAI,OAAO,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,CAAC,IAAI,CACT,IAAI,aAAa,qBAAqB,MAAM,CAAC,KAAK,sBAAsB,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YACxG,kDAAkD,CACrD,CAAC;IACJ,CAAC;IAED,OAAO;QACL,GAAG,IAAI;QACP,KAAK,EAAE,gBAAgB;KACxB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The registry FORMAT version this CLI understands.
|
|
3
|
+
*
|
|
4
|
+
* Not to be confused with the package version, which the index also publishes:
|
|
5
|
+
* that one says which release the content came from, this one says what shape it
|
|
6
|
+
* has. Without separating them there was no way for the registry to change shape
|
|
7
|
+
* without silently breaking whoever was already installed — the CLI would read
|
|
8
|
+
* `files` from an item with a different shape and get it wrong without a word.
|
|
9
|
+
*
|
|
10
|
+
* It goes up when the change breaks a reader: a field removed, a meaning
|
|
11
|
+
* altered, an item reorganized. A new optional field raises nothing.
|
|
12
|
+
*/
|
|
13
|
+
export declare const SUPPORTED_SCHEMA_VERSION = 1;
|
|
14
|
+
/**
|
|
15
|
+
* Rejects a document newer than this CLI knows how to read.
|
|
16
|
+
*
|
|
17
|
+
* A missing field means a registry older than the field itself, which is version
|
|
18
|
+
* 1 by definition.
|
|
19
|
+
*/
|
|
20
|
+
export declare function assertSupportedSchema(schemaVersion: number | undefined, source: string): void;
|
|
21
|
+
//# sourceMappingURL=schema-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-version.d.ts","sourceRoot":"","sources":["../../src/utils/schema-version.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAE1C;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAS7F"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SchemaVersionError } from '../utils/errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* The registry FORMAT version this CLI understands.
|
|
4
|
+
*
|
|
5
|
+
* Not to be confused with the package version, which the index also publishes:
|
|
6
|
+
* that one says which release the content came from, this one says what shape it
|
|
7
|
+
* has. Without separating them there was no way for the registry to change shape
|
|
8
|
+
* without silently breaking whoever was already installed — the CLI would read
|
|
9
|
+
* `files` from an item with a different shape and get it wrong without a word.
|
|
10
|
+
*
|
|
11
|
+
* It goes up when the change breaks a reader: a field removed, a meaning
|
|
12
|
+
* altered, an item reorganized. A new optional field raises nothing.
|
|
13
|
+
*/
|
|
14
|
+
export const SUPPORTED_SCHEMA_VERSION = 1;
|
|
15
|
+
/**
|
|
16
|
+
* Rejects a document newer than this CLI knows how to read.
|
|
17
|
+
*
|
|
18
|
+
* A missing field means a registry older than the field itself, which is version
|
|
19
|
+
* 1 by definition.
|
|
20
|
+
*/
|
|
21
|
+
export function assertSupportedSchema(schemaVersion, source) {
|
|
22
|
+
const version = schemaVersion ?? 1;
|
|
23
|
+
if (version > SUPPORTED_SCHEMA_VERSION) {
|
|
24
|
+
throw new SchemaVersionError(`This registry publishes ${source} in format v${version}, and this CLI reads up to v${SUPPORTED_SCHEMA_VERSION}. ` +
|
|
25
|
+
'Update it with `npm i -g zard-cli@latest`, or run it through npx, which always fetches the latest.');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=schema-version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-version.js","sourceRoot":"","sources":["../../src/utils/schema-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,aAAiC,EAAE,MAAc;IACrF,MAAM,OAAO,GAAG,aAAa,IAAI,CAAC,CAAC;IAEnC,IAAI,OAAO,GAAG,wBAAwB,EAAE,CAAC;QACvC,MAAM,IAAI,kBAAkB,CAC1B,2BAA2B,MAAM,eAAe,OAAO,+BAA+B,wBAAwB,IAAI;YAChH,oGAAoG,CACvG,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source edits that more than one init step needs to make.
|
|
3
|
+
*
|
|
4
|
+
* Inserting an import looks trivial until the file is in CRLF: a raw `\n`
|
|
5
|
+
* produces mixed endings, makes git mark the whole file as changed, and — when
|
|
6
|
+
* the expression that finds the imports forgets the `\r` — welds the new line
|
|
7
|
+
* onto the end of the previous one.
|
|
8
|
+
*/
|
|
9
|
+
/** The line ending the file already uses. */
|
|
10
|
+
export declare function lineEndingOf(content: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Inserts an import line just after the file's last import.
|
|
13
|
+
*
|
|
14
|
+
* Returns the content untouched when the import is already there, so calling it
|
|
15
|
+
* twice is the same as calling it once.
|
|
16
|
+
*/
|
|
17
|
+
export declare function withImport(content: string, importLine: string): string;
|
|
18
|
+
/** Where an array literal starts and ends, as indices into the content. */
|
|
19
|
+
export interface ArrayRange {
|
|
20
|
+
/** Index of the opening `[`. */
|
|
21
|
+
readonly open: number;
|
|
22
|
+
/** Index of the closing `]`. */
|
|
23
|
+
readonly close: number;
|
|
24
|
+
/** What sits between the two, without the brackets. */
|
|
25
|
+
readonly body: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The range of the array assigned to `key`, found by counting brackets.
|
|
29
|
+
*
|
|
30
|
+
* A regular expression stops at the first `]` it sees, and in real code that `]`
|
|
31
|
+
* is usually a nested array's — `withInterceptors([...])` inside `providers`, a
|
|
32
|
+
* plugin with options inside `plugins`. Anything inserted there landed in the
|
|
33
|
+
* wrong array, and the build broke with a type error that mentions ZardUI
|
|
34
|
+
* nowhere.
|
|
35
|
+
*
|
|
36
|
+
* Strings and comments are skipped, so a `]` written inside one does not count
|
|
37
|
+
* as a closing bracket.
|
|
38
|
+
*/
|
|
39
|
+
export declare function arrayRange(content: string, key: string): ArrayRange | null;
|
|
40
|
+
//# sourceMappingURL=source-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-file.d.ts","sourceRoot":"","sources":["../../src/utils/source-file.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,6CAA6C;AAC7C,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEpD;AAgBD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAYtE;AAED,2EAA2E;AAC3E,MAAM,WAAW,UAAU;IACzB,gCAAgC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gCAAgC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAyB1E"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source edits that more than one init step needs to make.
|
|
3
|
+
*
|
|
4
|
+
* Inserting an import looks trivial until the file is in CRLF: a raw `\n`
|
|
5
|
+
* produces mixed endings, makes git mark the whole file as changed, and — when
|
|
6
|
+
* the expression that finds the imports forgets the `\r` — welds the new line
|
|
7
|
+
* onto the end of the previous one.
|
|
8
|
+
*/
|
|
9
|
+
/** The line ending the file already uses. */
|
|
10
|
+
export function lineEndingOf(content) {
|
|
11
|
+
return content.includes('\r\n') ? '\r\n' : '\n';
|
|
12
|
+
}
|
|
13
|
+
/** The file's last `import ... from '...'`, or null when there is none. */
|
|
14
|
+
function lastImport(content) {
|
|
15
|
+
// `[\s\S]*?` rather than `.*`: the list of imported symbols often wraps across
|
|
16
|
+
// several lines, and a pattern anchored to a single line did not reach it — in
|
|
17
|
+
// such a file the new import was thrown in before all the others.
|
|
18
|
+
const importRegex = /^import\s[\s\S]*?from\s+'[^']*';\r?\n?/gm;
|
|
19
|
+
let last = null;
|
|
20
|
+
let match;
|
|
21
|
+
while ((match = importRegex.exec(content)) !== null)
|
|
22
|
+
last = match;
|
|
23
|
+
return last;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Inserts an import line just after the file's last import.
|
|
27
|
+
*
|
|
28
|
+
* Returns the content untouched when the import is already there, so calling it
|
|
29
|
+
* twice is the same as calling it once.
|
|
30
|
+
*/
|
|
31
|
+
export function withImport(content, importLine) {
|
|
32
|
+
if (content.includes(importLine))
|
|
33
|
+
return content;
|
|
34
|
+
const eol = lineEndingOf(content);
|
|
35
|
+
const last = lastImport(content);
|
|
36
|
+
if (!last)
|
|
37
|
+
return importLine + eol + content;
|
|
38
|
+
const end = last.index + last[0].length;
|
|
39
|
+
const alreadyBroken = /\r?\n$/.test(last[0]);
|
|
40
|
+
return content.slice(0, end) + (alreadyBroken ? '' : eol) + importLine + eol + content.slice(end);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The range of the array assigned to `key`, found by counting brackets.
|
|
44
|
+
*
|
|
45
|
+
* A regular expression stops at the first `]` it sees, and in real code that `]`
|
|
46
|
+
* is usually a nested array's — `withInterceptors([...])` inside `providers`, a
|
|
47
|
+
* plugin with options inside `plugins`. Anything inserted there landed in the
|
|
48
|
+
* wrong array, and the build broke with a type error that mentions ZardUI
|
|
49
|
+
* nowhere.
|
|
50
|
+
*
|
|
51
|
+
* Strings and comments are skipped, so a `]` written inside one does not count
|
|
52
|
+
* as a closing bracket.
|
|
53
|
+
*/
|
|
54
|
+
export function arrayRange(content, key) {
|
|
55
|
+
const opening = new RegExp(`\\b${key}\\s*:\\s*\\[`).exec(content);
|
|
56
|
+
if (!opening)
|
|
57
|
+
return null;
|
|
58
|
+
const open = opening.index + opening[0].length - 1;
|
|
59
|
+
let depth = 0;
|
|
60
|
+
for (let index = open; index < content.length; index++) {
|
|
61
|
+
const skipped = skipStringOrComment(content, index);
|
|
62
|
+
if (skipped !== index) {
|
|
63
|
+
index = skipped - 1;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const char = content[index];
|
|
67
|
+
if (char === '[')
|
|
68
|
+
depth++;
|
|
69
|
+
else if (char === ']' && --depth === 0) {
|
|
70
|
+
return { open, close: index, body: content.slice(open + 1, index) };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The index just past the string or comment starting at `index`.
|
|
77
|
+
*
|
|
78
|
+
* Returns `index` itself when there is neither — the caller uses that to know
|
|
79
|
+
* the character is code and should be taken into account.
|
|
80
|
+
*/
|
|
81
|
+
function skipStringOrComment(content, index) {
|
|
82
|
+
const char = content[index];
|
|
83
|
+
const next = content[index + 1];
|
|
84
|
+
if (char === '/' && next === '/') {
|
|
85
|
+
const end = content.indexOf('\n', index);
|
|
86
|
+
return end === -1 ? content.length : end;
|
|
87
|
+
}
|
|
88
|
+
if (char === '/' && next === '*') {
|
|
89
|
+
const end = content.indexOf('*/', index + 2);
|
|
90
|
+
return end === -1 ? content.length : end + 2;
|
|
91
|
+
}
|
|
92
|
+
if (char !== '"' && char !== "'" && char !== '`')
|
|
93
|
+
return index;
|
|
94
|
+
for (let cursor = index + 1; cursor < content.length; cursor++) {
|
|
95
|
+
if (content[cursor] === '\\') {
|
|
96
|
+
cursor++;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (content[cursor] === char)
|
|
100
|
+
return cursor + 1;
|
|
101
|
+
}
|
|
102
|
+
return content.length;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=source-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-file.js","sourceRoot":"","sources":["../../src/utils/source-file.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,6CAA6C;AAC7C,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC;AAED,2EAA2E;AAC3E,SAAS,UAAU,CAAC,OAAe;IACjC,+EAA+E;IAC/E,+EAA+E;IAC/E,kEAAkE;IAClE,MAAM,WAAW,GAAG,0CAA0C,CAAC;IAE/D,IAAI,IAAI,GAA2B,IAAI,CAAC;IACxC,IAAI,KAA6B,CAAC;IAClC,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI;QAAE,IAAI,GAAG,KAAK,CAAC;IAElE,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,UAAkB;IAC5D,IAAI,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,OAAO,CAAC;IAEjD,MAAM,GAAG,GAA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OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;QAC/D,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;YAC7B,MAAM,EAAE,CAAC;YACT,SAAS;QACX,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI;YAAE,OAAO,MAAM,GAAG,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,CAAC;AACxB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function getAvailableThemes(): string[];
|
|
2
|
-
export declare function getThemeContent(themeName: string): string;
|
|
2
|
+
export declare function getThemeContent(themeName: string, corePath: string): string;
|
|
3
3
|
export declare function getThemeDisplayName(themeName: string): string;
|
|
4
4
|
//# sourceMappingURL=theme-selector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-selector.d.ts","sourceRoot":"","sources":["../../src/utils/theme-selector.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAE7C;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"theme-selector.d.ts","sourceRoot":"","sources":["../../src/utils/theme-selector.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAE7C;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAkB3E;AAED,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAS7D"}
|
package/utils/theme-selector.js
CHANGED
|
@@ -2,20 +2,20 @@ import * as themes from '../core/themes/theme-definitions.js';
|
|
|
2
2
|
export function getAvailableThemes() {
|
|
3
3
|
return themes.availableThemes;
|
|
4
4
|
}
|
|
5
|
-
export function getThemeContent(themeName) {
|
|
5
|
+
export function getThemeContent(themeName, corePath) {
|
|
6
6
|
const content = (() => {
|
|
7
7
|
switch (themeName) {
|
|
8
8
|
case 'stone':
|
|
9
|
-
return themes.stone;
|
|
9
|
+
return themes.stone(corePath);
|
|
10
10
|
case 'zinc':
|
|
11
|
-
return themes.zinc;
|
|
11
|
+
return themes.zinc(corePath);
|
|
12
12
|
case 'gray':
|
|
13
|
-
return themes.gray;
|
|
13
|
+
return themes.gray(corePath);
|
|
14
14
|
case 'slate':
|
|
15
|
-
return themes.slate;
|
|
15
|
+
return themes.slate(corePath);
|
|
16
16
|
case 'neutral':
|
|
17
17
|
default:
|
|
18
|
-
return themes.neutral;
|
|
18
|
+
return themes.neutral(corePath);
|
|
19
19
|
}
|
|
20
20
|
})();
|
|
21
21
|
return content.trim();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-selector.js","sourceRoot":"","sources":["../../src/utils/theme-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uCAAuC,CAAC;AAEhE,MAAM,UAAU,kBAAkB;IAChC,OAAO,MAAM,CAAC,eAAe,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,SAAiB;
|
|
1
|
+
{"version":3,"file":"theme-selector.js","sourceRoot":"","sources":["../../src/utils/theme-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uCAAuC,CAAC;AAEhE,MAAM,UAAU,kBAAkB;IAChC,OAAO,MAAM,CAAC,eAAe,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,SAAiB,EAAE,QAAgB;IACjE,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE;QACpB,QAAQ,SAAS,EAAE,CAAC;YAClB,KAAK,OAAO;gBACV,OAAO,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAChC,KAAK,MAAM;gBACT,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC/B,KAAK,MAAM;gBACT,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC/B,KAAK,OAAO;gBACV,OAAO,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAChC,KAAK,SAAS,CAAC;YACf;gBACE,OAAO,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACpC,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IAEL,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,SAAiB;IACnD,MAAM,KAAK,GAA2B;QACpC,OAAO,EAAE,mBAAmB;QAC5B,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO;KACf,CAAC;IACF,OAAO,KAAK,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC;AACvC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-component.d.ts","sourceRoot":"","sources":["../../src/utils/fetch-component.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AA6EnD,wBAAsB,wBAAwB,CAC5C,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAYjB"}
|
package/utils/fetch-component.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { transformContent } from '../utils/registry.js';
|
|
2
|
-
import { execa } from 'execa';
|
|
3
|
-
import { readFileSync } from 'node:fs';
|
|
4
|
-
import { join, dirname } from 'node:path';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = dirname(__filename);
|
|
8
|
-
const GITHUB_API = 'https://api.github.com/repos/zard-ui/zardui/contents';
|
|
9
|
-
function getCliVersion() {
|
|
10
|
-
try {
|
|
11
|
-
const packageJsonPath = join(__dirname, '../package.json');
|
|
12
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
13
|
-
return packageJson.version;
|
|
14
|
-
}
|
|
15
|
-
catch (error) {
|
|
16
|
-
console.warn('Failed to read CLI version from package.json, falling back to master branch');
|
|
17
|
-
return 'master';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Get the GitHub ref (tag or branch) to fetch components from
|
|
22
|
-
* Uses the CLI version tag (e.g., v1.2.3) to ensure component compatibility
|
|
23
|
-
*/
|
|
24
|
-
function getGithubRef() {
|
|
25
|
-
const version = getCliVersion();
|
|
26
|
-
if (version === 'master' || version.includes('dev') || version === '0.0.0') {
|
|
27
|
-
return 'master';
|
|
28
|
-
}
|
|
29
|
-
return `v${version}`;
|
|
30
|
-
}
|
|
31
|
-
const GITHUB_REF = getGithubRef();
|
|
32
|
-
const GITHUB_RAW = `https://raw.githubusercontent.com/zard-ui/zardui/${GITHUB_REF}`;
|
|
33
|
-
async function fetchFromGitHubAPI(filePath) {
|
|
34
|
-
try {
|
|
35
|
-
const apiUrl = `${GITHUB_API}/${filePath}?ref=${GITHUB_REF}`;
|
|
36
|
-
const { stdout } = await execa('curl', [
|
|
37
|
-
'-s',
|
|
38
|
-
'-H',
|
|
39
|
-
'Accept: application/vnd.github.v3+json',
|
|
40
|
-
'-H',
|
|
41
|
-
'User-Agent: zard-cli',
|
|
42
|
-
apiUrl,
|
|
43
|
-
]);
|
|
44
|
-
const response = JSON.parse(stdout);
|
|
45
|
-
if (response.message) {
|
|
46
|
-
throw new Error(response.message);
|
|
47
|
-
}
|
|
48
|
-
if (response.content && response.encoding === 'base64') {
|
|
49
|
-
return Buffer.from(response.content, 'base64').toString('utf8');
|
|
50
|
-
}
|
|
51
|
-
throw new Error('Invalid response from GitHub API');
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
55
|
-
const rawUrl = `${GITHUB_RAW}/${filePath}`;
|
|
56
|
-
const { stdout } = await execa('curl', ['-s', '-H', 'User-Agent: zard-cli', rawUrl]);
|
|
57
|
-
if (!stdout || stdout.includes('429: Too Many Requests') || stdout.includes('404: Not Found')) {
|
|
58
|
-
throw new Error(`Failed to fetch from both API and raw URL: ${filePath}`);
|
|
59
|
-
}
|
|
60
|
-
return stdout;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
export async function fetchComponentFromGithub(componentName, fileName, config) {
|
|
64
|
-
try {
|
|
65
|
-
const filePath = `libs/zard/src/lib/components/${componentName}/${fileName}`;
|
|
66
|
-
const randomDelay = Math.random() * 2000 + 1000; // 1-3 seconds
|
|
67
|
-
await new Promise(resolve => setTimeout(resolve, randomDelay));
|
|
68
|
-
const content = await fetchFromGitHubAPI(filePath);
|
|
69
|
-
return transformContent(content, config);
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
throw new Error(`Failed to fetch component ${componentName}/${fileName}: ${error}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=fetch-component.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-component.js","sourceRoot":"","sources":["../../src/utils/fetch-component.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,MAAM,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