@muonic/muon 0.0.2-experimental-163-66fa43f.0 → 0.0.2-experimental-165-5c9b40f.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.3](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.2...v0.0.2-beta.3) (2023-02-21)
6
+
7
+
8
+ ### Features
9
+
10
+ * getters for style and class ([e486ea2](https://github.com/centrica-engineering/muon/commit/e486ea2d25c5a6eb0ce5acb1701cc33e1443bc56))
11
+
5
12
  ### [0.0.2-beta.2](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.1...v0.0.2-beta.2) (2023-02-16)
6
13
 
7
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muonic/muon",
3
- "version": "0.0.2-experimental-163-66fa43f.0",
3
+ "version": "0.0.2-experimental-165-5c9b40f.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,6 +15,7 @@ import stringTransform from '../../tokens/utils/transforms/string.js';
15
15
  import jsonReference from '../../tokens/utils/formats/reference.js';
16
16
  import { getConfig, getDestination } from './config.mjs';
17
17
  import { fileURLToPath } from 'url';
18
+ import merge from 'deepmerge';
18
19
 
19
20
  const __filename = fileURLToPath(import.meta.url);
20
21
  const __dirname = path.dirname(__filename);
@@ -206,16 +207,26 @@ const sourceFilesAnalyzer = async () => {
206
207
 
207
208
  const styleDictionary = async () => {
208
209
  const config = getConfig();
210
+ let dictionaryConfig = {
211
+ ...styleConfig
212
+ };
209
213
 
210
214
  // Set the overriding tokens if there are any
211
- if (config.tokens && config.tokens.dir) {
212
- styleConfig.source = config.tokens.dir;
215
+ if (config?.tokens?.dir) {
216
+ dictionaryConfig.source = config.tokens.dir;
217
+ }
218
+
219
+ if (config?.tokens?.configFile) {
220
+ const { default: tokensConfig } = await import(path.join(process.cwd(), config.tokens.configFile));
221
+ if (tokensConfig) {
222
+ dictionaryConfig = merge(dictionaryConfig, tokensConfig);
223
+ }
213
224
  }
214
225
 
215
226
  const tokenUtils = path.join(__dirname, '..', '..', 'tokens', 'utils');
216
227
  const cssFontTemplate = _.template(fs.readFileSync(path.join(tokenUtils, 'templates', 'font-face.css.template')));
217
228
 
218
- const styleDict = StyleDictionary.extend(styleConfig);
229
+ const styleDict = StyleDictionary.extend(dictionaryConfig);
219
230
 
220
231
  styleDict.registerFormat(jsonReference);
221
232
 
@@ -0,0 +1,4 @@
1
+ <%_.forIn(properties && properties.theme && properties.theme.font && properties.theme.font.family, function(fontFamily) {
2
+ %>
3
+ font-family: "<%= fontFamily.value %>";
4
+ <% }); %>
@@ -0,0 +1,14 @@
1
+ {
2
+ "components": {
3
+ "included": ["inputter" ,"card","image"],
4
+ "dir": "tests/scripts/utils/*-component.js"
5
+ },
6
+ "tokens": {
7
+ "dir": ["tokens/*.json"],
8
+ "theme": "default",
9
+ "configFile": "./tests/scripts/utils/style-dictionary.config.mjs"
10
+ },
11
+ "alias": {
12
+ "@muon/utils/validation": "./utils/validation"
13
+ }
14
+ }
@@ -0,0 +1,32 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import { fileURLToPath } from 'url';
4
+ import _ from 'lodash';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const root = path.join(__filename, '..', '..', '..', '..');
8
+ const buildPath = path.join(root, 'build', 'tokens');
9
+ export default {
10
+ format: {
11
+ 'font-template': ({ dictionary, platform }) => {
12
+ return _.template(fs.readFileSync(path.join(__filename, '..', 'font.css.template')))({ properties: dictionary.tokens });
13
+ }
14
+ },
15
+ platforms: {
16
+ template: {
17
+ buildPath: path.join(buildPath, 'css/'),
18
+ files: [
19
+ {
20
+ destination: 'font-family.css',
21
+ format: 'font-template'
22
+ }
23
+ ],
24
+ filter: {
25
+ attributes: {
26
+ category: 'theme',
27
+ type: 'font'
28
+ }
29
+ }
30
+ }
31
+ }
32
+ };
@@ -238,6 +238,21 @@ testRunner('sourceFilesAnalyzer single file', async (t) => {
238
238
  });
239
239
  });
240
240
 
241
+ testRunner('create template', async (t) => {
242
+ const stub = await esmock('../../../scripts/utils/index.mjs', {
243
+ '../../../scripts/utils/config.mjs': {
244
+ getConfig: (configFile) => JSON.parse(fs.readFileSync('tests/scripts/utils/muon.config.style-dictionary.test.json').toString())
245
+ }
246
+ });
247
+ await stub.createTokens();
248
+ t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'css', 'font-family.css')), 'font css file not exist');
249
+ t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'css', 'mn-fonts.css')), 'font css file not exist');
250
+ t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'es6', 'muon-tokens-module.js')), 'muon-tokens-module.js don\'t exist');
251
+ t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'es6', 'muon-tokens.js')), 'muon-tokens.js don\'t exist');
252
+ t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'es6', 'muon-tokens.mjs')), 'muon-tokens.mjs don\'t exist');
253
+ t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'json', 'muon-tokens-reference.json')), 'muon-tokens-reference.json don\'t exist');
254
+ });
255
+
241
256
  testRunner('create tokens', async (t) => {
242
257
  await utilsLibrary.createTokens();
243
258
  t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'css', 'mn-fonts.css')), 'font css file not exist');