Skip to content

Commit

Permalink
feat: Add templates generation (#207)
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 c361883 commit d6415ed
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 30 deletions.
63 changes: 42 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,45 @@ 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/shelve-config-schema.json))

## Usage

```bash
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 |
| pull | Retrieve the environment variables from Shelve | pl |
| push | Send the environment variables to Shelve | ps |

Use shelve <command|shortcut> --help for more information about a command.
Usage: shelve [options] [command]

The command-line interface for Shelve

Options:
-V, --version output the version number
-h, --help display help for command

Commands:
create|c [options] Create a new project
pull|pl [options] Pull variables for specified environment to .env file
push|ps [options] Push variables for specified environment to Shelve
generate|g Generate resources for a project
config|cf Show the current configuration
help [command] display help for command
```

<!-- automd:fetch url="gh:hugorcd/markdown/main/src/local_development.md" -->
Expand Down Expand Up @@ -71,13 +92,13 @@ To start contributing, you can follow these steps:

<!-- /automd -->

<!-- automd:contributors license=Apache author=HugoRCD github="hugorcd/shelve" -->
<!-- automd:contributors license=Apache author=HugoRCD github=HugoRCD/shelve -->

Published under the [APACHE](https://github.com/hugorcd/shelve/blob/main/LICENSE) license.
Made by [@HugoRCD](https://github.com/HugoRCD) and [community](https://github.com/hugorcd/shelve/graphs/contributors) 💛
Published under the [APACHE](https://github.com/HugoRCD/shelve/blob/main/LICENSE) license.
Made by [@HugoRCD](https://github.com/HugoRCD) and [community](https://github.com/HugoRCD/shelve/graphs/contributors) 💛
<br><br>
<a href="https://github.com/hugorcd/shelve/graphs/contributors">
<img src="https://contrib.rocks/image?repo=hugorcd/shelve" />
<a href="https://github.com/HugoRCD/shelve/graphs/contributors">
<img src="https://contrib.rocks/image?repo=HugoRCD/shelve" />
</a>

<!-- /automd -->
Expand All @@ -86,6 +107,6 @@ Made by [@HugoRCD](https://github.com/HugoRCD) and [community](https://github.co

---

_🤖 auto updated with [automd](https://automd.unjs.io) (last updated: Tue Aug 27 2024)_
_🤖 auto updated with [automd](https://automd.unjs.io) (last updated: Fri Sep 13 2024)_

<!-- /automd -->
Binary file modified bun.lockb
Binary file not shown.
3 changes: 1 addition & 2 deletions packages/cli/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Generated by Shelve CLI
SHELVE_TOKEN=your_value
TEST=your_value
SHELVE_URL=your_value
TEST=your_value
3 changes: 1 addition & 2 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

[![npm version](https://img.shields.io/npm/v/@shelve/cli?color=black)](https://npmjs.com/package/@shelve/cli)
[![npm downloads](https://img.shields.io/npm/dm/@shelve/cli?color=black)](https://npmjs.com/package/@shelve/cli)
[![license](https://img.shields.io/github/license/HugoRCD/shelve?color=black)](https://github.com/HugoRCD/shelve/blob/main/LICENSE)

<!-- /automd -->

Expand Down Expand Up @@ -108,6 +107,6 @@ Made by [@HugoRCD](https://github.com/HugoRCD) and [community](https://github.co

---

_🤖 auto updated with [automd](https://automd.unjs.io) (last updated: Mon Sep 09 2024)_
_🤖 auto updated with [automd](https://automd.unjs.io) (last updated: Fri Sep 13 2024)_

<!-- /automd -->
6 changes: 4 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shelve/cli",
"version": "2.1.0",
"version": "2.2.0",
"description": "The command-line interface for Shelve",
"author": "HugoRCD",
"type": "module",
Expand Down Expand Up @@ -32,14 +32,16 @@
"c12": "^1.11.2",
"commander": "^12.1.0",
"consola": "^3.2.3",
"giget": "^1.2.3",
"nypm": "^0.3.11",
"ofetch": "^1.3.4",
"unbuild": "^2.0.0"
},
"devDependencies": {
"@hrcd/eslint-config": "^2.0.2",
"@shelve/types": "workspace:*",
"@types/bun": "^1.1.9",
"@types/semver": "^7.5.8",
"eslint": "^9.10.0",
"release-it": "^17.6.0",
"vitest": "^2.1.0"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { intro, isCancel, outro, select } from '@clack/prompts'
import { Command } from 'commander'
import { generateEnvExampleFile } from '../utils/env'
import { onCancel } from '../utils'
import { getEslintConfig } from '../utils/templates'

export function generateCommand(program: Command): void {
program
Expand All @@ -25,6 +26,9 @@ export function generateCommand(program: Command): void {
case 'example':
await generateEnvExampleFile()
break
case 'eslint':
await getEslintConfig()
break
default:
onCancel('Invalid option')
}
Expand Down
3 changes: 0 additions & 3 deletions packages/cli/src/templates/eslint.config.js

This file was deleted.

46 changes: 46 additions & 0 deletions packages/cli/src/utils/templates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import fs from 'fs'
import { addDevDependency } from 'nypm'
import { spinner, confirm, isCancel, note, intro } from '@clack/prompts'
import { onCancel } from './index'

const s = spinner()

const templates = {
eslint: 'https://raw.githubusercontent.com/HugoRCD/templates/main/eslint.config.js'
}

export async function getEslintConfig(): Promise<void> {
intro('Generate ESLint config')

s.start('Fetching ESLint config')

try {
const response = await fetch(templates.eslint)
const text = await response.text()

fs.writeFileSync('./eslint.config.js', text)

s.stop('Fetching ESLint config')

note('ESLint config has been generated', 'ESLint config')

const install = await confirm({
message: 'Do you want to install ESLint and @hrcd/eslint-config?'
})

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

if (install) {
s.start('Installing eslint and @hrcd/eslint-config')
await addDevDependency('eslint', {
silent: true
})
await addDevDependency('@hrcd/eslint-config', {
silent: true
})
s.stop('Installing ESLint and @hrcd/eslint-config')
}
} catch (error) {
onCancel('Failed to fetch ESLint config')
}
}

0 comments on commit d6415ed

Please sign in to comment.