react-visualizer 5.1.1 → 5.2.1

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/README.md CHANGED
@@ -12,6 +12,10 @@ CLI example:
12
12
  npx react-visualizer makeVisualizerPage --help
13
13
  ```
14
14
 
15
+ Dev example:
16
+
17
+ node bin/makeVisualizerPage.js --config=config.example.json
18
+
15
19
  Node.js API: see options of `makeVisualizerPage` function.
16
20
 
17
21
  ## Visualizer
@@ -37,6 +37,12 @@ const { values: args } = parseArgs({
37
37
  type: "string",
38
38
  default: "query"
39
39
  },
40
+ viewURL: {
41
+ type: "string"
42
+ },
43
+ configURL: {
44
+ type: "string"
45
+ },
40
46
  config: {
41
47
  type: "string"
42
48
  }
@@ -86,6 +92,12 @@ Options:
86
92
 
87
93
  --scriptUrl <string>
88
94
  Script source url. You can specify this option multiple times to include multiple URLs.
95
+
96
+ --viewURL
97
+ URL to pass to the visualizer's data-ci-view attribute.
98
+
99
+ --configURL
100
+ URL to pass to the visualizer's data-ci-config attribute.
89
101
 
90
102
  --out <string>
91
103
  Output file path to which to write the html file
@@ -99,7 +111,7 @@ Options:
99
111
 
100
112
  --config <string>
101
113
  Path to a configuration file.
102
- Via the configuration file, you can specify additional options which should be passed to makeVisualizerPage generator.
114
+ The configuration file is read as JSON and passed as such to the makeVisualizerPage function.
103
115
  The "out" parameter must always be specified via the command line options.
104
116
  `);
105
117
  }
@@ -6,6 +6,8 @@ function makeVisualizerPage(options = {}) {
6
6
  fallbackVersion = "latest",
7
7
  queryType = "fragment",
8
8
  loadversion = "none",
9
+ configURL = "",
10
+ viewURL = "",
9
11
  scripts = []
10
12
  } = options;
11
13
  validateQueryType(queryType);
@@ -21,7 +23,7 @@ function makeVisualizerPage(options = {}) {
21
23
  throw new Error("script must have url or content");
22
24
  }
23
25
  }, "");
24
- return template.replace("{{ cdn }}", cdn).replace("{{ fallbackVersion }}", fallbackVersion).replace("{{ scripts }}", scriptsStr).replace("{{ queryType }}", queryType).replace("{{ loadversion }}", loadversion);
26
+ return template.replace("{{ cdn }}", cdn).replace("{{ fallbackVersion }}", fallbackVersion).replace("{{ scripts }}", scriptsStr).replace("{{ queryType }}", queryType).replace("{{ loadversion }}", loadversion).replace("{{ configURL }}", configURL).replace("{{ viewURL }}", viewURL);
25
27
  }
26
28
  module.exports = makeVisualizerPage;
27
29
  const validLoadversion = ["none", "exact", "latest-major"];
@@ -34,7 +34,7 @@ window.onload = function () {
34
34
  const queryType = '{{ queryType }}';
35
35
  const query = queryType === 'fragment' ? window.location.hash : window.location.search;
36
36
  const search = new URLSearchParams(query.startsWith("#") ? query.slice(1) : query);
37
- const url = search.get('viewURL');
37
+ const viewURL = search.get('viewURL');
38
38
  const v = search.get('v');
39
39
  const loadversion = search.get('loadversion') || '{{ loadversion }}';
40
40
  const fallbackVersion = search.get('fallbackVersion') || '{{ fallbackVersion }}';
@@ -43,11 +43,11 @@ window.onload = function () {
43
43
  return;
44
44
  }
45
45
 
46
- if (loadversion === 'none' || !url) {
46
+ if (loadversion === 'none' || !viewURL) {
47
47
  addVisualizer(fallbackVersion);
48
48
  } else {
49
49
  const viewReg = new RegExp('/view.json$');
50
- const docUrl = url.replace(viewReg, '');
50
+ const docUrl = viewURL.replace(viewReg, '');
51
51
  fetchUrl(docUrl)
52
52
  .then(function (data) {
53
53
  if (!data.version && (!data.$content || !data.$content.version))
@@ -56,7 +56,7 @@ window.onload = function () {
56
56
  })
57
57
  .catch(function () {
58
58
  // Try fetching the view.json if it did not work with the document
59
- return fetchUrl(url);
59
+ return fetchUrl(viewURL);
60
60
  })
61
61
  .then(function (data) {
62
62
  let version = checkVersion(data.version || data.$content.version);
@@ -72,11 +72,22 @@ window.onload = function () {
72
72
 
73
73
  function addVisualizer(version) {
74
74
  const cdn = '{{ cdn }}';
75
+ const viewURL = '{{ viewURL }}';
76
+ const configURL = '{{ configURL }}';
75
77
  const visualizer = document.createElement('script');
76
78
  const datamain = cdn + '/' + version + '/init';
77
79
  const requirejs = cdn + '/' + version + '/components/requirejs/require.js';
80
+
81
+ const visualizerDiv = document.getElementById('ci-visualizer');
82
+
78
83
 
79
84
  visualizer.setAttribute('data-main', datamain);
85
+ if(viewURL) {
86
+ visualizerDiv.setAttribute('data-ci-view', viewURL);
87
+ }
88
+ if(configURL) {
89
+ visualizerDiv.setAttribute('data-ci-config', configURL);
90
+ }
80
91
  visualizer.setAttribute('src', requirejs);
81
92
  document.head.appendChild(visualizer);
82
93
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-visualizer",
3
- "version": "5.1.1",
3
+ "version": "5.2.1",
4
4
  "description": "The visualizer in a react component",
5
5
  "main": "dist/src/index.js",
6
6
  "bin": {