-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Changes from all commits
33dfce0
831efbc
1d0b4f3
43c4064
959f2d9
d91f119
da51575
3bad9e2
ea5895a
3ff0eda
f23220b
b227812
e30f510
1266d0b
f9acaae
6e09334
61f6360
019f616
ddeb9cd
fb7281a
262f167
5f18a64
072bd18
95fa4da
c862d35
6baac94
53a0dad
d9317d8
f060df6
578ba6e
36c941a
c4389f7
a9b44a3
6a83e8a
955ed37
90b0c5b
d736e6c
1187c03
04852ae
d5f70b2
7828511
e7c9fc5
9f5d780
3fe7f0b
8bdf95b
707a18f
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,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 }, | ||
}; |
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'); | ||
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. Any reason for not using ES modules? 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. It would require |
||
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); | ||
}); |
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.
Changes to the docs will hot reload the site.
This is confusing. Yes, it does hot reload the side. Or, I'm missing something?
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.
@oliviertassinari
yarn docs:dev
has hot module replacement. That's what's written here. Is there some contradiction or why is this confusing?