Skip to content

Commit

Permalink
export blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
amcdnl committed May 14, 2024
1 parent 2b09d69 commit abf5d9a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"version": "7.6.0",
"description": "Component library for React",
"scripts": {
"build": "npm run build:js && npm run build:styles && npm run rewrite && npm run build:stories && npm run build:docs",
"build": "npm run build:js && npm run build:styles && npm run rewrite:stories && npm run rewrite:blocks && npm run build:stories && npm run build:docs",
"build-storybook": "storybook build",
"build:js": "vite build --mode library",
"build:stories": "tsc dist/stories/*.tsx --module esnext --jsx react-jsx --skipLibCheck true || exit 0;",
"build:styles": "tailwindcss -i ./src/index.css -o ./dist/index.css",
"build:docs": "node scripts/docs.js",
"rewrite": "node scripts/rewrite.cjs",
"rewrite:stories": "node scripts/stories.cjs",
"rewrite:blocks": "node scripts/blocks.cjs",
"lint": "eslint --ext js,ts,tsx",
"lint:fix": "eslint --ext js,ts,tsx --fix src",
"lint:prettier": "prettier --loglevel warn --write 'src/**/*.{ts,tsx,js,jsx}'",
Expand All @@ -30,7 +31,8 @@
"require": "./dist/index.umd.cjs",
"types": "./dist/index.d.ts"
},
"./stories/*": "./dist/stories/*"
"./stories/*": "./dist/stories/*",
"./blocks/*": "./dist/blocks/*"
},
"browser": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
36 changes: 36 additions & 0 deletions scripts/blocks.cjs
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.

0 comments on commit abf5d9a

Please sign in to comment.