forked from envault/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
3,514 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
*-debug.log | ||
*-error.log | ||
/.nyc_output | ||
/dist | ||
/lib | ||
/tmp | ||
/yarn.lock | ||
node_modules | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
const project = path.join(__dirname, '../tsconfig.json') | ||
const dev = fs.existsSync(project) | ||
|
||
if (dev) { | ||
require('ts-node').register({project}) | ||
} | ||
|
||
require(`../${dev ? 'src' : 'lib'}`).run() | ||
.catch(require('@oclif/errors/handle')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
|
||
node "%~dp0\run" %* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "envault", | ||
"version": "2.1.0", | ||
"main": "src/index.js", | ||
"author": "Envault", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/envault/envault/issues" | ||
}, | ||
"homepage": "https://github.com/envault/envault", | ||
"bin": { | ||
"envault": "src/index.js" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.21.1", | ||
"chalk": "^4.1.0", | ||
"dotenv": "^8.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
const addConfigToGitignore = require('../utils/addConfigToGitignore'); | ||
const axios = require('axios').default; | ||
const chalk = require('chalk'); | ||
const fs = require('fs'); | ||
const newLine = console.log; | ||
const print = console.log; | ||
const syncEnv = require('../utils/syncEnv'); | ||
const addConfigToGitignore = require('../utils/addConfigToGitignore') | ||
const axios = require('axios').default | ||
const chalk = require('chalk') | ||
const fs = require('fs') | ||
const newLine = console.log | ||
const print = console.log | ||
const syncEnv = require('../utils/syncEnv') | ||
|
||
module.exports = () => { | ||
// Get setup configuration from command arguments | ||
const domain = process.argv[2]; | ||
const appId = process.argv[3]; | ||
const token = process.argv[4]; | ||
const domain = process.argv[2] | ||
const appId = process.argv[3] | ||
const token = process.argv[4] | ||
|
||
// Make a setup call to the Envault Server API | ||
axios.post(`https://${domain}/api/v1/apps/${appId}/setup/${token}`) | ||
.then((response) => { | ||
if (! response.data.authToken) return; | ||
if (! response.data.authToken) return | ||
|
||
// Create configuration file | ||
fs.writeFileSync('.envault.json', JSON.stringify({ | ||
appId: appId, | ||
authToken: response.data.authToken, | ||
domain: domain, | ||
})); | ||
})) | ||
|
||
newLine(); | ||
print(chalk.green.bold('Configuration file set up.')); | ||
newLine() | ||
print(chalk.green.bold('Configuration file set up.')) | ||
|
||
addConfigToGitignore(); | ||
addConfigToGitignore() | ||
|
||
// If the .env file does not exist, create one and populate | ||
if (! fs.existsSync('.env')) { | ||
let template = ''; | ||
let template = '' | ||
|
||
response.data.app.variables.forEach((variable) => { | ||
template += `${variable.key}=\n`; | ||
}); | ||
template += `${variable.key}=\n` | ||
}) | ||
|
||
fs.writeFileSync('.env', template); | ||
}; | ||
fs.writeFileSync('.env', template) | ||
} | ||
|
||
syncEnv(response.data.app.variables, require('dotenv').config().parsed); | ||
syncEnv(response.data.app.variables, require('dotenv').config().parsed) | ||
|
||
newLine(); | ||
print(chalk.green.bold('All done! 🎉')); | ||
newLine() | ||
print(chalk.green.bold('All done! 🎉')) | ||
}) | ||
.catch((error) => { | ||
newLine(); | ||
print(chalk.bgRed.bold('Uh oh! Looks like your setup token is invalid, please get another!')); | ||
print(chalk.red(error)); | ||
}); | ||
}; | ||
newLine() | ||
print(chalk.bgRed.bold('Uh oh! Looks like your setup token is invalid, please get another!')) | ||
print(chalk.red(error)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
const axios = require('axios').default; | ||
const chalk = require('chalk'); | ||
const fs = require('fs'); | ||
const newLine = console.log; | ||
const print = console.log; | ||
const syncEnv = require('../utils/syncEnv'); | ||
const axios = require('axios').default | ||
const chalk = require('chalk') | ||
const fs = require('fs') | ||
const newLine = console.log | ||
const print = console.log | ||
const syncEnv = require('../utils/syncEnv') | ||
|
||
module.exports = () => { | ||
// If the .env file does not exist, throw error | ||
if (! fs.existsSync('.env')) return print(chalk.bgRed.bold('.env file does not exist.')); | ||
if (! fs.existsSync('.env')) return print(chalk.bgRed.bold('.env file does not exist.')) | ||
|
||
// If the configuration file does not exist, throw error | ||
if (! fs.existsSync('.envault.json')) return print(chalk.bgRed.bold('Please set Envault up before trying to sync with it.')); | ||
if (! fs.existsSync('.envault.json')) return print(chalk.bgRed.bold('Please set Envault up before trying to sync with it.')) | ||
|
||
// Parse configuration from the file | ||
const config = JSON.parse(fs.readFileSync('.envault.json')); | ||
const config = JSON.parse(fs.readFileSync('.envault.json')) | ||
|
||
// Make a sync call to the Envault Server API | ||
axios.defaults.headers.common['Authorization'] = `Bearer ${config.authToken}`; | ||
axios.defaults.headers.common['Authorization'] = `Bearer ${config.authToken}` | ||
axios.post(`https://${config.domain}/api/v1/apps/${config.appId}/update`) | ||
.then((response) => { | ||
syncEnv(response.data.variables, require('dotenv').config().parsed); | ||
syncEnv(response.data.variables, require('dotenv').config().parsed) | ||
|
||
newLine(); | ||
print(chalk.green.bold('All done! 🎉')); | ||
newLine() | ||
print(chalk.green.bold('All done! 🎉')) | ||
}) | ||
.catch((error) => { | ||
newLine(); | ||
print(chalk.bgRed.bold('Uh oh! There is an error with your Envault configuration, please set it up again!')); | ||
print(chalk.red(error)); | ||
}); | ||
}; | ||
newLine() | ||
print(chalk.bgRed.bold('Uh oh! There is an error with your Envault configuration, please set it up again!')) | ||
print(chalk.red(error)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env node | ||
|
||
const chalk = require('chalk') | ||
const newLine = console.log | ||
const print = console.log | ||
const setUp = require('./commands/setUp') | ||
const sync = require('./commands/sync') | ||
|
||
newLine() | ||
|
||
// Welcome | ||
print(chalk.magenta.bold.underline('Welcome to Envault!')) | ||
print('No more .env update nightmares from now on, we promise 🤗') | ||
|
||
newLine() | ||
print('Preparing a few things...') | ||
|
||
// Setup details have been supplied, so trigger a setup | ||
if (process.argv.length >= 5) return setUp() | ||
|
||
sync() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const chalk = require('chalk') | ||
const fs = require('fs') | ||
const newLine = console.log | ||
const print = console.log | ||
|
||
module.exports = () => { | ||
// If .gitignore exists, make sure that the configuration file is listed in it | ||
if (! fs.existsSync('.gitignore')) return | ||
|
||
const contents = fs.readFileSync('.gitignore').toString() | ||
|
||
if (contents.includes('.envault.json')) return | ||
|
||
fs.appendFileSync('.gitignore', '\n.envault.json') | ||
|
||
newLine() | ||
print(chalk.green.bold('.gitignore updated.')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
module.exports = (value = '') => { | ||
const end = value.length - 1; | ||
const end = value.length - 1 | ||
|
||
const isDoubleQuoted = value[0] === '"' && value[end] === '"'; | ||
const isSingleQuoted = value[0] === "'" && value[end] === "'"; | ||
const isDoubleQuoted = value[0] === '"' && value[end] === '"' | ||
const isSingleQuoted = value[0] === "'" && value[end] === "'" | ||
|
||
// If no single or double quotes detected, trim whitespace | ||
if (! isSingleQuoted && ! isDoubleQuoted) return value.trim(); | ||
if (! isSingleQuoted && ! isDoubleQuoted) return value.trim() | ||
|
||
// Remove quotes | ||
value = value.substring(1, end); | ||
value = value.substring(1, end) | ||
|
||
// If double quoted, expand new lines | ||
if (isDoubleQuoted) { | ||
value = value.replace(/\\n/g, '\n'); | ||
}; | ||
value = value.replace(/\\n/g, '\n') | ||
} | ||
|
||
return value; | ||
}; | ||
return value | ||
} |
Oops, something went wrong.