Skip to content

Commit

Permalink
add bundler package
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Jan 6, 2024
1 parent d48b8da commit a409130
Show file tree
Hide file tree
Showing 5 changed files with 582 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/bundles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# `@refina/basic-components`

[![npm](https://img.shields.io/npm/v/%40refina%2Fbasic-components?color=green)](https://www.npmjs.com/package/@refina/basic-components)

The bundled version of Refina libs.

To know more about Refina, please visit:

- [Documentation](https://refina.vercel.app).
- [Getting Started](https://refina.vercel.app/guide/introduction.html)
- [GitHub Repository](https://github.com/refinajs/refina).
- [Examples](https://gallery.refina.vercel.app).

## Usage

### Via CDN

```html
<script src="https://unpkg.com/@refina/bundles/<lib-name>"></script>
```

**Note:** Replace `<lib-name>` with the name of the lib you want to use.

Available libs:

- `basic-components`
- `core`
- `mdui`
- `transformer`
61 changes: 61 additions & 0 deletions packages/bundles/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as fsWalk from "@nodelib/fs.walk";
import { RefinaTransformer } from "@refina/transformer";
import { consola } from "consola";
import { execSync } from "node:child_process";
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { rimrafSync } from "rimraf";

consola.start("Starting bundle Refina libs...");

const libs = ["basic-components", "core", "mdui", "transformer"];
const __dirname = dirname(fileURLToPath(import.meta.url));
const tempDir = join(__dirname, "temp");

const transformer = new RefinaTransformer();

for (const lib of libs) {
try {
const sourceDir = join(__dirname, "..", lib, "src");
const tempDir = join(__dirname, "..", lib, "dist");

rimrafSync(tempDir);

const entries = fsWalk.walkSync(sourceDir, {
basePath: ".",
});

for (const entry of entries) {
if (entry.dirent.isFile()) {
const sourcePath = resolve(sourceDir, entry.path);
const tempPath = resolve(tempDir, entry.path);

const source = readFileSync(sourcePath, "utf-8");
const transformed =
transformer.transformFile(entry.name, source, true)?.code ?? source;

mkdirSync(dirname(tempPath), { recursive: true });
writeFileSync(tempPath, transformed);
}
}
} catch (e) {
consola.error(e);
throw e;
}

consola.success(`Transformed ${lib}!`);
}

const command = [
`pnpm exec tsup`,
...libs.map(lib => `--entry.${lib} ../${lib}/dist/index.ts`),
`--clean --format esm -d ./dist --no-splitting --minify terser --sourcemap`,
].join(" ");

execSync(command, {
stdio: "inherit",
cwd: __dirname,
});

consola.success("Bundling complete!");
41 changes: 41 additions & 0 deletions packages/bundles/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@refina/bundles",
"version": "0.0.1",
"description": "The bundled version of Refina libs.",
"keywords": [
"refina",
"bundle"
],
"files": [
"dist",
"README.md"
],
"type": "module",
"exports": {
"./*": "./dist/*"
},
"scripts": {
"build": "tsx ./bundle.ts",
"check": "tsc --noEmit",
"prepublishOnly": "npm run build"
},
"author": "_Kerman",
"repository": {
"type": "git",
"url": "git+https://github.com/KermanX/refina"
},
"readme": "https://github.com/KermanX/refina#readme",
"bugs": "https://github.com/KermanX/refina/issues",
"license": "MIT",
"devDependencies": {
"@nodelib/fs.walk": "^2.0.0",
"@refina/transformer": "workspace:^",
"@types/node": "^20.6.5",
"consola": "^3.2.3",
"rimraf": "^5.0.5",
"terser": "^5.26.0",
"tsup": "^7.2.0",
"tsx": "^4.7.0",
"typescript": "^5.2.2"
}
}
11 changes: 11 additions & 0 deletions packages/bundles/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"include": ["./bundle.ts"],
"exclude": ["./dist"],
"compilerOptions": {
"strict": true,
"moduleResolution": "NodeNext",
"module": "NodeNext",
"target": "ESNext",
"lib": ["ESNext"]
}
}
Loading

1 comment on commit a409130

@vercel
Copy link

@vercel vercel bot commented on a409130 Jan 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

refina-gallery – ./

gallery.refina.vercel.app
refina-gallery-git-main-refina.vercel.app
refina-gallery-refina.vercel.app

Please sign in to comment.