Skip to content

Commit 2868ef0

Browse files
committed
feat(documentation): Fixed api doc generation, added doc for dropdown component and fixed small bug
1 parent b03b3ab commit 2868ef0

16 files changed

+1450
-40
lines changed

build/paths.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
css: appRoot + '**/*.scss',
99
output: outputRoot,
1010
doc: './doc',
11-
docsOutput: outputRoot.concat('docs/api/'),
11+
apiDoc: './doc/api',
1212
e2eSpecsSrc: 'test/e2e/src/*.js',
1313
e2eSpecsDist: 'test/e2e/dist/'
1414
};

build/tasks/docs.js

+41-30
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,56 @@ const glob = require('glob');
66
const del = require('del');
77
const vinylPaths = require('vinyl-paths');
88
const docjs = require('documentation');
9+
const REGEX_FILE_NAME = /((\w)+(-)*(\w))+(?=.js)/g;
910

11+
function createDocForFile(filename) {
12+
const splittedName = filename.split('/');
13+
const filenameWithoutExt = filename.match(REGEX_FILE_NAME)[0];
1014

15+
return docjs.build([filename], {shallow: true})
16+
.then(result => docjs.formats.md(result, {}))
17+
.then(output => ({
18+
file: filenameWithoutExt,
19+
// get the parent folder of file
20+
folder: filenameWithoutExt !== 'index' ? splittedName[splittedName.length - 2] : 'index',
21+
markdown: output
22+
}));
23+
}
1124

1225
// deletes all files in the output path
1326
gulp.task('clean-docs', () =>
1427
gulp.src([`${paths.docsOutput}`])
1528
.pipe(vinylPaths(del))
1629
);
1730

18-
gulp.task('build-jsdoc-to-md', () => {
19-
const files = glob.sync(paths.source); // glob allows pattern matching for filenames
20-
const regexFileName = /((\w)+(\-)*(\w))+(?=.js)/g;
21-
const createdMdDocs = [];
22-
files
23-
.filter(filename => {
24-
const name = filename.match(regexFileName)[0];
25-
return name !== 'imports';
26-
})
27-
.map(filename => {
28-
const splittedName = filename.split('/');
29-
const filenameWithoutExt = filename.match(regexFileName)[0];
30-
const jsDocObj = docjs.buildSync([filename], {shallow: true});
31-
return docjs.formats.md(jsDocObj, {}, (err, output) => {
32-
createdMdDocs.push({
33-
file: filenameWithoutExt,
34-
folder: filenameWithoutExt !== 'index' ? splittedName[splittedName.length - 2] : '', // get the parent folder of file
35-
markdown: output
36-
});
37-
});
38-
});
39-
const writeMdFiles = createdMdDocs.map(mdDoc => {
40-
const folder = `${paths.docsOutput}${mdDoc.folder}`;
41-
const filePath = mdDoc.file !== 'index' ? `${paths.docsOutput}${mdDoc.folder}/${mdDoc.file}.md` : `${paths.docsOutput}${mdDoc.file}.md`;
42-
if (!fs.existsSync(folder)) {
43-
fs.mkdirSync(folder);
44-
}
45-
return fs.writeFile(filePath, mdDoc.markdown);
46-
});
47-
return Promise.all(writeMdFiles);
31+
gulp.task('build-jsdoc-to-md', done => {
32+
Promise.resolve(glob.sync(paths.source))
33+
// Filter file names to match tag name pattern
34+
.then(fileNames => fileNames.filter(fileName => {
35+
const name = fileName.match(REGEX_FILE_NAME)[0];
36+
return name !== 'imports';
37+
}))
38+
// Generate markdown for each file
39+
.then(fileNames =>
40+
Promise.all(fileNames.map(createDocForFile))
41+
)
42+
// Group the markdown docs by there folder
43+
.then(docs => docs.reduce((groups, doc) => {
44+
groups[doc.folder] = groups[doc.folder] || [];
45+
groups[doc.folder].push(doc);
46+
return groups;
47+
}, {}))
48+
// Create markdown files for each folder
49+
.then(groups => Object.keys(groups).forEach(folderName => {
50+
const group = groups[folderName];
51+
const fileName = `${paths.apiDoc}/${folderName}.md`;
52+
const content = `# ${folderName}\n${group.map(doc => doc.markdown).join('\n')}`;
53+
if (!fs.existsSync(paths.apiDoc)) {
54+
fs.mkdirSync(paths.apiDoc);
55+
}
56+
fs.writeFileSync(fileName, content);
57+
}))
58+
.then(done);
4859
});
4960

5061
gulp.task('generate-docs', done => runSequence('clean-docs', 'build-jsdoc-to-md', done));

build/tasks/lint.js

+16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
var gulp = require('gulp');
22
var paths = require('../paths');
33
var eslint = require('gulp-eslint');
4+
const glob = require('glob');
5+
const docjs = require('documentation');
6+
const REGEX_FILE_NAME = /((\w)+(-)*(\w))+(?=.js)/g;
47

58
// runs eslint on all .js files
69
gulp.task('lint', function() {
10+
Promise.resolve(glob.sync(paths.source))
11+
// Filter file names to match tag name pattern
12+
.then(fileNames => fileNames.filter(fileName => {
13+
const name = fileName.match(REGEX_FILE_NAME)[0];
14+
return name !== 'imports';
15+
}))
16+
// Generate markdown for each file
17+
.then(fileNames => fileNames.forEach(fileName =>
18+
docjs.lint(fileName, {}).then(lintOutput => {
19+
console.log(lintOutput);
20+
})
21+
));
22+
723
return gulp.src(paths.source)
824
.pipe(eslint())
925
.pipe(eslint.format())

circle.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ deployment:
4343
release:
4444
branch: [master, release]
4545
commands:
46-
- gulp prepare-release
47-
- git add package.json doc/CHANGELOG.md dist
46+
- gulp generate-docs bump-version changelog
47+
- git add package.json doc dist
4848
- git commit -m "Bumped version to $(jq -r .version package.json) [skip ci]"
4949
- git tag -f -a $(jq -r .version package.json) -m "Automatic release via CircleCI"
5050
- git push origin $CIRCLE_BRANCH

doc/api/index.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# index
2+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
3+
4+
## WHStyleguide
5+
6+
Our Wholesale-Styleguide Component documentation
7+
This is our Startpage for our component API
8+
based on jsDocs
9+
Here we should add more descriptions
10+
Below are all components referenced
11+
12+
- See [WSHeader](ws-header.md)
13+
- See [WSDatePicker](ws-date-picker.md)
14+
- See [WSDropdown](ws-dropdown.md)
15+
- See [WSNotification](ws-notification.md)
16+
- See [WSWeekPicker](ws-week-picker.md)

doc/api/ws-date-picker.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# ws-date-picker
2+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
3+
4+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
5+
6+
## WSDatePicker
7+
8+
**Extends Component**
9+
10+
Renders a date picker component which is based on flatpickr.
11+
Possible properties to set are the value as formatted string or Date object.
12+
To specify a date format pls have a look at the flatpickr formatting rules.
13+
You can set additional options to the flatpickr by passing the options property.
14+
If you only want to display an icon instead of a input set prop iconOnly.
15+
16+
**Parameters**
17+
18+
- `props`
19+
20+
### constructor
21+
22+
**Parameters**
23+
24+
- `props` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** React properties
25+
26+
### componentDidMount
27+
28+
Initialize the flatpickr with given options and prevent default change event
29+
30+
Returns **void**
31+
32+
### componentWillReceiveProps
33+
34+
Update flatpickr when prop's changed
35+
36+
**Parameters**
37+
38+
- `props` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** React props
39+
40+
Returns **void**
41+
42+
### componentWillUnmount
43+
44+
Destroy the flatpickr and all events and bindings
45+
46+
Returns **void**
47+
48+
### onChange
49+
50+
Handle date selections and propagate the value via an custom change event and onChange callback
51+
52+
**Parameters**
53+
54+
- `selectedDate` **[Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)** The currently selected date
55+
- `selectedDate.0`
56+
- `value` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The date as string using the in props specified formatting
57+
58+
Returns **void**
59+
60+
### render
61+
62+
Render the component
63+
64+
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**

0 commit comments

Comments
 (0)