-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const fs = require('fs'); | ||
const fg = require('fast-glob'); | ||
const { rewritePaths } = require('typescript-rewrite-paths'); | ||
const path = require('path'); | ||
|
||
/** | ||
* Replace all the paths in the stories from `./Block` to `reablocks` | ||
*/ | ||
function replacePaths() { | ||
// Grep all the stories | ||
const files = fg.sync('docs/blocks/**/*.tsx'); | ||
|
||
files.forEach((file) => { | ||
const code = fs.readFileSync(file, { encoding: 'utf-8' }); | ||
|
||
const output = rewritePaths(code, path => { | ||
if (path.startsWith('./') || path.startsWith('../')) { | ||
console.info(`Replacing ${path} with reablocks`); | ||
return 'reablocks'; | ||
} | ||
|
||
return path; | ||
}); | ||
|
||
const newPath = path.resolve('dist', 'blocks', path.basename(file)); | ||
const dir = path.dirname(newPath); | ||
|
||
if (!fs.existsSync(dir)){ | ||
fs.mkdirSync(dir); | ||
} | ||
|
||
fs.writeFileSync(newPath, output); | ||
}); | ||
} | ||
|
||
replacePaths(); |
File renamed without changes.