-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(create-pylon): add support for Deno runtime (#42)
* feat(create-pylon): add support for Deno runtime - Added support for detecting Deno as a package manager - Created a new file, detect-pm.ts, to handle package manager detection logic - Updated index.ts to include Deno as a runtime option - Added Deno-specific files and configurations to the default Deno template closes #41 * docs: add deno as supported runtime
- Loading branch information
Showing
11 changed files
with
251 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import * as fs from 'node:fs' | ||
import * as path from 'node:path' | ||
import process from 'node:process' | ||
import {execSync} from 'node:child_process' | ||
import consola from 'consola' | ||
|
||
// Helper function to check if a command exists | ||
function isCommandAvailable(command: string): boolean { | ||
try { | ||
execSync(`${command} --version`, {stdio: 'ignore'}) | ||
return true | ||
} catch (e) { | ||
console.error(e) | ||
return false | ||
} | ||
} | ||
|
||
// Detect Bun | ||
function isBun(): boolean { | ||
// @ts-ignore: Bun may not be defined | ||
return typeof Bun !== 'undefined' && isCommandAvailable('bun') | ||
} | ||
|
||
// Detect npm | ||
function isNpm(): boolean { | ||
return process.env.npm_execpath?.includes('npm') ?? false | ||
} | ||
|
||
// Detect Yarn | ||
function isYarn(): boolean { | ||
return process.env.npm_execpath?.includes('yarn') ?? false | ||
} | ||
|
||
// Detect Deno | ||
function isDeno(): boolean { | ||
// @ts-ignore: Deno may not be defined | ||
return typeof Deno !== 'undefined' && isCommandAvailable('deno') | ||
} | ||
|
||
// Detect pnpm | ||
function isPnpm(): boolean { | ||
return process.env.npm_execpath?.includes('pnpm') ?? false | ||
} | ||
|
||
// Detect based on lock files | ||
function detectByLockFiles(cwd: string): PackageManager | null { | ||
if (fs.existsSync(path.join(cwd, 'bun.lockb'))) { | ||
return 'bun' | ||
} | ||
if (fs.existsSync(path.join(cwd, 'package-lock.json'))) { | ||
return 'npm' | ||
} | ||
if (fs.existsSync(path.join(cwd, 'yarn.lock'))) { | ||
return 'yarn' | ||
} | ||
if ( | ||
fs.existsSync(path.join(cwd, 'deno.json')) || | ||
fs.existsSync(path.join(cwd, 'deno.lock')) | ||
) { | ||
return 'deno' | ||
} | ||
if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'))) { | ||
return 'pnpm' | ||
} | ||
return null | ||
} | ||
|
||
export type PackageManager = | ||
| 'bun' | ||
| 'npm' | ||
| 'yarn' | ||
| 'pnpm' | ||
| 'deno' | ||
| 'unknown' | ||
|
||
// Main detection function | ||
export function detectPackageManager({ | ||
preferredPm, | ||
cwd = process.cwd() | ||
}: { | ||
preferredPm?: PackageManager | ||
cwd?: string | ||
}): PackageManager { | ||
// Check the preferred package manager first | ||
if (preferredPm && isCommandAvailable(preferredPm)) { | ||
return preferredPm | ||
} | ||
|
||
// Proceed with detection logic | ||
if (isBun()) { | ||
return 'bun' | ||
} | ||
if (isNpm()) { | ||
return 'npm' | ||
} | ||
if (isPnpm()) { | ||
return 'pnpm' | ||
} | ||
if (isDeno()) { | ||
return 'deno' | ||
} | ||
if (isYarn()) { | ||
return 'yarn' | ||
} | ||
|
||
// Fallback to lock file detection | ||
const lockFileDetection = detectByLockFiles(cwd) | ||
if (lockFileDetection) { | ||
consola.info(`Detected package manager by lock file: ${lockFileDetection}`) | ||
if (isCommandAvailable(lockFileDetection)) { | ||
return lockFileDetection | ||
} else { | ||
consola.warn( | ||
`Lock file detected, but ${lockFileDetection} is not installed.` | ||
) | ||
} | ||
} | ||
|
||
return 'unknown' | ||
} | ||
|
||
type PackageManagerScript = | ||
| 'bun' | ||
| 'npm run' | ||
| 'yarn' | ||
| 'pnpm run' | ||
| 'deno task' | ||
|
||
// Run script detection | ||
export function getRunScript(pm: PackageManager): PackageManagerScript { | ||
switch (pm) { | ||
case 'bun': | ||
return 'bun' | ||
case 'npm': | ||
return 'npm run' | ||
case 'yarn': | ||
return 'yarn' | ||
case 'pnpm': | ||
return 'pnpm run' | ||
case 'deno': | ||
return 'deno task' | ||
default: | ||
throw new Error('Unknown package manager') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/create-pylon/templates/deno/default/.vscode/extensions.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"recommendations": [ | ||
"denoland.vscode-deno" | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/create-pylon/templates/deno/default/.vscode/settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"deno.enablePaths": [ | ||
"./" | ||
], | ||
"editor.inlayHints.enabled": "off" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM denoland/deno | ||
|
||
EXPOSE 3000 | ||
|
||
WORKDIR /app | ||
|
||
ADD . /app | ||
|
||
RUN deno install | ||
RUN deno task build | ||
|
||
CMD ["run", "-A", ".pylon/index.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"imports": { | ||
"@getcronit/pylon-dev": "npm:@getcronit/pylon-dev@^1.0.1", | ||
"@getcronit/pylon": "npm:@getcronit/pylon@^2.2.1" | ||
}, | ||
"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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {app} from '@getcronit/pylon' | ||
|
||
export const graphql = { | ||
Query: { | ||
hello: () => { | ||
return 'Hello, world!' | ||
} | ||
}, | ||
Mutation: {} | ||
} | ||
|
||
Deno.serve( | ||
{ | ||
port: 3000 | ||
}, | ||
app.fetch | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
de29921
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for pylon-docs ready!
✅ Preview
https://pylon-docs-h6jd6u8xn-schettns-projects.vercel.app
Built with commit de29921.
This pull request is being automatically deployed with vercel-action