@muonic/muon 0.0.2-experimental-138-4339428.0 → 0.0.2-experimental-141-5736c8b.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muonic/muon",
3
- "version": "0.0.2-experimental-138-4339428.0",
3
+ "version": "0.0.2-experimental-141-5736c8b.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,34 +18,36 @@
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
20
  "@open-wc/building-rollup": "2.0.1",
21
- "@open-wc/scoped-elements": "2.1.1",
21
+ "@open-wc/scoped-elements": "2.1.2",
22
22
  "@rollup/plugin-alias": "3.1.9",
23
23
  "@rollup/plugin-json": "4.1.0",
24
24
  "@rollup/plugin-replace": "4.0.0",
25
- "@rollup/plugin-virtual": "2.0.3",
26
- "@web/dev-server": "0.1.16",
27
- "@web/dev-server-rollup": "0.3.3",
25
+ "@rollup/plugin-virtual": "2.1.0",
26
+ "@web/dev-server": "0.1.32",
27
+ "@web/dev-server-rollup": "0.3.18",
28
28
  "@web/dev-server-storybook": "0.5.1",
29
- "@web/storybook-prebuilt": "0.1.32",
29
+ "@web/storybook-prebuilt": "0.1.34",
30
30
  "@webcomponents/scoped-custom-element-registry": "0.0.5",
31
31
  "app-root-path": "3.0.0",
32
- "autoprefixer": "10.4.0",
33
- "chokidar": "3.5.1",
34
- "chroma-js": "2.1.1",
35
- "command-line-args": "5.2.0",
32
+ "autoprefixer": "10.4.7",
33
+ "chokidar": "3.5.3",
34
+ "chroma-js": "2.4.2",
35
+ "command-line-args": "5.2.1",
36
+ "deep-equal": "^2.0.5",
36
37
  "deepmerge": "4.2.2",
37
- "glob": "7.1.6",
38
- "lit": "2.2.2",
38
+ "glob": "8.0.3",
39
+ "lit": "2.2.7",
39
40
  "lodash": "4.17.21",
40
41
  "path-is-inside": "1.0.2",
41
- "postcss": "8.2.13",
42
+ "postcss": "8.4.14",
42
43
  "postcss-clean": "1.2.2",
43
- "postcss-import": "14.0.1",
44
- "postcss-preset-env": "7.0.1",
44
+ "postcss-import": "14.1.0",
45
+ "postcss-preset-env": "7.7.2",
45
46
  "postcss-simple-vars": "6.0.3",
46
- "rollup-plugin-lit-css": "3.2.1",
47
+ "rollup-plugin-lit-css": "4.0.0",
47
48
  "rollup-plugin-styles": "4.0.0",
48
- "style-dictionary": "3.0.1",
49
+ "style-dictionary": "3.7.1",
50
+ "tmp": "^0.2.1",
49
51
  "web-component-analyzer": "1.1.6"
50
52
  },
51
53
  "devDependencies": {
@@ -55,7 +55,7 @@ const main = async () => {
55
55
  }
56
56
 
57
57
  await createTokens();
58
- await createComponentElementsJson('dist');
58
+ // await createComponentElementsJson('dist');
59
59
  await createGlobalCSS('dist');
60
60
 
61
61
  execSync(`build-storybook --output-dir ${outputDir} --config-dir ${configDir}`);
@@ -8,15 +8,89 @@ import postcssImport from 'postcss-import';
8
8
  import postcssVariables from 'postcss-simple-vars';
9
9
  import litcssPlugin from 'rollup-plugin-lit-css';
10
10
  import * as variables from '../build/tokens/es6/muon-tokens.mjs';
11
- import { getConfig } from './utils/index.mjs';
11
+ import { findComponents, getConfig, createComponentElementsJson } from './utils/index.mjs';
12
+
13
+ import { dirSync } from 'tmp';
14
+ import fs from 'fs';
12
15
  import path from 'path';
13
16
 
17
+ const config = getConfig(`muon.config.json`);
18
+
19
+ const tmp = dirSync({ unsafeCleanup: true });
20
+ const tmpName = tmp.name;
21
+
22
+ const writeFileSyncRecursive = (filename, content = '') => {
23
+ fs.mkdirSync(path.dirname(filename), { recursive: true });
24
+ fs.writeFileSync(filename, content);
25
+ };
26
+
27
+ const getTmpFilePath = (tmpName, file) => path.join(tmpName, path.relative(process.cwd(), file));
28
+
29
+ const runElementJson = async () => {
30
+ const files = (await findComponents()).map((file) => getTmpFilePath(tmpName, file));
31
+ await createComponentElementsJson(files);
32
+ };
33
+
34
+ const shouldSkip = (file) => {
35
+ return file.indexOf('virtual:') > 0;
36
+ };
37
+
38
+ const createElementJsonFile = async () => {
39
+ const destination = config?.destination || 'dist';
40
+ if (!fs.existsSync(destination)) {
41
+ fs.mkdirSync(destination, { recursive: true });
42
+ }
43
+ fs.writeFileSync(path.join(destination, 'custom-elements.json'), JSON.stringify({ tags: [] }));
44
+ };
45
+
46
+ let createElementJsonTimer;
47
+ const analyzerPlugin = () => {
48
+ return {
49
+ name: 'analyzer',
50
+ async moduleParsed(obj) {
51
+ if (shouldSkip(obj.id)) {
52
+ return;
53
+ }
54
+ writeFileSyncRecursive(getTmpFilePath(tmpName, obj.id), obj.code);
55
+ if (createElementJsonTimer) {
56
+ clearTimeout(createElementJsonTimer);
57
+ }
58
+ createElementJsonTimer = setTimeout(runElementJson, 500);
59
+ },
60
+ async serverStart() {
61
+ await createElementJsonFile();
62
+ },
63
+ serverStop() {
64
+ tmp.removeCallback();
65
+ },
66
+ async buildStart() {
67
+ await createElementJsonFile();
68
+ },
69
+ async buildEnd() {
70
+ tmp.removeCallback();
71
+ },
72
+ async generateBundle(options, bundle) {
73
+ let code = '';
74
+ Object.keys(bundle).forEach((file) => {
75
+ Object.keys(bundle[file].modules).forEach((module) => {
76
+ code += `
77
+ ${bundle[file].modules[module].code}
78
+ `;
79
+ });
80
+ });
81
+
82
+ writeFileSyncRecursive(getTmpFilePath(tmpName, 'code.js'), code);
83
+ createComponentElementsJson([getTmpFilePath(tmpName, 'code.js')]);
84
+ }
85
+ };
86
+ };
87
+
14
88
  const styles = fromRollup(stylesPlugin);
15
89
  const replace = fromRollup(replacePlugin);
16
90
  const litcss = fromRollup(litcssPlugin);
17
91
  const alias = fromRollup(aliasPlugin);
92
+ const analyzer = fromRollup(analyzerPlugin);
18
93
 
19
- const config = getConfig(`muon.config.json`);
20
94
  const additionalAlias = config?.alias?.map(({ find, replacement }) => {
21
95
  return {
22
96
  find,
@@ -69,12 +143,14 @@ export const serverPlugins = [
69
143
  alias(aliasConfig),
70
144
  replace(replaceConfig),
71
145
  styles(styleConfig),
72
- litcss({ exclude: ['**/css/*.css', '**/dist/*.css', 'muon.min.css'] })
146
+ litcss({ exclude: ['**/css/*.css', '**/dist/*.css', 'muon.min.css'] }),
147
+ analyzer()
73
148
  ];
74
149
 
75
150
  export const rollupPlugins = [
76
151
  aliasPlugin(aliasConfig),
77
152
  replacePlugin(replaceConfig),
78
153
  stylesPlugin(styleConfig),
79
- litcssPlugin({ exclude: ['**/css/*.css', '**/dist/*.css', 'muon.min.css'] })
154
+ litcssPlugin({ exclude: ['**/css/*.css', '**/dist/*.css', 'muon.min.css'] }),
155
+ analyzerPlugin()
80
156
  ];
@@ -4,7 +4,7 @@ import chokidar from 'chokidar';
4
4
  import { startDevServer } from '@web/dev-server';
5
5
  import commandLineArgs from 'command-line-args';
6
6
  import StorybookConfig from '../../storybook/server.config.mjs';
7
- import { getConfig, createComponentElementsJson, createTokens } from '../utils/index.mjs';
7
+ import { getConfig, createTokens } from '../utils/index.mjs';
8
8
 
9
9
  import postcss from 'postcss';
10
10
  import { postcssPlugins } from '../rollup-plugins.mjs';
@@ -59,11 +59,6 @@ const main = async () => {
59
59
  const destination = config?.destination || 'dist';
60
60
 
61
61
  await createStyleTokens(destination);
62
- await createComponentElementsJson();
63
-
64
- chokidar.watch('components/**/*-component.js', { ignoreInitial: true }).on('all', async () => {
65
- await createComponentElementsJson();
66
- });
67
62
 
68
63
  /* Internal dev mode */
69
64
  chokidar.watch(globalCSSUrl, { ignoreInitial: true }).on('all', async () => {
@@ -4,6 +4,7 @@ import StyleDictionary from 'style-dictionary';
4
4
  import formatHelpers from 'style-dictionary/lib/common/formatHelpers/index.js';
5
5
  import _ from 'lodash';
6
6
  import appRoot from 'app-root-path';
7
+ import deepEqual from 'deep-equal';
7
8
  import glob from 'glob';
8
9
  import fs from 'fs';
9
10
  import path from 'path';
@@ -94,12 +95,16 @@ const analyze = async () => {
94
95
  });
95
96
  };
96
97
 
97
- const createComponentElementsJson = async (overrideDest) => {
98
- const files = await findComponents();
98
+ const createComponentElementsJson = async (files) => {
99
+ if (!files) {
100
+ files = await findComponents();
101
+ }
99
102
  const config = await getConfig();
100
- const destination = overrideDest || config.destination || 'dist';
103
+ const destination = config.destination || 'dist';
104
+
101
105
  const results = await analyzeAndTransformGlobs(files, {
102
- format: 'json'
106
+ format: 'json',
107
+ discoverNodeModules: true
103
108
  });
104
109
 
105
110
  const jsonResults = JSON.parse(results);
@@ -112,7 +117,11 @@ const createComponentElementsJson = async (overrideDest) => {
112
117
  process.exit(1);
113
118
  }
114
119
 
115
- fs.writeFileSync(path.join(destination, 'custom-elements.json'), results);
120
+ const content = JSON.parse(fs.readFileSync(path.join(destination, 'custom-elements.json')));
121
+
122
+ if (!deepEqual(content, jsonResults)) {
123
+ fs.writeFileSync(path.join(destination, 'custom-elements.json'), results);
124
+ }
116
125
  return results;
117
126
  };
118
127
 
@@ -191,5 +200,6 @@ export {
191
200
  styleDictionary,
192
201
  createTokens,
193
202
  componentDefiner,
203
+ findComponents,
194
204
  runner
195
205
  };