@dotenv/cli
Advanced tools
Comparing version 0.6.0 to 0.7.0
import { Command } from '@oclif/command'; | ||
export default class Pull extends Command { | ||
static description: string; | ||
static args: ({ | ||
name: string; | ||
required: boolean; | ||
description: string; | ||
hidden: boolean; | ||
default: string; | ||
options: string[]; | ||
} | { | ||
name: string; | ||
required: boolean; | ||
description: string; | ||
hidden: boolean; | ||
default?: undefined; | ||
options?: undefined; | ||
})[]; | ||
run(): Promise<void>; | ||
} |
@@ -10,2 +10,3 @@ "use strict"; | ||
async run() { | ||
const { argv } = this.parse(Pull); | ||
// 0. check latest version | ||
@@ -18,3 +19,3 @@ await new check_latest_version_service_1.CheckLatestVersionService().run(); | ||
// 3. pull | ||
await new pull_service_1.PullService().run(); | ||
await new pull_service_1.PullService(argv[0], argv[1]).run(); | ||
} | ||
@@ -24,1 +25,17 @@ } | ||
Pull.description = 'pull .env'; | ||
Pull.args = [ | ||
{ | ||
name: 'environment', | ||
required: false, | ||
description: 'Pull .env.ci, .env.staging, and .env.production', | ||
hidden: false, | ||
default: 'development', | ||
options: ['development', 'ci', 'staging', 'production'], | ||
}, | ||
{ | ||
name: 'filename', | ||
required: false, | ||
description: 'Set output filename. Defaults to .env for development and .env.{environment} for other environments', | ||
hidden: false, | ||
}, | ||
]; |
@@ -8,7 +8,5 @@ "use strict"; | ||
const file = '.gitignore'; | ||
const envFormat = '.env'; | ||
const envMeFormat = '.env.me'; | ||
const envFormat = '.env*'; // asterisk | ||
const envProjectFormat = '!.env.project'; | ||
let envExists = false; | ||
let envMeExists = false; | ||
let envProjectExists = false; | ||
@@ -27,5 +25,2 @@ // 1. create .gitignore if doesn't exist | ||
} | ||
if (trimLine === envMeFormat) { | ||
envMeExists = true; | ||
} | ||
if (trimLine === envProjectFormat) { | ||
@@ -39,5 +34,2 @@ envProjectExists = true; | ||
} | ||
if (envMeExists === false) { | ||
fs.appendFileSync(file, '\n' + envMeFormat); | ||
} | ||
if (envProjectExists === false) { | ||
@@ -44,0 +36,0 @@ fs.appendFileSync(file, '\n' + envProjectFormat); |
import * as dotenv from 'dotenv'; | ||
declare class PullService { | ||
environment: string; | ||
filename: string; | ||
constructor(environment: string, filename: string); | ||
run(): Promise<void>; | ||
@@ -39,2 +42,3 @@ _pull(): Promise<void>; | ||
data: { | ||
environment: string; | ||
projectUid: string; | ||
@@ -50,3 +54,7 @@ meUid: string; | ||
get _DOTENV_PROJECT_NAME(): string; | ||
get _development(): boolean; | ||
get _envFileName(): string; | ||
get _envOutputFileName(): string; | ||
get _smartPullMessage(): string; | ||
} | ||
export { PullService }; |
@@ -14,2 +14,6 @@ "use strict"; | ||
class PullService { | ||
constructor(environment, filename) { | ||
this.environment = environment; | ||
this.filename = filename; | ||
} | ||
async run() { | ||
@@ -21,2 +25,3 @@ const meFile = '.env.me'; | ||
else { | ||
// TODO: prompt the user if they want to create a .env.me file - rather than raise an error. in dev maybe prompt but for prod, etc it should raise a stacktrace most likely. since machines won't be able to answer the prompts | ||
await new write_env_me_service_1.WriteEnvMeService().run(); | ||
@@ -30,21 +35,27 @@ this._auth(); | ||
// eslint-disable-next-line no-console | ||
console.log('remote: Securely pulling .env'); | ||
console.log(`remote: Securely pulling ${this._smartPullMessage}`); | ||
// eslint-disable-next-line no-console | ||
console.log('remote:'); | ||
const _this = this; | ||
axios(this._pullOptions) | ||
.then(response => { | ||
if (response.data.data.dotenv) { | ||
new write_env_service_1.WriteEnvService({ quiet: true }).run(); | ||
const oldData = fs.readFileSync('.env', 'UTF-8'); | ||
const newData = response.data.data.dotenv; | ||
fs.writeFileSync('.env', newData); | ||
const diff = gitDiff(oldData, newData); | ||
if (diff) { | ||
// eslint-disable-next-line no-console | ||
console.log('Updated.\n\n' + diff); | ||
// if development mode and user is NOT passing a custom filename | ||
if (this._development && !this.filename) { | ||
new write_env_service_1.WriteEnvService({ quiet: true }).run(); | ||
const oldData = fs.readFileSync(this._envFileName, 'UTF-8'); | ||
fs.writeFileSync(this._envFileName, newData); | ||
const diff = gitDiff(oldData, newData); | ||
if (diff) { | ||
// eslint-disable-next-line no-console | ||
console.log('Updated.\n\n' + diff); | ||
} | ||
else { | ||
// eslint-disable-next-line no-console | ||
console.log('Already up to date.'); | ||
} | ||
} | ||
else { | ||
// eslint-disable-next-line no-console | ||
console.log('Already up to date.'); | ||
// other environments: just write | ||
fs.writeFileSync(this._envOutputFileName, newData); | ||
} | ||
@@ -57,3 +68,3 @@ } | ||
if (error.response) { | ||
signale.fatal(_this._formatErrorBody(error.response.data)); | ||
signale.fatal(error.response.data.errors[0].message); | ||
} | ||
@@ -110,3 +121,3 @@ else { | ||
_formatErrorBody(body) { | ||
return body["errors"][0]["message"]; | ||
return body.errors[0].message; | ||
} | ||
@@ -147,2 +158,3 @@ _authOptions(email) { | ||
const data = { | ||
environment: this.environment, | ||
projectUid: this._DOTENV_PROJECT, | ||
@@ -174,3 +186,25 @@ meUid: this._DOTENV_ME, | ||
} | ||
get _development() { | ||
return this.environment === 'development'; | ||
} | ||
get _envFileName() { | ||
if (this._development) { | ||
return '.env'; | ||
} | ||
return `.env.${this.environment}`; | ||
} | ||
get _envOutputFileName() { | ||
// if user has set a filename for output then use that | ||
if (this.filename) { | ||
return this.filename; | ||
} | ||
return this._envFileName; | ||
} | ||
get _smartPullMessage() { | ||
if (this.filename) { | ||
return `${this._envFileName} to ${this._envOutputFileName}`; | ||
} | ||
return this._envFileName; | ||
} | ||
} | ||
exports.PullService = PullService; |
@@ -7,3 +7,2 @@ import * as dotenv from 'dotenv'; | ||
_promptForShortCode(): Promise<void>; | ||
_formatErrorBody(body: any): any; | ||
_authOptions(email: any): { | ||
@@ -10,0 +9,0 @@ method: string; |
@@ -29,3 +29,2 @@ "use strict"; | ||
console.log('remote:'); | ||
const _this = this; | ||
axios(this._pushOptions) | ||
@@ -38,3 +37,3 @@ .then(_response => { | ||
if (error.response) { | ||
signale.fatal(_this._formatErrorBody(error.response.data)); | ||
signale.fatal(error.response.data.errors[0].message); | ||
} | ||
@@ -90,5 +89,2 @@ else { | ||
} | ||
_formatErrorBody(body) { | ||
return body["errors"][0]["message"]; | ||
} | ||
_authOptions(email) { | ||
@@ -95,0 +91,0 @@ const url = vars_1.vars.apiUrl + '/v1/auth'; |
@@ -1,1 +0,1 @@ | ||
{"version":"0.6.0","commands":{"init":{"id":"init","description":"DEPRECATED: initialize .env.me and .env.project","pluginName":"@dotenv/cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"organizationSlug"}]},"new":{"id":"new","description":"create .env.project file","pluginName":"@dotenv/cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"pull":{"id":"pull","description":"pull .env","pluginName":"@dotenv/cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"push":{"id":"push","description":"push .env","pluginName":"@dotenv/cli","pluginType":"core","aliases":[],"flags":{},"args":[]}}} | ||
{"version":"0.7.0","commands":{"init":{"id":"init","description":"DEPRECATED: initialize .env.me and .env.project","pluginName":"@dotenv/cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"organizationSlug"}]},"new":{"id":"new","description":"create .env.project file","pluginName":"@dotenv/cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"pull":{"id":"pull","description":"pull .env","pluginName":"@dotenv/cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"environment","description":"Pull .env.ci, .env.staging, and .env.production","required":false,"options":["development","ci","staging","production"],"default":"development","hidden":false},{"name":"filename","description":"Set output filename. Defaults to .env for development and .env.{environment} for other environments","required":false,"hidden":false}]},"push":{"id":"push","description":"push .env","pluginName":"@dotenv/cli","pluginType":"core","aliases":[],"flags":{},"args":[]}}} |
{ | ||
"name": "@dotenv/cli", | ||
"description": "CLI to interact with dotenv", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"author": "motdotla @motdotla", | ||
@@ -6,0 +6,0 @@ "bin": { |
@@ -5,3 +5,3 @@ # @dotenv/cli | ||
Dotenv cli is a command line tool that syncs your `.env` files across machines and between your team members. It's like 1Password, but for developers. Designed by the same people that brought you [dotenv](https://github.com/motdotla/dotenv), it's a completely optional (but recommended) plugin for [dotenv](https://github.com/motdotla/dotenv). | ||
Dotenv cli is a command line tool that syncs your `.env` files across machines and between your team members. It's like 1Password, but for developers. Designed by the same people that brought you [dotenv](https://github.com/motdotla/dotenv), it's a recommended plugin for [dotenv](https://github.com/motdotla/dotenv). | ||
@@ -29,3 +29,3 @@ [![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io) | ||
In your terminal (and in your project folder), create a new .env.project file. | ||
Usage is easy! Run the command: | ||
@@ -36,7 +36,4 @@ ```bash | ||
This will ask you to visit Dotenv to create your project. Follow that for | ||
instructions on setting your `.env.project` file. | ||
Follow those instructions and then run: | ||
Then make changes to your `.env` file and when you do, run: | ||
```bash | ||
@@ -46,3 +43,3 @@ dotenv-cli push | ||
If you need to pull changes that another teammate made, run: | ||
And if you need to pull changes that another teammate made, run: | ||
@@ -72,2 +69,18 @@ ```bash | ||
### `dotenv-cli pull [ENVIRONMENT] [FILENAME]` | ||
By default `dotenv-cli pull` will pull your development environment to `.env`. | ||
Want to pull your staging secrets? Run.. | ||
```bash | ||
dotenv-cli pull staging | ||
``` | ||
Want to pull your production secrets but output them to `.env`. Run.. | ||
```bash | ||
dotenv-cli pull production .env | ||
``` | ||
## Development | ||
@@ -74,0 +87,0 @@ |
40368
1077
100