Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to integration template with build step #37

Merged
merged 7 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/blue-cycles-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"astro-pages": minor
---

- Added a build step and restructured the package.
- The `astro-integration-kit` plugin was removed, use the utility instead
- All exports from `astro-pages/plugins` and `astro-pages/utils` have been removed, import from `astro-pages` instead:

```ts
// Use the types
import type { Option, IntegrationOption } from 'astro-pages';

// Use the Astro integration
import addPageDirIntegration from 'astro-pages';

// Use the utility (inside an Astro integration)
import { addPageDir } from 'astro-pages';
```
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PNPM
run: corepack enable && pnpm -v

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.19.0
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm --filter astro-pages build
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
- name: Install Dependencies
run: pnpm install

- name: Build
run: pnpm --filter astro-pages build

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
Expand Down
23 changes: 1 addition & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
# build output
dist/

# generated types
.astro/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production

# macOS-specific files
.DS_Store
node_modules
4 changes: 0 additions & 4 deletions .vscode/extensions.json

This file was deleted.

11 changes: 0 additions & 11 deletions .vscode/launch.json

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.defaultFormatter": "biomejs.biome"
}
36 changes: 1 addition & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Add custom file based routing directories in Astro

### Examples

#### Integration
#### Astro Integration

```ts
// astro.config.mjs
Expand Down Expand Up @@ -53,37 +53,3 @@ export default function(options): AstroIntegration {
}
}
```

#### Astro Integration Kit Plugin

```ts
// package/index.ts
import { defineIntegration } from "astro-integration-kit";
import addPageDirPlugin from "astro-pages/plugins/astro-integration-kit.ts";

export default defineIntegration({
name: "my-integration",
plugins: [addPageDirPlugin],
setup() {
return {
"astro:config:setup": ({ addPageDir }) => {

const pageConfig = {
cwd: import.meta.url,
dir: "pages"
}

const {
pages,
injectPages
} = addPageDir(pageConfig)

// Injects pages inside 'package/pages'
injectPages()

}
}
}
})
```

5 changes: 4 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"linter": {
"enabled": true,
"rules": {
"recommended": true
"recommended": true,
"suspicious": {
"noExplicitAny": "warn"
}
}
},
"files": {
Expand Down
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
{
"name": "package-root",
"name": "root",
"private": true,
"version": "0.0.1",
"description": "",
"packageManager": "[email protected]",
"packageManager": "[email protected]",
"engines": {
"node": ">=18.19.0"
},
"scripts": {
"package:dev": "pnpm --filter astro-pages dev",
"playground:dev": "pnpm --filter playground dev",
"dev": "pnpm --stream -r -parallel dev",
"changeset": "changeset",
"release": "node scripts/release.mjs",
"lint": "biome check .",
"lint:fix": "biome check --apply ."
},
"license": "MIT",
"devDependencies": {
"@biomejs/biome": "^1.6.2",
"@changesets/cli": "^2.27.1",
"astro": "^4.5.9"
"@biomejs/biome": "1.6.4",
"@changesets/cli": "^2.27.1"
}
}
1 change: 1 addition & 0 deletions package/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
22 changes: 0 additions & 22 deletions package/CHANGELOG.md

This file was deleted.

33 changes: 0 additions & 33 deletions package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,39 +147,6 @@ export default function(options): AstroIntegration {
}
```

**Use as a [`astro-integration-kit`](https://astro-integration-kit.netlify.app/getting-started/installation/) plugin**

```js
// package/index.ts
import { defineIntegration } from "astro-integration-kit";
import addPageDirPlugin from "astro-pages/plugins/astro-integration-kit.ts";

export default defineIntegration({
name: "my-integration",
plugins: [addPageDirPlugin],
setup() {
return {
"astro:config:setup": ({ addPageDir }) => {

const pageConfig = {
cwd: import.meta.url,
dir: "pages"
}

const {
pages,
injectPages
} = addPageDir(pageConfig)

// Injects pages inside 'package/pages'
injectPages()

}
}
}
})
```

## `Option` Reference

### `dir`
Expand Down
24 changes: 16 additions & 8 deletions package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,28 @@
},
"bugs": "https://github.com/brycerussell/astro-pages/issues",
"homepage": "https://github.com/brycerussell/astro-pages",
"scripts": {},
"publishConfig": {
"access": "public"
},
"type": "module",
"sideEffects": false,
"exports": {
".": "./index.ts",
"./utils/*": "./utils/*",
"./plugins/*": "./plugins/*",
"./types": "./types.ts"
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"files": ["dist"],
"scripts": {
"dev": "tsup --watch",
"build": "tsup"
},
"peerDependencies": {
"astro": ">=3",
"astro-integration-kit": ">=0.1.0"
"astro": ">=3"
},
"devDependencies": {
"@types/node": "^20.11.30"
"@types/node": "^20.11.30",
"tsup": "^8.0.2"
},
"dependencies": {
"fast-glob": "^3.3.2"
Expand Down
26 changes: 0 additions & 26 deletions package/plugins/astro-integration-kit.ts

This file was deleted.

8 changes: 8 additions & 0 deletions package/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import integration from "./integration.js";
import addPageDir, { type IntegrationOption, type Option } from "./utility.js";

export type { IntegrationOption, Option };

export { addPageDir };

export default integration;
9 changes: 2 additions & 7 deletions package/index.ts → package/src/integration.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { AstroIntegration } from "astro";
import type { IntegrationOption, Option, Prettify } from "./types";
import { GLOB_PAGES, addPageDir } from "./utils/add-page-dir";
import addPageDir, { type IntegrationOption, type Option } from "./utility.js";

export default function (
...options: (string | Prettify<Option>)[]
): AstroIntegration {
export default function (...options: (string | Option)[]): AstroIntegration {
return {
name: "astro-pages",
hooks: {
Expand Down Expand Up @@ -38,5 +35,3 @@ export default function (
},
};
}

export { addPageDir, GLOB_PAGES };
Loading
Loading