Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: canary

on:
pull_request:
types: [opened, synchronize]
Comment thread
rsbh marked this conversation as resolved.
Outdated

jobs:
canary-release:
name: Publish canary to npm
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: ./packages/chronicle
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install --frozen-lockfile
working-directory: .

- name: Build CLI
run: bun build-cli.ts

- name: Set canary version
run: |
SHORT_SHA=$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-7)
VERSION=$(jq -r .version package.json)-canary.${SHORT_SHA}
jq --arg v "$VERSION" '.version = $v' package.json > package.tmp.json
mv package.tmp.json package.json
echo "Published version: $VERSION"

- name: Publish
run: bun publish --tag canary --access public
Comment thread
rsbh marked this conversation as resolved.
Outdated
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
Empty file modified packages/chronicle/bin/chronicle.js
100644 → 100755
Empty file.
6 changes: 4 additions & 2 deletions packages/chronicle/src/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { Command } from 'commander'
import { spawn } from 'child_process'
import path from 'path'
import { fileURLToPath } from 'url'
import { createRequire } from 'module'
import chalk from 'chalk'
import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '@/cli/utils'

const require = createRequire(import.meta.url)
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..')
const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next')
const nextCli = require.resolve('next/dist/bin/next')

export const buildCommand = new Command('build')
.description('Build for production')
Expand All @@ -18,7 +20,7 @@ export const buildCommand = new Command('build')
console.log(chalk.cyan('Building for production...'))
console.log(chalk.gray(`Content: ${contentDir}`))

const child = spawn(nextBin, ['build'], {
const child = spawn(process.execPath, [nextCli, 'build'], {
stdio: 'inherit',
cwd: PACKAGE_ROOT,
env: {
Expand Down
6 changes: 4 additions & 2 deletions packages/chronicle/src/cli/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { Command } from 'commander'
import { spawn } from 'child_process'
import path from 'path'
import { fileURLToPath } from 'url'
import { createRequire } from 'module'
import chalk from 'chalk'
import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '@/cli/utils'

const require = createRequire(import.meta.url)
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..')
const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next')
const nextCli = require.resolve('next/dist/bin/next')

export const devCommand = new Command('dev')
.description('Start development server')
Expand All @@ -19,7 +21,7 @@ export const devCommand = new Command('dev')
console.log(chalk.cyan('Starting dev server...'))
console.log(chalk.gray(`Content: ${contentDir}`))

const child = spawn(nextBin, ['dev', '-p', options.port], {
const child = spawn(process.execPath, [nextCli, 'dev', '-p', options.port], {
stdio: 'inherit',
cwd: PACKAGE_ROOT,
env: {
Expand Down
8 changes: 5 additions & 3 deletions packages/chronicle/src/cli/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { Command } from 'commander'
import { spawn } from 'child_process'
import path from 'path'
import { fileURLToPath } from 'url'
import { createRequire } from 'module'
import chalk from 'chalk'
import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '@/cli/utils'

const require = createRequire(import.meta.url)
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..')
const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next')
const nextCli = require.resolve('next/dist/bin/next')

export const serveCommand = new Command('serve')
.description('Build and start production server')
Expand All @@ -24,7 +26,7 @@ export const serveCommand = new Command('serve')
console.log(chalk.cyan('Building for production...'))
console.log(chalk.gray(`Content: ${contentDir}`))

const buildChild = spawn(nextBin, ['build'], {
const buildChild = spawn(process.execPath, [nextCli, 'build'], {
stdio: 'inherit',
cwd: PACKAGE_ROOT,
env,
Expand All @@ -41,7 +43,7 @@ export const serveCommand = new Command('serve')

console.log(chalk.cyan('Starting production server...'))

const startChild = spawn(nextBin, ['start', '-p', options.port], {
const startChild = spawn(process.execPath, [nextCli, 'start', '-p', options.port], {
stdio: 'inherit',
cwd: PACKAGE_ROOT,
env,
Expand Down
6 changes: 4 additions & 2 deletions packages/chronicle/src/cli/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { Command } from 'commander'
import { spawn } from 'child_process'
import path from 'path'
import { fileURLToPath } from 'url'
import { createRequire } from 'module'
import chalk from 'chalk'
import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '@/cli/utils'

const require = createRequire(import.meta.url)
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..')
const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next')
const nextCli = require.resolve('next/dist/bin/next')

export const startCommand = new Command('start')
.description('Start production server')
Expand All @@ -19,7 +21,7 @@ export const startCommand = new Command('start')
console.log(chalk.cyan('Starting production server...'))
console.log(chalk.gray(`Content: ${contentDir}`))

const child = spawn(nextBin, ['start', '-p', options.port], {
const child = spawn(process.execPath, [nextCli, 'start', '-p', options.port], {
stdio: 'inherit',
cwd: PACKAGE_ROOT,
env: {
Expand Down
14 changes: 11 additions & 3 deletions packages/chronicle/src/cli/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ export function resolveContentDir(contentFlag?: string): string {
return process.cwd()
}

function resolveConfigPath(contentDir: string): string | null {
const cwdPath = path.join(process.cwd(), 'chronicle.yaml')
if (fs.existsSync(cwdPath)) return cwdPath
const contentPath = path.join(contentDir, 'chronicle.yaml')
if (fs.existsSync(contentPath)) return contentPath
return null
}

export function loadCLIConfig(contentDir: string): CLIConfig {
const configPath = path.join(contentDir, 'chronicle.yaml')
const configPath = resolveConfigPath(contentDir)

if (!fs.existsSync(configPath)) {
console.log(chalk.red('Error: chronicle.yaml not found in'), contentDir)
if (!configPath) {
console.log(chalk.red('Error: chronicle.yaml not found in'), process.cwd(), 'or', contentDir)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
console.log(chalk.gray(`Run 'chronicle init' to create one`))
process.exit(1)
}
Expand Down
16 changes: 13 additions & 3 deletions packages/chronicle/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@ const defaultConfig: ChronicleConfig = {
search: { enabled: true, placeholder: 'Search...' },
}

function resolveConfigPath(): string | null {
const cwdPath = path.join(process.cwd(), CONFIG_FILE)
if (fs.existsSync(cwdPath)) return cwdPath
const contentDir = process.env.CHRONICLE_CONTENT_DIR
if (contentDir) {
const contentPath = path.join(contentDir, CONFIG_FILE)
if (fs.existsSync(contentPath)) return contentPath
}
return null
}

export function loadConfig(): ChronicleConfig {
const dir = process.env.CHRONICLE_CONTENT_DIR ?? process.cwd()
const configPath = path.join(dir, CONFIG_FILE)
const configPath = resolveConfigPath()

if (!fs.existsSync(configPath)) {
if (!configPath) {
return defaultConfig
}

Expand Down
Loading