Skip to content

Commit

Permalink
rfc(@blocks-*): added support modules and export default 🙈
Browse files Browse the repository at this point in the history
  • Loading branch information
wootsbot committed Oct 12, 2023
1 parent 87fdcff commit 33e5a10
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
],
"access": "restricted",
"baseBranch": "main",
"ignore": ["@examples/basic", "colors-radix-ui", "colors-tailwind-css"]
"ignore": ["@examples/basic", "@design-blocks/colors/radix-ui", "@design-blocks/colors/tailwind-css"]
}
6 changes: 6 additions & 0 deletions .changeset/real-planes-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@design-blocks/unstyled": minor
"@design-blocks/colors": minor
---

Added support modules and export default
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ jobs:
# run: |
# git tag | xargs git tag -d

# - name: blocks-unstyled
# run: node packages/@blocks-unstyled/scripts/formatPKJson.js
- name: config prepublish only
run: node packages/@blocks-unstyled/scripts/configPrepublishOnly

- name: Create Release Pull Request or Publish Design Blocks
id: changesets
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/src/screens/demo/screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "@design-blocks/primitives";
import colors from "@design-blocks/colors/tailwind-css";

import * as Button from "@design-blocks/unstyled/Button";
import { Button } from "@design-blocks/unstyled";

import { block, css } from "../../../blocks.config";

Expand Down
2 changes: 1 addition & 1 deletion packages/@blocks-colors/radix-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "colors-radix-ui",
"name": "@design-blocks/colors/radix-ui",
"version": "1.0.0",
"private": true,
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/@blocks-colors/tailwind-css/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "colors-tailwind-css",
"name": "@design-blocks/colors/tailwind-css",
"version": "1.0.0",
"private": true,
"sideEffects": false,
Expand Down
3 changes: 1 addition & 2 deletions packages/@blocks-unstyled/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
"clean:build": "rimraf -rf dist",
"lint": "../../node_modules/.bin/biome check src",
"lint:fix": "../../node_modules/.bin/biome check --apply-unsafe src",
"bundlesize": "bundlesize",
"prepublishOnly": "node ./scripts/formatPKJson.js"
"bundlesize": "bundlesize"
},
"bundlesize": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const sharedPkgFormat = JSON.parse(sharedPkg);
const currentScripts = sharedPkgFormat.scripts;
sharedPkgFormat.scripts = {
...currentScripts,
postinstall:
"node ./scripts/preparePackages.js && node ./scripts/copyFiles.js && node ./scripts/modulesGeneration.js",
postinstall: "node ./scripts/copyFiles.js",
};

fs.writeFileSync(
Expand Down
18 changes: 18 additions & 0 deletions packages/@blocks-unstyled/scripts/configPrepublishOnly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require("fs-extra");
const path = require("path");

const rootDirOutputPath = path.join(__dirname, "..");

const sharedPkg = fs.readFileSync("./package.json", "utf-8");
const sharedPkgFormat = JSON.parse(sharedPkg);

const currentScripts = sharedPkgFormat.scripts;
sharedPkgFormat.scripts = {
...currentScripts,
prepublishOnly: "node ./scripts/configPostinstall.js",
};

fs.writeFileSync(
path.join(rootDirOutputPath, "package.json"),
JSON.stringify(sharedPkgFormat, null, 2)
);
101 changes: 99 additions & 2 deletions packages/@blocks-unstyled/scripts/copyFiles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,103 @@
const fs = require("fs-extra");
const path = require("path");

const rootDirOutputPath = path.join(__dirname, "..");
const rootPath = path.join(__dirname, "..");
const rootDirOutputPath = path.join(__dirname, "..", "build");
const indexFilePath = path.join(rootPath, "src", "index.ts");

fs.copySync(path.join(__dirname, "../build"), path.join(rootDirOutputPath));
const content = fs.readFileSync(indexFilePath, "utf8");
const matches = content.match(/export \* from '\.\/(\w+)'/g);
const componentNames = matches
? matches.map((match) => match.match(/'\.\/(\w+)'/)[1])
: [];

if (!fs.existsSync(rootDirOutputPath)) {
fs.ensureDirSync(path.join(rootDirOutputPath));
}

/**
* Generate new package.json to be published
*/
const sharedPkg = fs.readFileSync("./package.json", "utf-8");
const sharedPkgFormat = JSON.parse(sharedPkg);
sharedPkgFormat.exports = {
"./package.json": "./package.json",
".": {
types: "./typescript/index.d.ts",
import: "./module/index.js",
require: "./commonjs/index.js",
},
};

sharedPkgFormat.main = "commonjs/index.js";
sharedPkgFormat.module = "module/index.js";
sharedPkgFormat.types = "typescript/index.d.ts";

// biome-ignore lint/performance/noDelete: <explanation>
delete sharedPkgFormat.scripts;

// biome-ignore lint/performance/noDelete: <explanation>
delete sharedPkgFormat.files;

// biome-ignore lint/performance/noDelete: <explanation>
delete sharedPkgFormat.devDependencies;

// biome-ignore lint/performance/noDelete: <explanation>
delete sharedPkgFormat.bundlesize;
// biome-ignore lint/performance/noDelete: <explanation>
delete sharedPkgFormat["react-native-builder-bob"];

fs.writeFileSync(
path.join(rootDirOutputPath, "package.json"),
JSON.stringify(sharedPkgFormat, null, 2)
);

fs.copySync(
path.join(__dirname, "../README.md"),
path.join(rootDirOutputPath, "README.md")
);

fs.copySync(
path.join(__dirname, "../src"),
path.join(rootDirOutputPath, "src")
);

fs.copySync(path.join(__dirname, "../build"), path.join(rootPath));
fs.removeSync(path.join(__dirname, "../build"));

function generatePackageJson(componentName) {
return JSON.stringify(
{
sideEffects: false,
module: `../module/${componentName}/index.js`,
main: `../commonjs/${componentName}/index.js`,
types: `../typescript/${componentName}/index.d.ts`,
},
null,
2
);
}

componentNames.forEach((name) => {
const outputPath = path.join(rootPath, name);

if (!fs.existsSync(outputPath)) {
fs.mkdirSync(outputPath);
}

fs.writeFileSync(
path.join(outputPath, "package.json"),
generatePackageJson(name)
);
});

const finalPkgFormat = JSON.parse(sharedPkg);
// biome-ignore lint/performance/noDelete: <explanation>
delete finalPkgFormat.scripts;

fs.writeFileSync(
path.join(rootDirOutputPath, "package.json"),
JSON.stringify(finalPkgFormat, null, 2)
);

fs.removeSync(path.join(__dirname, "../scripts"));
40 changes: 0 additions & 40 deletions packages/@blocks-unstyled/scripts/modulesGeneration.js

This file was deleted.

68 changes: 0 additions & 68 deletions packages/@blocks-unstyled/scripts/preparePackages.js

This file was deleted.

0 comments on commit 33e5a10

Please sign in to comment.