Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dotenvx/dotenvx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.25.1
Choose a base ref
...
head repository: dotenvx/dotenvx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.26.0
Choose a head ref
  • 7 commits
  • 6 files changed
  • 1 contributor

Commits on Mar 14, 2024

  1. use shorthand

    motdotla committed Mar 14, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    cbd10d6 View commit details

Commits on Mar 17, 2024

  1. start adding pull command

    motdotla committed Mar 17, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    2dbfd76 View commit details

Commits on Mar 18, 2024

  1. check if already existing and/or if same file contents

    motdotla committed Mar 18, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    74bf6a3 View commit details
  2. remove comments

    motdotla committed Mar 18, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    7e6affb View commit details
  3. update CHANGELOG

    motdotla committed Mar 18, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    7bce10e View commit details
  4. Merge pull request #129 from dotenvx/pull

    `dotenvx hub pull`
    motdotla authored Mar 18, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    55b8774 View commit details
  5. 0.26.0

    motdotla committed Mar 18, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    272f7c1 View commit details
Showing with 120 additions and 5 deletions.
  1. +5 −1 CHANGELOG.md
  2. +2 −2 package-lock.json
  3. +1 −1 package.json
  4. +104 −0 src/cli/actions/hub/pull.js
  5. +7 −0 src/cli/commands/hub.js
  6. +1 −1 src/lib/helpers/parseExpandAndEval.js
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,11 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v0.25.1...main)
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v0.26.0...main)

## 0.26.0

* add `hub pull` command to pull a repo's `.env.keys` down. ([#129](https://github.com/dotenvx/dotenvx/pull/129))

## 0.25.1

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.25.1",
"version": "0.26.0",
"name": "@dotenvx/dotenvx",
"description": "a better dotenv–from the creator of `dotenv`",
"author": "@motdotla",
104 changes: 104 additions & 0 deletions src/cli/actions/hub/pull.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
const fs = require('fs')
const path = require('path')
const { request } = require('undici')

const store = require('./../../../shared/store')
const logger = require('./../../../shared/logger')
const helpers = require('./../../helpers')
const createSpinner = require('./../../../shared/createSpinner')

const isGitRepo = require('./../../../lib/helpers/isGitRepo')
const isGithub = require('./../../../lib/helpers/isGithub')
const gitUrl = require('./../../../lib/helpers/gitUrl')
const gitRoot = require('./../../../lib/helpers/gitRoot')

const spinner = createSpinner('pulling')

// constants
const ENCODING = 'utf8'

// Create a simple-git instance for the current directory
async function pull (directory) {
spinner.start()
await helpers.sleep(500) // better dx

// debug args
logger.debug(`directory: ${directory}`)

// debug opts
const options = this.opts()
logger.debug(`options: ${JSON.stringify(options)}`)

// must be a git repo
if (!isGitRepo()) {
spinner.fail('oops, must be a git repository')
logger.help('? create one with [git init .]')
process.exit(1)
}
// must be a git root
const gitroot = gitRoot()
if (!gitroot) {
spinner.fail('oops, could not determine git repository\'s root')
logger.help('? create one with [git init .]')
process.exit(1)
}
// must have a remote origin url
const giturl = gitUrl()
if (!giturl) {
spinner.fail('oops, must have a remote origin (git remote -v)')
logger.help('? create it at [github.com/new] and then run [git remote add origin git@github.com:username/repository.git]')
process.exit(1)
}
// must be a github remote
if (!isGithub(giturl)) {
spinner.fail('oops, must be a github.com remote origin (git remote -v)')
logger.help('? create it at [github.com/new] and then run [git remote add origin git@github.com:username/repository.git]')
logger.help2('ℹ need support for other origins? [please tell us](https://github.com/dotenvx/dotenvx/issues)')
process.exit(1)
}

const envKeysFilepath = path.join(directory, '.env.keys')
const hostname = options.hostname
const pullUrl = `${hostname}/v1/pull`
const oauthToken = store.getToken()
const usernameName = helpers.extractUsernameName(giturl)
const relativeEnvKeysFilepath = path.relative(gitroot, path.join(process.cwd(), directory, '.env.keys')).replace(/\\/g, '/') // smartly determine path/to/.env.keys file from repository root - where user is cd-ed inside a folder or at repo root

try {
const response = await request(pullUrl, {
method: 'POST',
headers: {
Authorization: `Bearer ${oauthToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
username_name: usernameName,
filepath: relativeEnvKeysFilepath
})
})

const responseData = await response.body.json()

if (response.statusCode >= 400) {
logger.http(responseData)
spinner.fail(responseData.error.message)
if (response.statusCode === 404) {
logger.help(`? try visiting [${hostname}gh/${usernameName}] in your browser`)
}
process.exit(1)
}

if (fs.existsSync(envKeysFilepath) && fs.readFileSync(envKeysFilepath, ENCODING) === responseData.DOTENV_KEYS) {
spinner.done(`no changes (${envKeysFilepath})`)
} else {
fs.writeFileSync(envKeysFilepath, responseData.DOTENV_KEYS)
spinner.succeed(`pulled [${usernameName}]`)
logger.help2(`ℹ run [cat ${envKeysFilepath}] to view locally`)
}
} catch (error) {
spinner.fail(error.toString())
process.exit(1)
}
}

module.exports = pull
7 changes: 7 additions & 0 deletions src/cli/commands/hub.js
Original file line number Diff line number Diff line change
@@ -20,6 +20,13 @@ hub
.option('-h, --hostname <url>', 'set hostname', store.getHostname())
.action(require('./../actions/hub/push'))

hub
.command('pull')
.description('pull .env.keys from dotenvx hub')
.argument('[directory]', 'directory to pull', '.')
.option('-h, --hostname <url>', 'set hostname', store.getHostname())
.action(require('./../actions/hub/pull'))

hub
.command('open')
.description('view repository on dotenvx hub')
2 changes: 1 addition & 1 deletion src/lib/helpers/parseExpandAndEval.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ function parseExpandAndEval (src, overload) {
// eval parsed only. do NOT eval process.env ever. too risky/dangerous.
const inputParsed = {
processEnv: {},
parsed: parsed
parsed
}
const evaled = dotenvEval.eval(inputParsed).parsed