Skip to content

Commit

Permalink
fix: update authhero to support both cjs and esm
Browse files Browse the repository at this point in the history
  • Loading branch information
markusahlstrand committed Jul 14, 2024
1 parent 95b1659 commit 516e8a2
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 8 deletions.
6 changes: 6 additions & 0 deletions packages/authhero/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# authhero

## 0.2.0

### Minor Changes

- Update the package to support both esm and cjs

## 0.1.0

### Minor Changes
Expand Down
3 changes: 1 addition & 2 deletions packages/authhero/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "authhero",
"version": "0.1.0",
"type": "module",
"version": "0.2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
Expand Down
42 changes: 36 additions & 6 deletions packages/authhero/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
import path from "path";
import { defineConfig } from "vite";
import { resolve } from "path";
import dts from "vite-plugin-dts";

// https://vitejs.dev/config/
export default defineConfig({
const getPackageName = () => {
return "authhero";
};

const getPackageNameCamelCase = () => {
try {
return getPackageName().replace(/-./g, (char) => char[1].toUpperCase());
} catch (err) {
throw new Error("Name property in package.json is missing.");
}
};

const fileName = {
es: `${getPackageName()}.mjs`,
cjs: `${getPackageName()}.cjs`,
iife: `${getPackageName()}.iife.js`,
};

const formats = Object.keys(fileName) as Array<keyof typeof fileName>;

module.exports = defineConfig({
base: "./",
build: {
lib: { entry: resolve(__dirname, "src/index.ts"), formats: ["es"] },
outDir: "./build/dist",
lib: {
entry: path.resolve(__dirname, "src/index.ts"),
name: getPackageNameCamelCase(),
formats,
fileName: (format) => fileName[format],
},
},
resolve: {
alias: [
{ find: "@", replacement: path.resolve(__dirname, "src") },
{ find: "@@", replacement: path.resolve(__dirname) },
],
},
plugins: [dts()],
});
68 changes: 68 additions & 0 deletions packages/create-authhero/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Sure! Here's a `README.md` file for your CLI package:

````markdown
# create-authhero

`create-authhero` is a command-line tool for creating a new AuthHero project. It sets up a new project with the necessary configuration and template files, including SQLite templates.

## Usage

To create a new AuthHero project, run the following command:

```sh
npm create authhero <project-name>
```

If you don't specify a project name, you will be prompted to enter one.

### Example

```sh
npm create authhero my-auth-project
```

This will create a new directory named `my-auth-project` with the following structure:

```
my-auth-project
├── package.json
└── src
└── ... (template files)
```

The generated project is a small wrapper around the [authhero](https://www.npmjs.com/package/authhero) npm library which makes it easy to keep up to date with the latest changes. All the files in the `src` directory are templates that you can modify to fit your needs.

### Options

- `project-name` (optional): The name of the new project. If not provided, you will be prompted to enter it.

## Project Setup

When you run the `create-authhero` command, you will be prompted to enter some additional information for your new project:

- Project name

These details will be included in the `package.json` file of your new project.

## Development

To contribute to this project, clone the repository and install the dependencies:

```sh
git clone https://github.com/markusahlstrand/authhero
cd create-authhero
npm install
```

## License

MIT

## Author

Markus Ahlstrand

## Acknowledgments

- [Commander.js](https://github.com/tj/commander.js) - Command-line interfaces made easy
- [Inquirer.js](https://github.com/SBoudrias/Inquirer.js) - A collection of common interactive command line user interfaces
5 changes: 5 additions & 0 deletions packages/create-authhero/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"name": "create-authhero",
"homepage": "https://authhero.net",
"repository": {
"type": "git",
"url": "https://github.com/markusahlstrand/authhero"
},
"version": "0.1.0",
"type": "module",
"main": "dist/create-authhero.js",
Expand Down

0 comments on commit 516e8a2

Please sign in to comment.