-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Docs] Add versions to docs site #3383
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#!/usr/local/bin/node | ||
/** | ||
* Build a release for the gh-pages docs site. | ||
*/ | ||
|
||
var fs = require('fs'); | ||
var execSync = require('child_process').execSync; | ||
|
||
var usage = '\nbuild <vn.n.n[-pre[.n]]> | <HEAD> [-p]\n'; | ||
var versionsFile = './src/www/versions.json'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mbrookes Always try resolving these relative paths using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, much of the git wrangling assumes we're in I was assuming this is going to be called in an automated fashion either for HEAD builds, or as part of @hai-cea's release process, or, if run manually, by using the No harm in making it fool proof, but much easier to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I see, well you're right, I didn't take those into account 😅
That's actually a very smart move 👍 Yeah I think it's a lot safer 👍 |
||
|
||
// Read the command-line args | ||
var args = process.argv; | ||
|
||
if (args.length < 3) { | ||
exit(usage); | ||
} | ||
|
||
var version = args[2]; | ||
|
||
// The regex isn't a perfect filter (it allows any component parts of a pre-release in the right order) | ||
if (!version.match(/v\d{1,2}.\d{1,2}.\d{1,2}-?\w*\.?\d{0,2}/) && version !== 'HEAD') { | ||
exit(usage); | ||
} | ||
|
||
// Exit with a message | ||
function exit(message) { | ||
console.log(message,'\n'); | ||
process.exit(); | ||
} | ||
|
||
// Exec with echo | ||
function execho(command) { | ||
console.log(command); | ||
try { | ||
execSync(command, {stdio: 'inherit'}); | ||
} catch (error) { | ||
console.error(error.output[1]); | ||
process.exit(error.status); | ||
} | ||
} | ||
|
||
// Exec with return value or error | ||
function execReturn(command) { | ||
console.log(command); | ||
try { | ||
return execSync(command, {encoding: 'utf8'}); | ||
} catch (error) { | ||
console.error(error.output[1]); | ||
process.exit(error.status); | ||
} | ||
} | ||
|
||
function preRelease(version) { | ||
return /-/.test(version) || version === 'HEAD'; | ||
} | ||
|
||
function lastCommitIsHead() { | ||
// All the versions | ||
var log = execReturn('git log'); | ||
|
||
// Get the version number of the current commit (line 5, strip leading whitespace and trailing text) | ||
var version = (log.split('\n')[4]+' ').replace(/\s*(\S*).*/, '$1'); | ||
|
||
return version === 'HEAD'; | ||
} | ||
|
||
/** | ||
* Build the docs site on a detached branch, commit it on gh-pages branch. | ||
*/ | ||
function buildDocs() { | ||
// Ensure we're starting in the docs dir | ||
process.chdir(__dirname); | ||
|
||
// Checkout the tag 'version' | ||
execho('git checkout gh-pages'); | ||
|
||
// Delete last HEAD commit to keep the history clean | ||
if (lastCommitIsHead()) { | ||
execho('git reset --hard HEAD~1'); | ||
} | ||
|
||
// Checkout the tag 'version' | ||
if (version === 'HEAD') { | ||
execho('git checkout --detach master'); | ||
} else { | ||
execho('git checkout tags/' + version); | ||
} | ||
|
||
// Build the docs site | ||
execho('npm install && npm run browser:build'); | ||
|
||
// Version it | ||
execho('mv build ../' + version); | ||
|
||
// Move to the gh-pages branch | ||
execho('git checkout gh-pages'); | ||
|
||
// Symbolic link 'release' to latest version | ||
if (!preRelease(version)) { | ||
execho('ln -sfh ../' + version + ' ../release'); | ||
} | ||
|
||
// Commit the new version | ||
execho('git add .. && git commit -m \'' + version + '\''); | ||
|
||
if (args[3] === '-p') { | ||
execho('git push -f'); | ||
} | ||
} | ||
|
||
/** | ||
* Add new version number to versions.js | ||
* The checks for HEAD can be removed once HEAD builds are automated, as the first entry will always be HEAD. | ||
*/ | ||
function addMenuVersion(version) { | ||
// Return to master | ||
execho('git checkout master'); | ||
|
||
var versions = JSON.parse(fs.readFileSync(versionsFile, 'utf8')); | ||
var head; | ||
|
||
// If HEAD is first in the array, shift it off. | ||
if (versions[0] === 'HEAD') { | ||
head = versions.shift() | ||
} | ||
|
||
// Add the new version | ||
versions.unshift(version); | ||
|
||
// If the array had a HEAD version, and we didn't just add one, put it back. | ||
if (head && version !== 'HEAD') { | ||
versions.unshift('HEAD'); | ||
} | ||
|
||
fs.writeFileSync(versionsFile, JSON.stringify(versions, null, 2)); | ||
|
||
// If we're adding a new version, or first instance of 'HEAD', commit it (on master branch) | ||
if (version !=='HEAD' || (version === 'HEAD' && !head)) { | ||
execho('git add ' + versionsFile + ' && git commit -m ' + '\'Add ' + version + ' to versions.json\''); | ||
} | ||
} | ||
|
||
buildDocs(version); | ||
addMenuVersion(version); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import List from 'material-ui/lib/lists/list'; | |
import ListItem from 'material-ui/lib/lists/list-item'; | ||
import Divider from 'material-ui/lib/divider'; | ||
import Subheader from 'material-ui/lib/Subheader'; | ||
import DropDownMenu from 'material-ui/lib/DropDownMenu'; | ||
import MenuItem from 'material-ui/lib/menus/menu-item'; | ||
import {SelectableContainerEnhance} from 'material-ui/lib/hoc/selectable-enhance'; | ||
import { | ||
Spacing, | ||
|
@@ -30,6 +32,46 @@ const AppLeftNav = React.createClass({ | |
router: React.PropTypes.object.isRequired, | ||
}, | ||
|
||
getInitialState: () => { | ||
return ({ | ||
muiVersions: [], | ||
}); | ||
}, | ||
|
||
componentDidMount: function() { | ||
const self = this; | ||
const url = 'versions.json'; | ||
const request = new XMLHttpRequest(); | ||
|
||
request.onreadystatechange = function() { | ||
if (request.readyState === 4 && request.status === 200) { | ||
self.setState({ | ||
muiVersions: JSON.parse(request.responseText), | ||
version: JSON.parse(request.responseText)[0], | ||
}); | ||
} | ||
}; | ||
|
||
request.open('GET', url, true); | ||
request.send(); | ||
}, | ||
|
||
firstNonPreReleaseVersion: function() { | ||
let version; | ||
for (let i = 0; i < this.state.muiVersions.length; i++) { | ||
version = this.state.muiVersions[i]; | ||
// If the version doesn't contain '-' and isn't 'HEAD' | ||
if (!/-/.test(version) && version !== 'HEAD') { | ||
break; | ||
} | ||
} | ||
return version; | ||
}, | ||
|
||
handleVersionChange: function(event, index, value) { | ||
window.location = value; | ||
}, | ||
|
||
handleRequestChangeLink(event, value) { | ||
window.location = value; | ||
}, | ||
|
@@ -39,19 +81,21 @@ const AppLeftNav = React.createClass({ | |
this.props.onRequestChangeLeftNav(false); | ||
}, | ||
|
||
getStyles() { | ||
return { | ||
logo: { | ||
cursor: 'pointer', | ||
fontSize: 24, | ||
color: Typography.textFullWhite, | ||
lineHeight: `${Spacing.desktopKeylineIncrement}px`, | ||
fontWeight: Typography.fontWeightLight, | ||
backgroundColor: cyan500, | ||
paddingLeft: Spacing.desktopGutter, | ||
marginBottom: 8, | ||
}, | ||
}; | ||
styles: { | ||
logo: { | ||
cursor: 'pointer', | ||
fontSize: 24, | ||
color: Typography.textFullWhite, | ||
lineHeight: `${Spacing.desktopKeylineIncrement}px`, | ||
fontWeight: Typography.fontWeightLight, | ||
backgroundColor: cyan500, | ||
paddingLeft: Spacing.desktopGutter, | ||
marginBottom: 8, | ||
}, | ||
version: { | ||
paddingLeft: Spacing.desktopGutterLess, | ||
fontSize: 16, | ||
}, | ||
}, | ||
|
||
render() { | ||
|
@@ -64,11 +108,12 @@ const AppLeftNav = React.createClass({ | |
style, | ||
} = this.props; | ||
|
||
const { | ||
prepareStyles, | ||
} = this.context.muiTheme; | ||
|
||
const styles = this.getStyles(); | ||
let currentVersion; | ||
if (window.location.pathname === '/') { | ||
currentVersion = this.firstNonPreReleaseVersion(); | ||
} else { | ||
currentVersion = window.location.pathname; | ||
} | ||
|
||
return ( | ||
<LeftNav | ||
|
@@ -78,9 +123,26 @@ const AppLeftNav = React.createClass({ | |
onRequestChange={onRequestChangeLeftNav} | ||
containerStyle={{zIndex: zIndex.leftNav - 100}} | ||
> | ||
<div style={prepareStyles(styles.logo)} onTouchTap={this.handleTouchTapHeader}> | ||
<div style={this.styles.logo} onTouchTap={this.handleTouchTapHeader}> | ||
Material-UI | ||
</div> | ||
|
||
<span style={this.styles.version}>Version:</span> | ||
<DropDownMenu | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
value={currentVersion} | ||
onChange={this.handleVersionChange} | ||
maxHeight={300} | ||
style={{width: 181}} | ||
> | ||
{this.state.muiVersions.map((version) => ( | ||
<MenuItem | ||
key={version} | ||
value={version} | ||
primaryText={version} | ||
/> | ||
))} | ||
</DropDownMenu> | ||
|
||
<SelectableList | ||
valueLink={{value: location.pathname, requestChange: onRequestChangeList}} | ||
> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
[ | ||
"v0.14.4", | ||
"v0.14.3", | ||
"v0.14.2", | ||
"v0.14.1", | ||
"v0.14.0", | ||
"v0.13.4", | ||
"v0.13.3", | ||
"v0.13.2", | ||
"v0.13.1", | ||
"v0.13.0", | ||
"v0.12.5", | ||
"v0.12.4", | ||
"v0.12.3", | ||
"v0.12.2", | ||
"v0.12.1", | ||
"v0.12.0", | ||
"v0.11.1", | ||
"v0.11.0", | ||
"v0.10.4", | ||
"v0.10.3", | ||
"v0.10.2", | ||
"v0.10.1", | ||
"v0.10.0", | ||
"v0.9.2", | ||
"v0.9.1", | ||
"v0.9.0", | ||
"v0.8.0", | ||
"v0.7.5", | ||
"v0.7.2", | ||
"v0.7.1", | ||
"v0.5.0", | ||
"v0.7.4", | ||
"v0.7.3", | ||
"v0.7.0", | ||
"v0.6.1", | ||
"v0.6.0", | ||
"v0.4.1", | ||
"v0.4.0", | ||
"v0.3.3", | ||
"v0.3.2", | ||
"v0.3.1", | ||
"v0.3.0" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been meaning to open a PR for this but since you're editing this line anyway, could you update the link to the right PR? 3132 -> 3133? Technically some of the links above it are wrong too so we could also just fix this later/separately...