Skip to content

Commit

Permalink
breaking: Full CLI rewrite (#195)
Browse files Browse the repository at this point in the history
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
HugoRCD and autofix-ci[bot] authored Sep 13, 2024
1 parent 8a8f631 commit 99fafbc
Show file tree
Hide file tree
Showing 43 changed files with 597 additions and 689 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ dist

# Turbo
.turbo

# Intellij
.idea

.config/shelve*
shelve*
File renamed without changes.
15 changes: 9 additions & 6 deletions apps/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM oven/bun:latest as builder
FROM oven/bun:latest AS builder

# Définir le répertoire de travail à la racine du monorepo
WORKDIR /monorepo
WORKDIR /shelve

# Copier les fichiers nécessaires du monorepo
COPY package.json .
Expand All @@ -13,15 +13,18 @@ COPY packages ./packages
RUN bun install

# Construire l'application
WORKDIR /monorepo/apps/app
WORKDIR /shelve/apps/app
RUN bun run build

FROM oven/bun:latest as production
FROM oven/bun:latest AS production
WORKDIR /app

# Copier les fichiers nécessaires depuis le builder
COPY --from=builder /monorepo/apps/app /app
COPY --from=builder /monorepo/node_modules /app/node_modules
COPY --from=builder /shelve/apps/app/.output ./.output
COPY --from=builder /shelve/apps/app/package.json .
COPY --from=builder /shelve/apps/app/node_modules ./node_modules

RUN bun install

EXPOSE 3000

Expand Down
8 changes: 2 additions & 6 deletions apps/app/app/components/layout/SectionWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ defineProps({
</script>

<template>
<div class="main-container flex flex-1 flex-col overflow-hidden border border-neutral-200 dark:border-neutral-800">
<div class="flex justify-between gap-1 border-b border-inherit px-5 py-2">
<div class="main-container flex flex-1 flex-col overflow-hidden border-l border-l-neutral-200 dark:border-l-neutral-800">
<div class="flex justify-between gap-1 border-b border-neutral-200 px-5 py-2 dark:border-b-neutral-800">
<div class="flex items-center gap-2">
<Transition name="slide-to-bottom" mode="out-in">
<UIcon :key="navigation.icon" :name="navigation.icon" class="size-5" />
Expand All @@ -35,7 +35,3 @@ defineProps({
</div>
</div>
</template>

<style scoped>
</style>
6 changes: 5 additions & 1 deletion apps/app/server/api/project/name/[name].get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import { H3Event } from 'h3'
export default eventHandler(async (event: H3Event) => {
const paramName = getRouterParam(event, 'name')
if (!paramName) throw createError({ statusCode: 400, statusMessage: 'Missing params' })
return await prisma.project.findFirst({
const project = await prisma.project.findFirst({
where: {
name: {
equals: decodeURIComponent(paramName),
mode: 'insensitive',
},
},
})

if (!project) throw createError({ statusCode: 400, statusMessage: 'Project not found' })

return project
})
37 changes: 34 additions & 3 deletions apps/app/server/app/variableService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { unseal, seal } from '@shelve/crypto'
const varAssociation = {
production: 'production',
preview: 'preview',
staging: 'preview',
development: 'development',
prod: 'production',
dev: 'development',
Expand Down Expand Up @@ -46,10 +47,40 @@ export async function upsertVariable(variablesCreateInput: VariablesCreateInput)
create: variableCreateInput,
})
} // use on edit form variable/update or with CLI push command
return prisma.variables.createMany({
data: encryptedVariables,
skipDuplicates: true,
const method = variablesCreateInput.method || 'merge'
if (method === 'overwrite') {
await prisma.variables.deleteMany({ where: {
projectId: variablesCreateInput.projectId,
environment: varAssociation[variablesCreateInput.environment]
} })
return prisma.variables.createMany({
data: encryptedVariables,
skipDuplicates: true,
})
}
const existingVariables = await prisma.variables.findMany({
where: {
projectId: variablesCreateInput.projectId,
key: {
in: encryptedVariables.map(variable => variable.key)
}
},
select: {
id: true,
}
})
for (const variable of encryptedVariables) {
if (existingVariables.some(existingVariable => existingVariable.id === variable.id)) {
await prisma.variables.update({
where: { id: variable.id },
data: variable,
})
}
await prisma.variables.create({
data: variable,
})
}
return encryptedVariables
}

export async function getVariablesByProjectId(projectId: number, environment?: Environment): Promise<Variable[]> {
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 4 additions & 0 deletions packages/cli/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by Shelve CLI
SHELVE_TOKEN=your_value
TEST=your_value
SHELVE_URL=your_value
5 changes: 4 additions & 1 deletion packages/cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,7 @@ dist
dist

# Shelve config
.shelve
.shelve

.config/*
*shelve.config*
19 changes: 19 additions & 0 deletions packages/cli/.release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://unpkg.com/release-it@17/schema/release-it.json",
"git": {
"commitMessage": "chore(release): v${version}",
"tagName": "v${version}",
"commit": true,
"tag": true,
"push": true
},
"github": {
"release": true,
"releaseName": "v${version}",
"autoGenerate": true,
"web": true
},
"npm": {
"publish": true
}
}
29 changes: 23 additions & 6 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ Install the package globally:
npm install -g @shelve/cli
```

## Configuration

Configuration is loaded by [unjs/c12](https://github.com/unjs/c12) from cwd. You can use either `shelve.config.json`, `shelve.config.{ts,js,mjs,cjs}` or use the `shelve` field in `package.json`.
You have the option to create a `shelve.config.ts` file to enable type checking and autocompletion. The file should contain the following content:

```ts title="shelve.config.ts"
import { createShelveConfig } from "@shelve/cli"

export default createShelveConfig({
project: "my-project", // only required field
token: "my-token",
url: "https://shelve.hrcd.fr",
confirmChanges: false,
pushMethod: 'overwrite',
pullMethod: 'overwrite',
envFileName: '.env',
})
```

The CLI also has a json schema for the configuration file. that can be used to validate the configuration file. (see it [here](https://raw.githubusercontent.com/HugoRCD/shelve/main/packages/types/shelveConfigSchema.json))

## Usage

```bash
Expand All @@ -26,14 +47,10 @@ USAGE shelve <command|shortcut> [options]
| Commands | Description | Shortcut |
|----------|------------------------------------------------------|-----------|
| create | Create a new Shelve project | c |
| init | alias for create | i |
| link | Link the current directory with a Shelve project | l |
| unlink | Unlink the current directory from a Shelve project | ul |
| login | Authenticate with Shelve | li |
| logout | Logout the current authenticated user | lo |
| whoami | Shows the username of the currently logged-in user | w |
| init | Create a new Shelve project | i |
| pull | Retrieve the environment variables from Shelve | pl |
| push | Send the environment variables to Shelve | ps |
| generate | Generate a .env.example file, and more | g |

Use shelve <command|shortcut> --help for more information about a command.
```
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ export default createConfig({
enable: false,
},
tailwind: {
enable: true,
enable: false,
},
typescript: {
strict: true,
},
features: {
jsdoc: {
enable: true,
strict: true,
}
}
})
43 changes: 23 additions & 20 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
{
"name": "@shelve/cli",
"version": "1.1.1",
"version": "2.0.0",
"description": "The command-line interface for Shelve",
"author": "HugoRCD",
"type": "module",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/HugoRCD/shelve.git",
"directory": "packages/cli"
},
"funding": "https://github.com/sponsors/HugoRCD",
"bugs": {
"url": "https://github.com/HugoRCD/shelve/issues"
},
"homepage": "https://shelve.hrcd.fr",
"scripts": {
"build": "unbuild",
"start": "node ./dist/index.mjs",
"dev": "bun src/index.ts",
"dev:prod": "NODE_ENV=production bun src/index.ts",
"typecheck": "tsc --noEmit",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"release": "bun run test && changelogen --release && npm publish",
"test": "bun run build && bun run typecheck && bun run lint"
"release": "bun run test && release-it",
"release:edge": "release-it --preRelease=edge --npm.tag=edge",
"test": "bun run build && bun run typecheck && bun run lint && vitest run"
},
"bin": {
"shelve": "dist/index.mjs",
Expand All @@ -37,18 +28,30 @@
],
"types": "./dist/index.d.ts",
"dependencies": {
"citty": "^0.1.6",
"colorette": "^2.0.20",
"@clack/prompts": "^0.7.0",
"c12": "^1.11.2",
"commander": "^12.1.0",
"consola": "^3.2.3",
"giget": "^1.2.3",
"ofetch": "^1.3.4",
"rc9": "^2.1.2",
"semver": "^7.6.3",
"unbuild": "^2.0.0"
},
"devDependencies": {
"@shelve/types": "workspace:*",
"@types/bun": "^1.1.9",
"@types/semver": "^7.5.8",
"changelogen": "^0.5.5"
}
"release-it": "^17.6.0",
"vitest": "^2.1.0"
},
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/HugoRCD/shelve.git",
"directory": "packages/cli"
},
"funding": "https://github.com/sponsors/HugoRCD",
"bugs": {
"url": "https://github.com/HugoRCD/shelve/issues"
},
"homepage": "https://shelve.hrcd.fr"
}
11 changes: 11 additions & 0 deletions packages/cli/src/commands/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Command } from 'commander'
import { loadShelveConfig } from '../utils/config'

export function configCommand(program: Command): void {
program
.command('config')
.description('Manage Shelve config')
.action(async () => {
console.log(await loadShelveConfig())
})
}
28 changes: 0 additions & 28 deletions packages/cli/src/commands/create.ts

This file was deleted.

33 changes: 33 additions & 0 deletions packages/cli/src/commands/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { intro, isCancel, outro, select } from '@clack/prompts'
import { Command } from 'commander'
import { generateEnvExampleFile } from '../utils/env'
import { onCancel } from '../utils'

export function generateCommand(program: Command): void {
program
.command('generate')
.description('Generate resources for a project')
.action(async () => {
intro('Generate resources for a project')

const toGenerate = await select({
message: 'Select the resources to generate:',
options: [
{ value: 'example', label: '.env.example' },
{ value: 'eslint', label: 'ESLint config', hint: 'work in progress' },
]
})

if (isCancel(toGenerate)) onCancel('Operation cancelled.')

switch (toGenerate) {
case 'example':
await generateEnvExampleFile()
break
default:
onCancel('Invalid option')
}

outro('Done')
})
}
12 changes: 12 additions & 0 deletions packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Command } from 'commander'
import { configCommand } from './config'
import { pullCommand } from './pull'
import { pushCommand } from './push'
import { generateCommand } from './generate'

export function registerCommands(program: Command): void {
configCommand(program)
pullCommand(program)
pushCommand(program)
generateCommand(program)
}
Loading

0 comments on commit 99fafbc

Please sign in to comment.