Skip to content

Commit

Permalink
Add create command and some alias for command
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoRCD committed Sep 13, 2024
1 parent fa6c52b commit 3fa8855
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 26 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,3 @@ dist
.idea

.config/shelve*
shelve*
20 changes: 11 additions & 9 deletions apps/app/.env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
NUXT_PUBLIC_SITE_URL="http://localhost:3000"
NUXT_PRIVATE_AUTH_SECRET="your_auth_secret"
NUXT_PRIVATE_ENCRYPTION_KEY="your_secret_encryption_key"
NUXT_PRIVATE_RESEND_API_KEY="your_api_key"
NUXT_PRIVATE_REDIS_URL="redis://:your_password@localhost:6379"
NUXT_SESSION_PASSWORD="your_session_password"
NUXT_OAUTH_GITHUB_CLIENT_ID="your_github_client_id"
NUXT_OAUTH_GITHUB_CLIENT_SECRET="your_github_client_secret"
DATABASE_URL="your_database_url"
# Generated by Shelve CLI
NUXT_PUBLIC_SITE_URL=your_value
NUXT_PRIVATE_RESEND_API_KEY=your_value
NUXT_PRIVATE_AUTH_SECRET=your_value
NUXT_PRIVATE_ENCRYPTION_KEY=your_value
NUXT_PRIVATE_REDIS_URL=your_value
NUXT_OAUTH_GITHUB_CLIENT_ID=your_value
NUXT_OAUTH_GITHUB_CLIENT_SECRET=your_value
DATABASE_URL=your_value
NUXT_SESSION_PASSWORD=your_value
SHELVE_TOKEN=your_value
6 changes: 3 additions & 3 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default createShelveConfig({
})
```

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))
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/shelve-config-schema.json))

## Usage

Expand All @@ -46,11 +46,11 @@ USAGE shelve <command|shortcut> [options]

| Commands | Description | Shortcut |
|----------|------------------------------------------------------|-----------|
| create | Create a new Shelve project | c |
| init | Create a new Shelve project | i |
| create | Create a new Shelve project | c, init |
| 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 |
| config | Show the current configuration | cf |

Use shelve <command|shortcut> --help for more information about a command.
```
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { loadShelveConfig } from '../utils/config'
export function configCommand(program: Command): void {
program
.command('config')
.description('Manage Shelve config')
.alias('cf')
.description('Show the current configuration')
.action(async () => {
console.log(await loadShelveConfig())
})
Expand Down
32 changes: 32 additions & 0 deletions packages/cli/src/commands/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Command } from 'commander'
import { intro, isCancel, outro, text } from '@clack/prompts'
import { createProject } from '../utils/project'
import { onCancel } from '../utils'
import { createShelveConfig } from '../utils/config'

export function createCommand(program: Command): void {
program
.command('create')
.alias('c')
.alias('init')
.description('Create a new project')
.action(async () => {
intro('Create a new project')

const name = await text({
message: 'Enter the name of the project:',
placeholder: 'my-project',
validate(value) {
if (value.length === 0) return `Value is required!`
},
})

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

await createProject(name)

outro(`Project ${name} created successfully`)

await createShelveConfig(name)
})
}
1 change: 1 addition & 0 deletions packages/cli/src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { onCancel } from '../utils'
export function generateCommand(program: Command): void {
program
.command('generate')
.alias('g')
.description('Generate resources for a project')
.action(async () => {
intro('Generate resources for a project')
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { configCommand } from './config'
import { pullCommand } from './pull'
import { pushCommand } from './push'
import { generateCommand } from './generate'
import { createCommand } from './create'

export function registerCommands(program: Command): void {
configCommand(program)
createCommand(program)
pullCommand(program)
pushCommand(program)
generateCommand(program)
configCommand(program)
}
1 change: 1 addition & 0 deletions packages/cli/src/commands/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { onCancel } from '../utils'
export function pullCommand(program: Command): void {
program
.command('pull')
.alias('pl')
.description('Pull variables for specified environment to .env file')
.action(async () => {
const { project, pullMethod, envFileName } = await loadShelveConfig()
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { onCancel } from '../utils'
export function pushCommand(program: Command): void {
program
.command('push')
.alias('ps')
.description('Push variables for specified environment to Shelve')
.action(async () => {
const { project, pushMethod } = await loadShelveConfig()
Expand Down
28 changes: 17 additions & 11 deletions packages/cli/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ import { SHELVE_JSON_SCHEMA, ShelveConfig } from '@shelve/types'
import { getProjects } from './project'
import { onCancel } from './index'

async function createShelveConfig(): Promise<void> {
intro('No configuration file found, creating one')
export async function createShelveConfig(projectName?: string): Promise<string> {
intro(projectName ? `Create configuration for ${projectName}` : 'No configuration file found, create a new one')

const projects = await getProjects()
let project = projectName

const project = await select({
message: 'Select the project:',
options: projects.map(project => ({
value: project.name,
label: project.name
})),
}) as string
if (!projectName) {
const projects = await getProjects()

project = await select({
message: 'Select the project:',
options: projects.map(project => ({
value: project.name,
label: project.name
})),
}) as string
}

const configFile = JSON.stringify({
$schema: SHELVE_JSON_SCHEMA,
Expand All @@ -31,6 +35,8 @@ async function createShelveConfig(): Promise<void> {
if (isCancel(project)) onCancel('Operation cancelled.')

outro('Configuration file created successfully')

return project
}

export async function getConfig(): Promise<{
Expand Down Expand Up @@ -67,7 +73,7 @@ export async function loadShelveConfig(): Promise<ShelveConfig> {
const { config, configFile } = await getConfig()

if (configFile === 'shelve.config') {
await createShelveConfig()
config.project = await createShelveConfig()
}

if (!config.project) {
Expand Down
File renamed without changes.

0 comments on commit 3fa8855

Please sign in to comment.