forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Fix migration to have singular urls (mui#30695)
- Loading branch information
1 parent
5e3d995
commit 9316900
Showing
20 changed files
with
1,149 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import prettier from 'prettier'; | ||
import replaceMarkdownLinks from '../src/modules/utils/replaceMarkdownLinks'; | ||
|
||
const workspaceRoot = path.resolve(__dirname, '../../'); | ||
const prettierConfigPath = path.join(workspaceRoot, 'prettier.config.js'); | ||
|
||
function writePrettifiedFile(filename: string, data: string, options: object = {}) { | ||
const prettierConfig = prettier.resolveConfig.sync(filename, { | ||
config: prettierConfigPath, | ||
}); | ||
if (prettierConfig === null) { | ||
throw new Error( | ||
`Could not resolve config for '${filename}' using prettier config path '${prettierConfigPath}'.`, | ||
); | ||
} | ||
|
||
fs.writeFileSync(filename, prettier.format(data, { ...prettierConfig, filepath: filename }), { | ||
encoding: 'utf8', | ||
...options, | ||
}); | ||
} | ||
|
||
const readdirDeep = (directory: string, pathsProp: string[] = []) => { | ||
const paths: string[] = pathsProp; | ||
const items = fs.readdirSync(directory); | ||
items.forEach((item) => { | ||
const itemPath = path.resolve(directory, item); | ||
|
||
if (fs.statSync(itemPath).isDirectory()) { | ||
readdirDeep(itemPath, paths); | ||
} | ||
|
||
if (itemPath.match(/.*\/[^/]+\.[^.]+/)) { | ||
// ends with extension | ||
paths.push(itemPath); | ||
} | ||
}); | ||
|
||
return paths; | ||
}; | ||
|
||
function run() { | ||
fs.removeSync(path.resolve(`docs/pages/api-docs`)); | ||
fs.removeSync(path.resolve(`docs/pages/components`)); | ||
fs.removeSync(path.resolve(`docs/pages/customization`)); | ||
fs.removeSync(path.resolve(`docs/pages/discover-more`)); | ||
fs.removeSync(path.resolve(`docs/pages/getting-started`)); | ||
fs.removeSync(path.resolve(`docs/pages/guides`)); | ||
fs.removeSync(path.resolve(`docs/pages/styles`)); | ||
|
||
fs.removeSync(path.resolve(`test/e2e-website/material-current.spec.ts`)); | ||
|
||
const dataDir = readdirDeep(path.resolve(`docs/data`)); | ||
dataDir.forEach((filePath) => { | ||
if (filePath.endsWith('.md')) { | ||
let data = fs.readFileSync(filePath, { encoding: 'utf-8' }); | ||
|
||
data = replaceMarkdownLinks(data); | ||
|
||
writePrettifiedFile(filePath, data); | ||
} | ||
}); | ||
|
||
// Turn feature toggle `enable_product_scope: true` | ||
const featureTogglePath = path.join(process.cwd(), 'docs/src/featureToggle.js'); | ||
let featureToggle = fs.readFileSync(featureTogglePath, { encoding: 'utf8' }); | ||
|
||
featureToggle = featureToggle | ||
.replace(`enable_redirects: false`, `enable_redirects: true`) | ||
.replace(`enable_system_scope: false`, `enable_system_scope: true`); | ||
|
||
fs.writeFileSync(featureTogglePath, featureToggle); | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.