Skip to content
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] AppBar and Textfield demos in TypeScript #13229

Merged
merged 46 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
33dfce0
Squashed commit of the following:
eps1lon Nov 5, 2018
831efbc
removed the babel-generator-prettier plugin
Jan 11, 2019
1d0b4f3
Merge branch 'master' into docs/examples-in-typescript
eps1lon Jan 13, 2019
43c4064
[core] use link protocol for babel-plugin-unwrap-createStyles
eps1lon Jan 13, 2019
959f2d9
[babel-plugin-unwrap-createStyles] Improve code docs
eps1lon Jan 13, 2019
d91f119
[docs] Sync ts and js demos
eps1lon Jan 13, 2019
da51575
Merge remote-tracking branch 'upstream/master' into docs/examples-in-…
eps1lon Jan 13, 2019
3bad9e2
[ci] Use proper docs:ts:check command
eps1lon Jan 13, 2019
ea5895a
[docs] Improve TS demo workflow
eps1lon Jan 14, 2019
3ff0eda
[docs] Cleanup merge commit
eps1lon Jan 14, 2019
f23220b
[docs] Cleanup TS demo testing
eps1lon Jan 14, 2019
b227812
[docs] Furhter merge commit cleanup
eps1lon Jan 14, 2019
e30f510
[docs} Fix codesandbox demos
eps1lon Jan 14, 2019
1266d0b
[docs] remove unused lint directives
eps1lon Jan 14, 2019
f9acaae
[docs] Add analytics event to source switches
eps1lon Jan 14, 2019
6e09334
[core] cleanup tslint diff
eps1lon Jan 14, 2019
61f6360
[babel-plugin-unwrapCreateStyles] Cleanup package.json
eps1lon Jan 17, 2019
019f616
Merge branch 'master' into docs/examples-in-typescript
eps1lon Jan 17, 2019
ddeb9cd
[docs] fix bundle size limit
eps1lon Jan 17, 2019
fb7281a
remove blank line
oliviertassinari Jan 17, 2019
262f167
remove blank lines
oliviertassinari Jan 17, 2019
5f18a64
Update README.md
oliviertassinari Jan 17, 2019
072bd18
[docs] exit with non-zero if ts scripts fail
eps1lon Jan 17, 2019
95fa4da
[docs] Fix failing TS script
eps1lon Jan 17, 2019
c862d35
Update CONTRIBUTING.md
oliviertassinari Jan 17, 2019
6baac94
Update CONTRIBUTING.md
oliviertassinari Jan 17, 2019
53a0dad
Revert "remove blank lines"
eps1lon Jan 17, 2019
d9317d8
Merge branch 'docs/examples-in-typescript' of github.com:eps1lon/mate…
eps1lon Jan 17, 2019
f060df6
[docs] Update Hooks / JS / TS icons, remove code icon
mbrookes Jan 21, 2019
578ba6e
Merge branch 'master' into docs/examples-in-typescript
eps1lon Jan 29, 2019
36c941a
[docs] Format code
eps1lon Jan 29, 2019
c4389f7
[docs] Port #14266 to TS
eps1lon Jan 29, 2019
a9b44a3
[docs] Port #14281 to TS
eps1lon Jan 29, 2019
6a83e8a
[docs] Port #14023 to TS
eps1lon Jan 29, 2019
955ed37
[docs] Adjust bundle size
eps1lon Jan 29, 2019
90b0c5b
WIP dropdown
mbrookes Jan 21, 2019
d736e6c
Add a transition, highlight the correct toggle-button
mbrookes Jan 29, 2019
1187c03
Remove comment Tooltips
mbrookes Jan 29, 2019
04852ae
docs bundle size
mbrookes Jan 29, 2019
d5f70b2
Merge branch 'master' into docs/examples-in-typescript
eps1lon Jan 30, 2019
7828511
[docs] Update contributing with updated formatting ts demo task
eps1lon Jan 30, 2019
e7c9fc5
[docs] Remove commented code
eps1lon Jan 30, 2019
9f5d780
[docs] Update outdated API docs
eps1lon Jan 30, 2019
3fe7f0b
[docs] Remove unnecessary fragment
eps1lon Jan 31, 2019
8bdf95b
[docs] Replace string literals with enum values
eps1lon Jan 31, 2019
707a18f
[docs] Removed explicit property initialization
eps1lon Jan 31, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ jobs:
- *restore_yarn_offline_mirror
- *restore_yarn_cache
- *install_js
- run:
name: Transpile TypeScript demos
command: yarn docs:typescript:formatted
- run:
name: Are the compiled TypeScript demos equivalent to the JavaScript demos?
command: git diff --exit-code
- run:
name: Can we generate the @material-ui/core build?
command: cd packages/material-ui && yarn build
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/examples/create-react-app-with-flow/flow
/examples/create-react-app-with-flow/flow-typed
/examples/gatsby/public
/packages/babel-plugin-unwrap-createStyles/test/__fixtures__/
/packages/material-ui-codemod/lib
/packages/material-ui-codemod/src/*/*.test
/packages/material-ui-codemod/src/*/*.test.js
Expand Down
2 changes: 1 addition & 1 deletion .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = [
name: 'The main docs bundle',
webpack: false,
path: main.path,
limit: '191 KB',
limit: '193 KB',
},
{
name: 'The docs home page',
Expand Down
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ We will only accept a pull request for which all tests pass. Make sure the follo
- If API documentation is being changed in the source, `yarn docs:api` was run.
- If prop types were changed, the TypeScript declarations were updated.
- If TypeScript declarations were changed, `yarn typescript` passed.
- If demos were changed, make sure `yarn docs:typescript:formatted` does not introduce changes.
See [About TypeScript demos](#about-typescript-demos).
- The PR title follows the pattern `[Component] Imperative commit message`. (See: [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/#imperative) for a great explanation)

## Getting started
Expand Down Expand Up @@ -80,6 +82,8 @@ yarn
yarn docs:dev
```
You can now access the documentation site [locally](http://localhost:3000).
Changes to the docs will hot reload the site. If you make changes to TypeScript files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to the docs will hot reload the site.

This is confusing. Yes, it does hot reload the side. Or, I'm missing something?

Copy link
Member Author

@eps1lon eps1lon Jan 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oliviertassinari yarn docs:dev has hot module replacement. That's what's written here. Is there some contradiction or why is this confusing?

in the docs run `yarn docs:typescript --watch` in a separate terminal.

Test coverage is limited at present, but where possible, please add tests for any changes you make. Tests can be run with `yarn test`.

Expand Down Expand Up @@ -118,6 +122,14 @@ docs/src/pages/demos/buttons/
```
And let's give it a name: `SuperButtons.js`.

We try to also document how to use this library with TypeScript. If you are familiar with
that language try writing that demo in TypeScript in a *.tsx file. When you're done
run `yarn docs:typescript:formatted` to automatically add a JavaScript version.

Apart from the inherent pros and cons of TypeScript the demos are also used to test our
type declarations. This helps a lot in catching regressions when updating our type
declarations.

#### 2. Edit the page Markdown file.

The Markdown file is the source for the website documentation. So, whatever you wrote there will be reflected on the website.
Expand Down Expand Up @@ -155,6 +167,20 @@ Then, you will need to add the following code:

In case you missed something, [we have a real example that can be used as a summary report]((https://github.com/mui-org/material-ui/pull/8922/files)).

### About TypeScript demos

To help people use this library with TypeScript we try to provide equivalent demos
in TypeScript.

Changing demos in JavaScript requires a manual update of the TypeScript
version. If you are not familiar with this language you can add the filepath
of the TS demo to `docs/ts-demo-ignore.json`. See `docs/babel.config.ts.js` for more
information. Otherwise our CI will fail the `test_build` job.
A contributor can later update the TypeScript version of that demo.

If you are already familiar with TypeScript you can simply write the demo in TypeScript.
`yarn docs:typescript:formatted` will transpile it down to JavaScript.

## How do I use my local distribution of material-ui in any project?

Sometimes it is good to test your changes in a real world scenario, in order to do that you can install your local distribution of Material-UI in any project with [yarn link](https://yarnpkg.com/lang/en/docs/cli/link/).
Expand Down
24 changes: 24 additions & 0 deletions docs/babel.config.ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const path = require('path');
const ignoredDemos = require('./ts-demo-ignore.json');

/**
* babel config to transpile tsx demos to js
*
* Can be used to spot differences between ts and js demos which might indicate that they
* do different things at runtime.
*
* Demos listed in ts-demo-ignore are not transpiled. Their path should be relative
* to `${workspaceRoot}/docs/src/pages/demos`.
*/

const workspaceRoot = path.join(__dirname, '../');
const ignore = ignoredDemos.map(demoPath =>
path.join(workspaceRoot, 'docs/src/pages/demos', `${demoPath}.tsx`),
);

module.exports = {
presets: ['@babel/preset-typescript'],
plugins: ['unwrap-createStyles'],
ignore,
generatorOpts: { retainLines: true },
};
55 changes: 55 additions & 0 deletions docs/scripts/formattedTSDemos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Transpiles and formats TS demos.
* Can be used to verify that JS and TS demos are equivalent. No introduced change
* would indicate equivalence.
*/
const childProcess = require('child_process');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for not using ES modules?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would require babel-node without adding any benefit with the node runtime. Not sure what the state of esm, mjs and node is but I don't see the value in going down that rabbit hole.

const fse = require('fs-extra');
const path = require('path');
const prettier = require('prettier');
const util = require('util');

const exec = util.promisify(childProcess.exec);

async function getUnstagedGitFiles() {
const { stdout } = await exec('git diff --name-only');
const list = stdout.trim();

if (list === '') {
// "".split(" ") => [""]
return [];
}

return list.split('\n');
}

function fixBabelGeneratorIssues(source) {
return source.replace(/,\n\n/g, ',\n');
}

exec('yarn docs:typescript')
.then(() => {
const prettierConfigPath = path.join(__dirname, '../../prettier.config.js');
const prettierConfig = prettier.resolveConfig(process.cwd(), { config: prettierConfigPath });

return Promise.all([getUnstagedGitFiles(), prettierConfig]);
})
.then(([changedDemos, prettierConfig]) =>
Promise.all(
changedDemos.map(filename => {
const filepath = path.join(process.cwd(), filename);

return fse.readFile(filepath).then(source => {
const prettified = prettier.format(source.toString(), { ...prettierConfig, filepath });
const formatted = fixBabelGeneratorIssues(prettified);

return fse.writeFile(filepath, formatted);
});
}),
),
)
.catch(err => {
// eslint-disable-next-line no-console
console.error(err);
process.exit(1);
});
Loading