@muonic/muon 0.0.2-experimental-151-6e27a7a.0 → 0.0.2-experimental-153-7d10f5f.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,8 @@ import { Image } from '@muon/components/image';
5
5
  import styles from './card-styles.css';
6
6
 
7
7
  /**
8
+ * A card is a container for content.
9
+ *
8
10
  * @element card
9
11
  */
10
12
  export class Card extends ScopedElementsMixin(ImageHolderMixin(CardMixin(MuonElement))) {
@@ -9,8 +9,8 @@ import {
9
9
 
10
10
  import styles from './image-styles.css';
11
11
 
12
- /**.
13
- * Loading images with default lazy loading
12
+ /**
13
+ * Loading images with default lazy loading.
14
14
  *
15
15
  * @element image
16
16
  */
@@ -205,8 +205,8 @@ export class Inputter extends ScopedElementsMixin(ValidationMixin(MaskMixin(Muon
205
205
  }
206
206
  }
207
207
 
208
- /**.
209
- * InputterDetail component to handle helper text
208
+ /**
209
+ * InputterDetail component to handle helper text.
210
210
  *
211
211
  * @element inputter-detail
212
212
  * @private
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@muonic/muon",
3
- "version": "0.0.2-experimental-151-6e27a7a.0",
3
+ "version": "0.0.2-experimental-153-7d10f5f.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "web-test-runner \"./tests/**/*.test.js\" --coverage",
8
+ "test:scripts": "ava \"tests/scripts/utils/utils-test.js\"",
8
9
  "test:browserstack": "web-test-runner \"./tests/**/*.test.js\" --config web-test-runner.browserstack.config.mjs",
9
10
  "release": "standard-version"
10
11
  },
@@ -56,6 +57,7 @@
56
57
  "@web/test-runner": "0.14.0",
57
58
  "@web/test-runner-browserstack": "0.5.1",
58
59
  "@web/test-runner-playwright": "0.8.10",
60
+ "ava": "4.3.3",
59
61
  "sinon": "14.0.0"
60
62
  },
61
63
  "engines": {
@@ -4,7 +4,7 @@ import StorybookConfig from '../../storybook/server.config.mjs';
4
4
 
5
5
  const myServerDefinitions = [
6
6
  { name: 'no-open', type: Boolean },
7
- { name: 'no-watch', type: Boolean },
7
+ { name: 'no-watch', type: Boolean }
8
8
  ];
9
9
 
10
10
  const myConfig = commandLineArgs(myServerDefinitions, { partial: true });
@@ -21,6 +21,16 @@ export default {
21
21
  }
22
22
  ]
23
23
  },
24
+ ref: {
25
+ buildPath: path.join(buildPath, 'json/'),
26
+ transforms: ['color/css', 'size/rem'],
27
+ files: [
28
+ {
29
+ destination: 'muon-tokens-reference.json',
30
+ format: 'json/reference'
31
+ }
32
+ ]
33
+ },
24
34
  es6: {
25
35
  buildPath: path.join(buildPath, 'es6/'),
26
36
  transforms: ['name/cti/constant', 'color/css', 'size/rem'],
@@ -12,6 +12,7 @@ import path from 'path';
12
12
  import styleConfig from '../style-dictionary.mjs';
13
13
  import colorTransform from '../../tokens/utils/transforms/color.js';
14
14
  import stringTransform from '../../tokens/utils/transforms/string.js';
15
+ import jsonReference from '../../tokens/utils/formats/reference.js';
15
16
 
16
17
  import { fileURLToPath } from 'url';
17
18
 
@@ -138,7 +139,7 @@ const getAliasPaths = (type) => {
138
139
  obj[key] = [value];
139
140
  } else {
140
141
  // @TODO: This needs a better way to find the node_modules folder
141
- obj[key] = [`node_modules/${value}`];
142
+ obj[key] = [`${appRoot}/node_modules/${value}`];
142
143
  }
143
144
  });
144
145
 
@@ -176,7 +177,7 @@ const getAliasPaths = (type) => {
176
177
 
177
178
  const sourceFilesAnalyzer = async () => {
178
179
  const files = await findComponents();
179
- const paths = await getAliasPaths('glob');
180
+ const paths = getAliasPaths('glob');
180
181
  const options = {
181
182
  noEmitOnError: false,
182
183
  allowJs: true,
@@ -206,7 +207,8 @@ const sourceFilesAnalyzer = async () => {
206
207
  verbose: true,
207
208
  config: {
208
209
  format: 'json',
209
- discoverNodeModules: true
210
+ discoverNodeModules: true,
211
+ excludedDeclarationNames: ['ScopedElementsMixin']
210
212
  }
211
213
  }));
212
214
 
@@ -234,6 +236,8 @@ const styleDictionary = async () => {
234
236
 
235
237
  const styleDict = StyleDictionary.extend(styleConfig);
236
238
 
239
+ styleDict.registerFormat(jsonReference);
240
+
237
241
  styleDict.registerFormat({
238
242
  name: 'css/fonts',
239
243
  formatter: cssFontTemplate
@@ -0,0 +1,9 @@
1
+ {
2
+ "components": {
3
+ "included": "inputter,card,image"
4
+ },
5
+ "tokens": {
6
+ "dir": ["tokens/*.json"],
7
+ "theme": "default"
8
+ }
9
+ }
@@ -0,0 +1,134 @@
1
+ const testRunner = require('ava');
2
+ const sinon = require('sinon');
3
+ const appRoot = require('app-root-path');
4
+
5
+ let utilsLibrary;
6
+ testRunner.before(async () => {
7
+ await import('../../../scripts/utils/index.mjs').then((utils) => {
8
+ utilsLibrary = utils;
9
+ });
10
+ });
11
+
12
+ testRunner('filterPathToCustomElements default', async (t) => {
13
+ const componentList = await utilsLibrary.filterPathToCustomElements('all');
14
+ t.is(componentList, '*');
15
+ });
16
+
17
+ testRunner('filterPathToCustomElements default array', async (t) => {
18
+ const componentList = await utilsLibrary.filterPathToCustomElements(['all']);
19
+ t.is(componentList, '*');
20
+ });
21
+
22
+ testRunner('filterPathToCustomElements single component', async (t) => {
23
+ const componentList = await utilsLibrary.filterPathToCustomElements('inputter');
24
+ t.is(componentList, 'inputter');
25
+ });
26
+
27
+ testRunner('filterPathToCustomElements single component in array', async (t) => {
28
+ const componentList = await utilsLibrary.filterPathToCustomElements(['inputter']);
29
+ t.is(componentList, 'inputter');
30
+ });
31
+
32
+ testRunner('filterPathToCustomElements multiple component', async (t) => {
33
+ const componentList = await utilsLibrary.filterPathToCustomElements(['inputter', 'image']);
34
+ t.is(componentList, '{inputter,image}');
35
+ });
36
+
37
+ testRunner('getConfig default file and root', async (t) => {
38
+ const config = utilsLibrary.getConfig();
39
+ t.true(config !== undefined);
40
+ });
41
+
42
+ testRunner('getConfig new file default root', async (t) => {
43
+ const config = utilsLibrary.getConfig('browserstack.json');
44
+ t.true(config !== undefined);
45
+ });
46
+
47
+ testRunner('getConfig config file not exist', async (t) => {
48
+ sinon.stub(process, 'exit');
49
+ utilsLibrary.getConfig('test.json');
50
+ t.true(process.exit.called);
51
+ t.true(process.exit.calledWith(1));
52
+ });
53
+
54
+ testRunner('getConfig config file', async (t) => {
55
+ const config = utilsLibrary.getConfig('tests/scripts/utils/test.json');
56
+ t.true(config !== undefined);
57
+ });
58
+
59
+ const componentsDefinitionMacro = async (t, expected) => {
60
+ const componentDefinition = await utilsLibrary.componentDefiner();
61
+ t.true(componentDefinition !== undefined);
62
+ t.true(componentDefinition.indexOf(`import '@webcomponents/scoped-custom-element-registry';`) > -1);
63
+ Object.keys(expected).forEach((component) => {
64
+ t.true(componentDefinition.indexOf(`import { ${expected[component]} } from '${process.cwd()}/components/${component}/src/${component}-component.js';`) > -1);
65
+ t.true(componentDefinition.indexOf(`customElements.define('muon-${component}', ${expected[component]});`) > -1);
66
+ });
67
+ };
68
+ componentsDefinitionMacro.title = (providedTitle, expected) => `${providedTitle} => ${Object.keys(expected)}`;
69
+
70
+ testRunner('componentDefiner', componentsDefinitionMacro, { card: 'Card', cta: 'Cta', detail: 'Detail', form: 'Form', icon: 'Icon', inputter: 'Inputter', image: 'Image' });
71
+
72
+ testRunner('getAliasPath glob', async (t) => {
73
+ const alias = utilsLibrary.getAliasPaths('glob');
74
+
75
+ t.deepEqual(alias, {
76
+ '@muon/components/*': [`${appRoot}/node_modules/@muonic/muon/components/*`],
77
+ '@muon/mixins/*': [`${appRoot}/node_modules/@muonic/muon/mixins/*`],
78
+ '@muon/directives/*': [`${appRoot}/node_modules/@muonic/muon/directives/*`],
79
+ '@muon/utils/*': [`${appRoot}/node_modules/@muonic/muon/utils/*`],
80
+ '@muon/tokens': [`${appRoot}/node_modules/@muonic/muon/build/tokens/es6/muon-tokens`]
81
+ });
82
+ });
83
+
84
+ testRunner('getAliasPath regex', async (t) => {
85
+ const alias = utilsLibrary.getAliasPaths('regex');
86
+ t.deepEqual(alias, [
87
+ {
88
+ find: /^@muon\/components\/(.*)$/,
89
+ replacement: '@muonic/muon/components/$1'
90
+ },
91
+ {
92
+ find: /^@muon\/mixins\/(.*)$/,
93
+ replacement: '@muonic/muon/mixins/$1'
94
+ },
95
+ {
96
+ find: /^@muon\/directives\/(.*)$/,
97
+ replacement: '@muonic/muon/directives/$1'
98
+ },
99
+ {
100
+ find: /^@muon\/utils\/(.*)$/,
101
+ replacement: '@muonic/muon/utils/$1'
102
+ },
103
+ {
104
+ find: /^@muon\/tokens$/,
105
+ replacement: '@muonic/muon/build/tokens/es6/muon-tokens'
106
+ }
107
+ ]);
108
+ });
109
+
110
+ testRunner('sourceFilesAnalyzer', async (t) => {
111
+ const result = await utilsLibrary.sourceFilesAnalyzer();
112
+ const jsonResult = JSON.parse(result);
113
+
114
+ const components = ['card', 'cta', 'detail', 'form', 'icon', 'image', 'inputter', 'inputter-detail'];
115
+ const propertiesMap = {
116
+ card: ['standardTemplate', 'image', 'alt', 'background', 'type'],
117
+ cta: ['href', 'standardTemplate', 'submitTemplate', 'resetTemplate', 'loading', 'loadingMessage', 'disabled', 'icon', 'type'],
118
+ detail: ['icon', 'standardTemplate', 'open', 'type'],
119
+ form: ['standardTemplate', 'type'],
120
+ icon: ['size', 'sizes', 'iconSize', 'standardTemplate', 'name', 'category', 'allSizes', 'url', 'describe', 'type'],
121
+ image: ['src', 'placeholderImage', 'standardTemplate', 'background', 'backgroundsize', 'alt', 'ratio', 'placeholder', 'loading', 'type'],
122
+ inputter: ['helper', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'type'],
123
+ 'inputter-detail': ['icon', 'standardTemplate', 'open', 'type']
124
+ };
125
+ t.deepEqual(jsonResult.tags?.map((tag) => tag.name), components);
126
+
127
+ components.forEach((component) => {
128
+ t.deepEqual(jsonResult.tags.filter((tag) => tag.name === component)[0].properties?.map(
129
+ (property) => property.name), propertiesMap[component]);
130
+ });
131
+ jsonResult.tags?.map((tag) => {
132
+ t.true(tag.description !== undefined, `${tag.name} description is not present`);
133
+ });
134
+ });
@@ -0,0 +1,17 @@
1
+ module.exports = {
2
+ name: 'json/reference',
3
+ formatter: function ({ dictionary }) {
4
+ const tokens = dictionary.allTokens.map((token) => {
5
+ token.usesReference = dictionary.usesReference(token.original.value);
6
+ if (token.usesReference) {
7
+ token.references = dictionary.getReferences(token.original.value);
8
+ }
9
+
10
+ token.nestedName = token.path.join('.').toLowerCase();
11
+
12
+ return token;
13
+ });
14
+
15
+ return JSON.stringify(tokens, null, 2);
16
+ }
17
+ };