react-visualizer 5.1.0 → 5.2.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.
|
@@ -37,12 +37,18 @@ 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
|
}
|
|
43
49
|
}
|
|
44
50
|
});
|
|
45
|
-
const { help, config, scriptUrl, ...options } = args;
|
|
51
|
+
const { help, config, scriptUrl = [], ...options } = args;
|
|
46
52
|
const scripts = scriptUrl.map((url) => ({
|
|
47
53
|
url
|
|
48
54
|
}));
|
|
@@ -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
|
-
|
|
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
|
|
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' || !
|
|
46
|
+
if (loadversion === 'none' || !viewURL) {
|
|
47
47
|
addVisualizer(fallbackVersion);
|
|
48
48
|
} else {
|
|
49
49
|
const viewReg = new RegExp('/view.json$');
|
|
50
|
-
const docUrl =
|
|
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(
|
|
59
|
+
return fetchUrl(viewURL);
|
|
60
60
|
})
|
|
61
61
|
.then(function (data) {
|
|
62
62
|
let version = checkVersion(data.version || data.$content.version);
|
|
@@ -72,11 +72,19 @@ 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';
|
|
78
80
|
|
|
79
81
|
visualizer.setAttribute('data-main', datamain);
|
|
82
|
+
if(viewURL) {
|
|
83
|
+
visualizer.setAttribute('data-ci-view', viewURL);
|
|
84
|
+
}
|
|
85
|
+
if(configURL) {
|
|
86
|
+
visualizer.setAttribute('data-ci-config', configURL);
|
|
87
|
+
}
|
|
80
88
|
visualizer.setAttribute('src', requirejs);
|
|
81
89
|
document.head.appendChild(visualizer);
|
|
82
90
|
}
|