@abi-software/map-side-bar 2.3.0 → 2.4.0-alpha-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/.eslintrc.js +12 -12
- package/.postcssrc.json +5 -5
- package/LICENSE +201 -201
- package/README.md +168 -168
- package/cypress.config.js +23 -23
- package/dist/data/pmr-sample.json +3181 -0
- package/dist/map-side-bar.js +15142 -9024
- package/dist/map-side-bar.umd.cjs +50 -103
- package/dist/style.css +1 -1
- package/package.json +77 -77
- package/public/data/pmr-sample.json +3181 -0
- package/reporter-config.json +9 -9
- package/src/App.vue +266 -265
- package/src/algolia/algolia.js +255 -242
- package/src/algolia/utils.js +100 -100
- package/src/assets/_variables.scss +43 -43
- package/src/assets/styles.scss +6 -6
- package/src/components/BadgesGroup.vue +124 -124
- package/src/components/ConnectivityInfo.vue +619 -619
- package/src/components/DatasetCard.vue +367 -357
- package/src/components/EventBus.js +3 -3
- package/src/components/ExternalResourceCard.vue +113 -113
- package/src/components/FlatmapDatasetCard.vue +171 -0
- package/src/components/ImageGallery.vue +542 -542
- package/src/components/PMRDatasetCard.vue +237 -0
- package/src/components/SearchFilters.vue +1023 -1006
- package/src/components/SearchHistory.vue +175 -175
- package/src/components/SideBar.vue +436 -436
- package/src/components/SidebarContent.vue +730 -603
- package/src/components/Tabs.vue +145 -145
- package/src/components/allPaths.js +5928 -0
- package/src/components/index.js +8 -8
- package/src/components/pmrTest.js +4 -0
- package/src/components/species-map.js +8 -8
- package/src/components.d.ts +2 -0
- package/src/exampleConnectivityInput.js +291 -291
- package/src/flatmapQueries/flatmapQueries.js +169 -0
- package/src/main.js +9 -9
- package/src/mixins/S3Bucket.vue +37 -37
- package/src/mixins/mixedPageCalculation.vue +78 -0
- package/static.json +6 -6
- package/vite.config.js +55 -55
- package/vuese-generator.js +65 -65
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
function transformKeyValueArrayToObject(data) {
|
|
2
|
+
return data.values.map(valueArray =>
|
|
3
|
+
data.keys.reduce((acc, key, index) => {
|
|
4
|
+
acc[key] = valueArray[index];
|
|
5
|
+
return acc;
|
|
6
|
+
}, {})
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// remove duplicates by stringifying the objects
|
|
11
|
+
const removeDuplicates = function (arrayOfAnything) {
|
|
12
|
+
if (!arrayOfAnything) return []
|
|
13
|
+
return [...new Set(arrayOfAnything.map((e) => JSON.stringify(e)))].map((e) =>
|
|
14
|
+
JSON.parse(e)
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
let FlatmapQueries = function () {
|
|
20
|
+
this.initialise = function (flatmapApi) {
|
|
21
|
+
this.flatmapApi = flatmapApi
|
|
22
|
+
this.features = []
|
|
23
|
+
this.limit = 10
|
|
24
|
+
this.offset = 0
|
|
25
|
+
this.numberOfHits = 0
|
|
26
|
+
this.sqlPreOffset = ''
|
|
27
|
+
this.lookup = {}
|
|
28
|
+
this.createLookup()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
this.updateOffset = function (offset) {
|
|
32
|
+
this.offset = offset
|
|
33
|
+
}
|
|
34
|
+
this.updateLimit = function (limit) {
|
|
35
|
+
this.limit = limit
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
this.offsetText = function () {
|
|
39
|
+
return 'limit ' + this.limit + ' offset ' + this.offset
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this.pmrSQL = function (terms=[], search='') {
|
|
43
|
+
let sql = 'select distinct term, score, workspace, entity, metadata from pmr_models left join pmr_metadata on pmr_models.exposure=pmr_metadata.entity where metadata is not null and exposure is not null and score > 0.99 '
|
|
44
|
+
|
|
45
|
+
// filters for the terms
|
|
46
|
+
if (terms && terms.length > 0) {
|
|
47
|
+
sql += 'and '
|
|
48
|
+
sql += `term='${terms.join("' or term='")}'`
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// set a search if there is one and no terms to filter on
|
|
52
|
+
if (search && search !== '' && terms.length == 0) {
|
|
53
|
+
sql = `select * from pmr_metadata where JSON_EXTRACT(metadata, '$.title') like '%${search}%'`
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.sqlPreOffset = sql
|
|
57
|
+
|
|
58
|
+
// add the limit and offset for pagination
|
|
59
|
+
sql += ' ' + this.offsetText() + ';'
|
|
60
|
+
return sql
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.convertTermsToIds = function (terms) {
|
|
64
|
+
return terms.map(t => this.lookUpId(t))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
this.labelSQL = function (){
|
|
68
|
+
return "select entity, label from labels"
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this.countSQL = function (sql) {
|
|
72
|
+
sql = `select count(*) from (${sql})`
|
|
73
|
+
return sql
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
this.flatmapQuery = function (sql) {
|
|
78
|
+
const data = { sql: sql }
|
|
79
|
+
return fetch(`${this.flatmapApi}knowledge/query/`, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: {
|
|
82
|
+
'Content-Type': 'application/json',
|
|
83
|
+
},
|
|
84
|
+
body: JSON.stringify(data),
|
|
85
|
+
})
|
|
86
|
+
.then((response) => response.json())
|
|
87
|
+
.catch((error) => {
|
|
88
|
+
console.error('Error:', error)
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
this.processFilters = function (filters) {
|
|
93
|
+
let featureLabels = []
|
|
94
|
+
filters.forEach((f) => {
|
|
95
|
+
if (f.label !== 'Show all' && f.label !== 'PMR')
|
|
96
|
+
featureLabels.push(f.facet)
|
|
97
|
+
})
|
|
98
|
+
return featureLabels
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
this.pmrSearch = function (filters=[], search='') {
|
|
104
|
+
let features = this.processFilters(filters)
|
|
105
|
+
let featureIds = this.convertTermsToIds(features)
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
this.flatmapQuery(this.pmrSQL(featureIds, search))
|
|
108
|
+
.then(data => {
|
|
109
|
+
const pd = this.processFlatmapData(data)
|
|
110
|
+
this.setAvailableFeatures(pd)
|
|
111
|
+
|
|
112
|
+
// get the number of hits for pagination
|
|
113
|
+
this.flatmapQuery(this.countSQL(this.sqlPreOffset)).then(data => {
|
|
114
|
+
this.numberOfHits = data.values[0][0]
|
|
115
|
+
resolve(pd);
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
.catch(reject);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// setAvailableFeatures returns the available features in the flatmap for filtering
|
|
123
|
+
// pd is the processed data from the flatmap
|
|
124
|
+
this.setAvailableFeatures = function (pd) {
|
|
125
|
+
pd.forEach((d) => {
|
|
126
|
+
Object.keys(d).forEach((key) => {
|
|
127
|
+
if (!this.features.includes(key)) {
|
|
128
|
+
this.features.push(key)
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
this.processFlatmapData = function (data) {
|
|
136
|
+
// Convert the flatmap data into an array of objects
|
|
137
|
+
let dataObj = transformKeyValueArrayToObject(data)
|
|
138
|
+
|
|
139
|
+
// Only use the results with metadata
|
|
140
|
+
let metadataResults = dataObj.filter(d => d.metadata)
|
|
141
|
+
let metadataOnly = metadataResults.map(d => {
|
|
142
|
+
let md = JSON.parse(d.metadata)
|
|
143
|
+
md.dataSource = 'PMR'
|
|
144
|
+
return md
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
// Remove duplicates
|
|
148
|
+
let uniqueResults = removeDuplicates(metadataOnly)
|
|
149
|
+
return uniqueResults
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
this.createLookup = function () {
|
|
153
|
+
this.flatmapQuery(this.labelSQL())
|
|
154
|
+
.then(data => {
|
|
155
|
+
data.values.forEach(d => {
|
|
156
|
+
if (d[1] && (typeof d[1] === 'string' || d[1] instanceof String)) {
|
|
157
|
+
this.lookup[d[1].toLowerCase()] = d[0]
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this.lookUpId = function (label) {
|
|
164
|
+
return this.lookup[label.toLowerCase()]
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export default FlatmapQueries
|
package/src/main.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createApp } from 'vue'
|
|
2
|
-
import App from './App.vue'
|
|
3
|
-
import MapSideBar from './components/SideBar.vue'
|
|
4
|
-
|
|
5
|
-
const app = createApp(App);
|
|
6
|
-
|
|
7
|
-
app.component('MapSideBar', MapSideBar)
|
|
8
|
-
|
|
9
|
-
app.mount("#app");
|
|
1
|
+
import { createApp } from 'vue'
|
|
2
|
+
import App from './App.vue'
|
|
3
|
+
import MapSideBar from './components/SideBar.vue'
|
|
4
|
+
|
|
5
|
+
const app = createApp(App);
|
|
6
|
+
|
|
7
|
+
app.component('MapSideBar', MapSideBar)
|
|
8
|
+
|
|
9
|
+
app.mount("#app");
|
package/src/mixins/S3Bucket.vue
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
export default {
|
|
3
|
-
name: "S3Bucket",
|
|
4
|
-
data() {
|
|
5
|
-
return {
|
|
6
|
-
s3Bucket: undefined,
|
|
7
|
-
s3Prefix: "",
|
|
8
|
-
};
|
|
9
|
-
},
|
|
10
|
-
methods: {
|
|
11
|
-
updateS3Bucket: function(s3uri) {
|
|
12
|
-
this.s3Bucket = undefined;
|
|
13
|
-
if (s3uri) {
|
|
14
|
-
const substring = s3uri.split("//")[1];
|
|
15
|
-
if (substring) {
|
|
16
|
-
this.s3Bucket = substring.split("/")[0];
|
|
17
|
-
const n = substring.indexOf('/');
|
|
18
|
-
this.s3Prefix = substring.substring(n + 1);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
getS3Args: function() {
|
|
24
|
-
if (this.s3Bucket) {
|
|
25
|
-
return `?s3BucketName=${this.s3Bucket}`
|
|
26
|
-
}
|
|
27
|
-
return "";
|
|
28
|
-
},
|
|
29
|
-
getS3Prefix: function() {
|
|
30
|
-
return this.s3Prefix;
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
</script>
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
<script>
|
|
2
|
+
export default {
|
|
3
|
+
name: "S3Bucket",
|
|
4
|
+
data() {
|
|
5
|
+
return {
|
|
6
|
+
s3Bucket: undefined,
|
|
7
|
+
s3Prefix: "",
|
|
8
|
+
};
|
|
9
|
+
},
|
|
10
|
+
methods: {
|
|
11
|
+
updateS3Bucket: function(s3uri) {
|
|
12
|
+
this.s3Bucket = undefined;
|
|
13
|
+
if (s3uri) {
|
|
14
|
+
const substring = s3uri.split("//")[1];
|
|
15
|
+
if (substring) {
|
|
16
|
+
this.s3Bucket = substring.split("/")[0];
|
|
17
|
+
const n = substring.indexOf('/');
|
|
18
|
+
this.s3Prefix = substring.substring(n + 1);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
getS3Args: function() {
|
|
24
|
+
if (this.s3Bucket) {
|
|
25
|
+
return `?s3BucketName=${this.s3Bucket}`
|
|
26
|
+
}
|
|
27
|
+
return "";
|
|
28
|
+
},
|
|
29
|
+
getS3Prefix: function() {
|
|
30
|
+
return this.s3Prefix;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
};
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
const RatioOfPMRResults = 0.2; // Ratio of PMR results to Sparc results
|
|
3
|
+
|
|
4
|
+
// The functions below are needed because the number of results shown on the page is dependent what is available from each index.
|
|
5
|
+
// We fix this by calcuting how many results we have shown before the requested page and then calculating the offset based on that.
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
methods: {
|
|
9
|
+
|
|
10
|
+
// Calculate Variable Ratio is used as a number to determine how the ratio of PMR results to SPARC results
|
|
11
|
+
// will be shown on the page. 1 means only PMR results, 0 means only SPARC results.
|
|
12
|
+
calculateVariableRatio: function () {
|
|
13
|
+
if (this.page === 1) {
|
|
14
|
+
this.variableRatio = RatioOfPMRResults
|
|
15
|
+
} else if( this.npp_SPARC * (this.page -1) >= this.sparcNumberOfHits) {
|
|
16
|
+
this.variableRatio = 1
|
|
17
|
+
// calculate offset
|
|
18
|
+
let mixedOffest = this.page*RatioOfPMRResults
|
|
19
|
+
} else if(this.npp_PMR * (this.page - 1) >= this.pmrNumberOfHits) {
|
|
20
|
+
this.variableRatio = 0
|
|
21
|
+
} else {
|
|
22
|
+
this.variableRatio = RatioOfPMRResults
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
calculatePMROffest: function() {
|
|
26
|
+
if (this.variableRatio === RatioOfPMRResults) {
|
|
27
|
+
return (this.page-1)*this.npp_PMR
|
|
28
|
+
} else if (this.variableRatio === 1) {
|
|
29
|
+
|
|
30
|
+
// calculate how many results we showed before the requested page
|
|
31
|
+
let pageWhereSPARCResultsRanOut = Math.ceil(this.sparcNumberOfHits / this.npp_SPARC)
|
|
32
|
+
let numberOfPMRResultsShownInMixed = this.npp_PMR * pageWhereSPARCResultsRanOut
|
|
33
|
+
let numberOfPMRResultsShownInPMROnly = (this.page - 1 - pageWhereSPARCResultsRanOut) * this.numberPerPage
|
|
34
|
+
return numberOfPMRResultsShownInMixed + numberOfPMRResultsShownInPMROnly
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
calculateSPARCOffest: function() {
|
|
38
|
+
if(this.variableRatio === RatioOfPMRResults) {
|
|
39
|
+
return (this.page-1)*this.npp_SPARC
|
|
40
|
+
} else if (this.variableRatio === 0) {
|
|
41
|
+
|
|
42
|
+
// calculate how many results we showed before the requested page
|
|
43
|
+
let pageWherePMRResultsRanOut = Math.ceil(this.pmrNumberOfHits / this.npp_PMR)
|
|
44
|
+
let numberOfSPARCResultsShownInMixed = this.npp_SPARC * pageWherePMRResultsRanOut
|
|
45
|
+
let numberOfSPARCResultsShownInSPARCOnly = (this.page - 1 - pageWherePMRResultsRanOut) * this.numberPerPage
|
|
46
|
+
let offset = numberOfSPARCResultsShownInMixed + numberOfSPARCResultsShownInSPARCOnly
|
|
47
|
+
return offset
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
PMRLimit: function(pmrResultsOnlyFlag=false) {
|
|
51
|
+
if (pmrResultsOnlyFlag) {
|
|
52
|
+
return this.numberPerPage
|
|
53
|
+
}
|
|
54
|
+
if (this.variableRatio === RatioOfPMRResults) {
|
|
55
|
+
return this.npp_PMR
|
|
56
|
+
} else if (this.variableRatio === 1) {
|
|
57
|
+
return this.numberPerPage
|
|
58
|
+
} else if (this.variableRatio === 0) {
|
|
59
|
+
return 0
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
SPARCLimit: function(pmrResultsOnlyFlag=false) {
|
|
63
|
+
if(pmrResultsOnlyFlag) {
|
|
64
|
+
return 0
|
|
65
|
+
}
|
|
66
|
+
if (this.variableRatio === RatioOfPMRResults) {
|
|
67
|
+
return this.npp_SPARC
|
|
68
|
+
} else if (this.variableRatio === 0) {
|
|
69
|
+
return this.numberPerPage
|
|
70
|
+
} else if (this.variableRatio === 1) {
|
|
71
|
+
return 0
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
|
package/static.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": "dist",
|
|
3
|
-
"clean_urls": true,
|
|
4
|
-
"routes": {
|
|
5
|
-
"/**": "index.html"
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"root": "dist",
|
|
3
|
+
"clean_urls": true,
|
|
4
|
+
"routes": {
|
|
5
|
+
"/**": "index.html"
|
|
6
|
+
}
|
|
7
7
|
}
|
package/vite.config.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { resolve } from "node:path"
|
|
2
|
-
|
|
3
|
-
import { defineConfig } from 'vite'
|
|
4
|
-
import vue from '@vitejs/plugin-vue'
|
|
5
|
-
|
|
6
|
-
import Components from 'unplugin-vue-components/vite'
|
|
7
|
-
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
8
|
-
|
|
9
|
-
// https://vitejs.dev/config/
|
|
10
|
-
export default defineConfig({
|
|
11
|
-
server: {
|
|
12
|
-
port: 8081,
|
|
13
|
-
},
|
|
14
|
-
plugins: [
|
|
15
|
-
vue(),
|
|
16
|
-
Components({
|
|
17
|
-
// allow auto load markdown components under `./src/components/`
|
|
18
|
-
extensions: ['vue', 'md'],
|
|
19
|
-
// allow auto import and register components used in markdown
|
|
20
|
-
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
|
|
21
|
-
resolvers: [
|
|
22
|
-
ElementPlusResolver({
|
|
23
|
-
importStyle: 'sass',
|
|
24
|
-
}),
|
|
25
|
-
],
|
|
26
|
-
dts: './src/components.d.ts',
|
|
27
|
-
}),
|
|
28
|
-
],
|
|
29
|
-
resolve: {
|
|
30
|
-
alias: {
|
|
31
|
-
'@': resolve(__dirname, './src'),
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
build: {
|
|
35
|
-
lib: {
|
|
36
|
-
entry: resolve(__dirname, "./src/components/index.js"),
|
|
37
|
-
name: "MapSideBar",
|
|
38
|
-
fileName: 'map-side-bar',
|
|
39
|
-
},
|
|
40
|
-
rollupOptions: {
|
|
41
|
-
external: ["vue"],
|
|
42
|
-
output: {
|
|
43
|
-
globals: {
|
|
44
|
-
vue: "Vue",
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
css: {
|
|
50
|
-
preprocessorOptions: {
|
|
51
|
-
scss: {
|
|
52
|
-
additionalData: `@use './src/assets/styles' as *;`
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
1
|
+
import { resolve } from "node:path"
|
|
2
|
+
|
|
3
|
+
import { defineConfig } from 'vite'
|
|
4
|
+
import vue from '@vitejs/plugin-vue'
|
|
5
|
+
|
|
6
|
+
import Components from 'unplugin-vue-components/vite'
|
|
7
|
+
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
8
|
+
|
|
9
|
+
// https://vitejs.dev/config/
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
server: {
|
|
12
|
+
port: 8081,
|
|
13
|
+
},
|
|
14
|
+
plugins: [
|
|
15
|
+
vue(),
|
|
16
|
+
Components({
|
|
17
|
+
// allow auto load markdown components under `./src/components/`
|
|
18
|
+
extensions: ['vue', 'md'],
|
|
19
|
+
// allow auto import and register components used in markdown
|
|
20
|
+
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
|
|
21
|
+
resolvers: [
|
|
22
|
+
ElementPlusResolver({
|
|
23
|
+
importStyle: 'sass',
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
dts: './src/components.d.ts',
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
29
|
+
resolve: {
|
|
30
|
+
alias: {
|
|
31
|
+
'@': resolve(__dirname, './src'),
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
build: {
|
|
35
|
+
lib: {
|
|
36
|
+
entry: resolve(__dirname, "./src/components/index.js"),
|
|
37
|
+
name: "MapSideBar",
|
|
38
|
+
fileName: 'map-side-bar',
|
|
39
|
+
},
|
|
40
|
+
rollupOptions: {
|
|
41
|
+
external: ["vue"],
|
|
42
|
+
output: {
|
|
43
|
+
globals: {
|
|
44
|
+
vue: "Vue",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
css: {
|
|
50
|
+
preprocessorOptions: {
|
|
51
|
+
scss: {
|
|
52
|
+
additionalData: `@use './src/assets/styles' as *;`
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
56
|
})
|
package/vuese-generator.js
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vuese Generator
|
|
3
|
-
*
|
|
4
|
-
* To generate markdown files from Vue components
|
|
5
|
-
* To watch components changes for Vitepress on Dev Mode
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import fs from 'fs'
|
|
9
|
-
import path from 'path'
|
|
10
|
-
import chokidar from 'chokidar'
|
|
11
|
-
import { parser } from '@vuese/parser'
|
|
12
|
-
import { Render } from '@vuese/markdown-render'
|
|
13
|
-
|
|
14
|
-
const watchMode = process.argv.find((argv) => argv === 'watch')
|
|
15
|
-
|
|
16
|
-
const componentsDir = 'src/components'
|
|
17
|
-
const components = ['SideBar.vue']
|
|
18
|
-
const outputDir = 'docs/components'
|
|
19
|
-
|
|
20
|
-
function generateMarkdown(file) {
|
|
21
|
-
const fileWithPath = `${componentsDir}/${file}`
|
|
22
|
-
const fileContent = fs.readFileSync(fileWithPath, 'utf-8')
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const parserResult = parser(fileContent)
|
|
26
|
-
const r = new Render(parserResult)
|
|
27
|
-
const renderResult = r.render()
|
|
28
|
-
const markdownResult = r.renderMarkdown()
|
|
29
|
-
const markdownContent = markdownResult.content
|
|
30
|
-
const componentName = path.basename(fileWithPath, '.vue')
|
|
31
|
-
|
|
32
|
-
if (!fs.existsSync(outputDir)) {
|
|
33
|
-
fs.mkdirSync(outputDir)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
fs.writeFile(`${outputDir}/${componentName}.md`, markdownContent, (err) => {
|
|
37
|
-
if (err) {
|
|
38
|
-
console.error(`Error writing markdown file for ${componentName}`, err)
|
|
39
|
-
} else {
|
|
40
|
-
console.log(`Markdown file for ${componentName} is generated!`)
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
} catch(e) {
|
|
44
|
-
console.error(e)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// To generate markdown files - one time
|
|
49
|
-
components.forEach((component) => {
|
|
50
|
-
console.log(`Write markdown file for ${component} on first load.`)
|
|
51
|
-
generateMarkdown(component)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
// To watch component changes and generate markdown files
|
|
55
|
-
if (watchMode) {
|
|
56
|
-
const watcher = chokidar.watch(components, {
|
|
57
|
-
cwd: componentsDir,
|
|
58
|
-
ignoreInitial: true,
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
watcher.on('change', (file) => {
|
|
62
|
-
console.log(`The component ${file} has changed!`)
|
|
63
|
-
generateMarkdown(file)
|
|
64
|
-
})
|
|
65
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Vuese Generator
|
|
3
|
+
*
|
|
4
|
+
* To generate markdown files from Vue components
|
|
5
|
+
* To watch components changes for Vitepress on Dev Mode
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import fs from 'fs'
|
|
9
|
+
import path from 'path'
|
|
10
|
+
import chokidar from 'chokidar'
|
|
11
|
+
import { parser } from '@vuese/parser'
|
|
12
|
+
import { Render } from '@vuese/markdown-render'
|
|
13
|
+
|
|
14
|
+
const watchMode = process.argv.find((argv) => argv === 'watch')
|
|
15
|
+
|
|
16
|
+
const componentsDir = 'src/components'
|
|
17
|
+
const components = ['SideBar.vue']
|
|
18
|
+
const outputDir = 'docs/components'
|
|
19
|
+
|
|
20
|
+
function generateMarkdown(file) {
|
|
21
|
+
const fileWithPath = `${componentsDir}/${file}`
|
|
22
|
+
const fileContent = fs.readFileSync(fileWithPath, 'utf-8')
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const parserResult = parser(fileContent)
|
|
26
|
+
const r = new Render(parserResult)
|
|
27
|
+
const renderResult = r.render()
|
|
28
|
+
const markdownResult = r.renderMarkdown()
|
|
29
|
+
const markdownContent = markdownResult.content
|
|
30
|
+
const componentName = path.basename(fileWithPath, '.vue')
|
|
31
|
+
|
|
32
|
+
if (!fs.existsSync(outputDir)) {
|
|
33
|
+
fs.mkdirSync(outputDir)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fs.writeFile(`${outputDir}/${componentName}.md`, markdownContent, (err) => {
|
|
37
|
+
if (err) {
|
|
38
|
+
console.error(`Error writing markdown file for ${componentName}`, err)
|
|
39
|
+
} else {
|
|
40
|
+
console.log(`Markdown file for ${componentName} is generated!`)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
} catch(e) {
|
|
44
|
+
console.error(e)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// To generate markdown files - one time
|
|
49
|
+
components.forEach((component) => {
|
|
50
|
+
console.log(`Write markdown file for ${component} on first load.`)
|
|
51
|
+
generateMarkdown(component)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
// To watch component changes and generate markdown files
|
|
55
|
+
if (watchMode) {
|
|
56
|
+
const watcher = chokidar.watch(components, {
|
|
57
|
+
cwd: componentsDir,
|
|
58
|
+
ignoreInitial: true,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
watcher.on('change', (file) => {
|
|
62
|
+
console.log(`The component ${file} has changed!`)
|
|
63
|
+
generateMarkdown(file)
|
|
64
|
+
})
|
|
65
|
+
}
|