@muonic/muon 0.0.2-experimental-178-7990088.0 → 0.0.2-experimental-180-b50e9e6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.0.2-beta.10](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.9...v0.0.2-beta.10) (2023-05-04)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * move adding lightdom on perform ([41e7843](https://github.com/centrica-engineering/muon/commit/41e7843f57342e84d719a86a34de0ce1862081dc))
11
+
5
12
  ### [0.0.2-beta.9](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.8...v0.0.2-beta.9) (2023-04-21)
6
13
 
7
14
  ### [0.0.2-beta.8](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.7...v0.0.2-beta.8) (2023-04-20)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muonic/muon",
3
- "version": "0.0.2-experimental-178-7990088.0",
3
+ "version": "0.0.2-experimental-180-b50e9e6.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -61,19 +61,33 @@ const filterPathToCustomElements = async (componentsList) => {
61
61
 
62
62
  const findComponents = async () => {
63
63
  const config = getConfig();
64
- const additional = config?.components?.dir;
65
64
  const componentsList = config?.components?.included;
66
65
  const pathPattern = await filterPathToCustomElements(componentsList);
67
66
  // initial Muon components
68
67
  let muonComponents = path.join(__filename, '..', '..', '..', 'components', '**', `${pathPattern}-component.js`);
68
+
69
69
  // additional components
70
+ const additional = config?.components?.dir;
70
71
  if (additional) {
71
- muonComponents = `{${muonComponents},${additional}}`;
72
+ muonComponents = `{${muonComponents},${additional.toString()}}`;
72
73
  }
73
74
 
74
75
  return glob.sync(muonComponents).map((f) => path.resolve(f));
75
76
  };
76
77
 
78
+ const getPrefix = () => {
79
+ const config = getConfig();
80
+ return config?.components?.prefix || 'muon';
81
+ };
82
+
83
+ const getTagFromAnalyzerResult = (result) => {
84
+ // @TODO: An assumption that the first component in the file is the component we are looking for
85
+ const tags = result.componentDefinitions[0]?.declaration?.jsDoc?.tags;
86
+ const tagName = tags?.filter((jsDocTag) => jsDocTag.tag === 'element')?.[0]?.comment;
87
+ const prefix = tags?.filter((jsDocTag) => jsDocTag.tag === 'prefix')?.[0]?.comment ?? getPrefix();
88
+ return { tagName, prefix };
89
+ };
90
+
77
91
  const analyze = async () => {
78
92
  const files = (await findComponents()).map((file) => {
79
93
  const code = fs.readFileSync(file);
@@ -84,11 +98,12 @@ const analyze = async () => {
84
98
  const { results } = analyzeText(files);
85
99
 
86
100
  return results.map((result) => {
87
- // @TODO: An assumption that the first component in the file is the component we are looking for
101
+ const { tagName, prefix } = getTagFromAnalyzerResult(result);
88
102
  return {
89
103
  file: result.sourceFile.fileName,
90
- name: result.componentDefinitions[0].tagName,
91
- exportName: result.sourceFile?.symbol?.exports?.keys()?.next()?.value
104
+ name: tagName,
105
+ exportName: result.sourceFile?.symbol?.exports?.keys()?.next()?.value,
106
+ elementName: `${prefix}-${tagName}`
92
107
  };
93
108
  });
94
109
  };
@@ -194,7 +209,14 @@ const sourceFilesAnalyzer = async () => {
194
209
  }
195
210
  }));
196
211
 
197
- const tagNames = results?.map((result) => result.componentDefinitions[0].tagName);
212
+ const tagNames = results?.map((result) => {
213
+ const {tagName, prefix } = getTagFromAnalyzerResult(result);
214
+
215
+ const elementName = `${prefix}-${tagName}`;
216
+ result.componentDefinitions[0].tagName = elementName;
217
+ return elementName;
218
+ });
219
+
198
220
  const tagsSet = new Set(tagNames);
199
221
  if (tagsSet?.size !== tagNames?.length) {
200
222
  console.error('---------------------------------------------');
@@ -265,14 +287,12 @@ const createTokens = async () => {
265
287
  const componentDefiner = async () => {
266
288
  const config = getConfig();
267
289
  const compList = await analyze();
268
- const prefix = config?.components?.prefix || 'muon';
290
+ const prefix = getPrefix();
269
291
  let componentDefinition = `import '@webcomponents/scoped-custom-element-registry';`;
270
292
 
271
- componentDefinition += compList.map(({ file, name, exportName }) => {
272
- const elName = `${prefix}-${name}`;
273
-
293
+ componentDefinition += compList.map(({ file, name, exportName, elementName }) => {
274
294
  return `import { ${exportName} } from '${file}';
275
- customElements.define('${elName}', ${exportName});
295
+ customElements.define('${elementName}', ${exportName});
276
296
  `;
277
297
  }).join('');
278
298
 
@@ -1,7 +1,6 @@
1
1
  import { staticHTML, unsafeStatic } from '@muonic/muon';
2
- export default (name, el) => {
3
- const prefix = process.env.MUON_PREFIX;
4
- const element = `${prefix}-${name}`;
2
+ export default (name, el, prefix = process.env.MUON_PREFIX) => {
3
+ const element = prefix ? `${prefix}-${name}` : name;
5
4
 
6
5
  if (!customElements.get(element)) {
7
6
  customElements.define(element, el);
@@ -10,7 +9,7 @@ export default (name, el) => {
10
9
  const elName = name ? name : element;
11
10
  const defaultValues = {
12
11
  title: element,
13
- component: elName,
12
+ component: element,
14
13
  argTypes: {
15
14
  registry: {
16
15
  table: {
@@ -0,0 +1,17 @@
1
+ import { MuonElement } from '@muonic/muon';
2
+
3
+ /**
4
+ * A Nucleus call-to-action allows users to take action once they are ready for it.
5
+ *
6
+ * @element cta
7
+ * @prefix mnx
8
+ *
9
+ */
10
+
11
+ export class TestCta extends MuonElement {
12
+ static get properties() {
13
+ return {
14
+ enabled: { type: Boolean }
15
+ };
16
+ }
17
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "components": {
3
+ "included": ["inputter" ,"cta"],
4
+ "dir": "tests/scripts/utils/cta-component.js"
5
+ },
6
+ "tokens": {
7
+ "dir": ["tokens/*.json"],
8
+ "theme": "default"
9
+ },
10
+ "alias": {
11
+ "@muon/utils/validation": "./utils/validation"
12
+ }
13
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "components": {
3
- "included": ["inputter" ,"card","image"],
4
- "dir": "tests/scripts/utils/*-component.js"
3
+ "included": ["inputter" ,"card", "image"],
4
+ "dir": "tests/scripts/utils/card-component.js"
5
5
  },
6
6
  "tokens": {
7
7
  "dir": ["tokens/*.json"],
@@ -179,15 +179,15 @@ testRunner('sourceFilesAnalyzer', async (t) => {
179
179
  const result = await utilsLibrary.sourceFilesAnalyzer();
180
180
  const jsonResult = JSON.parse(result);
181
181
 
182
- const components = ['card', 'cta', 'detail', 'form', 'icon', 'image', 'inputter', 'inputter-detail'];
182
+ const components = ['muon-card', 'muon-cta', 'muon-detail', 'muon-form', 'muon-icon', 'muon-image', 'muon-inputter', 'inputter-detail'];
183
183
  const propertiesMap = {
184
- card: ['classes', 'inlineStyles', 'standardTemplate', 'image', 'alt', 'background', 'type'],
185
- cta: ['href', 'classes', 'inlineStyles', 'standardTemplate', 'submitTemplate', 'resetTemplate', 'loading', 'loadingMessage', 'disabled', 'icon', 'type'],
186
- detail: ['icon', 'classes', 'inlineStyles', 'standardTemplate', 'open', 'type'],
187
- form: ['standardTemplate', 'type'],
188
- icon: ['size', 'classes', 'inlineStyles', 'sizes', 'iconSize', 'standardTemplate', 'name', 'category', 'allSizes', 'describe', 'type'],
189
- image: ['src', 'classes', 'inlineStyles', 'placeholderImage', 'standardTemplate', 'background', 'backgroundsize', 'alt', 'ratio', 'placeholder', 'loading', 'type'],
190
- inputter: ['helper', 'classes', 'inlineStyles', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'type'],
184
+ 'muon-card': ['classes', 'inlineStyles', 'standardTemplate', 'image', 'alt', 'background', 'type'],
185
+ 'muon-cta': ['href', 'classes', 'inlineStyles', 'standardTemplate', 'submitTemplate', 'resetTemplate', 'loading', 'loadingMessage', 'disabled', 'icon', 'type'],
186
+ 'muon-detail': ['icon', 'classes', 'inlineStyles', 'standardTemplate', 'open', 'type'],
187
+ 'muon-form': ['standardTemplate', 'type'],
188
+ 'muon-icon': ['size', 'classes', 'inlineStyles', 'sizes', 'iconSize', 'standardTemplate', 'name', 'category', 'allSizes', 'describe', 'type'],
189
+ 'muon-image': ['src', 'classes', 'inlineStyles', 'placeholderImage', 'standardTemplate', 'background', 'backgroundsize', 'alt', 'ratio', 'placeholder', 'loading', 'type'],
190
+ 'muon-inputter': ['helper', 'classes', 'inlineStyles', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'type'],
191
191
  'inputter-detail': ['icon', 'classes', 'inlineStyles', 'standardTemplate', 'open', 'type']
192
192
  };
193
193
  t.deepEqual(jsonResult.tags?.map((tag) => tag.name).sort(), components.sort());
@@ -201,6 +201,33 @@ testRunner('sourceFilesAnalyzer', async (t) => {
201
201
  });
202
202
  });
203
203
 
204
+ testRunner('sourceFilesAnalyzer with prefix override', async (t) => {
205
+ const stub = await esmock('../../../scripts/utils/index.mjs', {
206
+ '../../../scripts/utils/config.mjs': {
207
+ getConfig: (configFile) => JSON.parse(fs.readFileSync('tests/scripts/utils/muon.config.prefix.override.json').toString())
208
+ }
209
+ });
210
+ const result = await stub.sourceFilesAnalyzer();
211
+ const jsonResult = JSON.parse(result);
212
+
213
+ const components = ['muon-cta', 'muon-inputter', 'inputter-detail', 'mnx-cta'];
214
+ const propertiesMap = {
215
+ 'muon-cta': ['href', 'classes', 'inlineStyles', 'standardTemplate', 'submitTemplate', 'resetTemplate', 'loading', 'loadingMessage', 'disabled', 'icon', 'type'],
216
+ 'muon-inputter': ['helper', 'classes', 'inlineStyles', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'type'],
217
+ 'inputter-detail': ['icon', 'classes', 'inlineStyles', 'standardTemplate', 'open', 'type'],
218
+ 'mnx-cta': ['enabled', 'type']
219
+ };
220
+ t.deepEqual(jsonResult.tags?.map((tag) => tag.name).sort(), components.sort());
221
+
222
+ components.forEach((component) => {
223
+ t.deepEqual(jsonResult.tags.filter((tag) => tag.name === component)[0].properties?.map(
224
+ (property) => property.name), propertiesMap[component], component);
225
+ });
226
+ jsonResult.tags?.map((tag) => {
227
+ t.true(tag.description !== undefined, `${tag.name} description is not present`);
228
+ });
229
+ });
230
+
204
231
  testRunner('sourceFilesAnalyzer error', async (t) => {
205
232
  const stub = await esmock('../../../scripts/utils/index.mjs', {
206
233
  '../../../scripts/utils/config.mjs': {
@@ -223,9 +250,9 @@ testRunner('sourceFilesAnalyzer single file', async (t) => {
223
250
  const result = await stub.sourceFilesAnalyzer();
224
251
  const jsonResult = JSON.parse(result);
225
252
 
226
- const components = ['card'];
253
+ const components = ['muon-card'];
227
254
  const propertiesMap = {
228
- card: ['classes', 'inlineStyles', 'standardTemplate', 'image', 'alt', 'background', 'type'],
255
+ 'muon-card': ['classes', 'inlineStyles', 'standardTemplate', 'image', 'alt', 'background', 'type'],
229
256
  };
230
257
  t.deepEqual(jsonResult.tags?.map((tag) => tag.name), components);
231
258