Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(icon-build-helpers): update metadata generation #5372

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
56a27a1
chore: check-in work
joshblack Feb 1, 2020
194e4e6
chore: check-in work
joshblack Feb 2, 2020
a312e7f
refactor(icons): update metadata build helpers
joshblack Feb 17, 2020
99f4e6e
chore(icons): run remove-usage-fields migration
joshblack Feb 17, 2020
a64a637
chore(icons): uncomment builder code
joshblack Feb 17, 2020
73b69a7
chore(icon-metadata): add special case for glyphs
joshblack Feb 17, 2020
4701d09
feat(metadata): add pictogram extension
joshblack Feb 17, 2020
85732d8
feat(icon-metadata): add support for extensions in ci-check
joshblack Feb 17, 2020
3310d37
refactor(pictograms): run migration for pictogram files
joshblack Feb 17, 2020
0472b53
feat(pictograms): add metadata support for pictograms
joshblack Feb 17, 2020
07eb3db
chore(icon-metadata): fix eslint violations
joshblack Feb 17, 2020
3f8fa0f
Merge branch 'master' of github.com:carbon-design-system/carbon into …
joshblack Feb 17, 2020
e14f42b
chore(icons): update metadata with new icon changes
joshblack Feb 17, 2020
36d0442
Merge branch 'master' into refactor/update-icon-metadata
joshblack Feb 17, 2020
988b1df
chore(icon-build-helpers): update comment with latest terminology
joshblack Feb 17, 2020
baec0ff
chore(pictograms): update scaffold task to only use pictograms extension
joshblack Feb 17, 2020
f08a879
Merge branch 'master' into refactor/update-icon-metadata
joshblack Feb 17, 2020
638b72c
chore(icons): update metadata with new icon changes
joshblack Feb 17, 2020
f623000
Merge branch 'master' into refactor/update-icon-metadata
joshblack Feb 18, 2020
d08fc30
Merge branch 'master' into refactor/update-icon-metadata
tw15egan Feb 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .yarn/offline-mirror/fast-extend-0.0.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/fast-extend-1.0.2.tgz
Binary file not shown.
Binary file removed .yarn/offline-mirror/memfs-2.17.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/memfs-3.0.4.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/icon-build-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"joi": "^14.3.1",
"js-yaml": "^3.12.1",
"klaw-sync": "^6.0.0",
"memfs": "^2.14.0",
"memfs": "^3.0.4",
"prettier": "^1.19.1",
"prop-types": "^15.6.2",
"react": "^16.6.0",
Expand Down
30 changes: 0 additions & 30 deletions packages/icon-build-helpers/src/build-metadata.js

This file was deleted.

206 changes: 0 additions & 206 deletions packages/icon-build-helpers/src/check.js

This file was deleted.

6 changes: 2 additions & 4 deletions packages/icon-build-helpers/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
'use strict';

const builders = require('./builders');
const buildMetadata = require('./build-metadata');
const check = require('./check');
const Metadata = require('./metadata');

module.exports = {
builders,
buildMetadata,
check,
Metadata,
};
37 changes: 37 additions & 0 deletions packages/icon-build-helpers/src/metadata/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Metadata

## About

We store metadata for a collection of SVG assets to help with searching and
using icons in the Carbon Design System. However, due to the large number of
assets we maintain, we needed to build a system for organizing information about
these icons and creating an output file to be consumed by tooling.

As a result, the Metadata module provides support for building, scaffolding, and
verifying metadata information about a collection of SVG assets. Under the hood,
this module will build up a registry of all available assets and compare them
against metadata files called "extensions". These files are typically written in
YAML and are separated to make authoring of specific types of data easier.

In general, we support the following extension types:

- Icons: provides information for icons available from the source directory of
SVG assets
- Categories: provides category and subcategory information for a collection of
icons
- Module name: provides computed names used in code for an icon
- Deprecations: provides a listing of icons that have been deprecated and
details how to update usage to the preferred format

To support the above use-cases, Metadata makes use of the following concepts:

- [Registry](./registry.js): build up a source of truth for all available SVG
assets in a source tree
- [Extensions](./extensions/index.js): distinct sources of metadata captured for
icons. These modules provide support for verifying file structure, extending
the resulting output metadata, and logical checks to verify information
present (or not present) in these files
- [Adapters](./adapters.js): provide support for authoring metadata in a variety
of formats, we currently author in YAML
- [Storage](./storage.js): ability to read and write extension files for a given
adapter
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Copyright IBM Corp. 2020, 2020
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment node
*/

'use strict';

describe('registry', () => {
let Registry;
let vol;

beforeEach(() => {
jest.mock('fs', () => {
const memfs = require('memfs');
vol = memfs.vol;
return memfs.fs;
});
Registry = require('../registry');
});

afterEach(() => {
vol.reset();
});

it('should register each asset from a directory', async () => {
const assets = ['a', 'b', 'c'];
const files = {};
for (const asset of assets) {
const filepath = `/svg/${asset}.svg`;
files[filepath] = 'mock';
}
vol.fromJSON(files);

const registry = await Registry.create('/svg');
for (const [id] of registry) {
expect(assets.indexOf(id)).not.toBe(-1);
}
});

it('should register each asset in nested directories', async () => {
const assets = ['foo/a', 'foo/bar/b', 'baz/c'];
const files = {};
for (const asset of assets) {
const filepath = `/svg/${asset}.svg`;
files[filepath] = 'mock';
}
vol.fromJSON(files);

const registry = await Registry.create('/svg');
for (const icon of registry.values()) {
const asset = icon.namespace.join('/') + '/' + icon.id;
expect(assets.indexOf(asset)).not.toBe(-1);
}
});

it('should register assets with the same name under the same icon', async () => {
const assets = ['16/a', '20/a', '32/a'];
const files = {};
for (const asset of assets) {
const filepath = `/svg/${asset}.svg`;
files[filepath] = 'mock';
}
vol.fromJSON(files);

const registry = await Registry.create('/svg');
expect(registry.size).toBe(1);

const icon = registry.get('a');
expect(icon.assets.length).toBe(assets.length);
expect(icon.assets[0].size).toBe(16);
expect(icon.assets[1].size).toBe(20);
expect(icon.assets[2].size).toBe(32);
});
});
Loading