zard-cli 1.0.0-beta.99 → 1.0.1
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 +98 -36
- package/commands/add/component-installer.d.ts +3 -0
- package/commands/add/component-installer.d.ts.map +1 -1
- package/commands/add/component-installer.js +31 -8
- 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 +16 -11
- package/commands/add/dark-mode-setup.js.map +1 -1
- package/commands/add/dependency-resolver.d.ts +8 -1
- package/commands/add/dependency-resolver.d.ts.map +1 -1
- package/commands/add/dependency-resolver.js +87 -16
- package/commands/add/dependency-resolver.js.map +1 -1
- package/commands/add/index.d.ts.map +1 -1
- package/commands/add/index.js +142 -96
- 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 +65 -3
- package/commands/init/config-prompter.d.ts.map +1 -1
- package/commands/init/config-prompter.js +93 -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 +54 -24
- package/commands/init/dependencies.js.map +1 -1
- package/commands/init/index.d.ts.map +1 -1
- package/commands/init/index.js +175 -81
- package/commands/init/index.js.map +1 -1
- package/commands/init/library-peers.d.ts +28 -0
- package/commands/init/library-peers.d.ts.map +1 -0
- package/commands/init/library-peers.js +61 -0
- package/commands/init/library-peers.js.map +1 -0
- 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 +188 -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 +47 -12
- package/commands/init/tailwind-setup.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 -50
- 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 +33 -0
- package/commands/init/wizard.d.ts.map +1 -0
- package/commands/init/wizard.js +561 -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 +498 -36
- package/core/registry/registry-data.js.map +1 -1
- package/core/themes/theme-definitions.d.ts.map +1 -1
- package/core/themes/theme-definitions.js +61 -72
- package/core/themes/theme-definitions.js.map +1 -1
- package/index.js +6 -3
- package/index.js.map +1 -1
- package/package.json +6 -11
- 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 +29 -0
- package/utils/config.d.ts.map +1 -1
- package/utils/config.js +50 -4
- package/utils/config.js.map +1 -1
- package/utils/errors.d.ts +11 -0
- package/utils/errors.d.ts.map +1 -1
- package/utils/errors.js +14 -0
- package/utils/errors.js.map +1 -1
- package/utils/get-project-info.d.ts +29 -0
- package/utils/get-project-info.d.ts.map +1 -1
- package/utils/get-project-info.js +246 -1
- package/utils/get-project-info.js.map +1 -1
- package/utils/http-client.d.ts.map +1 -1
- package/utils/http-client.js +18 -3
- package/utils/http-client.js.map +1 -1
- 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 +13 -1
- package/utils/logger.d.ts.map +1 -1
- package/utils/logger.js +95 -15
- package/utils/logger.js.map +1 -1
- package/utils/package-manager.d.ts +42 -1
- package/utils/package-manager.d.ts.map +1 -1
- package/utils/package-manager.js +204 -11
- package/utils/package-manager.js.map +1 -1
- package/utils/registry.d.ts +106 -2
- package/utils/registry.d.ts.map +1 -1
- package/utils/registry.js +155 -21
- 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/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
|
+
* The icons a component draws, as the registry publishes them.
|
|
6
|
+
*
|
|
7
|
+
* `family` is the family the files are written in — anyone installing with a
|
|
8
|
+
* different family in `components.json` learns from this field that they need
|
|
9
|
+
* rewriting. Absent from items published before this property existed.
|
|
10
|
+
*/
|
|
11
|
+
export interface RegistryIcons {
|
|
12
|
+
family: string;
|
|
13
|
+
symbols: string[];
|
|
14
|
+
tokens: string[];
|
|
15
|
+
/** The icons that only appear in the demos. Absent from the index, which does not carry them. */
|
|
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,43 @@ export interface RegistryItem {
|
|
|
11
29
|
dependencies?: string[];
|
|
12
30
|
devDependencies?: string[];
|
|
13
31
|
registryDependencies?: string[];
|
|
32
|
+
icons?: RegistryIcons;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A block, as the registry publishes it.
|
|
36
|
+
*
|
|
37
|
+
* Blocks live under `/blocks/` in their own index, and their file entries carry
|
|
38
|
+
* a `path` the components' do not — so they get their own type instead of being
|
|
39
|
+
* bent into `RegistryItem`.
|
|
40
|
+
*/
|
|
41
|
+
export interface BlockItem {
|
|
42
|
+
id: string;
|
|
43
|
+
title: string;
|
|
44
|
+
description: string;
|
|
45
|
+
category: string;
|
|
46
|
+
registryDependencies?: string[];
|
|
47
|
+
dependencies?: string[];
|
|
48
|
+
files: Array<{
|
|
49
|
+
name: string;
|
|
50
|
+
path: string;
|
|
51
|
+
content: string;
|
|
52
|
+
language: string;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
55
|
+
export interface BlocksIndex {
|
|
56
|
+
blocks: Array<{
|
|
57
|
+
id: string;
|
|
58
|
+
title: string;
|
|
59
|
+
description: string;
|
|
60
|
+
category: string;
|
|
61
|
+
registryDependencies?: string[];
|
|
62
|
+
dependencies?: string[];
|
|
63
|
+
}>;
|
|
14
64
|
}
|
|
15
65
|
export interface RegistryIndex {
|
|
16
66
|
$schema: string;
|
|
67
|
+
/** The file's shape. Absent from registries older than the field. */
|
|
68
|
+
schemaVersion?: number;
|
|
17
69
|
name: string;
|
|
18
70
|
homepage: string;
|
|
19
71
|
version: string;
|
|
@@ -24,15 +76,67 @@ export interface RegistryIndex {
|
|
|
24
76
|
dependencies?: string[];
|
|
25
77
|
devDependencies?: string[];
|
|
26
78
|
registryDependencies?: string[];
|
|
79
|
+
icons?: RegistryIcons;
|
|
27
80
|
files: string[];
|
|
28
81
|
}>;
|
|
29
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* The family the item's files are written in.
|
|
85
|
+
*
|
|
86
|
+
* An item with no `icons` — published before the property existed — is in
|
|
87
|
+
* lucide, which was the only possibility. So is an unknown value: better the
|
|
88
|
+
* right guess than refusing to install over an unfamiliar field.
|
|
89
|
+
*/
|
|
90
|
+
export declare function sourceFamilyOf(item: Pick<RegistryItem, 'icons'>): IconFamily;
|
|
30
91
|
export declare function getRegistryUrl(config?: Config): string;
|
|
31
92
|
export declare function validateRegistryUrl(url: string): void;
|
|
32
93
|
export declare function fetchRegistryIndex(registryUrl?: string): Promise<RegistryIndex>;
|
|
33
94
|
export declare function invalidateRegistryCache(): void;
|
|
34
95
|
export declare function fetchComponentFromRegistry(componentName: string, registryUrl?: string): Promise<RegistryItem>;
|
|
96
|
+
/**
|
|
97
|
+
* The block index, cached like the component one.
|
|
98
|
+
*
|
|
99
|
+
* A registry that predates blocks has no `blocks-registry.json`; that is not an
|
|
100
|
+
* error, it just means this registry publishes none.
|
|
101
|
+
*/
|
|
102
|
+
export declare function fetchBlocksIndex(registryUrl?: string): Promise<BlocksIndex>;
|
|
103
|
+
export declare function fetchBlockFromRegistry(blockId: string, registryUrl?: string): Promise<BlockItem>;
|
|
104
|
+
export declare function getAvailableBlocks(registryUrl?: string): Promise<string[]>;
|
|
35
105
|
export declare function getAvailableComponents(registryUrl?: string): Promise<string[]>;
|
|
36
|
-
export
|
|
37
|
-
|
|
106
|
+
export interface TransformOptions {
|
|
107
|
+
/**
|
|
108
|
+
* The destination came from `--path`, outside the configured alias.
|
|
109
|
+
*
|
|
110
|
+
* In that case the batch's components become neighbours on disk, and the
|
|
111
|
+
* relative path is what resolves — the alias would point at the folder they are
|
|
112
|
+
* not in. `utils` and `core` stay on the alias, because `init` installed them.
|
|
113
|
+
*/
|
|
114
|
+
readonly siblingComponents?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Where the file sits inside its registry item (`i18n/locales/en-us.ts`).
|
|
117
|
+
*
|
|
118
|
+
* A `../` only points at another component when it climbs out of the item.
|
|
119
|
+
* From a nested file it can stay inside — `core/i18n/locales/en-us.ts`
|
|
120
|
+
* importing `../i18n.types` — and turning that into the components alias made
|
|
121
|
+
* every fresh `init` ship imports that do not resolve.
|
|
122
|
+
*/
|
|
123
|
+
readonly fileName?: string;
|
|
124
|
+
}
|
|
125
|
+
export declare function transformContent(content: string, config: Config, options?: TransformOptions): string;
|
|
126
|
+
/**
|
|
127
|
+
* Rewrites aliased imports as paths relative to the file that holds them.
|
|
128
|
+
*
|
|
129
|
+
* A library cannot ship `@/shared/...`: ng-packagr leaves non-relative imports
|
|
130
|
+
* external, so the published bundle kept importing a path that only the
|
|
131
|
+
* library's own workspace maps — and every app installing it from npm failed to
|
|
132
|
+
* resolve them. Relative imports get bundled, and keep working inside the
|
|
133
|
+
* workspace too.
|
|
134
|
+
*
|
|
135
|
+
* `targets` pairs each alias with the directory it stands for. The longest
|
|
136
|
+
* alias goes first, so `@/shared/components` is not taken for a shorter prefix.
|
|
137
|
+
*/
|
|
138
|
+
export declare function relativizeImports(content: string, filePath: string, targets: Record<string, string>): string;
|
|
139
|
+
export declare function fetchComponent(componentName: string, config: Config, registryUrl?: string, options?: TransformOptions & {
|
|
140
|
+
isBlock?: boolean;
|
|
141
|
+
}): Promise<RegistryItem>;
|
|
38
142
|
//# 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,sB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AMILY } from '../core/icons/index.js';
|
|
2
3
|
import { ConfigError } from '../utils/errors.js';
|
|
3
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';
|
|
8
|
+
import * as path from 'node:path';
|
|
4
9
|
export const DEFAULT_REGISTRY_URL = process.env['ZARD_REGISTRY_URL'] ||
|
|
5
10
|
(BUILD_REGISTRY_URL !== '__REGISTRY_URL__' ? BUILD_REGISTRY_URL : 'https://zardui.com/r');
|
|
11
|
+
/**
|
|
12
|
+
* The family the item's files are written in.
|
|
13
|
+
*
|
|
14
|
+
* An item with no `icons` — published before the property existed — is in
|
|
15
|
+
* lucide, which was the only possibility. So is an unknown value: better the
|
|
16
|
+
* right guess than refusing to install over an unfamiliar field.
|
|
17
|
+
*/
|
|
18
|
+
export function sourceFamilyOf(item) {
|
|
19
|
+
const family = item.icons?.family;
|
|
20
|
+
return family !== undefined && isIconFamily(family, iconCatalog()) ? family : SOURCE_ICON_FAMILY;
|
|
21
|
+
}
|
|
6
22
|
export function getRegistryUrl(config) {
|
|
7
23
|
return config?.registryUrl || DEFAULT_REGISTRY_URL;
|
|
8
24
|
}
|
|
@@ -22,38 +38,95 @@ export function validateRegistryUrl(url) {
|
|
|
22
38
|
}
|
|
23
39
|
}
|
|
24
40
|
const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
|
25
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Keyed by registry URL, not global.
|
|
43
|
+
*
|
|
44
|
+
* `registryUrl` is a `components.json` field, so two registries can be read in one
|
|
45
|
+
* run — and a single cache entry handed the second call the first registry's index.
|
|
46
|
+
*/
|
|
47
|
+
const registryIndexCache = new Map();
|
|
26
48
|
export async function fetchRegistryIndex(registryUrl) {
|
|
27
49
|
const baseUrl = registryUrl || DEFAULT_REGISTRY_URL;
|
|
28
|
-
|
|
29
|
-
|
|
50
|
+
const cached = registryIndexCache.get(baseUrl);
|
|
51
|
+
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
|
|
52
|
+
return cached.data;
|
|
30
53
|
}
|
|
31
54
|
const url = `${baseUrl}/registry.json`;
|
|
32
55
|
const data = await fetchJson(url);
|
|
33
|
-
|
|
56
|
+
assertSupportedSchema(data.schemaVersion, 'registry.json');
|
|
57
|
+
registryIndexCache.set(baseUrl, { data, timestamp: Date.now() });
|
|
34
58
|
return data;
|
|
35
59
|
}
|
|
36
60
|
export function invalidateRegistryCache() {
|
|
37
|
-
registryIndexCache
|
|
61
|
+
registryIndexCache.clear();
|
|
62
|
+
blocksIndexCache.clear();
|
|
38
63
|
}
|
|
39
64
|
export async function fetchComponentFromRegistry(componentName, registryUrl) {
|
|
40
65
|
const baseUrl = registryUrl || DEFAULT_REGISTRY_URL;
|
|
41
66
|
const url = `${baseUrl}/${componentName}.json`;
|
|
42
67
|
return fetchJson(url);
|
|
43
68
|
}
|
|
69
|
+
const blocksIndexCache = new Map();
|
|
70
|
+
/**
|
|
71
|
+
* The block index, cached like the component one.
|
|
72
|
+
*
|
|
73
|
+
* A registry that predates blocks has no `blocks-registry.json`; that is not an
|
|
74
|
+
* error, it just means this registry publishes none.
|
|
75
|
+
*/
|
|
76
|
+
export async function fetchBlocksIndex(registryUrl) {
|
|
77
|
+
const baseUrl = registryUrl || DEFAULT_REGISTRY_URL;
|
|
78
|
+
const cached = blocksIndexCache.get(baseUrl);
|
|
79
|
+
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
|
|
80
|
+
return cached.data;
|
|
81
|
+
}
|
|
82
|
+
let data;
|
|
83
|
+
try {
|
|
84
|
+
data = await fetchJson(`${baseUrl}/blocks-registry.json`);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
data = { blocks: [] };
|
|
88
|
+
}
|
|
89
|
+
blocksIndexCache.set(baseUrl, { data, timestamp: Date.now() });
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
92
|
+
export async function fetchBlockFromRegistry(blockId, registryUrl) {
|
|
93
|
+
const baseUrl = registryUrl || DEFAULT_REGISTRY_URL;
|
|
94
|
+
return fetchJson(`${baseUrl}/blocks/${blockId}.json`);
|
|
95
|
+
}
|
|
96
|
+
export async function getAvailableBlocks(registryUrl) {
|
|
97
|
+
const index = await fetchBlocksIndex(registryUrl);
|
|
98
|
+
return index.blocks.map(block => block.id);
|
|
99
|
+
}
|
|
44
100
|
export async function getAvailableComponents(registryUrl) {
|
|
45
101
|
const index = await fetchRegistryIndex(registryUrl);
|
|
46
102
|
return index.items.map(item => item.name);
|
|
47
103
|
}
|
|
48
|
-
|
|
104
|
+
/** Sem isto, um alias digitado como `@/ui/components/` produz `@/ui/components//button`. */
|
|
105
|
+
function trimSlashes(alias) {
|
|
106
|
+
return alias.replace(/\/+$/, '');
|
|
107
|
+
}
|
|
108
|
+
export function transformContent(content, config, options = {}) {
|
|
49
109
|
let transformed = content;
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
110
|
+
const aliases = {
|
|
111
|
+
components: options.siblingComponents ? '..' : trimSlashes(config.aliases.components),
|
|
112
|
+
utils: trimSlashes(config.aliases.utils),
|
|
113
|
+
core: trimSlashes(config.aliases.core),
|
|
114
|
+
services: trimSlashes(config.aliases.services),
|
|
115
|
+
};
|
|
116
|
+
/*
|
|
117
|
+
* Blocks are authored inside the monorepo, so their sources import the library
|
|
118
|
+
* by its workspace alias (`@zard/components/card/card.imports`). Nothing maps
|
|
119
|
+
* that name in the installing project — left alone, every block would arrive
|
|
120
|
+
* with imports that do not resolve.
|
|
121
|
+
*/
|
|
122
|
+
transformed = transformed.replace(/(['"])@zard\/components\/([\w\-/.]+)\1/g, (_match, quote, subpath) => `${quote}${aliases.components}/${subpath}${quote}`);
|
|
123
|
+
// Replace relative imports that leave the item (`../button/button.component`)
|
|
124
|
+
// with the components alias; the ones that stay inside it are left relative.
|
|
125
|
+
const fileDir = path.posix.dirname(options.fileName ?? '');
|
|
126
|
+
transformed = transformed.replace(/from ['"](\.\.\/[\w\-/.]+)['"]/g, (match, specifier) => {
|
|
127
|
+
const resolved = path.posix.normalize(path.posix.join(fileDir, specifier));
|
|
128
|
+
return resolved.startsWith('../') ? `from '${aliases.components}/${resolved.slice(3)}'` : match;
|
|
129
|
+
});
|
|
57
130
|
// Replace ClassValue imports
|
|
58
131
|
transformed = transformed.replace(/import \{ ClassValue \} from ['"]class-variance-authority\/dist\/types['"]/g, `import { ClassValue } from 'clsx'`);
|
|
59
132
|
transformed = transformed.replace(/import \{ ClassValue \} from ['"]class-variance-authority['"]/g, `import { ClassValue } from 'clsx'`);
|
|
@@ -62,20 +135,81 @@ export function transformContent(content, config) {
|
|
|
62
135
|
if (!value) {
|
|
63
136
|
continue;
|
|
64
137
|
}
|
|
65
|
-
|
|
66
|
-
|
|
138
|
+
// The subpath is optional: `card.component.ts` imports the barrel directly
|
|
139
|
+
// (`from '@/shared/core'`). Requiring `/something` after the key let that
|
|
140
|
+
// import escape the substitution, and the installed component kept pointing
|
|
141
|
+
// at `@/shared/core` — a folder that does not exist under a custom alias.
|
|
142
|
+
const regex = new RegExp(`(['"])@\\/shared\\/${key}(\\/[\\w\\-\\/.]+)?\\1`, 'g');
|
|
143
|
+
transformed = transformed.replace(regex, (_match, quote, subpath) => {
|
|
144
|
+
return `${quote}${value}${subpath ?? ''}${quote}`;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return transformed;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Rewrites aliased imports as paths relative to the file that holds them.
|
|
151
|
+
*
|
|
152
|
+
* A library cannot ship `@/shared/...`: ng-packagr leaves non-relative imports
|
|
153
|
+
* external, so the published bundle kept importing a path that only the
|
|
154
|
+
* library's own workspace maps — and every app installing it from npm failed to
|
|
155
|
+
* resolve them. Relative imports get bundled, and keep working inside the
|
|
156
|
+
* workspace too.
|
|
157
|
+
*
|
|
158
|
+
* `targets` pairs each alias with the directory it stands for. The longest
|
|
159
|
+
* alias goes first, so `@/shared/components` is not taken for a shorter prefix.
|
|
160
|
+
*/
|
|
161
|
+
export function relativizeImports(content, filePath, targets) {
|
|
162
|
+
const fileDir = path.dirname(filePath);
|
|
163
|
+
let transformed = content;
|
|
164
|
+
for (const [alias, dir] of Object.entries(targets).sort(([a], [b]) => b.length - a.length)) {
|
|
165
|
+
const escaped = trimSlashes(alias).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
166
|
+
const regex = new RegExp(`(['"])${escaped}(\\/[\\w\\-\\/.]+)?\\1`, 'g');
|
|
167
|
+
transformed = transformed.replace(regex, (_match, quote, subpath) => {
|
|
168
|
+
const target = path.join(dir, ...(subpath ?? '').split('/').filter(Boolean));
|
|
169
|
+
const relative = path.relative(fileDir, target).split(path.sep).join('/') || '.';
|
|
170
|
+
return `${quote}${relative.startsWith('.') ? relative : `./${relative}`}${quote}`;
|
|
171
|
+
});
|
|
67
172
|
}
|
|
68
173
|
return transformed;
|
|
69
174
|
}
|
|
70
|
-
|
|
71
|
-
|
|
175
|
+
/**
|
|
176
|
+
* A block in the shape the installer already understands.
|
|
177
|
+
*
|
|
178
|
+
* The two differ only in what the registry carries: a block entry adds `path`
|
|
179
|
+
* and `language` per file, neither of which affects how the files are written.
|
|
180
|
+
*/
|
|
181
|
+
function blockAsRegistryItem(block) {
|
|
182
|
+
return {
|
|
183
|
+
name: block.id,
|
|
184
|
+
type: 'registry:component',
|
|
185
|
+
basePath: 'blocks',
|
|
186
|
+
dependencies: block.dependencies,
|
|
187
|
+
registryDependencies: block.registryDependencies,
|
|
188
|
+
files: block.files.map(file => ({ name: file.name, content: file.content })),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export async function fetchComponent(componentName, config, registryUrl, options = {}) {
|
|
192
|
+
const item = options.isBlock
|
|
193
|
+
? blockAsRegistryItem(await fetchBlockFromRegistry(componentName, registryUrl))
|
|
194
|
+
: await fetchComponentFromRegistry(componentName, registryUrl);
|
|
72
195
|
if (!item.files || !Array.isArray(item.files)) {
|
|
73
196
|
throw new ConfigError(`Component "${componentName}" has no files in the registry`);
|
|
74
197
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
198
|
+
const sourceFamily = sourceFamilyOf(item);
|
|
199
|
+
const missing = new Set();
|
|
200
|
+
const transformedFiles = item.files.map(file => {
|
|
201
|
+
const retargeted = retargetIcons(transformContent(file.content, config, { ...options, fileName: file.name }), sourceFamily, config.icons, iconCatalog());
|
|
202
|
+
for (const symbol of retargeted.missing)
|
|
203
|
+
missing.add(symbol);
|
|
204
|
+
return { name: file.name, content: retargeted.content };
|
|
205
|
+
});
|
|
206
|
+
// An icon with no equivalent in the chosen family keeps its original symbol,
|
|
207
|
+
// and its import no longer resolves. Failing the whole install over that would
|
|
208
|
+
// be worse: the rest of the component is correct and the fix is one line.
|
|
209
|
+
if (missing.size > 0) {
|
|
210
|
+
logger.warn(`"${componentName}" uses icons that ${config.icons} does not provide: ${[...missing].sort().join(', ')}. ` +
|
|
211
|
+
'They were left untouched — replace them by hand.');
|
|
212
|
+
}
|
|
79
213
|
return {
|
|
80
214
|
...item,
|
|
81
215
|
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,EA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AC;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,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;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