Skip to content

Commit 3479a14

Browse files
committedMar 14, 2022
Import/Export plugin and document scripts
1 parent 063bf84 commit 3479a14

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package-lock.json
1616
############################
1717
role-split
1818
*~
19+
wiki
1920

2021

2122
############################

‎package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"strapi-plugin-content-type-builder": "3.5.4",
2525
"strapi-plugin-email": "3.5.4",
2626
"strapi-plugin-graphql": "3.5.4",
27+
"strapi-plugin-import-export-content": "^0.4.2",
2728
"strapi-plugin-upload": "3.5.4",
2829
"strapi-plugin-users-permissions": "3.5.4",
2930
"strapi-provider-email-nodemailer": "3.6.0",
@@ -38,5 +39,10 @@
3839
"engines": {
3940
"npm": "^7.0.0"
4041
},
41-
"license": "MIT"
42+
"license": "MIT",
43+
"devDependencies": {
44+
"jsdoc-to-markdown": "^7.1.1",
45+
"lodash": "^4.17.21",
46+
"pluralize": "^8.0.0"
47+
}
4248
}

‎scripts/documentation.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* eslint-disable */
2+
3+
const jsdoc2md = require("jsdoc-to-markdown");
4+
const fs = require("fs");
5+
const pluralize = require("pluralize");
6+
const path = require("path");
7+
const groupBy = require("lodash/groupBy");
8+
const uniq = require("lodash/uniq");
9+
10+
/* input and output paths */
11+
const inputFile = "src/**/*";
12+
const outputDir = "wiki";
13+
const capitalize = (s) => {
14+
if (typeof s !== "string") return "";
15+
return s.charAt(0).toUpperCase() + s.slice(1);
16+
};
17+
18+
const templateData = jsdoc2md
19+
.getNamepaths({ files: inputFile, configure: "./scripts/jsdoc.conf.json" })
20+
.then((e) => {
21+
Object.keys(e).forEach((key) => {
22+
fs.writeFileSync(
23+
path.resolve(`${outputDir}/project/${pluralize(key)}.md`),
24+
`## ${capitalize(pluralize(key))}\n\n`
25+
);
26+
});
27+
})
28+
.then(() => {
29+
const getTemplateData = jsdoc2md.getTemplateDataSync({
30+
files: inputFile,
31+
configure: "jsdoc.conf.json",
32+
});
33+
const groups = groupBy(getTemplateData, "kind");
34+
35+
Object.keys(groups).forEach((key) => {
36+
const template = `
37+
{{>main}}
38+
39+
* * *
40+
41+
Last updated on ${new Date()}
42+
`;
43+
const output = jsdoc2md.renderSync({
44+
data: groups[key],
45+
configure: "./scripts/jsdoc.conf.json",
46+
template,
47+
});
48+
fs.writeFileSync(path.resolve(`${outputDir}/project/${pluralize(key)}.md`), output);
49+
});
50+
return groups;
51+
})
52+
.then((res) => {
53+
const sidebarText = [];
54+
Object.keys(res).forEach((key) => {
55+
sidebarText.push(`\n#### ${capitalize(pluralize(key))}`);
56+
res[key].forEach((e) => {
57+
sidebarText.push(`- [${e.name}](project/${pluralize(key)}#${e.name})`);
58+
});
59+
sidebarText.push("\n");
60+
});
61+
return uniq(sidebarText);
62+
})
63+
.then((res) => {
64+
const data = fs.readFileSync("wiki/Home.md", "utf8").split("<!-- OCTAWEBDOC -->");
65+
let id = 0;
66+
if (data.length > 1) {
67+
id = 1;
68+
}
69+
data[id] = "<!-- OCTAWEBDOC -->\n" + res.join("\n");
70+
fs.writeFileSync("wiki/Home.md", data.join(""), "utf8");
71+
});

0 commit comments

Comments
 (0)
Please sign in to comment.