@astryxdesign/cli 0.7.11 → 0.7.12-canary.0085c0f
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/api/build/blocks/blocks.d.mts +41 -0
- package/api/build/blocks/blocks.mjs +118 -68
- package/api/build/kit/rank.mjs +21 -4
- package/api/build/kit/words.d.mts +1 -0
- package/api/build/kit/words.mjs +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +5 -5
- package/api/docs/_adapter.d.mts +22 -0
- package/api/docs/_adapter.mjs +81 -3
- package/api/docs/docs.doc.mjs +5 -5
- package/api/docs/docs.type.d.mts +21 -0
- package/api/docs/docs.type.mjs +11 -0
- package/api/docs/list/list.d.mts +5 -1
- package/api/docs/list/list.mjs +72 -6
- package/api/docs/node/node.mjs +2 -40
- package/api/doctor/doctor.d.mts +4 -4
- package/api/doctor/doctor.mjs +248 -78
- package/api/icon/_adapter.d.mts +3 -2
- package/api/icon/_adapter.mjs +8 -2
- package/api/icon/_authoring.d.mts +1 -0
- package/api/icon/_authoring.mjs +594 -67
- package/api/icon/_default-look.d.mts +155 -0
- package/api/icon/_default-look.mjs +474 -0
- package/api/icon/_records.d.mts +1 -1
- package/api/icon/_records.mjs +1 -0
- package/api/icon/add/add.mjs +269 -43
- package/api/icon/icon.type.d.mts +46 -2
- package/api/icon/icon.type.mjs +12 -2
- package/api/icon/iconAdd.doc.mjs +2 -2
- package/api/icon/iconNewDefinition.doc.mjs +3 -2
- package/api/icon/iconNewSet.doc.mjs +4 -4
- package/api/icon/map/map.mjs +11 -4
- package/api/icon/search/search.mjs +10 -9
- package/api/index.d.mts +1 -0
- package/api/index.mjs +1 -0
- package/api/integration/add-helpers.d.mts +15 -1
- package/api/integration/add-helpers.mjs +5 -2
- package/api/integration/authoring-checks.d.mts +0 -2
- package/api/integration/authoring-checks.mjs +1 -6
- package/api/logger.mjs +2 -1
- package/api/render/_adapter.mjs +9 -0
- package/api/render/render.doc.mjs +3 -3
- package/api/render/render.type.d.mts +1 -1
- package/api/render/render.type.mjs +1 -1
- package/api/search/ORDERING.md +3 -0
- package/api/search/_adapter.d.mts +32 -3
- package/api/search/_adapter.mjs +50 -22
- package/api/search/_fit-order.d.mts +47 -0
- package/api/search/_fit-order.mjs +257 -0
- package/api/search/_main-searcher.mjs +15 -5
- package/api/search/exportSearchIndex.doc.d.mts +10 -0
- package/api/search/exportSearchIndex.doc.mjs +58 -0
- package/api/search/rankSearchIndex.doc.d.mts +10 -0
- package/api/search/rankSearchIndex.doc.mjs +79 -0
- package/api/search/search-index.d.mts +44 -0
- package/api/search/search-index.mjs +270 -0
- package/api/search/search.type.d.mts +28 -0
- package/api/search/search.type.mjs +17 -0
- package/api/swizzle/_adapter.d.mts +1 -0
- package/api/swizzle/_adapter.mjs +4 -1
- package/api/swizzle/_moduleGraph.d.mts +178 -0
- package/api/swizzle/_moduleGraph.mjs +903 -0
- package/api/swizzle/copy/copy.d.mts +2 -43
- package/api/swizzle/copy/copy.mjs +287 -315
- package/api/swizzle/swizzle.d.mts +0 -2
- package/api/swizzle/swizzle.doc.mjs +13 -4
- package/api/swizzle/swizzle.mjs +3 -7
- package/api/swizzle/swizzle.type.d.mts +7 -1
- package/api/swizzle/swizzle.type.mjs +4 -2
- package/api/template/skeleton/skeleton.mjs +1 -1
- package/api/template/template.mjs +1 -0
- package/assets/codemods/transforms/v0.1.0/drop-xds-prefix-imports.mjs +1 -1
- package/assets/codemods/transforms/v0.1.0/index.mjs +1 -1
- package/assets/discover/official-packages.json +40 -0
- package/assets/docs/browser-support.doc.mjs +2 -2
- package/assets/docs/styling-overview.doc.mjs +6 -2
- package/assets/docs/tree/icon-sets.doc.mjs +13 -7
- package/assets/docs/tree/render-pages.doc.mjs +3 -3
- package/assets/docs/tree/tailwind.doc.mjs +41 -1
- package/assets/docs/tree/type-scale.doc.mjs +19 -2
- package/assets/templates/blocks/components/Calendar/useCalendarConstraintsHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Calendar/useCalendarConstraintsHookUsage.tsx +146 -0
- package/assets/templates/blocks/components/Calendar/useCalendarNavigationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Calendar/useCalendarNavigationHookUsage.tsx +173 -0
- package/assets/templates/blocks/components/Hooks/useInputStatusIconHookUsage.tsx +1 -0
- package/assets/templates/blocks/components/Hooks/useInteractiveRoleHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useInteractiveRoleHookUsage.tsx +56 -0
- package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.doc.mjs +2 -2
- package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.tsx +66 -10
- package/assets/templates/blocks/components/Link/useLinkifyHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Link/useLinkifyHookUsage.tsx +39 -0
- package/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.tsx +83 -0
- package/assets/templates/blocks/components/Table/RowsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/RowsVirtualizationHookUsage.tsx +41 -0
- package/assets/templates/blocks/components/Table/TableRowIndexTable.doc.mjs +1 -1
- package/assets/templates/blocks/components/Table/TableRowIndexTable.tsx +2 -2
- package/assets/templates/blocks/components/Table/useTableColumnSettingsStateHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/useTableColumnSettingsStateHookUsage.tsx +97 -0
- package/assets/templates/pages/course-detail/page.tsx +699 -0
- package/assets/templates/pages/course-detail/template.doc.mjs +37 -0
- package/assets/templates/pages/file-explorer/page.tsx +103 -79
- package/assets/templates/pages/table-filter/page.tsx +15 -23
- package/assets/templates/pages/table-grouped/page.tsx +190 -262
- package/assets/templates/pages/table-grouped/template.doc.mjs +0 -2
- package/assets/templates/pages/table-inbox/page.tsx +3 -6
- package/assets/templates/pages/theme-showcase/page.tsx +724 -792
- package/assets/templates/pages/theme-showcase/template.doc.mjs +4 -5
- package/assets/templates/themes/butter/butterTheme.ts +2 -2
- package/assets/templates/themes/gothic/gothicTheme.ts +16 -0
- package/assets/templates/themes/matcha/matchaTheme.ts +1 -1
- package/assets/templates/themes/neutral/neutralTheme.ts +6 -0
- package/assets/templates/themes/stone/stoneTheme.ts +1 -1
- package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/y2k/y2kTheme.ts +2 -2
- package/authoring/doctypes/template/type.ts +1 -0
- package/clients/cli/commands/docs.doc.mjs +5 -1
- package/clients/cli/commands/docs.mjs +30 -2
- package/clients/cli/commands/experimental/icon.mjs +56 -14
- package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +2 -1
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
- package/clients/cli/commands/experimental-render.doc.mjs +1 -1
- package/clients/cli/commands/swizzle.doc.mjs +12 -3
- package/clients/cli/commands/swizzle.mjs +33 -9
- package/clients/cli/commands/template.mjs +204 -181
- package/clients/cli/lib/resolve-theme.mjs +16 -7
- package/foundation/discovery/component-discovery.mjs +1 -1
- package/foundation/discovery/component-loader.d.mts +1 -1
- package/foundation/discovery/doc-types.mjs +9 -2
- package/foundation/discovery/hook-discovery.mjs +31 -8
- package/foundation/discovery/icon-ranking.d.mts +27 -3
- package/foundation/discovery/icon-ranking.mjs +125 -8
- package/foundation/discovery/icon-set-checks.mjs +44 -35
- package/foundation/discovery/icon-set-discovery.d.mts +13 -0
- package/foundation/discovery/icon-set-discovery.mjs +25 -0
- package/foundation/discovery/icon-set-writer.d.mts +258 -20
- package/foundation/discovery/icon-set-writer.mjs +785 -87
- package/foundation/discovery/module-exports.d.mts +3 -2
- package/foundation/discovery/module-exports.mjs +167 -37
- package/foundation/discovery/template-adapter.mjs +2 -2
- package/foundation/doc-compiler/import.d.mts +5 -1
- package/foundation/doc-compiler/import.mjs +40 -6
- package/foundation/fs/import-url.d.mts +20 -0
- package/foundation/fs/import-url.mjs +22 -0
- package/foundation/fs/module-loader.d.mts +24 -3
- package/foundation/fs/module-loader.mjs +69 -47
- package/foundation/fs/paths.d.mts +2 -1
- package/foundation/fs/paths.mjs +3 -4
- package/foundation/render/charts.d.mts +59 -0
- package/foundation/render/charts.mjs +216 -0
- package/foundation/render/embedded-imports.d.mts +7 -7
- package/foundation/render/embedded-imports.mjs +63 -54
- package/foundation/render/page-host.d.mts +4 -0
- package/foundation/render/page-host.mjs +45 -0
- package/foundation/render/page-worker.mjs +350 -57
- package/foundation/render/render-page.d.mts +11 -6
- package/foundation/render/render-page.mjs +164 -54
- package/foundation/render/ts-paths.d.mts +63 -0
- package/foundation/render/ts-paths.mjs +138 -0
- package/foundation/response/error-codes.doc.mjs +3 -3
- package/foundation/response/error-codes.mjs +3 -2
- package/foundation/text/levenshtein.d.mts +6 -1
- package/foundation/text/levenshtein.mjs +25 -9
- package/foundation/text/shell-arg.d.mts +14 -0
- package/foundation/text/shell-arg.mjs +17 -0
- package/foundation/text/suggest-order.d.mts +8 -1
- package/foundation/text/suggest-order.mjs +72 -6
- package/foundation/xle/registry-core.mjs +1 -1
- package/package.json +7 -6
package/api/icon/_authoring.mjs
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import * as fs from 'node:fs';
|
|
14
14
|
import * as path from 'node:path';
|
|
15
15
|
import {AstryxError} from '../error.mjs';
|
|
16
|
+
import {logger} from '../logger.mjs';
|
|
16
17
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
17
18
|
import {
|
|
18
19
|
assertWithin,
|
|
@@ -41,8 +42,13 @@ import {
|
|
|
41
42
|
iconSetDataText,
|
|
42
43
|
journalFile,
|
|
43
44
|
librarySource,
|
|
45
|
+
everyLibraryIcon,
|
|
44
46
|
libraryIcons,
|
|
47
|
+
libraryLooks,
|
|
48
|
+
lookPositions,
|
|
49
|
+
moduleNaming,
|
|
45
50
|
nonIconExports,
|
|
51
|
+
packageRootMoves,
|
|
46
52
|
resolveIconSource,
|
|
47
53
|
peerNote,
|
|
48
54
|
typecheckNote,
|
|
@@ -50,6 +56,16 @@ import {
|
|
|
50
56
|
writeGeneratedIcons,
|
|
51
57
|
writeIconSetData,
|
|
52
58
|
} from '../../foundation/discovery/icon-set-writer.mjs';
|
|
59
|
+
import {
|
|
60
|
+
describedLooks,
|
|
61
|
+
drawnLooks,
|
|
62
|
+
resolveDefaultLook,
|
|
63
|
+
} from './_default-look.mjs';
|
|
64
|
+
import {shellArg} from '../../foundation/text/shell-arg.mjs';
|
|
65
|
+
import {
|
|
66
|
+
hasLicenseNotice,
|
|
67
|
+
licenseNoticeFix,
|
|
68
|
+
} from '../../foundation/discovery/icon-set-discovery.mjs';
|
|
53
69
|
import {astryxIconDefinitions} from '../../foundation/discovery/icon-definition-discovery.mjs';
|
|
54
70
|
import {suggestedIcons} from '../../foundation/discovery/icon-set-checks.mjs';
|
|
55
71
|
import {
|
|
@@ -99,7 +115,7 @@ function quoteJs(value) {
|
|
|
99
115
|
*/
|
|
100
116
|
export async function addIconSet(name, options) {
|
|
101
117
|
const {cwd = process.cwd(), dryRun = false, from} = options;
|
|
102
|
-
const
|
|
118
|
+
const given = variantOptions(options);
|
|
103
119
|
const exclude =
|
|
104
120
|
typeof options.exclude === 'string'
|
|
105
121
|
? options.exclude
|
|
@@ -192,7 +208,30 @@ export async function addIconSet(name, options) {
|
|
|
192
208
|
dryRun,
|
|
193
209
|
from,
|
|
194
210
|
exclude,
|
|
195
|
-
looks,
|
|
211
|
+
looks: given,
|
|
212
|
+
describe: {
|
|
213
|
+
displayName: options.displayName,
|
|
214
|
+
description: options.description,
|
|
215
|
+
},
|
|
216
|
+
packageDir,
|
|
217
|
+
rootPath,
|
|
218
|
+
manifestPath: projectPath(path.relative(packageDir, manifestFile)),
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
// Without --from, an existing set takes new variants, a default variant, a
|
|
222
|
+
// display name or a description in place, and nothing else changes.
|
|
223
|
+
if (
|
|
224
|
+
from == null &&
|
|
225
|
+
fs.existsSync(docFile) &&
|
|
226
|
+
fs.existsSync(dataFile) &&
|
|
227
|
+
(given != null ||
|
|
228
|
+
options.displayName?.trim() ||
|
|
229
|
+
options.description?.trim())
|
|
230
|
+
) {
|
|
231
|
+
return redeclareIconSet(name, {
|
|
232
|
+
cwd,
|
|
233
|
+
dryRun,
|
|
234
|
+
looks: given,
|
|
196
235
|
describe: {
|
|
197
236
|
displayName: options.displayName,
|
|
198
237
|
description: options.description,
|
|
@@ -227,14 +266,48 @@ export async function addIconSet(name, options) {
|
|
|
227
266
|
let skipped = [];
|
|
228
267
|
/** @type {ReturnType<typeof librarySource>} */
|
|
229
268
|
let library = null;
|
|
269
|
+
/** @type {{summary: import('../../foundation/discovery/icon-set-writer.mjs').LibraryLookSummary | null}} */
|
|
270
|
+
const lookFound = {summary: null};
|
|
271
|
+
// Without --from the set has no icons yet, so no look to match.
|
|
272
|
+
let looks =
|
|
273
|
+
from == null
|
|
274
|
+
? resolveDefaultLook({
|
|
275
|
+
name,
|
|
276
|
+
given,
|
|
277
|
+
current: undefined,
|
|
278
|
+
icons: 0,
|
|
279
|
+
drawn: null,
|
|
280
|
+
library: null,
|
|
281
|
+
}).looks
|
|
282
|
+
: null;
|
|
230
283
|
if (from != null) {
|
|
231
284
|
const source = await iconAuthoring(() =>
|
|
232
285
|
resolveIconSource(from, {packageDir, pkg}),
|
|
233
286
|
);
|
|
234
|
-
const found = libraryIcons(source.file, {
|
|
287
|
+
const found = libraryIcons(source.file, {
|
|
288
|
+
exclude,
|
|
289
|
+
// The library's look words decide the default before any glyph is
|
|
290
|
+
// picked, so each icon's export draws it.
|
|
291
|
+
prefer: positions => {
|
|
292
|
+
looks = resolveDefaultLook({
|
|
293
|
+
name,
|
|
294
|
+
given,
|
|
295
|
+
current: undefined,
|
|
296
|
+
icons: 0,
|
|
297
|
+
drawn: null,
|
|
298
|
+
library: {module: source.module, positions},
|
|
299
|
+
}).looks;
|
|
300
|
+
return looks ? [looks.default] : [];
|
|
301
|
+
},
|
|
302
|
+
module: source.module,
|
|
303
|
+
progress: line => logger.warn(line),
|
|
304
|
+
summary: each => {
|
|
305
|
+
lookFound.summary = each;
|
|
306
|
+
},
|
|
307
|
+
});
|
|
235
308
|
if (found.length === 0) {
|
|
236
309
|
throw new AstryxError(
|
|
237
|
-
`"${from}" exports no icon components this command can read. If its icons are data (objects or SVG strings), run \`astryx experimental icon new-set ${name}\`, declare an "adapter" in ${name}.icons.json, and run this command again; or add icons one at a time with \`astryx experimental icon add <Export> --from ${from}\`.`,
|
|
310
|
+
`"${from}" exports no icon components this command can read. If its icons are data (objects or SVG strings), run \`astryx experimental icon new-set ${name}\`, declare an "adapter" in ${name}.icons.json, and run this command again; or add icons one at a time with \`astryx experimental icon add <Export> --from ${from} --set ${name}\`.`,
|
|
238
311
|
undefined,
|
|
239
312
|
ERROR_CODES.ERR_NOT_FOUND,
|
|
240
313
|
);
|
|
@@ -413,6 +486,11 @@ export async function addIconSet(name, options) {
|
|
|
413
486
|
writtenFiles,
|
|
414
487
|
dryRun,
|
|
415
488
|
);
|
|
489
|
+
const missingNotice = noticeToAdd(
|
|
490
|
+
library,
|
|
491
|
+
packageDir,
|
|
492
|
+
projectPath(path.relative(packageDir, setDir)),
|
|
493
|
+
);
|
|
416
494
|
{
|
|
417
495
|
result.data.icons = icons.length;
|
|
418
496
|
if (from != null) {
|
|
@@ -452,14 +530,221 @@ export async function addIconSet(name, options) {
|
|
|
452
530
|
`Left out ${skipped.length} exports that are not icons: ${skipped.slice(0, 12).join(', ')}${skipped.length > 12 ? ', …' : ''}.`,
|
|
453
531
|
]
|
|
454
532
|
: []),
|
|
455
|
-
...
|
|
456
|
-
|
|
533
|
+
...(from != null && lookFound.summary == null
|
|
534
|
+
? [`Found ${icons.length} icons in ${from}.`]
|
|
535
|
+
: []),
|
|
536
|
+
...(from != null && lookFound.summary != null
|
|
537
|
+
? lookNotes(lookFound.summary, icons.length, from, looks, name)
|
|
538
|
+
: []),
|
|
539
|
+
...(missingNotice ? [missingNotice.note] : []),
|
|
540
|
+
...mappedNotes(map, name),
|
|
541
|
+
...suggestionNotes(suggestions, name),
|
|
457
542
|
'Run `astryx integration check` to see the icon definitions still to map.',
|
|
458
543
|
];
|
|
544
|
+
if (missingNotice) {
|
|
545
|
+
result.data.licenseNoticeMissing = missingNotice.receipt;
|
|
546
|
+
}
|
|
459
547
|
}
|
|
460
548
|
return result;
|
|
461
549
|
}
|
|
462
550
|
|
|
551
|
+
/**
|
|
552
|
+
* The license notice the author must add when the wrapped library ships no
|
|
553
|
+
* license file to copy and the package root has none. The CLI never writes
|
|
554
|
+
* it: the license text is the author's to state. Null when nothing is
|
|
555
|
+
* missing.
|
|
556
|
+
* @param {{package: string, version: string, notices: string[]} | null} library
|
|
557
|
+
* @param {string} packageDir
|
|
558
|
+
* @param {string} setDir the set directory, from the package root
|
|
559
|
+
* @returns {{note: string, receipt: {library: string, path: string}} | null}
|
|
560
|
+
*/
|
|
561
|
+
function noticeToAdd(library, packageDir, setDir) {
|
|
562
|
+
if (!library || library.notices.length > 0) return null;
|
|
563
|
+
if (hasLicenseNotice(packageDir)) return null;
|
|
564
|
+
const named = `${library.package}@${library.version}`;
|
|
565
|
+
return {
|
|
566
|
+
note: `${named} ships no LICENSE or NOTICE file to copy, so the set has no license notice. ${licenseNoticeFix(setDir, named)}`,
|
|
567
|
+
receipt: {library: named, path: `${setDir}/NOTICE`},
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* A set descriptor's source with `--display-name` and `--description`
|
|
573
|
+
* written into its fields; the rest as it was.
|
|
574
|
+
* @param {string} source
|
|
575
|
+
* @param {{displayName?: string, description?: string}} describe
|
|
576
|
+
*/
|
|
577
|
+
function describedDoc(source, describe) {
|
|
578
|
+
let out = source;
|
|
579
|
+
for (const [field, value] of /** @type {const} */ ([
|
|
580
|
+
['displayName', describe.displayName],
|
|
581
|
+
['description', describe.description],
|
|
582
|
+
])) {
|
|
583
|
+
if (!value?.trim()) continue;
|
|
584
|
+
out = out.replace(
|
|
585
|
+
new RegExp(`^(\\s*${field}:\\s*)(['"\`])(?:\\\\.|(?!\\2).)*\\2,?$`, 'mu'),
|
|
586
|
+
(_, lead) => `${lead}${quoteJs(value.trim())},`,
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
return out;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* `new-set <name>` without `--from` over an existing set: declare its
|
|
594
|
+
* variants and default variant, and rewrite its display name and
|
|
595
|
+
* description, in place. Its icons, map and generated module stay as they
|
|
596
|
+
* are. A variant an icon still has must stay declared, and the default
|
|
597
|
+
* variant is one no icon lists as an extra look. A set with icons keeps its
|
|
598
|
+
* default variant: only a refresh with `--from` from a library whose names
|
|
599
|
+
* name its looks moves it. With none declared,
|
|
600
|
+
* its default is the look its icons' exports draw.
|
|
601
|
+
* @param {string} name
|
|
602
|
+
* @param {{cwd: string, dryRun: boolean, looks: Looks | null, describe: {displayName?: string, description?: string}, packageDir: string, rootPath: string, manifestPath: string}} options
|
|
603
|
+
*/
|
|
604
|
+
async function redeclareIconSet(
|
|
605
|
+
name,
|
|
606
|
+
{cwd, dryRun, looks: given, describe, packageDir, rootPath, manifestPath},
|
|
607
|
+
) {
|
|
608
|
+
return iconAuthoring(async () => {
|
|
609
|
+
const where = await findLocalIconSet(cwd, name);
|
|
610
|
+
const {set} = where;
|
|
611
|
+
const current = set.data.default?.variant;
|
|
612
|
+
const drawn =
|
|
613
|
+
given && set.data.icons.length > 0
|
|
614
|
+
? drawnLooks(set, packageDir, module =>
|
|
615
|
+
libraryPositions(module, where, Boolean(set.data.adapter)),
|
|
616
|
+
)
|
|
617
|
+
: null;
|
|
618
|
+
const {looks} = resolveDefaultLook({
|
|
619
|
+
name,
|
|
620
|
+
given,
|
|
621
|
+
current,
|
|
622
|
+
icons: set.data.icons.length,
|
|
623
|
+
drawn,
|
|
624
|
+
library: null,
|
|
625
|
+
});
|
|
626
|
+
if (looks) {
|
|
627
|
+
const declared = new Set(looks.variants);
|
|
628
|
+
const dropped = set.data.icons.flatMap(icon =>
|
|
629
|
+
(icon.variants ?? [])
|
|
630
|
+
.filter(each => !declared.has(each.variant))
|
|
631
|
+
.map(each => `${icon.id} (${each.variant})`),
|
|
632
|
+
);
|
|
633
|
+
if (dropped.length > 0) {
|
|
634
|
+
throw new AstryxError(
|
|
635
|
+
`These icons still have a variant --variants leaves out: ${dropped.slice(0, 8).join(', ')}${dropped.length > 8 ? ', …' : ''}. Keep it in --variants.`,
|
|
636
|
+
[
|
|
637
|
+
{
|
|
638
|
+
name: `--variants ${[...new Set([...looks.variants, ...set.data.icons.flatMap(icon => (icon.variants ?? []).map(each => each.variant))])].join(',')}`,
|
|
639
|
+
reason: 'keep every variant an icon has',
|
|
640
|
+
},
|
|
641
|
+
],
|
|
642
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
const asExtra = set.data.icons
|
|
646
|
+
.filter(icon =>
|
|
647
|
+
(icon.variants ?? []).some(each => each.variant === looks.default),
|
|
648
|
+
)
|
|
649
|
+
.map(icon => icon.id);
|
|
650
|
+
if (asExtra.length > 0) {
|
|
651
|
+
throw new AstryxError(
|
|
652
|
+
`"${looks.default}" can't be the default variant: ${asExtra.length} icons list it as another look (${asExtra.slice(0, 8).join(', ')}${asExtra.length > 8 ? ', …' : ''}), and each icon's own export draws the default.`,
|
|
653
|
+
undefined,
|
|
654
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
const next = {
|
|
659
|
+
...set.data,
|
|
660
|
+
...(looks
|
|
661
|
+
? {variants: looks.variants, default: {variant: looks.default}}
|
|
662
|
+
: {}),
|
|
663
|
+
};
|
|
664
|
+
const docFile = path.join(set.dir, `${set.name}.doc.mjs`);
|
|
665
|
+
const docBefore = fs.readFileSync(docFile, 'utf-8');
|
|
666
|
+
const docAfter = describedDoc(docBefore, describe);
|
|
667
|
+
const dataChanged =
|
|
668
|
+
iconSetDataText(next) !== fs.readFileSync(set.dataPath, 'utf-8');
|
|
669
|
+
/** @type {string[]} */
|
|
670
|
+
const files = [];
|
|
671
|
+
if (dataChanged) {
|
|
672
|
+
files.push(projectPath(path.relative(packageDir, set.dataPath)));
|
|
673
|
+
}
|
|
674
|
+
if (docAfter !== docBefore) {
|
|
675
|
+
files.push(projectPath(path.relative(packageDir, docFile)));
|
|
676
|
+
}
|
|
677
|
+
if (!dryRun) {
|
|
678
|
+
if (dataChanged) writeIconSetData(set, next);
|
|
679
|
+
if (docAfter !== docBefore) {
|
|
680
|
+
journalFile(docFile);
|
|
681
|
+
fs.writeFileSync(docFile, docAfter);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
const result = receipt(
|
|
685
|
+
'icon-set',
|
|
686
|
+
name,
|
|
687
|
+
{path: rootPath, created: false},
|
|
688
|
+
manifestPath,
|
|
689
|
+
files,
|
|
690
|
+
dryRun,
|
|
691
|
+
);
|
|
692
|
+
result.data.icons = set.data.icons.length;
|
|
693
|
+
result.data.updated = true;
|
|
694
|
+
if (where.moduleUpdate) result.data.moduleUpdate = where.moduleUpdate;
|
|
695
|
+
// A look the icons' own library draws comes from that library, so its
|
|
696
|
+
// command runs as printed; any other look comes from a module the
|
|
697
|
+
// author names.
|
|
698
|
+
/** @param {string} variant */
|
|
699
|
+
const fromFor = variant =>
|
|
700
|
+
drawn != null && drawn.positions.some(each => each.has(variant))
|
|
701
|
+
? shellArg(drawn.module)
|
|
702
|
+
: '<module>';
|
|
703
|
+
const added = (looks?.variants ?? []).filter(
|
|
704
|
+
variant =>
|
|
705
|
+
variant !== looks?.default &&
|
|
706
|
+
!(set.data.variants ?? []).includes(variant),
|
|
707
|
+
);
|
|
708
|
+
result.data.notes = [
|
|
709
|
+
files.length === 0
|
|
710
|
+
? `Icon set "${name}" already declares this; nothing changed.`
|
|
711
|
+
: `Updated icon set "${name}" in place; its icons, map and generated module are unchanged.`,
|
|
712
|
+
...(added.length > 0
|
|
713
|
+
? [
|
|
714
|
+
`Give each icon its ${added.join(', ')} look: ${added.map(variant => `\`astryx experimental icon add --variant ${variant} --from ${fromFor(variant)} --all --set ${name}\``).join(', ')}, or one icon with \`astryx experimental icon add <Export> --from <module> --id <icon> --variant <name> --set ${name}\`.`,
|
|
715
|
+
]
|
|
716
|
+
: []),
|
|
717
|
+
];
|
|
718
|
+
return result;
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* The receipt's notes for a library that draws each icon in several looks
|
|
724
|
+
* (a style, a size, a weight): what it found, the look the set took, and
|
|
725
|
+
* how to add another look as a variant.
|
|
726
|
+
* @param {import('../../foundation/discovery/icon-set-writer.mjs').LibraryLookSummary} summary
|
|
727
|
+
* @param {number} count icons in the set
|
|
728
|
+
* @param {string} from
|
|
729
|
+
* @param {{variants: string[], default: string} | null} looks
|
|
730
|
+
* @param {string} name the set's name
|
|
731
|
+
* @returns {string[]}
|
|
732
|
+
*/
|
|
733
|
+
function lookNotes(summary, count, from, looks, name) {
|
|
734
|
+
const described = describedLooks(summary.positions);
|
|
735
|
+
const taken = [...summary.preferred].reverse().join(' ');
|
|
736
|
+
const styles = new Set(summary.positions.flat());
|
|
737
|
+
const others = (looks?.variants ?? []).filter(
|
|
738
|
+
variant => variant !== looks?.default && styles.has(variant),
|
|
739
|
+
);
|
|
740
|
+
return [
|
|
741
|
+
`Found ${count} icons in ${from}, each drawn in several looks (${described}) by ${summary.exports} exports. The set wraps each icon once, in the ${taken} look, named without the look words (\`x\`, \`XIcon\`).`,
|
|
742
|
+
others.length > 0
|
|
743
|
+
? `Add the ${others.join(', ')} look${others.length > 1 ? 's' : ''} as variant${others.length > 1 ? 's' : ''}: ${others.map(variant => `\`astryx experimental icon add --variant ${variant} --from ${from} --all --set ${name}\``).join(', ')}.`
|
|
744
|
+
: `To offer another look as a variant, declare it with \`astryx experimental icon new-set ${name} --variants ${[...summary.preferred].reverse()[0]},<look>\` (no --from: the set's icons stay as they are) and run \`astryx experimental icon add --variant <look> --from ${from} --all --set ${name}\`.`,
|
|
745
|
+
];
|
|
746
|
+
}
|
|
747
|
+
|
|
463
748
|
/**
|
|
464
749
|
* An icon's words from its id: each part, leaving out a bare number
|
|
465
750
|
* (`volume-2` is `volume`) unless the id is only numbers.
|
|
@@ -520,36 +805,40 @@ function definitionSuggestions(icons, map) {
|
|
|
520
805
|
/**
|
|
521
806
|
* The receipt's note for the suggestions, if any.
|
|
522
807
|
* @param {Array<{definition: string, icon: string}>} suggestions
|
|
808
|
+
* @param {string} name the set's name
|
|
523
809
|
*/
|
|
524
|
-
function suggestionNotes(suggestions) {
|
|
810
|
+
function suggestionNotes(suggestions, name) {
|
|
525
811
|
if (suggestions.length === 0) return [];
|
|
526
812
|
const count = new Set(suggestions.map(each => each.definition)).size;
|
|
527
813
|
return [
|
|
528
|
-
`${count} unmapped icon definitions have possible icons (listed under Suggestions; nothing was written for them). Check each meaning, then map the ones that fit: \`astryx experimental icon map <definition> <icon
|
|
814
|
+
`${count} unmapped icon definitions have possible icons (listed under Suggestions; nothing was written for them). Check each meaning, then map the ones that fit: \`astryx experimental icon map <definition> <icon> --set ${name}\`.`,
|
|
529
815
|
];
|
|
530
816
|
}
|
|
531
817
|
|
|
532
818
|
/**
|
|
533
819
|
* The receipt's note for the entries an exact name wrote, if any.
|
|
534
820
|
* @param {Record<string, string>} map
|
|
821
|
+
* @param {string} name the set's name
|
|
535
822
|
*/
|
|
536
|
-
function mappedNotes(map) {
|
|
823
|
+
function mappedNotes(map, name) {
|
|
537
824
|
const count = Object.keys(map).length;
|
|
538
825
|
if (count === 0) return [];
|
|
539
826
|
return [
|
|
540
|
-
`${count} icon definitions were mapped because an icon has their exact name (listed under Mapped by name). A library can draw another meaning under the same name, such as a backspace key named delete: check each, and remap with \`astryx experimental icon map <definition> <icon
|
|
827
|
+
`${count} icon definitions were mapped because an icon has their exact name (listed under Mapped by name). A library can draw another meaning under the same name, such as a backspace key named delete: check each, and remap with \`astryx experimental icon map <definition> <icon> --set ${name}\`.`,
|
|
541
828
|
];
|
|
542
829
|
}
|
|
543
830
|
|
|
831
|
+
/** @typedef {import('./_default-look.mjs').Looks} Looks */
|
|
832
|
+
|
|
544
833
|
/** A variant name: lower-kebab, such as `outline` or `mini-solid`. */
|
|
545
834
|
const VARIANT_NAME_RE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
|
|
546
835
|
|
|
547
836
|
/**
|
|
548
837
|
* The variants and default variant `--variants` and `--default-variant`
|
|
549
|
-
* declare, or
|
|
550
|
-
*
|
|
838
|
+
* declare, or null when neither is given. Unless named, `default` is the
|
|
839
|
+
* first variant until {@link resolveDefaultLook} decides it.
|
|
551
840
|
* @param {{variants?: string[] | string, defaultVariant?: string}} options
|
|
552
|
-
* @returns {
|
|
841
|
+
* @returns {Looks | null}
|
|
553
842
|
*/
|
|
554
843
|
function variantOptions(options) {
|
|
555
844
|
const given =
|
|
@@ -594,7 +883,28 @@ function variantOptions(options) {
|
|
|
594
883
|
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
595
884
|
);
|
|
596
885
|
}
|
|
597
|
-
return {variants, default: chosen || variants[0]};
|
|
886
|
+
return {variants, default: chosen || variants[0], named: Boolean(chosen)};
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* The look positions of a library the set's generated module names, or
|
|
891
|
+
* null when it can't be read.
|
|
892
|
+
* @param {string} module
|
|
893
|
+
* @param {{packageDir: string, pkg: Record<string, any>}} where
|
|
894
|
+
* @param {boolean} adapter
|
|
895
|
+
* @returns {Array<Set<string>> | null}
|
|
896
|
+
*/
|
|
897
|
+
function libraryPositions(module, where, adapter) {
|
|
898
|
+
try {
|
|
899
|
+
const source = resolveIconSource(module, where);
|
|
900
|
+
return moduleNaming(source.file, {
|
|
901
|
+
adapter,
|
|
902
|
+
module,
|
|
903
|
+
progress: line => logger.warn(line),
|
|
904
|
+
}).positions;
|
|
905
|
+
} catch {
|
|
906
|
+
return null;
|
|
907
|
+
}
|
|
598
908
|
}
|
|
599
909
|
|
|
600
910
|
/**
|
|
@@ -626,13 +936,77 @@ async function iconAuthoring(step) {
|
|
|
626
936
|
}
|
|
627
937
|
}
|
|
628
938
|
|
|
939
|
+
/**
|
|
940
|
+
* Whether an id is one an id rule derives from a library glyph: the glyph id,
|
|
941
|
+
* or its library export, broken into words another way (`squares-2-x2` for
|
|
942
|
+
* `squares-2x2`, `glyph-eye` for `glyphEye`). Any other id is the author's.
|
|
943
|
+
* @param {string} id
|
|
944
|
+
* @param {{id: string, export: string}} glyph
|
|
945
|
+
*/
|
|
946
|
+
function derivedId(id, glyph) {
|
|
947
|
+
const flat = (/** @type {string} */ text) =>
|
|
948
|
+
text.toLowerCase().replace(/[^a-z0-9]/gu, '');
|
|
949
|
+
return [glyph.id, glyph.export, glyph.export.replace(/Icon$/u, '')]
|
|
950
|
+
.map(flat)
|
|
951
|
+
.includes(flat(id));
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* Keep the root moves that give each root export to one export of the set.
|
|
956
|
+
* A root export that an export of the set already reads, or that an earlier
|
|
957
|
+
* move takes, stays where it is. The icon that would move keeps its own file,
|
|
958
|
+
* and its variants stay with it. Returns the kept moves and the ids of the
|
|
959
|
+
* icons that stay (with `(<variant>)` for a variant that stays).
|
|
960
|
+
* @param {{data: {module: string, icons: Array<{id: string, export: string, module?: string, variants?: Array<{variant: string, export: string}>}>}}} set
|
|
961
|
+
* @param {Map<string, {module: string, source: string}>} origins
|
|
962
|
+
* @param {string} root
|
|
963
|
+
* @param {Map<string, {source: string, from: string}>} moves
|
|
964
|
+
*/
|
|
965
|
+
function claimRootMoves(set, origins, root, moves) {
|
|
966
|
+
/** @type {Map<string, {source: string, from: string}>} */
|
|
967
|
+
const kept = new Map();
|
|
968
|
+
/** @type {string[]} */
|
|
969
|
+
const skipped = [];
|
|
970
|
+
const claimed = new Set(
|
|
971
|
+
[...origins.values()]
|
|
972
|
+
.filter(origin => sameIconModule(origin.module, root))
|
|
973
|
+
.map(origin => origin.source),
|
|
974
|
+
);
|
|
975
|
+
for (const icon of set.data.icons) {
|
|
976
|
+
if ((icon.module ?? set.data.module) !== set.data.module) continue;
|
|
977
|
+
const own = moves.get(icon.export);
|
|
978
|
+
const origin = origins.get(icon.export);
|
|
979
|
+
const readsRoot = origin != null && sameIconModule(origin.module, root);
|
|
980
|
+
if (own) {
|
|
981
|
+
if (claimed.has(own.source)) {
|
|
982
|
+
skipped.push(icon.id);
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
claimed.add(own.source);
|
|
986
|
+
kept.set(icon.export, own);
|
|
987
|
+
} else if (!readsRoot) continue;
|
|
988
|
+
for (const each of icon.variants ?? []) {
|
|
989
|
+
const move = moves.get(each.export);
|
|
990
|
+
if (!move) continue;
|
|
991
|
+
if (claimed.has(move.source)) {
|
|
992
|
+
skipped.push(`${icon.id} (${each.variant})`);
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
claimed.add(move.source);
|
|
996
|
+
kept.set(each.export, move);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
skipped.sort();
|
|
1000
|
+
return {moves: kept, skipped};
|
|
1001
|
+
}
|
|
1002
|
+
|
|
629
1003
|
/**
|
|
630
1004
|
* Wrap a library into an existing set again: its icons are replaced by what
|
|
631
1005
|
* the library exports now (an icon whose words the author extended keeps
|
|
632
1006
|
* them), the generated module gains the new exports, `map` keeps every entry
|
|
633
1007
|
* whose icon still exists, and the receipt names the entries that lost theirs.
|
|
634
1008
|
* @param {string} name
|
|
635
|
-
* @param {{cwd: string, dryRun: boolean, from: string, exclude: string[], looks:
|
|
1009
|
+
* @param {{cwd: string, dryRun: boolean, from: string, exclude: string[], looks: Looks | null, describe: {displayName?: string, description?: string}, packageDir: string, rootPath: string, manifestPath: string}} options
|
|
636
1010
|
*/
|
|
637
1011
|
async function refreshIconSet(
|
|
638
1012
|
name,
|
|
@@ -641,7 +1015,7 @@ async function refreshIconSet(
|
|
|
641
1015
|
dryRun,
|
|
642
1016
|
from,
|
|
643
1017
|
exclude,
|
|
644
|
-
looks,
|
|
1018
|
+
looks: given,
|
|
645
1019
|
describe,
|
|
646
1020
|
packageDir,
|
|
647
1021
|
rootPath,
|
|
@@ -651,24 +1025,73 @@ async function refreshIconSet(
|
|
|
651
1025
|
return iconAuthoring(async () => {
|
|
652
1026
|
const where = await findLocalIconSet(cwd, name);
|
|
653
1027
|
const {set} = where;
|
|
1028
|
+
const current = set.data.default?.variant;
|
|
654
1029
|
const source = resolveIconSource(from, where);
|
|
655
1030
|
// Exports left out before stay out; --exclude adds to them.
|
|
656
1031
|
const excluded = [
|
|
657
1032
|
...new Set([...(set.data.exclude ?? []), ...exclude]),
|
|
658
1033
|
].sort();
|
|
659
|
-
const
|
|
1034
|
+
const everyIcon = everyLibraryIcon(source.file, {
|
|
660
1035
|
adapter: Boolean(set.data.adapter),
|
|
661
1036
|
exclude: excluded,
|
|
1037
|
+
module: source.module,
|
|
1038
|
+
progress: line => logger.warn(line),
|
|
662
1039
|
});
|
|
1040
|
+
const libraryLookPositions = lookPositions(everyIcon.map(icon => icon.id));
|
|
1041
|
+
// The look the icons from this library draw now decides whether a named
|
|
1042
|
+
// default moves them.
|
|
1043
|
+
const {looks, moved} = resolveDefaultLook({
|
|
1044
|
+
name,
|
|
1045
|
+
given,
|
|
1046
|
+
current,
|
|
1047
|
+
icons: set.data.icons.length,
|
|
1048
|
+
drawn: drawnLooks(set, packageDir, () => libraryLookPositions, {
|
|
1049
|
+
module: source.module,
|
|
1050
|
+
}),
|
|
1051
|
+
library: {module: source.module, positions: libraryLookPositions},
|
|
1052
|
+
});
|
|
1053
|
+
if (looks) {
|
|
1054
|
+
const asExtra = set.data.icons
|
|
1055
|
+
.filter(icon =>
|
|
1056
|
+
(icon.variants ?? []).some(each => each.variant === looks.default),
|
|
1057
|
+
)
|
|
1058
|
+
.map(icon => icon.id);
|
|
1059
|
+
if (asExtra.length > 0) {
|
|
1060
|
+
throw new AstryxError(
|
|
1061
|
+
`"${looks.default}" can't be the default variant: ${asExtra.length} icons list it as another look (${asExtra.slice(0, 8).join(', ')}${asExtra.length > 8 ? ', …' : ''}), and each icon's own export draws the default.`,
|
|
1062
|
+
undefined,
|
|
1063
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
663
1068
|
// A refresh changes only the icons the refreshed module supplies: those
|
|
664
1069
|
// the generated module re-exports or adapts from it. Every other icon
|
|
665
1070
|
// (your own `./` artwork, another library's) is kept as it is, with its
|
|
666
1071
|
// map entries and variants.
|
|
667
1072
|
const generatedBefore = generatedModulePath(set, packageDir);
|
|
668
1073
|
const origins = generatedOrigins(packageDir, generatedBefore);
|
|
1074
|
+
// A refresh from a package root also supplies the exports that read one
|
|
1075
|
+
// file of that package, when the root exports the same icon. They move to
|
|
1076
|
+
// the root import, so the set has one import style.
|
|
1077
|
+
const {moves: rootMoves, skipped: skippedMoves} = claimRootMoves(
|
|
1078
|
+
set,
|
|
1079
|
+
origins,
|
|
1080
|
+
source.module,
|
|
1081
|
+
packageRootMoves(
|
|
1082
|
+
origins,
|
|
1083
|
+
source,
|
|
1084
|
+
everyIcon.map(icon => icon.export),
|
|
1085
|
+
where,
|
|
1086
|
+
),
|
|
1087
|
+
);
|
|
1088
|
+
/** @param {string} name the set's export */
|
|
1089
|
+
const libraryExportOf = name =>
|
|
1090
|
+
rootMoves.get(name)?.source ?? origins.get(name)?.source;
|
|
669
1091
|
/** @param {{export: string, module?: string}} icon */
|
|
670
1092
|
const suppliedHere = icon => {
|
|
671
1093
|
if ((icon.module ?? set.data.module) !== set.data.module) return false;
|
|
1094
|
+
if (rootMoves.has(icon.export)) return true;
|
|
672
1095
|
const origin = origins.get(icon.export);
|
|
673
1096
|
return origin != null && sameIconModule(origin.module, source.module);
|
|
674
1097
|
};
|
|
@@ -676,39 +1099,93 @@ async function refreshIconSet(
|
|
|
676
1099
|
const others = set.data.icons.filter(icon => !suppliedHere(icon));
|
|
677
1100
|
// An existing icon is the same icon when the library still exports it:
|
|
678
1101
|
// its identity is the library export its generated module re-exports
|
|
679
|
-
// (`HiSquares2X2Icon
|
|
680
|
-
// public names are derived, and a
|
|
681
|
-
// (`squares-2-x2` is now
|
|
682
|
-
//
|
|
683
|
-
//
|
|
1102
|
+
// (`HiSquares2X2Icon`, or the root export a per-file icon moves to), then
|
|
1103
|
+
// its public export, then its id. Ids and public names are derived, and a
|
|
1104
|
+
// newer rule may spell them differently (`squares-2-x2` is now
|
|
1105
|
+
// `squares-2x2`); an icon matched this way keeps its public export byte
|
|
1106
|
+
// for byte, every field it had (its variants, the words the author added,
|
|
1107
|
+
// its module), and its map entries. The same rule holds on every refresh,
|
|
1108
|
+
// so a second refresh changes nothing the first one wrote.
|
|
1109
|
+
const moving = new Set(supplied.filter(icon => rootMoves.has(icon.export)));
|
|
684
1110
|
const byId = new Map(supplied.map(icon => [icon.id, icon]));
|
|
685
1111
|
const byExport = new Map(supplied.map(icon => [icon.export, icon]));
|
|
686
1112
|
const bySource = new Map(
|
|
687
|
-
supplied.map(icon => [
|
|
1113
|
+
supplied.map(icon => [libraryExportOf(icon.export), icon]),
|
|
1114
|
+
);
|
|
1115
|
+
// One icon per glyph. A look the set already wraps keeps its icon and id.
|
|
1116
|
+
// A new glyph comes in once, in the preferred look. A new default variant
|
|
1117
|
+
// moves each glyph's icon to that look.
|
|
1118
|
+
const preferred = looks?.default ?? current;
|
|
1119
|
+
const {icons: looksOf} = libraryLooks(
|
|
1120
|
+
everyIcon,
|
|
1121
|
+
preferred ? [preferred] : [],
|
|
688
1122
|
);
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
1123
|
+
const iconByExport = new Map(everyIcon.map(icon => [icon.export, icon]));
|
|
1124
|
+
/** @type {string[]} the set's exports whose statement now names another look */
|
|
1125
|
+
const repicked = [];
|
|
1126
|
+
/** @type {Map<string, (typeof supplied)[number]>} the new look's export → the icon it now draws */
|
|
1127
|
+
const repickedBy = new Map();
|
|
1128
|
+
const found = looksOf.flatMap(icon => {
|
|
1129
|
+
const wrapped = (icon.looks ?? []).filter(look => bySource.has(look));
|
|
1130
|
+
if (wrapped.length === 0) return [icon];
|
|
1131
|
+
return wrapped.map(look => {
|
|
1132
|
+
const prior = /** @type {(typeof supplied)[number]} */ (
|
|
1133
|
+
bySource.get(look)
|
|
1134
|
+
);
|
|
1135
|
+
// A moved icon is the glyph its root export draws, whatever its id.
|
|
1136
|
+
const sameGlyph = moving.has(prior) || prior.id === icon.id;
|
|
1137
|
+
if (moved && sameGlyph && !bySource.has(icon.export)) {
|
|
1138
|
+
repicked.push(prior.export);
|
|
1139
|
+
repickedBy.set(icon.export, prior);
|
|
1140
|
+
return icon;
|
|
1141
|
+
}
|
|
1142
|
+
const own = /** @type {(typeof everyIcon)[number]} */ (
|
|
1143
|
+
iconByExport.get(look)
|
|
1144
|
+
);
|
|
1145
|
+
// Read by the glyph's id when the set already names it so.
|
|
1146
|
+
return prior.id === icon.id
|
|
1147
|
+
? {...own, id: icon.id, name: icon.name}
|
|
1148
|
+
: own;
|
|
1149
|
+
});
|
|
1150
|
+
});
|
|
1151
|
+
/** @param {{export: string}} glyph */
|
|
1152
|
+
const resolvedPrior = glyph =>
|
|
1153
|
+
repickedBy.get(glyph.export) ?? bySource.get(glyph.export) ?? null;
|
|
1154
|
+
// An icon its library export already gives to one glyph is never given to
|
|
1155
|
+
// a second glyph by name or id: that glyph is left out.
|
|
1156
|
+
const resolved = new Set(found.map(resolvedPrior).filter(Boolean));
|
|
1157
|
+
const takenIds = new Set(others.map(icon => icon.id));
|
|
1158
|
+
const takenExports = new Set(others.map(icon => icon.export));
|
|
1159
|
+
/** @type {string[]} library icons left out: an icon of the set has the id or name */
|
|
698
1160
|
const shadowed = [];
|
|
699
1161
|
/** @type {Map<string, string>} old id → new id */
|
|
700
1162
|
const renames = new Map();
|
|
701
1163
|
/** @type {Map<string, string>} the library export → the set's export */
|
|
702
1164
|
const publicName = new Map();
|
|
703
1165
|
const fromLibrary = found.flatMap(icon => {
|
|
704
|
-
const
|
|
1166
|
+
const byOrigin = resolvedPrior(icon);
|
|
1167
|
+
const byName = byOrigin
|
|
1168
|
+
? null
|
|
1169
|
+
: (byExport.get(icon.name) ?? byId.get(icon.id) ?? null);
|
|
1170
|
+
const prior = byOrigin ?? (resolved.has(byName) ? null : byName);
|
|
705
1171
|
const name = prior?.export ?? icon.name;
|
|
706
|
-
if (
|
|
1172
|
+
if (
|
|
1173
|
+
!prior &&
|
|
1174
|
+
(byName || takenIds.has(icon.id) || takenExports.has(name))
|
|
1175
|
+
) {
|
|
707
1176
|
shadowed.push(icon.id);
|
|
708
1177
|
return [];
|
|
709
1178
|
}
|
|
710
|
-
if (prior && prior.id !== icon.id) renames.set(prior.id, icon.id);
|
|
711
1179
|
publicName.set(icon.export, name);
|
|
1180
|
+
if (prior && byOrigin && !derivedId(prior.id, icon)) {
|
|
1181
|
+
return [
|
|
1182
|
+
{
|
|
1183
|
+
...prior,
|
|
1184
|
+
words: [...new Set([...(prior.words ?? []), ...icon.aliases])],
|
|
1185
|
+
},
|
|
1186
|
+
];
|
|
1187
|
+
}
|
|
1188
|
+
if (prior && prior.id !== icon.id) renames.set(prior.id, icon.id);
|
|
712
1189
|
// The words its old id gave are the old rule's, not the author's.
|
|
713
1190
|
const oldIdWords =
|
|
714
1191
|
prior && prior.id !== icon.id ? new Set(idWords(prior.id)) : new Set();
|
|
@@ -728,17 +1205,42 @@ async function refreshIconSet(
|
|
|
728
1205
|
];
|
|
729
1206
|
});
|
|
730
1207
|
const icons = [...fromLibrary, ...others];
|
|
1208
|
+
// An icon is listed under `moved` when it or one of its variants moves.
|
|
1209
|
+
/** @type {Array<{id: string, from: string, to: string}>} */
|
|
1210
|
+
const movedIcons = [];
|
|
1211
|
+
/** @type {import('../../foundation/discovery/icon-set-writer.mjs').GeneratedIcon[]} */
|
|
1212
|
+
const movedVariants = [];
|
|
1213
|
+
for (const icon of fromLibrary) {
|
|
1214
|
+
const variantMoves = (icon.variants ?? []).filter(each =>
|
|
1215
|
+
rootMoves.has(each.export),
|
|
1216
|
+
);
|
|
1217
|
+
for (const each of variantMoves) {
|
|
1218
|
+
const move = /** @type {{source: string, from: string}} */ (
|
|
1219
|
+
rootMoves.get(each.export)
|
|
1220
|
+
);
|
|
1221
|
+
movedVariants.push({
|
|
1222
|
+
name: each.export,
|
|
1223
|
+
from: source.module,
|
|
1224
|
+
source: move.source,
|
|
1225
|
+
adapt: iconByExport.get(move.source)?.adapt ?? false,
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
const from = (
|
|
1229
|
+
rootMoves.get(icon.export) ?? rootMoves.get(variantMoves[0]?.export)
|
|
1230
|
+
)?.from;
|
|
1231
|
+
if (from) movedIcons.push({id: icon.id, from, to: source.module});
|
|
1232
|
+
}
|
|
1233
|
+
movedIcons.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
731
1234
|
// The icons this module supplied that it no longer exports: they leave
|
|
732
1235
|
// the set and its generated module, and the receipt names them.
|
|
733
1236
|
// Each is named for why it left: `--exclude` (or the data file's
|
|
734
1237
|
// `exclude`) names its library export, or the library no longer exports
|
|
735
1238
|
// it.
|
|
736
1239
|
const excludedNames = new Set(excluded);
|
|
737
|
-
const
|
|
738
|
-
|
|
739
|
-
);
|
|
1240
|
+
const keptExports = new Set(fromLibrary.map(each => each.export));
|
|
1241
|
+
const gone = supplied.filter(icon => !keptExports.has(icon.export));
|
|
740
1242
|
const isExcluded = (/** @type {{export: string}} */ icon) =>
|
|
741
|
-
excludedNames.has(
|
|
1243
|
+
excludedNames.has(libraryExportOf(icon.export) ?? '') ||
|
|
742
1244
|
excludedNames.has(icon.export);
|
|
743
1245
|
const goneExcluded = gone.filter(isExcluded);
|
|
744
1246
|
const goneMissing = gone.filter(icon => !isExcluded(icon));
|
|
@@ -782,20 +1284,7 @@ async function refreshIconSet(
|
|
|
782
1284
|
// --display-name and --description rewrite the descriptor's fields.
|
|
783
1285
|
const docFile = path.join(set.dir, `${set.name}.doc.mjs`);
|
|
784
1286
|
const docBefore = fs.readFileSync(docFile, 'utf-8');
|
|
785
|
-
let docAfter = docBefore;
|
|
786
|
-
for (const [field, value] of /** @type {const} */ ([
|
|
787
|
-
['displayName', describe.displayName],
|
|
788
|
-
['description', describe.description],
|
|
789
|
-
])) {
|
|
790
|
-
if (!value?.trim()) continue;
|
|
791
|
-
docAfter = docAfter.replace(
|
|
792
|
-
new RegExp(
|
|
793
|
-
`^(\\s*${field}:\\s*)(['"\`])(?:\\\\.|(?!\\2).)*\\2,?$`,
|
|
794
|
-
'mu',
|
|
795
|
-
),
|
|
796
|
-
(_, lead) => `${lead}${quoteJs(value.trim())},`,
|
|
797
|
-
);
|
|
798
|
-
}
|
|
1287
|
+
let docAfter = describedDoc(docBefore, describe);
|
|
799
1288
|
// A refresh that first records the library as the set's source does what
|
|
800
1289
|
// `new-set --from` does: the descriptor takes the library's license, but
|
|
801
1290
|
// only over the value `new-set` wrote by default (the package's license,
|
|
@@ -840,21 +1329,31 @@ async function refreshIconSet(
|
|
|
840
1329
|
files.push(projectPath(path.relative(packageDir, target)));
|
|
841
1330
|
}
|
|
842
1331
|
if (!dryRun) {
|
|
1332
|
+
const rewritten = found
|
|
1333
|
+
.map(icon => ({
|
|
1334
|
+
name: publicName.get(icon.export) ?? icon.name,
|
|
1335
|
+
from: source.module,
|
|
1336
|
+
source: icon.export,
|
|
1337
|
+
adapt: icon.adapt,
|
|
1338
|
+
}))
|
|
1339
|
+
.filter(icon => publicName.has(icon.source))
|
|
1340
|
+
.concat(movedVariants);
|
|
1341
|
+
const rewrittenNames = new Set(rewritten.map(icon => icon.name));
|
|
843
1342
|
const written = writeGeneratedIcons(
|
|
844
1343
|
packageDir,
|
|
845
1344
|
generated,
|
|
846
1345
|
next,
|
|
847
|
-
|
|
848
|
-
.map(icon => ({
|
|
849
|
-
name: publicName.get(icon.export) ?? icon.name,
|
|
850
|
-
from: source.module,
|
|
851
|
-
source: icon.export,
|
|
852
|
-
adapt: icon.adapt,
|
|
853
|
-
}))
|
|
854
|
-
.filter(icon => publicName.has(icon.source)),
|
|
1346
|
+
rewritten,
|
|
855
1347
|
// The icons the library no longer exports leave the module too; a
|
|
856
|
-
// renamed icon keeps its export.
|
|
857
|
-
|
|
1348
|
+
// renamed icon keeps its export. An icon moved to the new default
|
|
1349
|
+
// look keeps its export, which now names that look. An export moved
|
|
1350
|
+
// to the root is written again with the root import. Every other
|
|
1351
|
+
// export stays as it is, because the data file still lists it.
|
|
1352
|
+
[
|
|
1353
|
+
...gone.map(icon => icon.export),
|
|
1354
|
+
...repicked,
|
|
1355
|
+
...[...rootMoves.keys()].filter(name => rewrittenNames.has(name)),
|
|
1356
|
+
],
|
|
858
1357
|
);
|
|
859
1358
|
files.push(...written.files);
|
|
860
1359
|
try {
|
|
@@ -890,6 +1389,7 @@ async function refreshIconSet(
|
|
|
890
1389
|
);
|
|
891
1390
|
result.data.icons = icons.length;
|
|
892
1391
|
result.data.refreshed = true;
|
|
1392
|
+
if (where.moduleUpdate) result.data.moduleUpdate = where.moduleUpdate;
|
|
893
1393
|
// Every entry an exact name gives, kept or new, so a refresh lists
|
|
894
1394
|
// them for review again.
|
|
895
1395
|
const byName = Object.fromEntries(
|
|
@@ -906,15 +1406,32 @@ async function refreshIconSet(
|
|
|
906
1406
|
if (renames.size > 0) {
|
|
907
1407
|
result.data.renamed = [...renames].map(([from, to]) => ({from, to}));
|
|
908
1408
|
}
|
|
1409
|
+
if (movedIcons.length > 0) result.data.moved = movedIcons;
|
|
1410
|
+
const missingNotice = hasLicenseNotice(set.dir)
|
|
1411
|
+
? null
|
|
1412
|
+
: noticeToAdd(
|
|
1413
|
+
library,
|
|
1414
|
+
packageDir,
|
|
1415
|
+
projectPath(path.relative(packageDir, set.dir)),
|
|
1416
|
+
);
|
|
1417
|
+
if (missingNotice) {
|
|
1418
|
+
result.data.licenseNoticeMissing = missingNotice.receipt;
|
|
1419
|
+
}
|
|
909
1420
|
result.data.notes = [
|
|
910
1421
|
...(licenseNote ? [licenseNote] : []),
|
|
1422
|
+
...(missingNotice ? [missingNotice.note] : []),
|
|
911
1423
|
...(renames.size > 0
|
|
912
1424
|
? [
|
|
913
1425
|
`${renames.size} icons have a new id under this release's id rule, and keep their map entries, variants, and words: ${[...renames].map(([from, to]) => `${from} -> ${to}`).join(', ')}.`,
|
|
914
1426
|
]
|
|
915
1427
|
: []),
|
|
916
|
-
...
|
|
917
|
-
|
|
1428
|
+
...(movedIcons.length > 0
|
|
1429
|
+
? [
|
|
1430
|
+
`${movedIcons.length} icons now import from ${source.module} instead of one file each, and keep their ids, exports, map entries, variants, and words: ${movedIcons.map(each => each.id).join(', ')}.`,
|
|
1431
|
+
]
|
|
1432
|
+
: []),
|
|
1433
|
+
...mappedNotes(byName, name),
|
|
1434
|
+
...suggestionNotes(suggestions, name),
|
|
918
1435
|
...(goneMissing.length > 0
|
|
919
1436
|
? [
|
|
920
1437
|
`${goneMissing.length} icons the library no longer exports were removed from the set: ${goneMissing.map(icon => icon.id).join(', ')}.`,
|
|
@@ -937,7 +1454,12 @@ async function refreshIconSet(
|
|
|
937
1454
|
: []),
|
|
938
1455
|
...(shadowed.length > 0
|
|
939
1456
|
? [
|
|
940
|
-
`Left out ${shadowed.length} library icons whose id or name an icon of
|
|
1457
|
+
`Left out ${shadowed.length} library icons whose id or name an icon of the set already has: ${shadowed.join(', ')}.`,
|
|
1458
|
+
]
|
|
1459
|
+
: []),
|
|
1460
|
+
...(skippedMoves.length > 0
|
|
1461
|
+
? [
|
|
1462
|
+
`${skippedMoves.length} icons stay on their own file, because another icon of the set already reads the same export of ${source.module}: ${skippedMoves.join(', ')}.`,
|
|
941
1463
|
]
|
|
942
1464
|
: []),
|
|
943
1465
|
astryxIconDefinitions().definitions.every(({doc}) => map[doc.name])
|
|
@@ -1022,7 +1544,7 @@ export async function addIconDefinition(name, options) {
|
|
|
1022
1544
|
throw error;
|
|
1023
1545
|
}
|
|
1024
1546
|
}
|
|
1025
|
-
|
|
1547
|
+
const result = receipt(
|
|
1026
1548
|
'icon-definition',
|
|
1027
1549
|
doc.name,
|
|
1028
1550
|
{
|
|
@@ -1039,5 +1561,10 @@ export async function addIconDefinition(name, options) {
|
|
|
1039
1561
|
files,
|
|
1040
1562
|
dryRun,
|
|
1041
1563
|
);
|
|
1564
|
+
// Only a new definition with an icon writes the data file.
|
|
1565
|
+
if (icon != null && where.moduleUpdate) {
|
|
1566
|
+
result.data.moduleUpdate = where.moduleUpdate;
|
|
1567
|
+
}
|
|
1568
|
+
return result;
|
|
1042
1569
|
});
|
|
1043
1570
|
}
|