create-pylon
Version:
CLI for creating a Pylon
882 lines (719 loc) • 30.6 kB
JavaScript
#!/usr/bin/env node
import i from"chalk";import{Option as h,program as D}from"commander";import c from"consola";import*as y from"fs";import N from"path";import w from"fs/promises";import _ from"path";var u="^2.0.0",g="^1.0.0",b={ALL:[{path:".gitignore",content:`# Logs
logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# Runtime data
pids
_.pid
_.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# wrangler project
.dev.vars
.wrangler/
# Pylon project
.pylon
`},{path:".dockerignore",content:`node_modules
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
LICENSE
.vscode
Makefile
helm-charts
.env
.editorconfig
.idea
coverage*
`,specificRuntimes:["node","bun"]},{path:".github/workflows/publish.yml",content:`name: publish
on: [push]
env:
IMAGE_NAME: __PYLON_NAME__
jobs:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
publish-container:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Log into registry
run: echo "\${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u \${{ github.actor }} --password-stdin
- name: Push image
run: |
IMAGE_ID=ghcr.io/\${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "\${{ github.ref }}" | sed -e 's,.*/\\(.*\\),\\1,')
# Strip "v" prefix from tag name
[[ "\${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker \`latest\` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
# SPDX-License-Identifier: (EUPL-1.2)
# Copyright \xA9 2024 cronit KG`,specificRuntimes:["node","bun"]}],bun:[{path:"package.json",content:`{
"name": "__PYLON_NAME__",
"private": true,
"version": "0.0.1",
"type": "module",
"description": "Generated with \`npm create pylon\`",
"scripts": {
"dev": "pylon dev -c \\"bun run .pylon/index.js\\"",
"build": "pylon build"
},
"dependencies": {
"@getcronit/pylon": "${u}",
},
"devDependencies": {
"@getcronit/pylon-dev": "${g}",
"@types/bun": "^1.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/getcronit/pylon.git"
},
"homepage": "https://pylon.cronit.io",
"packageManager": "bun"
}
`},{path:"Dockerfile",content:`# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1 as base
LABEL description="Offical docker image for Pylon services (Bun)"
LABEL org.opencontainers.image.source="https://github.com/getcronit/pylon"
LABEL maintainer="office@cronit.io"
WORKDIR /usr/src/pylon
# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile
# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production
# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM install AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .
# [optional] tests & build
ENV NODE_ENV=production
# Create .pylon folder (mkdir)
RUN mkdir -p .pylon
# RUN bun test
RUN bun run pylon build
# copy production dependencies and source code into final image
FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/pylon/.pylon .pylon
COPY --from=prerelease /usr/src/pylon/package.json .
# run the app
USER bun
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "run", "/usr/src/pylon/.pylon/index.js" ]
`}],node:[{path:"package.json",content:`{
"name": "__PYLON_NAME__",
"private": true,
"version": "0.0.1",
"type": "module",
"description": "Generated with \`npm create pylon\`",
"scripts": {
"dev": "pylon dev -c \\"node --enable-source-maps .pylon/index.js\\"",
"build": "pylon build"
},
"dependencies": {
"@getcronit/pylon": "${u}",
"@hono/node-server": "^1.12.2"
},
"devDependencies": {
"@getcronit/pylon-dev": "${g}"
},
"repository": {
"type": "git",
"url": "https://github.com/getcronit/pylon.git"
},
"homepage": "https://pylon.cronit.io"
}
`},{path:"Dockerfile",content:`# Use the official Node.js 20 image as the base
FROM node:20-alpine as base
LABEL description="Offical docker image for Pylon services (Node.js)"
LABEL org.opencontainers.image.source="https://github.com/getcronit/pylon"
LABEL maintainer="office@cronit.io"
WORKDIR /usr/src/pylon
# install dependencies into a temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json package-lock.json /temp/dev/
RUN cd /temp/dev && npm ci
# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json package-lock.json /temp/prod/
RUN cd /temp/prod && npm ci --only=production
# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM install AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .
# [optional] tests & build
ENV NODE_ENV=production
# Create .pylon folder (mkdir)
RUN mkdir -p .pylon
# RUN npm test
RUN npm run pylon build
# copy production dependencies and source code into final image
FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/pylon/.pylon .pylon
COPY --from=prerelease /usr/src/pylon/package.json .
# run the app
USER node
EXPOSE 3000/tcp
ENTRYPOINT [ "node", "/usr/src/pylon/.pylon/index.js" ]
`}],"cf-workers":[{path:"package.json",content:`{
"name": "__PYLON_NAME__",
"type": "module",
"description": "Generated with \`npm create pylon\`",
"version": "0.0.1",
"private": true,
"scripts": {
"deploy": "pylon build && wrangler deploy",
"dev": "pylon dev -c \\"wrangler dev\\"",
"cf-typegen": "wrangler types"
},
"dependencies": {
"@getcronit/pylon": "${u}",
},
"devDependencies": {
"@getcronit/pylon-dev": "${g}",
"@cloudflare/vitest-pool-workers": "^0.4.5",
"@cloudflare/workers-types": "^4.20240903.0",
"typescript": "^5.5.2",
"wrangler": "^3.60.3"
},
"repository": {
"type": "git",
"url": "https://github.com/getcronit/pylon.git"
},
"homepage": "https://pylon.cronit.io"
}
`},{path:"wrangler.toml",content:`#:schema node_modules/wrangler/config-schema.json
name = "__PYLON_NAME__"
main = ".pylon/index.js"
compatibility_date = "2024-09-03"
compatibility_flags = ["nodejs_compat_v2"]
# Automatically place your workloads in an optimal location to minimize latency.
# If you are running back-end logic in a Worker, running it closer to your back-end infrastructure
# rather than the end user may result in better performance.
# Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
# [placement]
# mode = "smart"
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
# Docs:
# - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
# Note: Use secrets to store sensitive data.
# - https://developers.cloudflare.com/workers/configuration/secrets/
# [vars]
# MY_VARIABLE = "production_value"
# Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare\u2019s global network
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#workers-ai
# [ai]
# binding = "AI"
# Bind an Analytics Engine dataset. Use Analytics Engine to write analytics within your Pages Function.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#analytics-engine-datasets
# [[analytics_engine_datasets]]
# binding = "MY_DATASET"
# Bind a headless browser instance running on Cloudflare's global network.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#browser-rendering
# [browser]
# binding = "MY_BROWSER"
# Bind a D1 database. D1 is Cloudflare\u2019s native serverless SQL database.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
# [[d1_databases]]
# binding = "MY_DB"
# database_name = "my-database"
# database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# Bind a dispatch namespace. Use Workers for Platforms to deploy serverless functions programmatically on behalf of your customers.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#dispatch-namespace-bindings-workers-for-platforms
# [[dispatch_namespaces]]
# binding = "MY_DISPATCHER"
# namespace = "my-namespace"
# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
# [[durable_objects.bindings]]
# name = "MY_DURABLE_OBJECT"
# class_name = "MyDurableObject"
# Durable Object migrations.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
# [[migrations]]
# tag = "v1"
# new_classes = ["MyDurableObject"]
# Bind a Hyperdrive configuration. Use to accelerate access to your existing databases from Cloudflare Workers.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#hyperdrive
# [[hyperdrive]]
# binding = "MY_HYPERDRIVE"
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces
# [[kv_namespaces]]
# binding = "MY_KV_NAMESPACE"
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Bind an mTLS certificate. Use to present a client certificate when communicating with another service.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates
# [[mtls_certificates]]
# binding = "MY_CERTIFICATE"
# certificate_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
# [[queues.producers]]
# binding = "MY_QUEUE"
# queue = "my-queue"
# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
# [[queues.consumers]]
# queue = "my-queue"
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#r2-buckets
# [[r2_buckets]]
# binding = "MY_BUCKET"
# bucket_name = "my-bucket"
# Bind another Worker service. Use this binding to call another Worker without network overhead.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
# [[services]]
# binding = "MY_SERVICE"
# service = "my-service"
# Bind a Vectorize index. Use to store and query vector embeddings for semantic search, classification and other vector search use-cases.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#vectorize-indexes
# [[vectorize]]
# binding = "MY_INDEX"
# index_name = "my-index"
`}],deno:[{path:".vscode/settings.json",content:`{
"deno.enablePaths": [
"./"
],
"editor.inlayHints.enabled": "off"
}`},{path:".vscode/extensions.json",content:`{
"recommendations": [
"denoland.vscode-deno"
]
}`},{path:"deno.json",content:`{
"imports": {
"@getcronit/pylon-dev": "npm:@getcronit/pylon-dev@${g}",
"@getcronit/pylon": "npm:@getcronit/pylon@${u}"
},
"tasks": {
"dev": "pylon dev -c \\"deno run -A .pylon/index.js --config tsconfig.json\\"",
"build": "pylon build"
},
"compilerOptions": {
"jsx": "precompile",
"jsxImportSource": "hono/jsx"
},
"nodeModulesDir": "auto",
"packageManager": "deno"
}
`}]};var m=[{key:"bun",name:"Bun.js",website:"https://bunjs.dev",supportedFeatures:["auth","pages"]},{key:"node",name:"Node.js",website:"https://nodejs.org",supportedFeatures:["auth","pages"]},{key:"cf-workers",name:"Cloudflare Workers",website:"https://workers.cloudflare.com",supportedFeatures:["auth"]},{key:"deno",name:"Deno",website:"https://deno.land"}],v=[{key:"auth",name:"Authentication",website:"https://pylon.cronit.io/docs/authentication"},{key:"pages",name:"Pages",website:"https://pylon.cronit.io/docs/pages"}],A=(e,r)=>{let o=["app","PylonConfig"],t=[];r.includes("auth")&&(o.push("useAuth"),t.push("useAuth({issuer: 'https://test-0o6zvq.zitadel.cloud'})")),r.includes("pages")&&(o.push("usePages"),t.push("usePages()"));let n="";return n+=`import {${o.join(", ")}} from '@getcronit/pylon'
`,e==="node"&&(n+=`import {serve} from '@hono/node-server'
`),n+=`
`,n+=`export const graphql = {
Query: {
hello: () => {
return 'Hello, world!'
}
},
Mutation: {}
}`,n+=`
`,e==="bun"||e==="cf-workers"?n+="export default app":e==="node"?n+="serve(app, info => {\n console.log(`Server running at ${info.port}`)\n})":e==="deno"&&(n+=`Deno.serve({port: 3000}, app.fetch)
`),n+=`
`,n+=`export const config: PylonConfig = {
plugins: [${t.join(", ")}]
}`,n},M=async(e,r)=>{let o=`import '@getcronit/pylon'
declare module '@getcronit/pylon' {
interface Bindings {}
interface Variables {}
}
`;return r.includes("pages")&&(o+=`import {useQuery} from './.pylon/client'
declare module '@getcronit/pylon/pages' {
interface PageData extends ReturnType<typeof useQuery> {}
}`),o},I=async(e,r)=>{let o={extends:"@getcronit/pylon/tsconfig.pylon.json",include:["pylon.d.ts","src/**/*.ts"]};return e==="cf-workers"&&o.include.push("worker-configuration.d.ts"),r.includes("pages")&&(o.compilerOptions={baseUrl:".",paths:{"@/*":["./*"]},jsx:"react-jsx"},o.include.push("pages","components",".pylon")),JSON.stringify(o,null,2)},S=async e=>{let r=[{path:"pages/layout.tsx",content:`import '../globals.css'
export default function RootLayout({children}: {children: React.ReactNode}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
`},{path:"pages/page.tsx",content:`import { Button } from '@/components/ui/button'
import { PageProps } from '@getcronit/pylon/pages'
const Page: React.FC<PageProps> = props => {
return (
<div className="container">
<title>{props.data.hello}</title>
<Button>Hello {props.data.hello}</Button>
</div>
)
}
export default Page
`},{path:"globals.css",content:`@import 'tailwindcss';
@plugin 'tailwindcss-animate';
@custom-variant dark (&:is(.dark *));
@theme {
--color-background: hsl(var(--background));
--color-foreground: hsl(var(--foreground));
--color-card: hsl(var(--card));
--color-card-foreground: hsl(var(--card-foreground));
--color-popover: hsl(var(--popover));
--color-popover-foreground: hsl(var(--popover-foreground));
--color-primary: hsl(var(--primary));
--color-primary-foreground: hsl(var(--primary-foreground));
--color-secondary: hsl(var(--secondary));
--color-secondary-foreground: hsl(var(--secondary-foreground));
--color-muted: hsl(var(--muted));
--color-muted-foreground: hsl(var(--muted-foreground));
--color-accent: hsl(var(--accent));
--color-accent-foreground: hsl(var(--accent-foreground));
--color-destructive: hsl(var(--destructive));
--color-destructive-foreground: hsl(var(--destructive-foreground));
--color-border: hsl(var(--border));
--color-input: hsl(var(--input));
--color-ring: hsl(var(--ring));
--color-chart-1: hsl(var(--chart-1));
--color-chart-2: hsl(var(--chart-2));
--color-chart-3: hsl(var(--chart-3));
--color-chart-4: hsl(var(--chart-4));
--color-chart-5: hsl(var(--chart-5));
--color-sidebar: hsl(var(--sidebar-background));
--color-sidebar-foreground: hsl(var(--sidebar-foreground));
--color-sidebar-primary: hsl(var(--sidebar-primary));
--color-sidebar-primary-foreground: hsl(var(--sidebar-primary-foreground));
--color-sidebar-accent: hsl(var(--sidebar-accent));
--color-sidebar-accent-foreground: hsl(var(--sidebar-accent-foreground));
--color-sidebar-border: hsl(var(--sidebar-border));
--color-sidebar-ring: hsl(var(--sidebar-ring));
--radius-lg: var(--radius);
--radius-md: calc(var(--radius) - 2px);
--radius-sm: calc(var(--radius) - 4px);
--animate-accordion-down: accordion-down 0.2s ease-out;
--animate-accordion-up: accordion-up 0.2s ease-out;
@keyframes accordion-down {
from {
height: 0;
}
to {
height: var(--radix-accordion-content-height);
}
}
@keyframes accordion-up {
from {
height: var(--radix-accordion-content-height);
}
to {
height: 0;
}
}
}
/*
The default border color has changed to \`currentColor\` in Tailwind CSS v4,
so we've added these compatibility styles to make sure everything still
looks the same as it did with Tailwind CSS v3.
If we ever want to remove these styles, we need to add an explicit border
color utility to any element that depends on these defaults.
*/
@layer base {
*,
::after,
::before,
::backdrop,
::file-selector-button {
border-color: var(--color-gray-200, currentColor);
}
}
@layer utilities {
body {
font-family: Arial, Helvetica, sans-serif;
}
}
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 0 0% 3.9%;
--card: 0 0% 100%;
--card-foreground: 0 0% 3.9%;
--popover: 0 0% 100%;
--popover-foreground: 0 0% 3.9%;
--primary: 0 0% 9%;
--primary-foreground: 0 0% 98%;
--secondary: 0 0% 96.1%;
--secondary-foreground: 0 0% 9%;
--muted: 0 0% 96.1%;
--muted-foreground: 0 0% 45.1%;
--accent: 0 0% 96.1%;
--accent-foreground: 0 0% 9%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 0 0% 98%;
--border: 0 0% 89.8%;
--input: 0 0% 89.8%;
--ring: 0 0% 3.9%;
--chart-1: 12 76% 61%;
--chart-2: 173 58% 39%;
--chart-3: 197 37% 24%;
--chart-4: 43 74% 66%;
--chart-5: 27 87% 67%;
--radius: 0.5rem;
--sidebar-background: 0 0% 98%;
--sidebar-foreground: 240 5.3% 26.1%;
--sidebar-primary: 240 5.9% 10%;
--sidebar-primary-foreground: 0 0% 98%;
--sidebar-accent: 240 4.8% 95.9%;
--sidebar-accent-foreground: 240 5.9% 10%;
--sidebar-border: 220 13% 91%;
--sidebar-ring: 217.2 91.2% 59.8%;
}
.dark {
--background: 0 0% 3.9%;
--foreground: 0 0% 98%;
--card: 0 0% 3.9%;
--card-foreground: 0 0% 98%;
--popover: 0 0% 3.9%;
--popover-foreground: 0 0% 98%;
--primary: 0 0% 98%;
--primary-foreground: 0 0% 9%;
--secondary: 0 0% 14.9%;
--secondary-foreground: 0 0% 98%;
--muted: 0 0% 14.9%;
--muted-foreground: 0 0% 63.9%;
--accent: 0 0% 14.9%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 0 0% 98%;
--border: 0 0% 14.9%;
--input: 0 0% 14.9%;
--ring: 0 0% 83.1%;
--chart-1: 220 70% 50%;
--chart-2: 160 60% 45%;
--chart-3: 30 80% 55%;
--chart-4: 280 65% 60%;
--chart-5: 340 75% 55%;
--sidebar-background: 240 5.9% 10%;
--sidebar-foreground: 240 4.8% 95.9%;
--sidebar-primary: 224.3 76.3% 48%;
--sidebar-primary-foreground: 0 0% 100%;
--sidebar-accent: 240 3.7% 15.9%;
--sidebar-accent-foreground: 240 4.8% 95.9%;
--sidebar-border: 240 3.7% 15.9%;
--sidebar-ring: 217.2 91.2% 59.8%;
}
}
@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
}
/*
---break---
*/
@layer base {
* {
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
}
}
`},{path:"postcss.config.js",content:`import tailwindPostCss from '@tailwindcss/postcss'
export default {
plugins: [tailwindPostCss]
}
`},{path:"components.json",content:`{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "globals.css",
"baseColor": "zinc",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"iconLibrary": "lucide"
}`},{path:"lib/utils.ts",content:`import {clsx, type ClassValue} from 'clsx'
import {twMerge} from 'tailwind-merge'
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}`},{path:"components/ui/button.tsx",content:`import * as React from 'react'
import {Slot} from '@radix-ui/react-slot'
import {cva, type VariantProps} from 'class-variance-authority'
import {cn} from '@/lib/utils'
const buttonVariants = cva(
"inline-flexxx items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-[color,box-shadow] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 ring-ring/10 dark:ring-ring/20 dark:outline-ring/40 outline-ring/50 focus-visible:ring-4 focus-visible:outline-1 aria-invalid:focus-visible:ring-0",
{
variants: {
variant: {
default:
'bg-primary text-primary-foreground shadow-sm hover:bg-primary/90',
destructive:
'bg-destructive text-destructive-foreground shadow-xs hover:bg-destructive/90',
outline:
'border border-input bg-background shadow-xs hover:bg-accent hover:text-accent-foreground',
secondary:
'bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80',
ghost: 'hover:bg-accent hover:text-accent-foreground',
link: 'text-primary underline-offset-4 hover:underline'
},
size: {
default: 'h-9 px-4 py-2 has-[>svg]:px-3',
sm: 'h-8 rounded-md px-3 has-[>svg]:px-2.5',
lg: 'h-10 rounded-md px-6 has-[>svg]:px-4',
icon: 'size-9'
}
},
defaultVariants: {
variant: 'default',
size: 'default'
}
}
)
function Button({
className,
variant,
size,
asChild = false,
...props
}: React.ComponentProps<'button'> &
VariantProps<typeof buttonVariants> & {
asChild?: boolean
}) {
const Comp = asChild ? Slot : 'button'
return (
<Comp
data-slot="button"
className={cn(buttonVariants({variant, size, className}))}
{...props}
/>
)
}
export {Button, buttonVariants}
`}];e.push(...r);let o=e.find(t=>t.path==="package.json");if(o){let t=JSON.parse(o.content);t.dependencies={...t.dependencies,"@gqty/react":"^3.1.0",gqty:"^3.4.0","@radix-ui/react-slot":"^1.1.2","class-variance-authority":"^0.7.1",clsx:"^2.1.1","lucide-react":"^0.474.0",react:"^19.0.0","react-dom":"^19.0.0","tailwind-merge":"^3.0.1",tailwindcss:"^4.0.4","tailwindcss-animate":"^1.0.7"},t.devDependencies={...t.devDependencies,"@tailwindcss/postcss":"^4.0.6","@types/react":"^19.0.8"},o.content=JSON.stringify(t,null,2)}return e},$=(e,r)=>{let o=e;return Object.entries(r).forEach(([t,n])=>{o=o.replaceAll(t,n)}),o},j=async e=>{let{destination:r,runtime:o,features:t}=e,n=b.ALL.concat(b[o]||[]).filter(l=>l.specificRuntimes?l.specificRuntimes.includes(o):!0),k=A(o,t),d=await I(o,t),p=await M(o,t);n.push({path:"tsconfig.json",content:d},{path:"pylon.d.ts",content:p},{path:"src/index.ts",content:k}),t.includes("pages")&&(n=await S(n));for(let l of n){let a=_.join(r,l.path);await w.mkdir(_.dirname(a),{recursive:!0}),await w.writeFile(a,$(l.content,e.variables))}};import B from"node:process";import{detect as L}from"package-manager-detector/detect";import U from"consola";async function f(e=B.cwd()){return(await L({cwd:e,onUnknown(o){U.warn("Unknown packageManager:",o)}}))?.agent||null}function E(e){if(e===null)return null;let[r]=e.split("@");switch(r){case"bun":return"bun";case"npm":return"npm run";case"yarn":return"yarn";case"pnpm":return"pnpm run";case"deno":return"deno task";default:return null}}import{existsSync as Y}from"node:fs";import{resolve as V}from"node:path";import F from"node:process";import{x as T}from"tinyexec";async function P(e,r={}){let o=r.packageManager||await f(r.cwd)||"npm",[t]=o.split("@");Array.isArray(e)||(e=[e]);let n=(typeof r.additionalArgs=="function"?r.additionalArgs(t,o):r.additionalArgs)||[];return r.preferOffline&&(o==="yarn@berry"?n.unshift("--cached"):n.unshift("--prefer-offline")),t==="pnpm"&&Y(V(r.cwd??F.cwd(),"pnpm-workspace.yaml"))&&n.unshift("-w","--prod=false"),T(t,[t==="yarn"?"add":"install",r.dev?"-D":"",...n,...e].filter(Boolean),{nodeOptions:{stdio:r.silent?"ignore":"inherit",cwd:r.cwd},throwOnError:!0})}import{PostHog as G}from"posthog-node";import z from"conf";import{readFileSync as q}from"fs";import{randomUUID as O}from"crypto";var J={distinctId:{type:"string",default:O()}},W=new z({projectName:"pylon",schema:J}),R=W.get("distinctId"),xe=O(),x=new G("phc_KN4qCOcCdkXp6sHLIuMWGRfzZWuNht69oqv5Kw5rGxj",{host:"https://eu.i.posthog.com",disabled:process.env.PYLON_DISABLE_TELEMETRY==="true"}),H=()=>{let e;try{e=JSON.parse(q("./package.json","utf8"))}catch{e={}}let r=e.dependencies||{},o=e.devDependencies||{},t=e.peerDependencies||{};return{dependencies:r,devDependencies:o,peerDependencies:t}},ke=H();var C="1.1.5-canary-20260313082843.34aeeac66642f7cc26d40ebdc0f36eb226a68aca";D.name("create-pylon").version(C).arguments("[target]").addOption(new h("-i, --install","Install dependencies")).addOption(new h("-r, --runtime <runtime>","Runtime").choices(m.map(({key:e})=>e))).addOption(new h("--features [features...]","Features").choices(v.map(({key:e})=>e))).addOption(new h("-pm, --package-manager <packageManager>","Package manager")).action(Q);async function Q(e,r,o){c.log(`${o.name()} version ${o.version()}`);try{e||(e=await c.prompt("Where should the project be created?",{default:"./my-pylon",placeholder:"./my-pylon",cancel:"reject"}));let t="";if(e==="."?t=N.basename(process.cwd()):t=N.basename(e),!r.runtime){let a=await c.prompt("Select a runtime environment:",{type:"select",options:m.map(s=>({label:s.name,value:s.key,hint:s.website})),cancel:"reject"});r.runtime=a}let n=m.find(a=>a.key===r.runtime);if(!n)throw new Error(`Invalid runtime selected: ${r.runtime}`);if(!r.features){let a=await c.prompt("Configure features:",{type:"multiselect",options:v.filter(s=>n.supportedFeatures?.includes(s.key)).map(s=>({label:s.name,value:s.key,hint:s.website})),required:!1,cancel:"reject"});r.features=a}for(let a of r.features)if(!n.supportedFeatures?.includes(a))throw new Error(`Invalid feature selected: ${a}`);if(!await c.prompt(`Ready to create the project in ${i.blue(e)}?`,{type:"confirm",initial:!0,cancel:"reject"})){let a=new Error("Prompt cancelled.");throw a.name="ConsolaPromptCancelledError",a}if(y.existsSync(e)&&y.readdirSync(e).length>0&&!await c.prompt("Directory not empty. Continue?",{type:"confirm",cancel:"reject"})){let s=new Error("Prompt cancelled.");throw s.name="ConsolaPromptCancelledError",s}await j({variables:{__PYLON_NAME__:t},runtime:n.key,features:r.features,destination:e});let d=r.packageManager||await f(e)||"npm";r.install===void 0&&(r.install=await c.prompt(`Installed dependencies with ${d} now? You can also do this later.`,{type:"confirm",initial:!0,cancel:"reject"})),r.install&&await P([]),x.capture({distinctId:R,event:"create-pylon",properties:{runtime:n.key,features:r.features,packageManager:d,install:r.install}});let p=E(d),l=`
\u{1F389} ${i.green.bold("Pylon created successfully.")}
\u{1F4BB} ${i.cyan.bold("Continue Developing")}
${i.yellow("Change directories:")} cd ${i.blue(e)}
${i.yellow("Start dev server:")} ${p} dev
${n.key==="cf-workers"?`${i.yellow("Deploy:")} ${p} deploy`:""}
\u{1F4D6} ${i.cyan.bold("Explore Documentation")}
${i.underline.blue("https://pylon.cronit.io/docs")}
\u{1F4AC} ${i.cyan.bold("Join our Community")}
${i.underline.blue("https://discord.gg/cbJjkVrnHe")}
`;c.box(l)}catch(t){c.error(t)}finally{await x.shutdown()}}D.parse();
//# sourceMappingURL=index.js.map