zard-cli 1.0.0-beta.11 → 1.0.0-beta.110
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 +4 -1
- package/commands/add/component-installer.d.ts.map +1 -1
- package/commands/add/component-installer.js +33 -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 +3 -2
- package/commands/add/dependency-resolver.d.ts.map +1 -1
- package/commands/add/dependency-resolver.js +23 -9
- package/commands/add/dependency-resolver.js.map +1 -1
- package/commands/add/index.d.ts.map +1 -1
- package/commands/add/index.js +137 -85
- package/commands/add/index.js.map +1 -1
- package/commands/add/wizard.d.ts +31 -0
- package/commands/add/wizard.d.ts.map +1 -0
- package/commands/add/wizard.js +289 -0
- package/commands/add/wizard.js.map +1 -0
- package/commands/init/config-prompter.d.ts +61 -56
- package/commands/init/config-prompter.d.ts.map +1 -1
- package/commands/init/config-prompter.js +84 -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 +47 -16
- 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 +16 -0
- package/commands/init/steps.d.ts.map +1 -0
- package/commands/init/steps.js +153 -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 +10 -0
- package/commands/init/vite-setup.d.ts.map +1 -0
- package/commands/init/vite-setup.js +60 -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/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 +130 -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 +571 -84
- 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 +65 -61
- package/core/themes/theme-definitions.js.map +1 -1
- package/index.js +40 -4
- package/index.js.map +1 -1
- package/package.json +4 -7
- package/ui/blocks.d.ts +70 -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 +39 -0
- package/ui/engine/animation/index.d.ts.map +1 -0
- package/ui/engine/animation/index.js +103 -0
- package/ui/engine/animation/index.js.map +1 -0
- package/ui/engine/ansi/index.d.ts +52 -0
- package/ui/engine/ansi/index.d.ts.map +1 -0
- package/ui/engine/ansi/index.js +117 -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 +17 -0
- package/ui/engine/cursor/index.d.ts.map +1 -0
- package/ui/engine/cursor/index.js +41 -0
- package/ui/engine/cursor/index.js.map +1 -0
- package/ui/engine/diff/index.d.ts +27 -0
- package/ui/engine/diff/index.d.ts.map +1 -0
- package/ui/engine/diff/index.js +57 -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 +27 -0
- package/ui/engine/theme/index.d.ts.map +1 -0
- package/ui/engine/theme/index.js +129 -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 +30 -0
- package/ui/text-input.d.ts.map +1 -0
- package/ui/text-input.js +87 -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/config.d.ts +52 -69
- package/utils/config.d.ts.map +1 -1
- package/utils/config.js +58 -7
- 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 +68 -0
- package/utils/http-client.js.map +1 -0
- package/utils/icon-catalog.d.ts +33 -0
- package/utils/icon-catalog.d.ts.map +1 -0
- package/utils/icon-catalog.js +62 -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 +44 -2
- package/utils/registry.d.ts.map +1 -1
- package/utils/registry.js +82 -27
- package/utils/registry.js.map +1 -1
- package/utils/schema-version.d.ts +20 -0
- package/utils/schema-version.d.ts.map +1 -0
- package/utils/schema-version.js +27 -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.d.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
|
+
import { type IconFamily } from '../core/icons/index.js';
|
|
1
2
|
import type { Config } from '../utils/config.js';
|
|
2
3
|
export declare const DEFAULT_REGISTRY_URL: string;
|
|
4
|
+
/**
|
|
5
|
+
* Os ícones que um componente desenha, como o registry os publica.
|
|
6
|
+
*
|
|
7
|
+
* `family` é a família em que os arquivos estão escritos — quem instala com
|
|
8
|
+
* outra família em `components.json` sabe, por este campo, que precisa
|
|
9
|
+
* reescrevê-los. Ausente nos itens publicados antes desta propriedade.
|
|
10
|
+
*/
|
|
11
|
+
export interface RegistryIcons {
|
|
12
|
+
family: string;
|
|
13
|
+
symbols: string[];
|
|
14
|
+
tokens: string[];
|
|
15
|
+
/** Os ícones que só aparecem nos demos. Ausente no índice, que não os carrega. */
|
|
16
|
+
demos?: {
|
|
17
|
+
symbols: string[];
|
|
18
|
+
tokens: string[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
3
21
|
export interface RegistryItem {
|
|
4
22
|
name: string;
|
|
5
23
|
type: 'registry:component';
|
|
@@ -11,9 +29,12 @@ export interface RegistryItem {
|
|
|
11
29
|
dependencies?: string[];
|
|
12
30
|
devDependencies?: string[];
|
|
13
31
|
registryDependencies?: string[];
|
|
32
|
+
icons?: RegistryIcons;
|
|
14
33
|
}
|
|
15
34
|
export interface RegistryIndex {
|
|
16
35
|
$schema: string;
|
|
36
|
+
/** A forma do arquivo. Ausente nos registries anteriores ao campo. */
|
|
37
|
+
schemaVersion?: number;
|
|
17
38
|
name: string;
|
|
18
39
|
homepage: string;
|
|
19
40
|
version: string;
|
|
@@ -24,13 +45,34 @@ export interface RegistryIndex {
|
|
|
24
45
|
dependencies?: string[];
|
|
25
46
|
devDependencies?: string[];
|
|
26
47
|
registryDependencies?: string[];
|
|
48
|
+
icons?: RegistryIcons;
|
|
27
49
|
files: string[];
|
|
28
50
|
}>;
|
|
29
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* A família em que os arquivos do item estão escritos.
|
|
54
|
+
*
|
|
55
|
+
* Um item sem `icons` — publicado antes da propriedade — está em lucide, que
|
|
56
|
+
* era a única possibilidade. Um valor desconhecido também: preferir o palpite
|
|
57
|
+
* certo a recusar a instalação por causa de um campo novo.
|
|
58
|
+
*/
|
|
59
|
+
export declare function sourceFamilyOf(item: Pick<RegistryItem, 'icons'>): IconFamily;
|
|
30
60
|
export declare function getRegistryUrl(config?: Config): string;
|
|
61
|
+
export declare function validateRegistryUrl(url: string): void;
|
|
31
62
|
export declare function fetchRegistryIndex(registryUrl?: string): Promise<RegistryIndex>;
|
|
63
|
+
export declare function invalidateRegistryCache(): void;
|
|
32
64
|
export declare function fetchComponentFromRegistry(componentName: string, registryUrl?: string): Promise<RegistryItem>;
|
|
33
65
|
export declare function getAvailableComponents(registryUrl?: string): Promise<string[]>;
|
|
34
|
-
export
|
|
35
|
-
|
|
66
|
+
export interface TransformOptions {
|
|
67
|
+
/**
|
|
68
|
+
* O destino veio de `--path`, fora do alias configurado.
|
|
69
|
+
*
|
|
70
|
+
* Nesse caso os componentes do lote viram vizinhos no disco, e é o caminho
|
|
71
|
+
* relativo que resolve — o alias apontaria para a pasta onde eles não estão.
|
|
72
|
+
* `utils` e `core` continuam no alias, porque quem os instalou foi o `init`.
|
|
73
|
+
*/
|
|
74
|
+
readonly siblingComponents?: boolean;
|
|
75
|
+
}
|
|
76
|
+
export declare function transformContent(content: string, config: Config, options?: TransformOptions): string;
|
|
77
|
+
export declare function fetchComponent(componentName: string, config: Config, registryUrl?: string, options?: TransformOptions): Promise<RegistryItem>;
|
|
36
78
|
//# sourceMappingURL=registry.d.ts.map
|
package/utils/registry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/utils/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/utils/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAmD,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC5G,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAOnD,eAAO,MAAM,oBAAoB,QAE0D,CAAC;AAE5F;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,kFAAkF;IAClF,KAAK,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CACjD;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,oBAAoB,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM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Aa,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAInH;AAED,wBAAsB,sBAAsB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAGpF;AAOD,MAAM,WAAW,gBAAgB;IAC/B;;;;;;OAMG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CACtC;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAoDxG;AAED,wBAAsB,cAAc,CAClC,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,YAAY,CAAC,CAoCvB"}
|
package/utils/registry.js
CHANGED
|
@@ -1,38 +1,56 @@
|
|
|
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
|
+
* A família em que os arquivos do item estão escritos.
|
|
12
|
+
*
|
|
13
|
+
* Um item sem `icons` — publicado antes da propriedade — está em lucide, que
|
|
14
|
+
* era a única possibilidade. Um valor desconhecido também: preferir o palpite
|
|
15
|
+
* certo a recusar a instalação por causa de um campo novo.
|
|
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
|
+
let registryIndexCache = null;
|
|
32
41
|
export async function fetchRegistryIndex(registryUrl) {
|
|
33
42
|
const baseUrl = registryUrl || DEFAULT_REGISTRY_URL;
|
|
43
|
+
if (registryIndexCache && Date.now() - registryIndexCache.timestamp < CACHE_TTL) {
|
|
44
|
+
return registryIndexCache.data;
|
|
45
|
+
}
|
|
34
46
|
const url = `${baseUrl}/registry.json`;
|
|
35
|
-
|
|
47
|
+
const data = await fetchJson(url);
|
|
48
|
+
assertSupportedSchema(data.schemaVersion, 'registry.json');
|
|
49
|
+
registryIndexCache = { data, timestamp: Date.now() };
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
export function invalidateRegistryCache() {
|
|
53
|
+
registryIndexCache = null;
|
|
36
54
|
}
|
|
37
55
|
export async function fetchComponentFromRegistry(componentName, registryUrl) {
|
|
38
56
|
const baseUrl = registryUrl || DEFAULT_REGISTRY_URL;
|
|
@@ -43,9 +61,18 @@ export async function getAvailableComponents(registryUrl) {
|
|
|
43
61
|
const index = await fetchRegistryIndex(registryUrl);
|
|
44
62
|
return index.items.map(item => item.name);
|
|
45
63
|
}
|
|
46
|
-
|
|
64
|
+
/** Sem isto, um alias digitado como `@/ui/components/` produz `@/ui/components//button`. */
|
|
65
|
+
function trimSlashes(alias) {
|
|
66
|
+
return alias.replace(/\/+$/, '');
|
|
67
|
+
}
|
|
68
|
+
export function transformContent(content, config, options = {}) {
|
|
47
69
|
let transformed = content;
|
|
48
|
-
const
|
|
70
|
+
const aliases = {
|
|
71
|
+
components: options.siblingComponents ? '..' : trimSlashes(config.aliases.components),
|
|
72
|
+
utils: trimSlashes(config.aliases.utils),
|
|
73
|
+
core: trimSlashes(config.aliases.core),
|
|
74
|
+
services: trimSlashes(config.aliases.services),
|
|
75
|
+
};
|
|
49
76
|
// Replace utils imports
|
|
50
77
|
transformed = transformed.replace(/from ['"]\.\.\/\.\.\/shared\/utils\/utils['"]/g, `from '${aliases.utils}/merge-classes'`);
|
|
51
78
|
transformed = transformed.replace(/from ['"]\.\.\/\.\.\/shared\/utils\/number['"]/g, `from '${aliases.utils}/number'`);
|
|
@@ -55,14 +82,42 @@ export function transformContent(content, config) {
|
|
|
55
82
|
// Replace ClassValue imports
|
|
56
83
|
transformed = transformed.replace(/import \{ ClassValue \} from ['"]class-variance-authority\/dist\/types['"]/g, `import { ClassValue } from 'clsx'`);
|
|
57
84
|
transformed = transformed.replace(/import \{ ClassValue \} from ['"]class-variance-authority['"]/g, `import { ClassValue } from 'clsx'`);
|
|
85
|
+
// Transform default @/shared/* to match aliases
|
|
86
|
+
for (const [key, value] of Object.entries(aliases)) {
|
|
87
|
+
if (!value) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
// O subpath é opcional: `card.component.ts` importa o barrel direto
|
|
91
|
+
// (`from '@/shared/core'`). Exigindo `/algo` depois da chave, esse import
|
|
92
|
+
// escapava da substituição e o componente instalado continuava apontando
|
|
93
|
+
// para `@/shared/core` — uma pasta que não existe com alias customizado.
|
|
94
|
+
const regex = new RegExp(`(['"])@\\/shared\\/${key}(\\/[\\w\\-\\/.]+)?\\1`, 'g');
|
|
95
|
+
transformed = transformed.replace(regex, (_match, quote, subpath) => {
|
|
96
|
+
return `${quote}${value}${subpath ?? ''}${quote}`;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
58
99
|
return transformed;
|
|
59
100
|
}
|
|
60
|
-
export async function fetchComponent(componentName, config, registryUrl) {
|
|
101
|
+
export async function fetchComponent(componentName, config, registryUrl, options = {}) {
|
|
61
102
|
const item = await fetchComponentFromRegistry(componentName, registryUrl);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
103
|
+
if (!item.files || !Array.isArray(item.files)) {
|
|
104
|
+
throw new ConfigError(`Component "${componentName}" has no files in the registry`);
|
|
105
|
+
}
|
|
106
|
+
const sourceFamily = sourceFamilyOf(item);
|
|
107
|
+
const missing = new Set();
|
|
108
|
+
const transformedFiles = item.files.map(file => {
|
|
109
|
+
const retargeted = retargetIcons(transformContent(file.content, config, options), sourceFamily, config.icons, iconCatalog());
|
|
110
|
+
for (const symbol of retargeted.missing)
|
|
111
|
+
missing.add(symbol);
|
|
112
|
+
return { name: file.name, content: retargeted.content };
|
|
113
|
+
});
|
|
114
|
+
// Um ícone sem equivalente na família escolhida fica no símbolo original, e o
|
|
115
|
+
// import dele não resolve mais. Falhar a instalação inteira por causa disso
|
|
116
|
+
// seria pior: o resto do componente está correto e o conserto é uma linha.
|
|
117
|
+
if (missing.size > 0) {
|
|
118
|
+
logger.warn(`"${componentName}" uses icons that ${config.icons} does not provide: ${[...missing].sort().join(', ')}. ` +
|
|
119
|
+
'They were left untouched — replace them by hand.');
|
|
120
|
+
}
|
|
66
121
|
return {
|
|
67
122
|
...item,
|
|
68
123
|
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,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AAI,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,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A versão do FORMATO do registry que esta CLI entende.
|
|
3
|
+
*
|
|
4
|
+
* Não confundir com a versão do pacote, que o índice também publica: aquela diz
|
|
5
|
+
* de que release o conteúdo saiu, esta diz que forma ele tem. Sem separá-las não
|
|
6
|
+
* havia como o registry mudar de forma sem quebrar em silêncio quem já estava
|
|
7
|
+
* instalado — a CLI leria `files` de um item com outro shape e erraria calada.
|
|
8
|
+
*
|
|
9
|
+
* Sobe quando a mudança quebra quem lê: campo removido, significado alterado,
|
|
10
|
+
* item reorganizado. Campo novo e opcional não sobe nada.
|
|
11
|
+
*/
|
|
12
|
+
export declare const SUPPORTED_SCHEMA_VERSION = 1;
|
|
13
|
+
/**
|
|
14
|
+
* Recusa um documento mais novo do que esta CLI sabe ler.
|
|
15
|
+
*
|
|
16
|
+
* A ausência do campo é um registry anterior à existência dele, que por
|
|
17
|
+
* definição é a versão 1.
|
|
18
|
+
*/
|
|
19
|
+
export declare function assertSupportedSchema(schemaVersion: number | undefined, source: string): void;
|
|
20
|
+
//# 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;;;;;;;;;;GAUG;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,27 @@
|
|
|
1
|
+
import { SchemaVersionError } from '../utils/errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* A versão do FORMATO do registry que esta CLI entende.
|
|
4
|
+
*
|
|
5
|
+
* Não confundir com a versão do pacote, que o índice também publica: aquela diz
|
|
6
|
+
* de que release o conteúdo saiu, esta diz que forma ele tem. Sem separá-las não
|
|
7
|
+
* havia como o registry mudar de forma sem quebrar em silêncio quem já estava
|
|
8
|
+
* instalado — a CLI leria `files` de um item com outro shape e erraria calada.
|
|
9
|
+
*
|
|
10
|
+
* Sobe quando a mudança quebra quem lê: campo removido, significado alterado,
|
|
11
|
+
* item reorganizado. Campo novo e opcional não sobe nada.
|
|
12
|
+
*/
|
|
13
|
+
export const SUPPORTED_SCHEMA_VERSION = 1;
|
|
14
|
+
/**
|
|
15
|
+
* Recusa um documento mais novo do que esta CLI sabe ler.
|
|
16
|
+
*
|
|
17
|
+
* A ausência do campo é um registry anterior à existência dele, que por
|
|
18
|
+
* definição é a versão 1.
|
|
19
|
+
*/
|
|
20
|
+
export function assertSupportedSchema(schemaVersion, source) {
|
|
21
|
+
const version = schemaVersion ?? 1;
|
|
22
|
+
if (version > SUPPORTED_SCHEMA_VERSION) {
|
|
23
|
+
throw new SchemaVersionError(`This registry publishes ${source} in format v${version}, and this CLI reads up to v${SUPPORTED_SCHEMA_VERSION}. ` +
|
|
24
|
+
'Update it with `npm i -g zard-cli@latest`, or run it through npx, which always fetches the latest.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# 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;;;;;;;;;;GAUG;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
|
+
* Edições de código-fonte que mais de um passo do init precisa fazer.
|
|
3
|
+
*
|
|
4
|
+
* Inserir um import parece trivial até o arquivo estar em CRLF: um `\n` cru
|
|
5
|
+
* gera terminações misturadas, faz o git marcar o arquivo inteiro como alterado
|
|
6
|
+
* e — quando a expressão que procura os imports esquece o `\r` — emenda a linha
|
|
7
|
+
* nova no fim da anterior.
|
|
8
|
+
*/
|
|
9
|
+
/** A quebra de linha que o arquivo já usa. */
|
|
10
|
+
export declare function lineEndingOf(content: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Insere uma linha de import logo depois do último import do arquivo.
|
|
13
|
+
*
|
|
14
|
+
* Devolve o conteúdo intocado quando o import já está lá, para que chamar duas
|
|
15
|
+
* vezes seja o mesmo que chamar uma.
|
|
16
|
+
*/
|
|
17
|
+
export declare function withImport(content: string, importLine: string): string;
|
|
18
|
+
/** Onde um literal de array começa e termina, em índices do conteúdo. */
|
|
19
|
+
export interface ArrayRange {
|
|
20
|
+
/** Índice do `[` que abre. */
|
|
21
|
+
readonly open: number;
|
|
22
|
+
/** Índice do `]` que fecha. */
|
|
23
|
+
readonly close: number;
|
|
24
|
+
/** O que está entre os dois, sem os colchetes. */
|
|
25
|
+
readonly body: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* O intervalo do array atribuído a `key`, achado contando colchetes.
|
|
29
|
+
*
|
|
30
|
+
* Uma expressão regular para no primeiro `]` que aparece, e em código real esse
|
|
31
|
+
* `]` costuma ser o de um array aninhado — `withInterceptors([...])` num
|
|
32
|
+
* `providers`, um plugin com opções num `plugins`. O que fosse inserido ali
|
|
33
|
+
* caía dentro do array errado, e o build quebrava com um erro de tipo que não
|
|
34
|
+
* menciona ZardUI em lugar nenhum.
|
|
35
|
+
*
|
|
36
|
+
* Strings e comentários são pulados, para que um `]` escrito dentro deles não
|
|
37
|
+
* conte como fechamento.
|
|
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,8CAA8C;AAC9C,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,yEAAyE;AACzE,MAAM,WAAW,UAAU;IACzB,8BAA8B;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,kDAAkD;IAClD,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
|
+
* Edições de código-fonte que mais de um passo do init precisa fazer.
|
|
3
|
+
*
|
|
4
|
+
* Inserir um import parece trivial até o arquivo estar em CRLF: um `\n` cru
|
|
5
|
+
* gera terminações misturadas, faz o git marcar o arquivo inteiro como alterado
|
|
6
|
+
* e — quando a expressão que procura os imports esquece o `\r` — emenda a linha
|
|
7
|
+
* nova no fim da anterior.
|
|
8
|
+
*/
|
|
9
|
+
/** A quebra de linha que o arquivo já usa. */
|
|
10
|
+
export function lineEndingOf(content) {
|
|
11
|
+
return content.includes('\r\n') ? '\r\n' : '\n';
|
|
12
|
+
}
|
|
13
|
+
/** O último `import ... from '...'` do arquivo, ou null se não houver nenhum. */
|
|
14
|
+
function lastImport(content) {
|
|
15
|
+
// `[\s\S]*?` em vez de `.*`: a lista de símbolos importados quebra em várias
|
|
16
|
+
// linhas com frequência, e um padrão preso a uma linha só não a alcançava —
|
|
17
|
+
// num arquivo assim o import novo era jogado para antes de todos os outros.
|
|
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
|
+
* Insere uma linha de import logo depois do último import do arquivo.
|
|
27
|
+
*
|
|
28
|
+
* Devolve o conteúdo intocado quando o import já está lá, para que chamar duas
|
|
29
|
+
* vezes seja o mesmo que chamar uma.
|
|
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
|
+
* O intervalo do array atribuído a `key`, achado contando colchetes.
|
|
44
|
+
*
|
|
45
|
+
* Uma expressão regular para no primeiro `]` que aparece, e em código real esse
|
|
46
|
+
* `]` costuma ser o de um array aninhado — `withInterceptors([...])` num
|
|
47
|
+
* `providers`, um plugin com opções num `plugins`. O que fosse inserido ali
|
|
48
|
+
* caía dentro do array errado, e o build quebrava com um erro de tipo que não
|
|
49
|
+
* menciona ZardUI em lugar nenhum.
|
|
50
|
+
*
|
|
51
|
+
* Strings e comentários são pulados, para que um `]` escrito dentro deles não
|
|
52
|
+
* conte como fechamento.
|
|
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
|
+
* O índice logo após a string ou o comentário que começa em `index`.
|
|
77
|
+
*
|
|
78
|
+
* Devolve o próprio `index` quando não há nenhum ali — quem chama usa isso para
|
|
79
|
+
* saber que o caractere é código e deve ser considerado.
|
|
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,8CAA8C;AAC9C,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,iFAAiF;AACjF,SAAS,UAAU,CAAC,OAAe;IACjC,6EAA6E;IAC7E,4EAA4E;IAC5E,4EAA4E;IAC5E,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,GAAG,YAAY,CAAC,OAAO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AAE,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,UAAU,GAAG,sDAAsD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