Skip to content

Commit 1dcc59b

Browse files
committed
build: added website directory to prettier and eslint checks
1 parent 50454d7 commit 1dcc59b

File tree

3 files changed

+38
-58
lines changed

3 files changed

+38
-58
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@
7474
"docs:start": "cd website/ && yarn start",
7575
"docs:deploy": "cd website/ && yarn deploy",
7676
"lint": "yarn run lint:prettier && yarn run lint:eslint",
77-
"lint:prettier": "prettier --check \"{src,test,scripts}/**/*.js\"",
78-
"lint:eslint": "eslint \"{src,test,scripts}/**/*.js\"",
77+
"lint:prettier": "prettier --check \"{src,test,scripts,website}/**/*.js\"",
78+
"lint:eslint": "eslint \"{src,test,scripts,website}/**/*.js\"",
7979
"fix": "yarn run fix:eslint && yarn run fix:prettier",
80-
"fix:prettier": "prettier --write \"{src,test,scripts}/**/*.js\"",
81-
"fix:eslint": "eslint --fix \"{src,test,scripts}/**/*.js\""
80+
"fix:prettier": "prettier --write \"{src,test,scripts,website}/**/*.js\"",
81+
"fix:eslint": "eslint --fix \"{src,test,scripts,website}/**/*.js\""
8282
},
8383
"bugs": {
8484
"url": "https://github.com/amplitude/amplitude-javascript/issues"
@@ -93,7 +93,7 @@
9393
}
9494
},
9595
"lint-staged": {
96-
"{src,test,scripts}/**/*.js": [
96+
"{src,test,scripts,website}/**/*.js": [
9797
"prettier --write",
9898
"eslint --fix"
9999
]

website/docusaurus.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ module.exports = {
4343
path: 'docs',
4444
routeBasePath: '/',
4545
sidebarPath: require.resolve('./sidebars.js'),
46-
editUrl:
47-
'https://github.com/amplitude/Amplitude-JavaScript/website',
46+
editUrl: 'https://github.com/amplitude/Amplitude-JavaScript/website',
4847
},
4948
theme: {
5049
customCss: require.resolve('./src/css/custom.css'),

website/generate-jsdoc.js

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,37 @@
1-
const jsdoc2md = require("jsdoc-to-markdown");
2-
const fs = require("fs");
3-
const path = require("path");
4-
const prettier = require("prettier");
5-
const publicClassFiles = [
6-
"amplitude-client.js",
7-
"amplitude.js",
8-
"identify.js",
9-
"revenue.js",
10-
];
11-
const publicTypedefFiles = ["options.js"];
12-
const srcDir = path.join(__dirname, "../", "src");
13-
const outputDir = path.join(__dirname, "docs");
1+
const jsdoc2md = require('jsdoc-to-markdown');
2+
const fs = require('fs');
3+
const path = require('path');
4+
const prettier = require('prettier');
5+
const publicClassFiles = ['amplitude-client.js', 'amplitude.js', 'identify.js', 'revenue.js'];
6+
const publicTypedefFiles = ['options.js'];
7+
const srcDir = path.join(__dirname, '../', 'src');
8+
const outputDir = path.join(__dirname, 'docs');
149

1510
function generateTypedefMarkdown(inputFile) {
1611
const inputFilePath = path.join(srcDir, inputFile);
1712
const data = jsdoc2md.getTemplateDataSync({ files: inputFilePath });
18-
const name = data.find((e) => e.kind === "typedef").name;
19-
const filteredData = data.filter((e) => e.kind === "typedef");
20-
const outputFilePath = path.join(outputDir, `${name}.md`);
21-
const markdownOutput = filteredData
22-
.map((item) => documentOptionsFile(item))
23-
.join("\n");
24-
fs.writeFileSync(
25-
path.join(outputDir, `${name}.md`),
26-
prettier.format(markdownOutput, { parser: "mdx" })
27-
);
13+
const name = data.find((e) => e.kind === 'typedef').name;
14+
const filteredData = data.filter((e) => e.kind === 'typedef');
15+
16+
const markdownOutput = filteredData.map((item) => documentOptionsFile(item)).join('\n');
17+
fs.writeFileSync(path.join(outputDir, `${name}.md`), prettier.format(markdownOutput, { parser: 'mdx' }));
2818
}
2919

3020
function generateClassMarkdown(inputFile) {
3121
const inputFilePath = path.join(srcDir, inputFile);
3222
const data = jsdoc2md.getTemplateDataSync({ files: inputFilePath });
33-
const className = data.find((e) => e.kind === "class").name;
23+
const className = data.find((e) => e.kind === 'class').name;
3424
const filteredData = data.filter(
35-
(e) =>
36-
e.kind === "constructor" ||
37-
(e.access === "public" && (e.kind === "function" || e.kind === "member"))
38-
);
39-
const outputFilePath = path.join(outputDir, `${className}.md`);
40-
41-
const markdownOutput = filteredData
42-
.map((item) => documentClassFile(item))
43-
.join("\n");
44-
fs.writeFileSync(
45-
path.join(outputDir, `${className}.md`),
46-
prettier.format(markdownOutput, { parser: "mdx" })
25+
(e) => e.kind === 'constructor' || (e.access === 'public' && (e.kind === 'function' || e.kind === 'member')),
4726
);
27+
28+
const markdownOutput = filteredData.map((item) => documentClassFile(item)).join('\n');
29+
fs.writeFileSync(path.join(outputDir, `${className}.md`), prettier.format(markdownOutput, { parser: 'mdx' }));
4830
}
4931

5032
function documentOptionsFile(data) {
5133
return `${documentHeader(data)}
52-
34+
5335
${data.description}
5436
5537
Option | Type | Description | Default
@@ -63,25 +45,25 @@ function documentOptionsProperties(data) {
6345
return data.properties
6446
.map(
6547
(prop) =>
66-
`${prop.name || ""} | ${data.properties[0].type.names.join("|")} | ${
67-
prop.defaultvalue || ""
68-
} | ${prop.description || ""}`
48+
`${prop.name || ''} | ${data.properties[0].type.names.join('|')} | ${prop.defaultvalue || ''} | ${
49+
prop.description || ''
50+
}`,
6951
)
70-
.join("\n");
52+
.join('\n');
7153
}
7254

7355
function documentClassFile(data) {
7456
return `${documentHeader(data)}
7557
76-
${data.examples ? documentExamples(data) : ""}
58+
${data.examples ? documentExamples(data) : ''}
7759
78-
${data.description || ""}
60+
${data.description || ''}
7961
80-
${data.deprecated ? documentDeprecated(data) : ""}
62+
${data.deprecated ? documentDeprecated(data) : ''}
8163
82-
${data.params ? documentParams(data) : ""}
64+
${data.params ? documentParams(data) : ''}
8365
84-
${data.returns ? documentReturn(data) : ""}
66+
${data.returns ? documentReturn(data) : ''}
8567
`;
8668
}
8769

@@ -106,18 +88,18 @@ function documentDeprecated(data) {
10688

10789
function documentParams(data) {
10890
const params = data.params.map(
109-
(param) => `- \`${param.name}\` (\`${param.type.names.join("|")}\`)
91+
(param) => `- \`${param.name}\` (\`${param.type.names.join('|')}\`)
11092
${param.description}
111-
`
93+
`,
11294
);
11395
return `### Parameters
114-
${params.join("\n")}
96+
${params.join('\n')}
11597
`;
11698
}
11799

118100
function documentReturn(data) {
119101
return `### Return Value
120-
- (\`${data.returns[0].type.names.join("|")}\`)
102+
- (\`${data.returns[0].type.names.join('|')}\`)
121103
${data.returns[0].description}
122104
`;
123105
}
@@ -135,4 +117,3 @@ for (const file of publicClassFiles) {
135117
for (const file of publicTypedefFiles) {
136118
generateTypedefMarkdown(file);
137119
}
138-

0 commit comments

Comments
 (0)