@astryxdesign/cli 0.7.4 → 0.7.5-canary.2a50a80
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 +18 -18
- package/api/icon/_adapter.d.mts +3 -2
- package/api/icon/_adapter.mjs +16 -3
- package/api/icon/_authoring.d.mts +5 -1
- package/api/icon/_authoring.mjs +478 -63
- package/api/icon/_options.d.mts +11 -0
- package/api/icon/_options.mjs +39 -4
- package/api/icon/_records.d.mts +19 -0
- package/api/icon/_records.mjs +25 -0
- package/api/icon/add/add.d.mts +3 -3
- package/api/icon/add/add.mjs +227 -14
- package/api/icon/all-or-nothing.test.mjs +283 -0
- package/api/icon/detail/detail.mjs +2 -13
- package/api/icon/error-codes.test.mjs +14 -7
- package/api/icon/icon.d.mts +2 -2
- package/api/icon/icon.doc.mjs +30 -2
- package/api/icon/icon.mjs +57 -8
- package/api/icon/icon.test.mjs +133 -1
- package/api/icon/icon.type.d.mts +126 -1
- package/api/icon/icon.type.mjs +67 -3
- package/api/icon/iconAdd.doc.mjs +22 -6
- package/api/icon/iconMap.doc.mjs +24 -8
- package/api/icon/iconNewDefinition.doc.mjs +2 -2
- package/api/icon/iconNewSet.doc.mjs +30 -2
- package/api/icon/iconUse.doc.mjs +4 -1
- package/api/icon/map/map.d.mts +4 -4
- package/api/icon/map/map.mjs +134 -9
- package/api/icon/new-definition/new-definition.mjs +6 -2
- package/api/icon/new-set/new-set.mjs +2 -2
- package/api/icon/new-set/new-set.test.mjs +60 -10
- package/api/icon/option-pairs.test.mjs +368 -0
- package/api/icon/search/search.d.mts +10 -0
- package/api/icon/search/search.mjs +55 -14
- package/api/icon/use/use.mjs +2 -13
- package/api/integration/add-helpers.d.mts +15 -1
- package/api/integration/add-helpers.mjs +1 -1
- package/api/integration/validate-integration.type.d.mts +3 -2
- package/api/integration/validate-integration.type.mjs +3 -2
- package/api/template/template.type.d.mts +2 -1
- package/api/template/template.type.mjs +1 -1
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
- package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +50 -20
- package/assets/icons/definitions/activity.doc.mjs +1 -1
- package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
- package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
- package/assets/icons/definitions/alignStart.doc.mjs +10 -0
- package/assets/icons/definitions/archive.doc.mjs +1 -1
- package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
- package/assets/icons/definitions/attach.doc.mjs +1 -1
- package/assets/icons/definitions/audio.doc.mjs +1 -1
- package/assets/icons/definitions/cart.doc.mjs +1 -1
- package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
- package/assets/icons/definitions/close.doc.mjs +1 -1
- package/assets/icons/definitions/collapse.doc.mjs +1 -1
- package/assets/icons/definitions/compose.doc.mjs +1 -1
- package/assets/icons/definitions/conversation.doc.mjs +1 -1
- package/assets/icons/definitions/copy.doc.mjs +1 -1
- package/assets/icons/definitions/cpu.doc.mjs +9 -0
- package/assets/icons/definitions/database.doc.mjs +1 -1
- package/assets/icons/definitions/desktop.doc.mjs +1 -1
- package/assets/icons/definitions/discount.doc.mjs +1 -1
- package/assets/icons/definitions/download.doc.mjs +1 -1
- package/assets/icons/definitions/emoji.doc.mjs +1 -1
- package/assets/icons/definitions/error.doc.mjs +1 -1
- package/assets/icons/definitions/expand.doc.mjs +1 -1
- package/assets/icons/definitions/experiment.doc.mjs +1 -1
- package/assets/icons/definitions/externalLink.doc.mjs +7 -1
- package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
- package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
- package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
- package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
- package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
- package/assets/icons/definitions/gitFork.doc.mjs +9 -0
- package/assets/icons/definitions/info.doc.mjs +1 -1
- package/assets/icons/definitions/location.doc.mjs +1 -1
- package/assets/icons/definitions/mention.doc.mjs +1 -1
- package/assets/icons/definitions/menu.doc.mjs +1 -1
- package/assets/icons/definitions/microphone.doc.mjs +1 -1
- package/assets/icons/definitions/mobile.doc.mjs +1 -1
- package/assets/icons/definitions/money.doc.mjs +1 -1
- package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
- package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
- package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
- package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
- package/assets/icons/definitions/panelRight.doc.mjs +10 -0
- package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
- package/assets/icons/definitions/redo.doc.mjs +1 -1
- package/assets/icons/definitions/refresh.doc.mjs +1 -1
- package/assets/icons/definitions/rotate.doc.mjs +9 -0
- package/assets/icons/definitions/scale.doc.mjs +10 -0
- package/assets/icons/definitions/search.doc.mjs +1 -1
- package/assets/icons/definitions/send.doc.mjs +1 -1
- package/assets/icons/definitions/settings.doc.mjs +1 -1
- package/assets/icons/definitions/star.doc.mjs +1 -1
- package/assets/icons/definitions/stop.doc.mjs +1 -1
- package/assets/icons/definitions/success.doc.mjs +1 -1
- package/assets/icons/definitions/textCase.doc.mjs +9 -0
- package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
- package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
- package/assets/icons/definitions/trendDown.doc.mjs +7 -1
- package/assets/icons/definitions/trendUp.doc.mjs +1 -1
- package/assets/icons/definitions/undo.doc.mjs +1 -1
- package/assets/icons/definitions/upload.doc.mjs +1 -1
- package/assets/icons/definitions/userAdd.doc.mjs +1 -1
- package/assets/icons/definitions/warning.doc.mjs +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +9 -8
- package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
- package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
- package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
- package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
- package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
- package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
- package/authoring/doctypes/icon-set/parse.d.mts +1 -0
- package/authoring/doctypes/icon-set/parse.mjs +1 -0
- package/authoring/doctypes/icon-set/type.ts +5 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +2 -1
- package/clients/cli/commands/doctor.mjs +16 -17
- package/clients/cli/commands/experimental/icon.mjs +167 -35
- package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
- package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
- package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
- package/clients/cli/commands/experimental.doc.mjs +2 -1
- package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
- package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
- package/clients/cli/commands/icon.test.mjs +1 -1
- package/clients/cli/commands/template.mjs +4 -1
- package/foundation/discovery/component-discovery.d.mts +2 -1
- package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
- package/foundation/discovery/component-discovery.mjs +13 -7
- package/foundation/discovery/icon-set-checks.d.mts +43 -9
- package/foundation/discovery/icon-set-checks.mjs +296 -21
- package/foundation/discovery/icon-set-checks.test.mjs +125 -12
- package/foundation/discovery/icon-set-writer.d.mts +192 -3
- package/foundation/discovery/icon-set-writer.mjs +608 -34
- package/foundation/discovery/icon-set-writer.test.mjs +26 -0
- package/foundation/discovery/module-exports.mjs +82 -25
- package/foundation/discovery/module-exports.test.mjs +38 -1
- package/foundation/discovery/package-exports.d.mts +13 -0
- package/foundation/discovery/package-exports.mjs +40 -1
- package/foundation/discovery/template-icons.d.mts +6 -0
- package/foundation/discovery/template-icons.mjs +98 -10
- package/foundation/discovery/template-icons.test.mjs +103 -0
- package/foundation/doc-compiler/tree.mjs +3 -1
- package/foundation/response/response-types.doc.mjs +25 -1
- package/foundation/text/string-utils.mjs +33 -0
- package/foundation/text/string-utils.test.mjs +17 -0
- package/package.json +9 -9
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Every pair of options an icon command declares has a decided result
|
|
5
|
+
* (spec:AST-042 FR5): for each command, the pairs come from its CommandDoc
|
|
6
|
+
* (its options and its optional arguments; a required argument is always
|
|
7
|
+
* given), and each pair is either
|
|
8
|
+
* - refused together with `ERR_INVALID_OPTION` (the `refused` table), or
|
|
9
|
+
* - composed: the call succeeds with both (the `composes` table), or
|
|
10
|
+
* - prevented by another rule: the call fails with another code the
|
|
11
|
+
* function documents (every other pair).
|
|
12
|
+
* A pair that succeeds without being listed as composing fails this test, so
|
|
13
|
+
* a new option, or a change that starts ignoring one, is decided in review.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import * as fs from 'node:fs';
|
|
17
|
+
import * as os from 'node:os';
|
|
18
|
+
import * as path from 'node:path';
|
|
19
|
+
import {afterAll, beforeAll, describe, expect, it} from 'vitest';
|
|
20
|
+
import {writeIconSetProject} from '../../test-utils/icon-set-fixture.mjs';
|
|
21
|
+
import {icon} from './icon.mjs';
|
|
22
|
+
import {iconAdd} from './add/add.mjs';
|
|
23
|
+
import {iconMap} from './map/map.mjs';
|
|
24
|
+
import {iconNewSet} from './new-set/new-set.mjs';
|
|
25
|
+
import {iconNewDefinition} from './new-definition/new-definition.mjs';
|
|
26
|
+
import {iconUse} from './use/use.mjs';
|
|
27
|
+
import {doc as iconCommand} from '../../clients/cli/commands/experimental-icon.doc.mjs';
|
|
28
|
+
import {doc as addCommand} from '../../clients/cli/commands/experimental-icon-add.doc.mjs';
|
|
29
|
+
import {doc as mapCommand} from '../../clients/cli/commands/experimental-icon-map.doc.mjs';
|
|
30
|
+
import {doc as newSetCommand} from '../../clients/cli/commands/experimental-icon-new-set.doc.mjs';
|
|
31
|
+
import {doc as newDefinitionCommand} from '../../clients/cli/commands/experimental-icon-new-definition.doc.mjs';
|
|
32
|
+
import {doc as useCommand} from '../../clients/cli/commands/experimental-icon-use.doc.mjs';
|
|
33
|
+
import {doc as iconFn} from './icon.doc.mjs';
|
|
34
|
+
import {doc as addFn} from './iconAdd.doc.mjs';
|
|
35
|
+
import {doc as mapFn} from './iconMap.doc.mjs';
|
|
36
|
+
import {doc as newSetFn} from './iconNewSet.doc.mjs';
|
|
37
|
+
import {doc as newDefinitionFn} from './iconNewDefinition.doc.mjs';
|
|
38
|
+
import {doc as useFn} from './iconUse.doc.mjs';
|
|
39
|
+
|
|
40
|
+
/** @type {string} */
|
|
41
|
+
let tmp;
|
|
42
|
+
beforeAll(() => {
|
|
43
|
+
tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-icon-pairs-'));
|
|
44
|
+
});
|
|
45
|
+
afterAll(() => {
|
|
46
|
+
fs.rmSync(tmp, {recursive: true, force: true});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const FROM = '@acme/glyph-library';
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* An icon-set package `@acme/icons` with an installed library, and, unless
|
|
53
|
+
* `bare`, its set `glyphs` made from that library with two variants.
|
|
54
|
+
* @param {{bare?: boolean}} [options]
|
|
55
|
+
* @returns {Promise<string>}
|
|
56
|
+
*/
|
|
57
|
+
async function makePackage({bare = false} = {}) {
|
|
58
|
+
const dir = fs.mkdtempSync(path.join(tmp, 'pkg-'));
|
|
59
|
+
fs.writeFileSync(
|
|
60
|
+
path.join(dir, 'package.json'),
|
|
61
|
+
`${JSON.stringify({name: '@acme/icons', version: '1.0.0', license: 'MIT', type: 'module'}, null, 2)}\n`,
|
|
62
|
+
);
|
|
63
|
+
const lib = path.join(dir, 'node_modules', '@acme', 'glyph-library');
|
|
64
|
+
fs.mkdirSync(lib, {recursive: true});
|
|
65
|
+
fs.writeFileSync(
|
|
66
|
+
path.join(lib, 'package.json'),
|
|
67
|
+
JSON.stringify({
|
|
68
|
+
name: '@acme/glyph-library',
|
|
69
|
+
version: '2.0.0',
|
|
70
|
+
type: 'module',
|
|
71
|
+
exports: {'.': './index.js', './solid': './solid.js'},
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
const icons =
|
|
75
|
+
'export const Bin = props => null;\nexport const Close = props => null;\n';
|
|
76
|
+
fs.writeFileSync(path.join(lib, 'index.js'), icons);
|
|
77
|
+
fs.writeFileSync(path.join(lib, 'solid.js'), icons);
|
|
78
|
+
if (!bare) {
|
|
79
|
+
await iconNewSet('glyphs', {
|
|
80
|
+
cwd: dir,
|
|
81
|
+
from: FROM,
|
|
82
|
+
variants: 'outline,solid',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return dir;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @typedef {object} Case
|
|
90
|
+
* @property {any} command the CommandDoc
|
|
91
|
+
* @property {any} fn the FunctionDoc
|
|
92
|
+
* @property {(...args: any[]) => Promise<unknown>} call
|
|
93
|
+
* @property {() => Promise<string>} cwd a fresh folder for one call
|
|
94
|
+
* @property {Record<string, unknown>} values a value for each API parameter
|
|
95
|
+
* @property {Array<[string, string]>} refused pairs refused together
|
|
96
|
+
* @property {Array<[string, string]>} composes pairs that succeed together
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
/** @type {Record<string, Case>} */
|
|
100
|
+
const CASES = {
|
|
101
|
+
'experimental icon': {
|
|
102
|
+
command: iconCommand,
|
|
103
|
+
fn: iconFn,
|
|
104
|
+
call: icon,
|
|
105
|
+
cwd: async () =>
|
|
106
|
+
writeIconSetProject(fs.mkdtempSync(path.join(tmp, 'app-'))),
|
|
107
|
+
values: {
|
|
108
|
+
query: 'trash',
|
|
109
|
+
'options.list': true,
|
|
110
|
+
'options.set': 'glyphs',
|
|
111
|
+
'options.limit': 3,
|
|
112
|
+
'options.definitions': true,
|
|
113
|
+
'options.allIcons': true,
|
|
114
|
+
},
|
|
115
|
+
refused: [
|
|
116
|
+
['query', '--list'],
|
|
117
|
+
['query', '--definitions'],
|
|
118
|
+
['query', '--all-icons'],
|
|
119
|
+
['--list', '--set'],
|
|
120
|
+
['--list', '--limit'],
|
|
121
|
+
['--list', '--definitions'],
|
|
122
|
+
['--list', '--all-icons'],
|
|
123
|
+
['--set', '--definitions'],
|
|
124
|
+
['--limit', '--definitions'],
|
|
125
|
+
['--limit', '--all-icons'],
|
|
126
|
+
['--definitions', '--all-icons'],
|
|
127
|
+
],
|
|
128
|
+
composes: [
|
|
129
|
+
['query', '--set'],
|
|
130
|
+
['query', '--limit'],
|
|
131
|
+
['--set', '--all-icons'],
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
'experimental icon add': {
|
|
135
|
+
command: addCommand,
|
|
136
|
+
fn: addFn,
|
|
137
|
+
call: iconAdd,
|
|
138
|
+
cwd: () => makePackage(),
|
|
139
|
+
values: {
|
|
140
|
+
exportName: 'Bin',
|
|
141
|
+
'options.from': FROM,
|
|
142
|
+
'options.definition': 'delete',
|
|
143
|
+
'options.newDefinition': 'binIt',
|
|
144
|
+
'options.description': 'Put something in the bin.',
|
|
145
|
+
'options.words': ['bin'],
|
|
146
|
+
'options.useDefault': true,
|
|
147
|
+
'options.variant': 'solid',
|
|
148
|
+
'options.all': true,
|
|
149
|
+
'options.id': 'bin',
|
|
150
|
+
'options.set': 'glyphs',
|
|
151
|
+
},
|
|
152
|
+
refused: [
|
|
153
|
+
['export', '--all'],
|
|
154
|
+
['--definition', '--new-definition'],
|
|
155
|
+
['--definition', '--description'],
|
|
156
|
+
['--definition', '--words'],
|
|
157
|
+
['--definition', '--all'],
|
|
158
|
+
['--new-definition', '--all'],
|
|
159
|
+
['--description', '--all'],
|
|
160
|
+
['--words', '--all'],
|
|
161
|
+
['--default', '--all'],
|
|
162
|
+
['--all', '--id'],
|
|
163
|
+
// A description and words describe only a new definition.
|
|
164
|
+
['export', '--description'],
|
|
165
|
+
['export', '--words'],
|
|
166
|
+
['--from', '--description'],
|
|
167
|
+
['--from', '--words'],
|
|
168
|
+
['--description', '--words'],
|
|
169
|
+
['--description', '--default'],
|
|
170
|
+
['--description', '--variant'],
|
|
171
|
+
['--description', '--id'],
|
|
172
|
+
['--description', '--set'],
|
|
173
|
+
['--words', '--default'],
|
|
174
|
+
['--words', '--variant'],
|
|
175
|
+
['--words', '--id'],
|
|
176
|
+
['--words', '--set'],
|
|
177
|
+
],
|
|
178
|
+
composes: [['export', '--from']],
|
|
179
|
+
},
|
|
180
|
+
'experimental icon map': {
|
|
181
|
+
command: mapCommand,
|
|
182
|
+
fn: mapFn,
|
|
183
|
+
call: iconMap,
|
|
184
|
+
cwd: () => makePackage(),
|
|
185
|
+
values: {
|
|
186
|
+
definition: 'delete',
|
|
187
|
+
icon: 'bin',
|
|
188
|
+
'options.set': 'glyphs',
|
|
189
|
+
'options.remove': true,
|
|
190
|
+
'options.pairs': 'close=close',
|
|
191
|
+
},
|
|
192
|
+
refused: [
|
|
193
|
+
['definition', '--pairs'],
|
|
194
|
+
['icon', '--remove'],
|
|
195
|
+
['icon', '--pairs'],
|
|
196
|
+
['--remove', '--pairs'],
|
|
197
|
+
],
|
|
198
|
+
composes: [
|
|
199
|
+
['definition', 'icon'],
|
|
200
|
+
['definition', '--remove'],
|
|
201
|
+
['--set', '--pairs'],
|
|
202
|
+
],
|
|
203
|
+
},
|
|
204
|
+
'experimental icon new-set': {
|
|
205
|
+
command: newSetCommand,
|
|
206
|
+
fn: newSetFn,
|
|
207
|
+
call: iconNewSet,
|
|
208
|
+
cwd: () => makePackage({bare: true}),
|
|
209
|
+
values: {
|
|
210
|
+
name: 'glyphs',
|
|
211
|
+
'options.dryRun': true,
|
|
212
|
+
'options.from': FROM,
|
|
213
|
+
'options.exclude': 'Close',
|
|
214
|
+
'options.variants': 'outline,solid',
|
|
215
|
+
'options.defaultVariant': 'solid',
|
|
216
|
+
'options.displayName': 'Glyphs',
|
|
217
|
+
'options.description': 'Glyph icons.',
|
|
218
|
+
},
|
|
219
|
+
refused: [
|
|
220
|
+
// `--exclude` needs `--from`, `--default-variant` needs `--variants`.
|
|
221
|
+
['--dry-run', '--exclude'],
|
|
222
|
+
['--dry-run', '--default-variant'],
|
|
223
|
+
['--exclude', '--variants'],
|
|
224
|
+
['--exclude', '--default-variant'],
|
|
225
|
+
['--exclude', '--display-name'],
|
|
226
|
+
['--exclude', '--description'],
|
|
227
|
+
['--from', '--default-variant'],
|
|
228
|
+
['--default-variant', '--display-name'],
|
|
229
|
+
['--default-variant', '--description'],
|
|
230
|
+
],
|
|
231
|
+
composes: [
|
|
232
|
+
['--dry-run', '--from'],
|
|
233
|
+
['--dry-run', '--variants'],
|
|
234
|
+
['--dry-run', '--display-name'],
|
|
235
|
+
['--dry-run', '--description'],
|
|
236
|
+
['--from', '--exclude'],
|
|
237
|
+
['--from', '--variants'],
|
|
238
|
+
['--from', '--display-name'],
|
|
239
|
+
['--from', '--description'],
|
|
240
|
+
['--variants', '--default-variant'],
|
|
241
|
+
['--variants', '--display-name'],
|
|
242
|
+
['--variants', '--description'],
|
|
243
|
+
['--display-name', '--description'],
|
|
244
|
+
],
|
|
245
|
+
},
|
|
246
|
+
'experimental icon new-definition': {
|
|
247
|
+
command: newDefinitionCommand,
|
|
248
|
+
fn: newDefinitionFn,
|
|
249
|
+
call: iconNewDefinition,
|
|
250
|
+
cwd: () => makePackage(),
|
|
251
|
+
values: {
|
|
252
|
+
name: 'binIt',
|
|
253
|
+
'options.dryRun': true,
|
|
254
|
+
'options.set': 'glyphs',
|
|
255
|
+
'options.description': 'Put something in the bin.',
|
|
256
|
+
'options.words': ['bin'],
|
|
257
|
+
'options.icon': 'bin',
|
|
258
|
+
},
|
|
259
|
+
refused: [],
|
|
260
|
+
composes: [['--description', '--words']],
|
|
261
|
+
},
|
|
262
|
+
'experimental icon use': {
|
|
263
|
+
command: useCommand,
|
|
264
|
+
fn: useFn,
|
|
265
|
+
call: iconUse,
|
|
266
|
+
cwd: async () =>
|
|
267
|
+
writeIconSetProject(fs.mkdtempSync(path.join(tmp, 'app-'))),
|
|
268
|
+
values: {set: 'glyphs'},
|
|
269
|
+
refused: [],
|
|
270
|
+
composes: [],
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The pair members a command declares: its optional arguments, by name, and
|
|
276
|
+
* its options, by long flag; each with the API parameter it sets.
|
|
277
|
+
* @param {any} command
|
|
278
|
+
* @returns {Array<{label: string, param: string}>}
|
|
279
|
+
*/
|
|
280
|
+
function members(command) {
|
|
281
|
+
return [
|
|
282
|
+
...(command.args ?? [])
|
|
283
|
+
.filter((/** @type {any} */ arg) => arg.required !== true)
|
|
284
|
+
.map((/** @type {any} */ arg) => ({label: arg.name, param: arg.param})),
|
|
285
|
+
...(command.options ?? []).map((/** @type {any} */ option) => ({
|
|
286
|
+
label: option.flag.split(/[\s,]/u)[0],
|
|
287
|
+
param: option.param,
|
|
288
|
+
})),
|
|
289
|
+
];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** @param {[string, string]} pair */
|
|
293
|
+
const key = ([a, b]) => [a, b].sort().join(' + ');
|
|
294
|
+
|
|
295
|
+
describe.each(Object.entries(CASES))('%s', (_name, spec) => {
|
|
296
|
+
const declared = members(spec.command);
|
|
297
|
+
const labels = declared.map(each => each.label);
|
|
298
|
+
/** @type {Array<[string, string]>} */
|
|
299
|
+
const pairs = [];
|
|
300
|
+
for (let i = 0; i < declared.length; i++) {
|
|
301
|
+
for (let j = i + 1; j < declared.length; j++) {
|
|
302
|
+
pairs.push([declared[i].label, declared[j].label]);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const refused = new Set(spec.refused.map(key));
|
|
306
|
+
const composes = new Set(spec.composes.map(key));
|
|
307
|
+
const documented = new Set(
|
|
308
|
+
(spec.fn.throws ?? []).map((/** @type {any} */ each) => each.code),
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
it('names only pairs the command declares, each in one table', () => {
|
|
312
|
+
for (const pair of [...spec.refused, ...spec.composes]) {
|
|
313
|
+
expect(labels, key(pair)).toEqual(expect.arrayContaining(pair));
|
|
314
|
+
}
|
|
315
|
+
expect([...refused].filter(each => composes.has(each))).toEqual([]);
|
|
316
|
+
for (const {param} of declared) {
|
|
317
|
+
expect(Object.keys(spec.values), param).toContain(param);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
if (pairs.length === 0) return;
|
|
322
|
+
it.each(pairs)('%s with %s', async (a, b) => {
|
|
323
|
+
const given = new Set([a, b]);
|
|
324
|
+
const cwd = await spec.cwd();
|
|
325
|
+
// Required arguments are always given, in order; the rest only when
|
|
326
|
+
// they are one of the pair.
|
|
327
|
+
const args = (spec.command.args ?? []).map((/** @type {any} */ arg) =>
|
|
328
|
+
arg.required === true || given.has(arg.name)
|
|
329
|
+
? spec.values[arg.param]
|
|
330
|
+
: undefined,
|
|
331
|
+
);
|
|
332
|
+
/** @type {Record<string, unknown>} */
|
|
333
|
+
const options = {cwd};
|
|
334
|
+
for (const {label, param} of declared) {
|
|
335
|
+
if (given.has(label) && param.startsWith('options.')) {
|
|
336
|
+
options[param.slice('options.'.length)] = spec.values[param];
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/** @type {any} */
|
|
340
|
+
let error = null;
|
|
341
|
+
try {
|
|
342
|
+
await spec.call(...args, options);
|
|
343
|
+
} catch (thrown) {
|
|
344
|
+
error = thrown;
|
|
345
|
+
}
|
|
346
|
+
const pair = key([a, b]);
|
|
347
|
+
if (refused.has(pair)) {
|
|
348
|
+
expect(error?.code, `${pair}: ${error?.message}`).toBe(
|
|
349
|
+
'ERR_INVALID_OPTION',
|
|
350
|
+
);
|
|
351
|
+
} else if (composes.has(pair)) {
|
|
352
|
+
expect(error, `${pair}: ${error?.message}`).toBeNull();
|
|
353
|
+
} else {
|
|
354
|
+
// Prevented by another rule: a documented code, never a silent
|
|
355
|
+
// success and never an unknown error.
|
|
356
|
+
expect(
|
|
357
|
+
error,
|
|
358
|
+
`${pair} succeeded but is not listed as composing`,
|
|
359
|
+
).not.toBeNull();
|
|
360
|
+
expect(error.code, `${pair}: ${error.message}`).not.toBe(
|
|
361
|
+
'ERR_INVALID_OPTION',
|
|
362
|
+
);
|
|
363
|
+
expect([...documented], `${pair}: ${error.message}`).toContain(
|
|
364
|
+
error.code,
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
});
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Every icon of one set, by id: `--set <name> --all-icons`, so an author can read
|
|
6
|
+
* a whole library's ids, words, and the definitions each icon draws.
|
|
7
|
+
* @param {{cwd: string, set: string}} options
|
|
8
|
+
* @returns {Promise<import('../icon.type.mjs').IconSetIconsResponse>}
|
|
9
|
+
*/
|
|
10
|
+
export function iconSetIcons({ cwd, set }: {
|
|
11
|
+
cwd: string;
|
|
12
|
+
set: string;
|
|
13
|
+
}): Promise<import("../icon.type.mjs").IconSetIconsResponse>;
|
|
4
14
|
/**
|
|
5
15
|
* Rank every installed icon against a query.
|
|
6
16
|
* @param {string} query
|
|
@@ -12,7 +12,54 @@
|
|
|
12
12
|
import {AstryxError} from '../../error.mjs';
|
|
13
13
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
14
14
|
import {loadIconSets} from '../_adapter.mjs';
|
|
15
|
-
import {
|
|
15
|
+
import {rankIcons, setsNamed, unusableSet} from '../_records.mjs';
|
|
16
|
+
|
|
17
|
+
/** The lowest score of a whole-word or word-start match. */
|
|
18
|
+
const WORD_SCORE = 60;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Every icon of one set, by id: `--set <name> --all-icons`, so an author can read
|
|
22
|
+
* a whole library's ids, words, and the definitions each icon draws.
|
|
23
|
+
* @param {{cwd: string, set: string}} options
|
|
24
|
+
* @returns {Promise<import('../icon.type.mjs').IconSetIconsResponse>}
|
|
25
|
+
*/
|
|
26
|
+
export async function iconSetIcons({cwd, set}) {
|
|
27
|
+
const {sets, withdrawn} = await loadIconSets(cwd);
|
|
28
|
+
const named = setsNamed(sets, set);
|
|
29
|
+
if (named.length === 0) throw unusableSet(sets, withdrawn, set);
|
|
30
|
+
if (named.length > 1) {
|
|
31
|
+
throw new AstryxError(
|
|
32
|
+
`"${set}" names ${named.length} sets; name one as <package>/<set>`,
|
|
33
|
+
named.map(each => ({
|
|
34
|
+
name: `${each.package}/${each.name}`,
|
|
35
|
+
reason: 'name the package',
|
|
36
|
+
})),
|
|
37
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
const [only] = named;
|
|
41
|
+
/** @type {Map<string, string[]>} */
|
|
42
|
+
const drawn = new Map();
|
|
43
|
+
for (const [definition, id] of Object.entries(only.data.map ?? {})) {
|
|
44
|
+
drawn.set(id, [...(drawn.get(id) ?? []), definition]);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
type: 'icon.setIcons',
|
|
48
|
+
data: {
|
|
49
|
+
set: only.name,
|
|
50
|
+
package: only.package,
|
|
51
|
+
iconCount: only.data.icons.length,
|
|
52
|
+
icons: [...only.data.icons]
|
|
53
|
+
.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))
|
|
54
|
+
.map(icon => ({
|
|
55
|
+
id: icon.id,
|
|
56
|
+
export: icon.export,
|
|
57
|
+
words: icon.words,
|
|
58
|
+
definitions: (drawn.get(icon.id) ?? []).sort(),
|
|
59
|
+
})),
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
16
63
|
|
|
17
64
|
/**
|
|
18
65
|
* Rank every installed icon against a query.
|
|
@@ -25,20 +72,14 @@ export async function iconSearch(query, {cwd, set, limit}) {
|
|
|
25
72
|
let searched = sets;
|
|
26
73
|
if (set != null) {
|
|
27
74
|
searched = setsNamed(sets, set);
|
|
28
|
-
if (searched.length === 0)
|
|
29
|
-
throw new AstryxError(
|
|
30
|
-
withdrawnReason(withdrawn, set) ??
|
|
31
|
-
`No installed icon set named "${set}"`,
|
|
32
|
-
closest(
|
|
33
|
-
set,
|
|
34
|
-
sets.flatMap(each => [each.name, `${each.package}/${each.name}`]),
|
|
35
|
-
'installed icon set',
|
|
36
|
-
),
|
|
37
|
-
ERROR_CODES.ERR_NOT_FOUND,
|
|
38
|
-
);
|
|
39
|
-
}
|
|
75
|
+
if (searched.length === 0) throw unusableSet(sets, withdrawn, set);
|
|
40
76
|
}
|
|
41
|
-
const
|
|
77
|
+
const ranked = rankIcons(searched, query);
|
|
78
|
+
// A partial match (`pin` inside `shopping`) answers only when nothing
|
|
79
|
+
// matches a whole word or a word start.
|
|
80
|
+
const matches = ranked.some(each => each.score >= WORD_SCORE)
|
|
81
|
+
? ranked.filter(each => each.score >= WORD_SCORE)
|
|
82
|
+
: ranked;
|
|
42
83
|
return {
|
|
43
84
|
type: 'icon.search',
|
|
44
85
|
data: {
|
package/api/icon/use/use.mjs
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
refuseOutsideProject,
|
|
19
19
|
setConfigString,
|
|
20
20
|
} from '../_adapter.mjs';
|
|
21
|
-
import {
|
|
21
|
+
import {setsNamed, unusableSet} from '../_records.mjs';
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Make an installed set the project's icon set.
|
|
@@ -45,18 +45,7 @@ export async function iconUse(selector, {cwd = process.cwd()} = {}) {
|
|
|
45
45
|
refuseOutsideProject(cwd, 'experimental icon use', 'the app project');
|
|
46
46
|
const {projectDir, sets, withdrawn} = await loadIconProject(cwd);
|
|
47
47
|
const named = setsNamed(sets, selector);
|
|
48
|
-
if (named.length === 0)
|
|
49
|
-
throw new AstryxError(
|
|
50
|
-
withdrawnReason(withdrawn, selector) ??
|
|
51
|
-
`No installed icon set is named "${selector}".`,
|
|
52
|
-
closest(
|
|
53
|
-
selector,
|
|
54
|
-
sets.flatMap(set => [set.name, iconSetKey(set)]),
|
|
55
|
-
'an installed icon set',
|
|
56
|
-
),
|
|
57
|
-
ERROR_CODES.ERR_NOT_FOUND,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
48
|
+
if (named.length === 0) throw unusableSet(sets, withdrawn, selector);
|
|
60
49
|
if (named.length > 1) {
|
|
61
50
|
throw new AstryxError(
|
|
62
51
|
`Two installed packages ship an icon set named "${selector}"; name it with its package.`,
|
|
@@ -92,7 +92,7 @@ export function loadCurrentManifest(manifestFile: string, manifestExists: boolea
|
|
|
92
92
|
* @param {string} manifestPath
|
|
93
93
|
* @param {string[]} files
|
|
94
94
|
* @param {boolean} dryRun
|
|
95
|
-
* @returns {{type: 'integration.add', data: Omit<import('./integration-authoring.type.mjs').IntegrationAddData, 'kind'> & {kind: K, icons?: number, notes?: string[]}}}
|
|
95
|
+
* @returns {{type: 'integration.add', data: Omit<import('./integration-authoring.type.mjs').IntegrationAddData, 'kind'> & {kind: K, icons?: number, refreshed?: boolean, renamed?: Array<{from: string, to: string}>, mapped?: Array<{definition: string, icon: string}>, suggestions?: Array<{definition: string, icon: string, word: string}>, notes?: string[]}}}
|
|
96
96
|
*/
|
|
97
97
|
export function receipt<K extends import("./integration-authoring.type.mjs").IntegrationAddData["kind"] | import("../icon/icon.type.mjs").IconNewData["kind"]>(kind: K, name: string, root: {
|
|
98
98
|
path: string;
|
|
@@ -102,6 +102,20 @@ export function receipt<K extends import("./integration-authoring.type.mjs").Int
|
|
|
102
102
|
data: Omit<import("./integration-authoring.type.mjs").IntegrationAddData, "kind"> & {
|
|
103
103
|
kind: K;
|
|
104
104
|
icons?: number;
|
|
105
|
+
refreshed?: boolean;
|
|
106
|
+
renamed?: Array<{
|
|
107
|
+
from: string;
|
|
108
|
+
to: string;
|
|
109
|
+
}>;
|
|
110
|
+
mapped?: Array<{
|
|
111
|
+
definition: string;
|
|
112
|
+
icon: string;
|
|
113
|
+
}>;
|
|
114
|
+
suggestions?: Array<{
|
|
115
|
+
definition: string;
|
|
116
|
+
icon: string;
|
|
117
|
+
word: string;
|
|
118
|
+
}>;
|
|
105
119
|
notes?: string[];
|
|
106
120
|
};
|
|
107
121
|
};
|
|
@@ -483,7 +483,7 @@ export async function loadCurrentManifest(manifestFile, manifestExists) {
|
|
|
483
483
|
* @param {string} manifestPath
|
|
484
484
|
* @param {string[]} files
|
|
485
485
|
* @param {boolean} dryRun
|
|
486
|
-
* @returns {{type: 'integration.add', data: Omit<import('./integration-authoring.type.mjs').IntegrationAddData, 'kind'> & {kind: K, icons?: number, notes?: string[]}}}
|
|
486
|
+
* @returns {{type: 'integration.add', data: Omit<import('./integration-authoring.type.mjs').IntegrationAddData, 'kind'> & {kind: K, icons?: number, refreshed?: boolean, renamed?: Array<{from: string, to: string}>, mapped?: Array<{definition: string, icon: string}>, suggestions?: Array<{definition: string, icon: string, word: string}>, notes?: string[]}}}
|
|
487
487
|
*/
|
|
488
488
|
export function receipt(kind, name, root, manifestPath, files, dryRun) {
|
|
489
489
|
return {
|
|
@@ -166,8 +166,9 @@ export type IconSetCoverage = {
|
|
|
166
166
|
}>;
|
|
167
167
|
/**
|
|
168
168
|
* For each
|
|
169
|
-
* unmapped definition (built-in, optional, or the set's own), the icon
|
|
170
|
-
*
|
|
169
|
+
* unmapped definition (built-in, optional, or the set's own), the best icon
|
|
170
|
+
* `integration check` gives it, by the rule `experimental icon new-set`
|
|
171
|
+
* uses for its suggestions, when one is.
|
|
171
172
|
*/
|
|
172
173
|
suggestions: Array<{
|
|
173
174
|
definition: string;
|
|
@@ -126,8 +126,9 @@
|
|
|
126
126
|
* Astryx's optional (not built-in) definitions the set's `map` does not
|
|
127
127
|
* name. An unmapped built-in definition is an error issue instead.
|
|
128
128
|
* @property {Array<{definition: string, icon: string}>} suggestions For each
|
|
129
|
-
* unmapped definition (built-in, optional, or the set's own), the icon
|
|
130
|
-
*
|
|
129
|
+
* unmapped definition (built-in, optional, or the set's own), the best icon
|
|
130
|
+
* `integration check` gives it, by the rule `experimental icon new-set`
|
|
131
|
+
* uses for its suggestions, when one is.
|
|
131
132
|
* @property {Array<{icon?: string, adapter?: string, entry?: string, reason: string}>} unchecked
|
|
132
133
|
* What the checks could not judge, each with the reason: an icon export
|
|
133
134
|
* whose module is an `exports` target not built yet, or that the reader
|
|
@@ -131,7 +131,7 @@ export type TemplateIconsReport = {
|
|
|
131
131
|
*/
|
|
132
132
|
reason: string;
|
|
133
133
|
/**
|
|
134
|
-
* Icons rewritten to the project's set, and the rule that chose each one: a reviewed `exact` or `strong` match, or the icon the set's `map` names for the icon definition the template declares.
|
|
134
|
+
* Icons rewritten to the project's set, and the rule that chose each one: a reviewed `exact` or `strong` match, or the icon the set's `map` names for the icon definition the template declares. `dropped` names the library's sizing props (`size`, `strokeWidth`, `absoluteStrokeWidth`) removed from the icon's elements: an icon set's icons take their size from CSS.
|
|
135
135
|
*/
|
|
136
136
|
mapped: Array<{
|
|
137
137
|
source: {
|
|
@@ -146,6 +146,7 @@ export type TemplateIconsReport = {
|
|
|
146
146
|
export: string;
|
|
147
147
|
};
|
|
148
148
|
by: "match" | "definition";
|
|
149
|
+
dropped?: string[];
|
|
149
150
|
}>;
|
|
150
151
|
/**
|
|
151
152
|
* Icons left as the template wrote them, with why, and a `likely` reviewed match as a suggestion when the project set has one. Every declared key is mapped or kept; `module` is null for a key the template does not import, and `export` is `default` for a default import and `*` for a namespace import.
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
* @property {'selected' | 'none' | 'ambiguous' | 'missing' | 'withdrawn'} status The project's icon-set state.
|
|
97
97
|
* @property {string | null} set The project's icon set as `<package>/<set>`, when selected.
|
|
98
98
|
* @property {string} reason Why the project has that set, or none.
|
|
99
|
-
* @property {Array<{source: {module: string, export: string}, target: {set: string, package: string, id: string, module: string, export: string}, by: 'match' | 'definition'}>} mapped Icons rewritten to the project's set, and the rule that chose each one: a reviewed `exact` or `strong` match, or the icon the set's `map` names for the icon definition the template declares.
|
|
99
|
+
* @property {Array<{source: {module: string, export: string}, target: {set: string, package: string, id: string, module: string, export: string}, by: 'match' | 'definition', dropped?: string[]}>} mapped Icons rewritten to the project's set, and the rule that chose each one: a reviewed `exact` or `strong` match, or the icon the set's `map` names for the icon definition the template declares. `dropped` names the library's sizing props (`size`, `strokeWidth`, `absoluteStrokeWidth`) removed from the icon's elements: an icon set's icons take their size from CSS.
|
|
100
100
|
* @property {Array<{module: string | null, export: string, reason: string, suggestion?: {set: string, id: string, module: string, export: string, confidence: 'likely'}}>} kept Icons left as the template wrote them, with why, and a `likely` reviewed match as a suggestion when the project set has one. Every declared key is mapped or kept; `module` is null for a key the template does not import, and `export` is `default` for a default import and `*` for a namespace import.
|
|
101
101
|
*/
|
|
102
102
|
|
|
@@ -18,7 +18,7 @@ export const docs = {
|
|
|
18
18
|
stability: 'experimental',
|
|
19
19
|
title: 'Icon definitions',
|
|
20
20
|
summary:
|
|
21
|
-
'
|
|
21
|
+
'Every icon definition: what an icon stands for, and the shared name icon sets map their icons to.',
|
|
22
22
|
keywords: [
|
|
23
23
|
'icon definition',
|
|
24
24
|
'icon definitions',
|
|
@@ -42,7 +42,7 @@ export const docs = {
|
|
|
42
42
|
blocks: [
|
|
43
43
|
{
|
|
44
44
|
type: 'prose',
|
|
45
|
-
text: "An icon definition is one thing an icon stands for, such as `close` or `delete`. Every icon set registers its icons against definitions in its data file's `map`, and templates are written against definitions, so a project that switches icon sets gets the same definition from the new set. Built-in definitions are the shared names Core renders; every set maps them. A set may add its own definitions; in a project that sets `experimental.iconSet`, they are listed here with the package that ships them. `astryx experimental icon <definition>` finds the icon each installed set draws for it. Icon definitions are experimental: they may change or be removed in a patch release.",
|
|
45
|
+
text: "An icon definition is one thing an icon stands for, such as `close` or `delete`. Every icon set registers its icons against definitions in its data file's `map`, and templates are written against definitions, so a project that switches icon sets gets the same definition from the new set. Built-in definitions, marked [built-in], are the shared names Core renders (the semantic icon names in `astryx docs icons`); every set maps them, and `integration check` fails until it does. The others are optional: map each one your library draws. `map` keys a definition by its camelCase name, shown after the id (`eyeSlash`); `experimental icon map` and `--pairs` take either spelling. A set may add its own definitions; in a project that sets `experimental.iconSet`, they are listed here with the package that ships them. `astryx experimental icon <definition>` finds the icon each installed set draws for it. Icon definitions are experimental: they may change or be removed in a patch release.",
|
|
46
46
|
},
|
|
47
47
|
],
|
|
48
48
|
};
|
|
@@ -28,6 +28,6 @@ export const docs = {
|
|
|
28
28
|
'IconDefinitionDoc',
|
|
29
29
|
],
|
|
30
30
|
description:
|
|
31
|
-
'
|
|
31
|
+
'Every field of the files an icon set is made of: the descriptor, the data file, and an icon definition.',
|
|
32
32
|
sections: await buildExperimentalAuthoringSections(),
|
|
33
33
|
};
|