Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit e98bde9

Browse files
committed
better doc generation
1 parent 110c3ae commit e98bde9

File tree

4 files changed

+94
-35
lines changed

4 files changed

+94
-35
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.DS_Store
1+
.DS_Store
2+
node_modules

README.md

+18-10
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ It's easy! Simply activate snippets by typing a mnemonic followed by TAB.
3939
#### Available snippets:
4040

4141
```
42-
cs→ var cx = React.addons.classSet;
43-
4442
cdm→ componentDidMount: fn() { ... }
4543
4644
cdup→ componentDidUpdate: fn(pp, ps) { ... }
4745
48-
cwmcomponentWillMount: fn() { ... }
46+
csvar cx = React.addons.classSet;
4947
50-
cxcx({ ... })
48+
cwmcomponentWillMount: fn() { ... }
5149
5250
cwr→ componentWillReceiveProps: fn(np) { ... }
5351
52+
cwu→ componentWillUpdate: fn(np, ns) { ... }
53+
5454
cwun→ componentWillUnmount: fn() { ... }
5555
56-
cwucomponentWillUpdate: fn(np, ns) { ... }
56+
cxcx({ ... })
5757
5858
fup→ forceUpdate(...)
5959
@@ -63,21 +63,29 @@ It's easy! Simply activate snippets by typing a mnemonic followed by TAB.
6363
6464
ism→ isMounted()
6565
66-
pt→ propTypes { ... }
67-
6866
jsx→ /** @jsx */
6967
70-
rcccomponent skeleton
68+
propsthis.props.
7169
72-
sst→ setState({ ... })
70+
pt→ propTypes { ... }
71+
72+
rcc→ component skeleton
7373
7474
ren→ render: fn() { return ... }
7575
7676
scu→ shouldComponentUpdate: fn(np, ns) { ... }
7777
78-
propsthis.props.
78+
sstsetState({ ... })
7979
8080
state→ this.state.
8181
8282
trp→ transferPropsTo( ... )
8383
84+
```
85+
86+
## Contributing
87+
88+
### Rebuilding the docs
89+
90+
After making changes to snippet files, run `npm install && npm run build-docs` to automatically generate this document from source.
91+

generateReadme.js

+57-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var fs = require('fs');
2+
var async = require('async');
23

3-
fs.writeFile(
4-
'README.md', '# sublime-react\n\n' +
4+
var DOCUMENTATION_TOP =
5+
'# sublime-react\n\n' +
56
'Snippets and syntax highlighting for React.js / JSX.\n\n' +
67
'![alt tag](https://raw.github.com/jgebhardt/sublime-react/master/docs/img/sr-rcc-out.gif)\n\n' +
78
'## Installation\n\n' +
@@ -21,38 +22,70 @@ fs.writeFile(
2122
'It\'s easy! Simply activate snippets by typing a mnemonic followed by TAB.\n\n' +
2223
'![alt tag](https://raw.github.com/jgebhardt/sublime-react/master/docs/img/sr-snippets-out.gif)\n\n' +
2324
'#### Available snippets:\n\n' +
24-
'```\n', function (err) {
25-
if (err) {
26-
throw err;
27-
}
28-
});
25+
'```\n';
26+
27+
var DOCUMENTATION_BOTTOM =
28+
'```\n\n' +
29+
'## Contributing\n\n' +
30+
'### Rebuilding the docs\n\n' +
31+
'After making changes to snippet files, run `npm install && npm run build-docs` to automatically generate this document from source.\n\n';
2932

3033
fs.readdir('./snippets', function(err, files) {
31-
files
32-
.filter(function(file) {
33-
return file.substr(-16) === '.sublime-snippet';
34-
})
35-
.forEach(function(file) {
36-
fs.readFile('./snippets/' + file, 'utf-8', function(err, contents) {
37-
if (!err) {
38-
inspectFile(contents);
39-
}
40-
});
34+
var snippets = files.filter(function(file) {
35+
return file.substr(-16) === '.sublime-snippet';
36+
}).map(function(file) {
37+
return './snippets/' + file;
38+
});
39+
async.map(snippets, readAndInspect, function(err, results) {
40+
if (err) {
41+
console.error('error mapping snippets', err);
42+
}
43+
var snippetDocs =
44+
DOCUMENTATION_TOP +
45+
results.map(function(snippet) {
46+
return inspectFile(snippet);
47+
}).sort(function(a, b) {
48+
return a.abbreviation > b.abbreviation
49+
? 1
50+
: a.abbreviation === b.abbreviation
51+
? 0
52+
: -1;
53+
}).map(function(snippet) {
54+
return snippet.docBlock;
55+
}).join('') +
56+
DOCUMENTATION_BOTTOM;
57+
fs.writeFile('README.md', snippetDocs, function (err) {
58+
if (err) {
59+
console.error('error appending README:', err);
60+
}
4161
});
62+
});
4263
});
4364

65+
function readAndInspect(fileName, cb) {
66+
fs.readFile(fileName, 'utf-8', function(err, contents) {
67+
if (!err) {
68+
cb(null, contents);
69+
}
70+
});
71+
}
72+
4473
function inspectFile(contents) {
4574
var match = contents.match(
4675
/[\s\S]*<tabTrigger>(.*?)<\/tabTrigger>[\s\S]*?<description>(React: )?(.*?)<\/description>[\s\S]*/i
4776
);
4877
var docBlock = '';
78+
var abbreviation = '';
79+
var description = '';
4980
if (match !== null) {
50-
var shortCut = ' '.substring(0, 5 - match[1].length) + match[1];
51-
docBlock = ' ' + shortCut + '→ ' + match[3] + '\n\n';
81+
abbreviation = match[1];
82+
description = match[3];
83+
var shortCut = ' '.substring(0, 5 - abbreviation.length) + abbreviation;
84+
docBlock = ' ' + shortCut + '→ ' + description + '\n\n';
5285
}
53-
fs.appendFile('README.md', docBlock, function (err) {
54-
if (err) {
55-
console.error('error appending README:', err);
56-
}
57-
});
86+
return {
87+
docBlock: docBlock,
88+
abbreviation: abbreviation,
89+
description: description
90+
};
5891
}

package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "sublime-react",
3+
"version": "0.1.0",
4+
"author": "Jonas Gebhardt <jonas.gebhardt@gmail.com>",
5+
"description": "a simple zero-configuration command-line http server",
6+
"scripts": {
7+
"build-docs": "node ./generateReadme.js"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/reactjs/sublime-react.git"
12+
},
13+
"dependencies" : {
14+
"async": "~0.7.0"
15+
},
16+
"license": "Apache 2.0"
17+
}

0 commit comments

Comments
 (0)