zard-cli 1.0.0-beta.98 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -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 +10 -4
- 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.map +1 -1
- package/commands/add/dark-mode-setup.js +2 -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 +128 -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 +55 -3
- 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 -25
- package/commands/init/dependencies.js.map +1 -1
- package/commands/init/index.d.ts.map +1 -1
- package/commands/init/index.js +147 -81
- 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 -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 +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 +482 -37
- 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 +176 -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 +84 -2
- package/utils/registry.d.ts.map +1 -1
- package/utils/registry.js +121 -18
- 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.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { DEFAULT_REGISTRY_URL as BUILD_REGISTRY_URL } from '../config/registry-config.js';
|
|
2
|
+
import { isIconFamily, retargetIcons, SOURCE_ICON_FAMILY } 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';
|
|
4
8
|
export const DEFAULT_REGISTRY_URL = process.env['ZARD_REGISTRY_URL'] ||
|
|
5
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
|
+
}
|
|
6
21
|
export function getRegistryUrl(config) {
|
|
7
22
|
return config?.registryUrl || DEFAULT_REGISTRY_URL;
|
|
8
23
|
}
|
|
@@ -22,35 +37,88 @@ export function validateRegistryUrl(url) {
|
|
|
22
37
|
}
|
|
23
38
|
}
|
|
24
39
|
const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
|
25
|
-
|
|
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();
|
|
26
47
|
export async function fetchRegistryIndex(registryUrl) {
|
|
27
48
|
const baseUrl = registryUrl || DEFAULT_REGISTRY_URL;
|
|
28
|
-
|
|
29
|
-
|
|
49
|
+
const cached = registryIndexCache.get(baseUrl);
|
|
50
|
+
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
|
|
51
|
+
return cached.data;
|
|
30
52
|
}
|
|
31
53
|
const url = `${baseUrl}/registry.json`;
|
|
32
54
|
const data = await fetchJson(url);
|
|
33
|
-
|
|
55
|
+
assertSupportedSchema(data.schemaVersion, 'registry.json');
|
|
56
|
+
registryIndexCache.set(baseUrl, { data, timestamp: Date.now() });
|
|
34
57
|
return data;
|
|
35
58
|
}
|
|
36
59
|
export function invalidateRegistryCache() {
|
|
37
|
-
registryIndexCache
|
|
60
|
+
registryIndexCache.clear();
|
|
61
|
+
blocksIndexCache.clear();
|
|
38
62
|
}
|
|
39
63
|
export async function fetchComponentFromRegistry(componentName, registryUrl) {
|
|
40
64
|
const baseUrl = registryUrl || DEFAULT_REGISTRY_URL;
|
|
41
65
|
const url = `${baseUrl}/${componentName}.json`;
|
|
42
66
|
return fetchJson(url);
|
|
43
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
|
+
}
|
|
44
99
|
export async function getAvailableComponents(registryUrl) {
|
|
45
100
|
const index = await fetchRegistryIndex(registryUrl);
|
|
46
101
|
return index.items.map(item => item.name);
|
|
47
102
|
}
|
|
48
|
-
|
|
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 = {}) {
|
|
49
108
|
let transformed = content;
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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}`);
|
|
54
122
|
// Replace relative component imports with aliased imports
|
|
55
123
|
const componentImportRegex = /from ['"]\.\.\/([\w-/.]+)['"]/g;
|
|
56
124
|
transformed = transformed.replace(componentImportRegex, `from '${aliases.components}/$1'`);
|
|
@@ -62,20 +130,55 @@ export function transformContent(content, config) {
|
|
|
62
130
|
if (!value) {
|
|
63
131
|
continue;
|
|
64
132
|
}
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
});
|
|
67
141
|
}
|
|
68
142
|
return transformed;
|
|
69
143
|
}
|
|
70
|
-
|
|
71
|
-
|
|
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);
|
|
72
164
|
if (!item.files || !Array.isArray(item.files)) {
|
|
73
165
|
throw new ConfigError(`Component "${componentName}" has no files in the registry`);
|
|
74
166
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
+
}
|
|
79
182
|
return {
|
|
80
183
|
...item,
|
|
81
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,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,kBAAkB,CAAC;AACnG,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,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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;IAEjC,IAAI,CAAC,IAAI;Q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