Comparing version 1.0.0 to 1.0.1
55
index.js
require('dotenv').config() | ||
const { program } = require('commander'); | ||
const rest = require('./integration/envsync-rest'); | ||
const rest = require('./integration/securenv-rest'); | ||
const fs = require('fs'); | ||
const { config } = require('dotenv'); | ||
getEnvsync = () => { | ||
try { | ||
const content = fs.readFileSync('.envsync', 'utf8'); | ||
return JSON.parse(content); | ||
} catch (error) { | ||
throw new Error(`You are not logged in`); | ||
} | ||
} | ||
@@ -37,3 +30,3 @@ getEnvPath = (environment) => { | ||
program | ||
.name('envsync') | ||
.name('securenv') | ||
.description('CLI to sync env files') | ||
@@ -47,10 +40,7 @@ .version('0.0.1'); | ||
.argument('<password>', 'your password') | ||
.action(async (login, password) => { | ||
.argument('[host]', 'securenv host') | ||
.action(async (login, password, host) => { | ||
try { | ||
const jwt = await rest.login(login, password) | ||
fs.writeFileSync('.envsync', JSON.stringify({ | ||
host: undefined, | ||
token: jwt | ||
})); | ||
const config = await rest.login(host, login, password) | ||
fs.writeFileSync('.securenv', JSON.stringify(config)); | ||
console.log('You are in!') | ||
@@ -69,9 +59,16 @@ } | ||
try { | ||
const { token } = getEnvsync(); | ||
const environments = await rest.list(token, project) | ||
const environments = await rest.list(project) | ||
if(environments) { | ||
console.log(`Listing [${environments.length}] environments for [${project}]...`); | ||
environments.map(env => { | ||
console.log(`=> PROJECT ${env.project} ENVIRONMENT ${env.environment} AUTHOR ${env.login} UPDATED AT ${env.updatedAt} VERSIONS ${env.versions.length+1}`); | ||
}) | ||
console.log(`=> ${env.project.toUpperCase()} at ${env.environment} has ${env.versions.length+1} version(s):`); | ||
console.log(''); | ||
console.log(` - CURRENT by ${env.login} updated at ${env.updatedAt}`); | ||
env.versions.map(version => { | ||
console.log(` - ${version.id} by ${env.login} updated at ${env.updatedAt}`); | ||
}); | ||
console.log(''); | ||
console.log(''); | ||
}); | ||
console.log('If you need to get an specific vesion, just do: securenv get [project] [env] [version-id]') | ||
} else { | ||
@@ -91,13 +88,14 @@ console.log(`This environment does not exists yet [${project}] [${environment || 'production'}]`); | ||
.argument('[environment]', 'Environment of env file') | ||
.action(async (project, environment) => { | ||
.argument('[versionId]', 'Id of an version') | ||
.action(async (project, environment, versionId) => { | ||
try { | ||
const { token } = getEnvsync(); | ||
const result = await rest.get(token, project, environment || 'production') | ||
const result = await rest.get(project, environment || 'production', versionId) | ||
if(result) { | ||
console.log(`Loading [${result.project}] [${result.environment}] environment ...`); | ||
console.log(`Last Author [${result.login}] at [${result.updatedAt}]`); | ||
console.log(`Loading [${result.project}] [${result.environment}] [${versionId || 'current'}] ...`); | ||
console.log(`Author [${result.login}] at [${result.updatedAt}]`); | ||
console.log('env', result.content) | ||
setEnvFile(environment, result.content); | ||
console.log('Done! You are up to date!'); | ||
} else { | ||
console.log(`This environment does not exists yet [${project}] [${environment || 'production'}]`); | ||
console.log(`This environment/version does not exists yet [${project}] [${environment || 'production'}] [${versionId || 'current'}]`); | ||
} | ||
@@ -117,5 +115,4 @@ } | ||
try { | ||
const { token } = getEnvsync(); | ||
const content = getEnvFile(environment) | ||
await rest.set(token, project, environment || 'production', content) | ||
await rest.set(project, environment || 'production', content) | ||
console.log(`Uploading environment [${project}] [${environment || 'production'}]...`); | ||
@@ -122,0 +119,0 @@ console.log('Done! Your environment was uploaded!'); |
{ | ||
"name": "securenv", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Securenv its a CLI for securenv API that stores and gets secure env files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
8963
218
4
5