Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
upgrade AIK (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adammatthiesen authored Apr 1, 2024
1 parent b86ff79 commit 87777a6
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 167 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-parents-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@matthiesenxyz/astro-hashnode": patch
---

[internal] Upgrade AIK from 0.7.0 to 0.8.0
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"ci:publish": "pnpm changeset publish"
},
"devDependencies": {
"@biomejs/biome": "1.6.2",
"@changesets/cli": "^2.27.1"
"@biomejs/biome": "1.6.3",
"@changesets/cli": "2.27.1"
}
}
13 changes: 8 additions & 5 deletions package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
"src"
],
"exports": {
".": "./src/index.ts",
".": {
"types": "./src/index.d.ts",
"import": "./src/index.ts"
},
"./api": "./src/hn-gql/index.ts",
"./components/*": "./src/components/*"
},
Expand All @@ -41,18 +44,18 @@
"astro": ">=4.4.1"
},
"devDependencies": {
"vite": "^5.2.6"
"vite": "^5.2.7"
},
"dependencies": {
"@tailwindcss/vite": "4.0.0-alpha.10",
"@tailwindcss/vite": "4.0.0-alpha.11",
"astro-font": "^0.0.78",
"astro-integration-kit": "~0.7.1",
"astro-integration-kit": "^0.8.0",
"astro-remote": "^0.3.2",
"astro-seo": "^0.8.3",
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"picocolors": "^1.0.0",
"tailwindcss": "4.0.0-alpha.10",
"tailwindcss": "4.0.0-alpha.11",
"ultrahtml": "^1.5.3"
}
}
56 changes: 28 additions & 28 deletions package/src/astro-hashnode.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
import { createResolver, defineIntegration } from "astro-integration-kit";
import { addDtsPlugin, corePlugins } from "astro-integration-kit/plugins";
import { addDts, addVirtualImports, addVitePlugin, createResolver, defineIntegration } from "astro-integration-kit";
import tailwindcss from "@tailwindcss/vite";
import { optionsSchema } from "./schemas/user-config";
import c from "picocolors";
import { AstroError } from "astro/errors";
import { readFileSync } from "node:fs";
import { squooshImageService } from "astro/config";
import { fileFactory } from "./utils/filefactory";

/**
* Astro-Hashnode Integration
*/
export default defineIntegration({
name: "@matthiesenxyz/astro-hashnode",
name: "astro-hashnode",
optionsSchema,
plugins: [ ...corePlugins, addDtsPlugin ],
setup({ options }) {
setup({ name, options }) {
type outputType = "static" | "hybrid" | "server";

return {
"astro:config:setup": ({
watchIntegration,
addVitePlugin,
addVirtualImports,
addDts,
injectScript,
injectRoute,
updateConfig,
config,
logger,
}) => {
"astro:config:setup": ( params ) => {

const { config, logger, injectScript, updateConfig, injectRoute } = params;

logger.info("Initializing...")
// Create Resolvers
const { resolve } = createResolver(import.meta.url);
const { resolve: rootResolve} = createResolver(config.root.pathname)

// Watch Integration for changes in DEV
watchIntegration(resolve())

const HashLogger = logger.fork(c.bold(c.blue("Astro-Hashnode")));
const hashLogNoVerbose = (message:string) => {
Expand Down Expand Up @@ -78,22 +67,33 @@ export default defineIntegration({
layoutComponentPath = resolve('./layouts/Layout.astro')
}

addVirtualImports({
addVirtualImports(params, {name, imports: {
'virtual:astro-hashnode/config': `export default ${JSON.stringify(options) }`,
'virtual:astro-hashnode/components': `export { default as Layout } from "${layoutComponentPath}";`,
})
}})

addDts({
name: 'astro-hashnode',
content: readFileSync(resolve("./definitions/astro-hashnode.d.ts"), "utf-8"),
const hashnodeDTS = fileFactory()

hashnodeDTS.addLines(`
declare module 'virtual:astro-hashnode/config' {
const Config: import("${resolve("./schemas/user-config")}").Options;
export default Config;
}
declare module 'virtual:astro-hashnode/components' {
export const Layout: typeof import("${layoutComponentPath}").default
}
`)

addDts(params, {
name,
content: hashnodeDTS.text(),
})

// Add & Setup Tailwind CSS
hashLog("Setting up 'Tailwind CSS v4' Integration")
const twplugin = tailwindcss();
for (const twp of twplugin) {
addVitePlugin(twp);
}
addVitePlugin(params, { plugin: tailwindcss() });

// Inject CSS
injectScript(
"page-ssr",
`import "${resolve("./styles/tailwind.css")}";`
Expand Down
8 changes: 0 additions & 8 deletions package/src/definitions/astro-hashnode.d.ts

This file was deleted.

11 changes: 11 additions & 0 deletions package/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Options } from "./schemas/user-config";
import type { AstroIntegration } from "astro";

/**
* Astro-Hashnode Integration - A Hashnode Integration for Astro
*
* By: MatthiesenXYZ
*
* @see https://github.com/matthiesenxyz/astro-hashnode
*/
export default function astroHashnode(opts: Options): AstroIntegration
2 changes: 1 addition & 1 deletion package/src/styles/tailwind.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@import "tailwindcss";
@import 'tailwindcss';
13 changes: 13 additions & 0 deletions package/src/utils/filefactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const fileFactory = () => {
// biome-ignore lint/style/noUnusedTemplateLiteral: <explanation>
let file = ``

return {
addLines(lines: string) {
file += lines
},
text() {
return file
}
}
}
4 changes: 2 additions & 2 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"dependencies": {
"@astrojs/node": "8.2.5",
"@matthiesenxyz/astro-hashnode": "workspace:*",
"astro": "^4.5.9"
"astro": "^4.5.12"
},
"devDependencies": {
"@astrojs/check": "^0.5.10",
"@types/node": "^20.11.30",
"@types/node": "^20.12.2",
"typescript": "^5.4.3"
}
}
Loading

0 comments on commit 87777a6

Please sign in to comment.