Skip to content

Commit

Permalink
Add Changesets and Linting (#13)
Browse files Browse the repository at this point in the history
* Install dep for changesets and linting

- Install dep for changesets and linting
- Add scripts

* Add changesets action

* lint

* Add LICENSE

* Initialize changesets cli

* add changeset
  • Loading branch information
BryceRussell authored Mar 1, 2024
1 parent 54bba06 commit e0ed6c4
Show file tree
Hide file tree
Showing 16 changed files with 1,805 additions and 928 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": [ "playground" ]
}
5 changes: 5 additions & 0 deletions .changeset/rare-jeans-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-pages": patch
---

Add Changesets and Linting
40 changes: 40 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Release

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Setup PNPM
uses: pnpm/action-setup@v2

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "pnpm"

- name: Install Dependencies
run: pnpm install

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
version: pnpm exec changeset version --ignore playground
publish: pnpm exec changeset publish
commit: "[ci] release"
title: "[ci] release"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>
15 changes: 15 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.2/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"files": {
"ignore": ["dist", ".astro", ".vscode"]
}
}
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
"private": true,
"version": "0.0.1",
"description": "",
"scripts": {},
"scripts": {
"playground:dev": "pnpm --filter playground dev",
"changeset": "changeset",
"lint": "biome check .",
"lint:fix": "biome check --apply ."
},
"license": "MIT",
"devDependencies": {
"astro": "^4.3.3"
"astro": "^4.4.6",
"@biomejs/biome": "^1.5.3",
"@changesets/cli": "^2.27.1"
}
}
83 changes: 41 additions & 42 deletions package/index.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@

import type { AstroIntegration } from 'astro';
import type { IntegrationOption, Option, Prettify } from './types';
import addPageDir from './utils/add-page-dir';

export default function(...options: (string | Prettify<Option>)[]): AstroIntegration {
return {
name: 'astro-pages',
hooks: {
'astro:config:setup': ({ config, logger, injectRoute }) => {
for (let option of options) {

const defaults = {
config,
logger,
injectRoute
}
if (typeof option === 'string') {
option = {
dir: option
}
}

if (!option || !option?.dir || typeof option?.dir !== "string") {
logger.warn(`Skipping invalid option "${JSON.stringify(option, null, 4)}"`)
continue
}
Object.assign(defaults, option)

const { injectPages } = addPageDir(defaults as IntegrationOption)

injectPages()
}
}
}
}
import type { AstroIntegration } from "astro";
import type { IntegrationOption, Option, Prettify } from "./types";
import addPageDir from "./utils/add-page-dir";

export default function (
...options: (string | Prettify<Option>)[]
): AstroIntegration {
return {
name: "astro-pages",
hooks: {
"astro:config:setup": ({ config, logger, injectRoute }) => {
for (let option of options) {
const defaults = {
config,
logger,
injectRoute,
};

if (typeof option === "string") {
option = {
dir: option,
};
}

if (!option || !option?.dir || typeof option?.dir !== "string") {
logger.warn(
`Skipping invalid option "${JSON.stringify(option, null, 4)}"`,
);
continue;
}

Object.assign(defaults, option);

const { injectPages } = addPageDir(defaults as IntegrationOption);

injectPages();
}
},
},
};
}

export { addPageDir }

export { addPageDir };
39 changes: 19 additions & 20 deletions package/plugins/astro-integration-kit.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import type { Option } from "../types";
import { definePlugin } from "astro-integration-kit";
import type { Option } from "../types";
import addPageDir from "../utils/add-page-dir";

export default definePlugin({
name: "addPageDir",
hook: "astro:config:setup",
implementation:
({ config, logger, injectRoute }) => {
return (option: string | Option) => {
if (typeof option === "string") {
option = {
dir: option
}
}
return addPageDir({
...option,
config,
logger,
injectRoute
})
}
}
});
name: "addPageDir",
hook: "astro:config:setup",
implementation: ({ config, logger, injectRoute }) => {
return (option: string | Option) => {
if (typeof option === "string") {
option = {
dir: option,
};
}
return addPageDir({
...option,
config,
logger,
injectRoute,
});
};
},
});
32 changes: 16 additions & 16 deletions package/types.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import type { HookParameters } from "astro";

export type Prettify<T> = { [K in keyof T]: T[K]; } & {};
export type Prettify<T> = { [K in keyof T]: T[K] } & {};

export interface Option {
log?: "verbose" | "minimal" | boolean | null | undefined;
cwd?: string;
dir: string;
glob?: string | string[];
pattern?: (context: {
cwd: string;
dir: string;
entrypoint: string;
ext: string;
pattern: string;
}) => string;
log?: "verbose" | "minimal" | boolean | null | undefined;
cwd?: string;
dir: string;
glob?: string | string[];
pattern?: (context: {
cwd: string;
dir: string;
entrypoint: string;
ext: string;
pattern: string;
}) => string;
}

export interface IntegrationOption extends Option {
config: HookParameters<"astro:config:setup">["config"];
logger: HookParameters<"astro:config:setup">["logger"];
injectRoute: HookParameters<"astro:config:setup">["injectRoute"];
}
config: HookParameters<"astro:config:setup">["config"];
logger: HookParameters<"astro:config:setup">["logger"];
injectRoute: HookParameters<"astro:config:setup">["injectRoute"];
}
Loading

0 comments on commit e0ed6c4

Please sign in to comment.