Skip to content

Commit

Permalink
Add base bunx/npx script with checks (#3)
Browse files Browse the repository at this point in the history
* Add bunx/npx script start

* Add tsup as dev dependency

* Add Github Action workflow

* Change working directory

* Rename jobs

* Combine into single file

* Reseparate workflows

* Change workflow names

* Fix mistakes

* Change working directory, remove build

* Switch working directory for all commands

* Add prettier as dev dependency for CLI
  • Loading branch information
natesawant authored May 10, 2024
1 parent ecfd597 commit dcfa465
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 4 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/cli.node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: CLI Checks

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
cli:
name: Format & build the CLI tool
runs-on: ubuntu-latest

steps:
# ...
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1

# run any `bun` or `bunx` command
- run: bun install
working-directory: ./cli
- run: bun run format
working-directory: ./cli
- run: bun test
working-directory: ./cli
- run: bun run build
working-directory: ./cli
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI
name: Server Checks

on:
push:
Expand All @@ -10,8 +10,8 @@ on:
branches: ["main"]

jobs:
build:
name: build
server:
name: Format & build the main Next.js server
runs-on: ubuntu-latest

env:
Expand Down
5 changes: 4 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
bun install
bun run format
bun test
bun run build
cd ./cli
bun install
bun run format
bun test
Binary file modified bun.lockb
Binary file not shown.
175 changes: 175 additions & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache

# 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/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# 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

# 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.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
15 changes: 15 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# generate-routes-cli

To build the script, change directory to `routes/cli` run the following

```bash
bun run build
bun link
```

To run the executable script anywhere else, run the following:

```bash
bun link generate-routes-cli
bunx generate-routes-cli # or npx instead
```
Binary file added cli/bun.lockb
Binary file not shown.
19 changes: 19 additions & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "generate-routes-cli",
"type": "module",
"exports": "./dist/index.js",
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"format": "prettier --write ."
},
"bin": "./dist/index.js",
"devDependencies": {
"@types/bun": "latest",
"prettier": "^3.2.5",
"tsup": "^8.0.2"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}
3 changes: 3 additions & 0 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

console.log("Hello via Bun!");
22 changes: 22 additions & 0 deletions cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

/* Linting */
"skipLibCheck": true,
"strict": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true
}
}
13 changes: 13 additions & 0 deletions cli/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from "tsup";

const isDev = process.env.npm_lifecycle_event === "dev";

export default defineConfig({
clean: true,
entry: ["src/index.ts"],
format: ["esm"],
minify: !isDev,
target: "esnext",
outDir: "dist",
onSuccess: isDev ? "node dist/index.js" : undefined,
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"prettier-plugin-tailwindcss": "^0.5.11",
"prisma": "^5.10.2",
"tailwindcss": "^3.4.1",
"tsup": "^8.0.2",
"typescript": "^5.4.2"
},
"ct3aMetadata": {
Expand Down

0 comments on commit dcfa465

Please sign in to comment.