Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

feat: cli orm #45

Merged
merged 20 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pergel",
"type": "module",
"version": "0.0.5",
"version": "0.0.12-beta.4",
"packageManager": "[email protected]",
"description": "Full Stack Nuxt Application. It contains the necessary toolkits for a software developer and a fast, clean, tested toolkit.",
"author": "Mehmet @productdevbook",
Expand Down Expand Up @@ -63,7 +63,8 @@
"test": "vitest",
"test:watch": "vitest --watch",
"test:coverage": "vitest --coverage",
"prepack": "tsup"
"prepack": "tsup",
"release": "pnpm build && pnpm bumpp --commit='version(cli): release %s' --no-tag && pnpm publish"
},
"dependencies": {
"@antfu/ni": "^0.21.12",
Expand Down
19 changes: 19 additions & 0 deletions packages/cli/playground/pergel/README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ main:
# Env variables are not supported in this version
graphql:
project2:
# Script Commands
scripts:
migrate: 'drizzle-kit generate:pg --config=pergel/main/project2/drizzle/drizzle.config.js'
push: 'drizzle-kit push:pg --config=pergel/main/project2/drizzle/drizzle.config.js'
# Please install the following dependencies:
packageJson:
dependencies: '@pergel/[email protected]'
devDependencies:
project1:
# Please install the following dependencies:
packageJson:
dependencies: '@pergel/[email protected]'
devDependencies:
drizzle:
project2:
# Script Commands
scripts:
migrate: drizzle-kit generate:pg --config=pergel/main/project2/drizzle/drizzle.config.js
push: drizzle-kit push:pg --config=pergel/main/project2/drizzle/drizzle.config.js
# Please install the following dependencies:
packageJson:
dependencies: '@pergel/[email protected]'
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { writeFileSync } from 'node:fs'
import { defineCommand } from 'citty'

const template = `
const template = `import { definePergel } from 'pergel/core'

export default definePergel({
srcDir: 'pergel',
src: 'pergel',
activeBranch: 'main',
})
`

Expand Down
105 changes: 105 additions & 0 deletions packages/cli/src/commands/orm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { defineCommand } from 'citty'
import { loadConfig } from 'c12'
import { consola } from 'consola'
import { parse } from 'yaml'
import { parseNa, run } from '@antfu/ni'
import type { PergelConfig, PergelYaml } from '../types'

export default defineCommand({
meta: {
name: 'Orm Command',
description: 'Orm Command',
version: '0.0.0',
},
args: {
driver: {
type: 'string',
description: 'Name of the orm',
alias: 'd',
},
branch: {
type: 'string',
description: 'Name of the branch',
alias: 'b',
},
project: {
type: 'string',
description: 'Name of the project',
alias: 'p',
},
script: {
type: 'string',
description: 'Name of the script',
alias: 's',
},
},
async run({ args }) {
try {
const file = await loadConfig<Required<PergelConfig>>({
cwd: process.cwd(),
configFile: 'pergel.config.ts',
defaultConfig: {
src: 'pergel',
activeBranch: 'main',
cli: {
database: {
driver: (args.driver as any) ?? 'drizzle',
branch: args.branch,
project: args.project,
selectedScript: args.script,
},
},
},
})

consola.info(file.config?.cli.database)

if (!file.config) {
consola.error('No config file found')
return
}

if (!file.config.cli || !file.config.cli.database) {
consola.error('Pergel config file is not configured')
return
}

const readmeString = readFileSync(resolve(file.config.src, 'README.yaml')).toString()
const json = parse(readmeString) as PergelYaml

const project = json[file.config.activeBranch ?? 'main'][file.config.cli.database.driver ?? 'drizzle'][file.config.cli.database.project]

const script = project?.scripts ?? {}

if (Object.keys(script).length === 0)
consola.error('No script found')

const selectedScript = script[file.config.cli.database.selectedScript ?? 'undefined']

if (!selectedScript)
consola.error('No script found')

// if (file.config.cli.database.driver === 'drizzle') {
// consola.info('Dont forget to install drizzle-kit and drizzle-orm')
// consola.info('pnpm -g i drizzle-kit drizzle-orm')
// }

try {
await run(async (agent, args, ctx) => {
const command = await parseNa(agent, args, ctx)
return command ? command.replace(/"/g, '') : undefined
}, [selectedScript], { programmatic: true }).then(() => {
consola.success('Script executed successfully')
})
}
catch (error) {
consola.error(error)
}
}
catch (error) {
consola.log(error)
}
},
})
14 changes: 1 addition & 13 deletions packages/cli/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
interface PergelConfig {
/**
* The name of the project.
* @default 'Pergel'
*/
src?: string

/**
* The branch to use for the active version of the project.
* @default 'main'
*/
activeBranch?: string
}
import type { PergelConfig } from './types'

export function definePergel(config: PergelConfig) {
return config
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const main = defineCommand({
upgrade: () => import('./commands/upgrade').then(m => m.default),
init: () => import('./commands/init').then(m => m.default),
install: () => import('./commands/install').then(m => m.default),
orm: () => import('./commands/orm').then(m => m.default),
},
run({ args }) {
console.warn('Pergel CLI')
Expand Down
41 changes: 41 additions & 0 deletions packages/cli/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export interface PergelConfig {
/**
* The name of the project.
* @default 'Pergel'
*/
src?: string

/**
* The branch to use for the active version of the project.
* @default 'main'
*/
activeBranch?: string

cli?: {
database?: {
driver: 'drizzle'
project: string
branch: string
selectedScript?: string
}
}
}

export interface PergelYaml {
[branchName: string]: {
[moduleName: string]: {
[projectName: string]: {
packageJson?: {
dependencies?: string
devDependencies?: string
}
scripts?: {
[scriptName: string]: string
}
env?: {
[envName: string]: string
}
}
}
}
}
8 changes: 8 additions & 0 deletions packages/nuxt/bumpp.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'bumpp'

export default defineConfig({
noVerify: true,
commit: 'version(nuxt): release %s',
push: false,
tag: false,
})