Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Jan 6, 2021
1 parent 352b83d commit 8a64ae8
Show file tree
Hide file tree
Showing 22 changed files with 3,514 additions and 146 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
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
8 changes: 7 additions & 1 deletion .gitignore
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
13 changes: 13 additions & 0 deletions bin/run
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'))
3 changes: 3 additions & 0 deletions bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
69 changes: 69 additions & 0 deletions old/package-lock.json

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

19 changes: 19 additions & 0 deletions old/package.json
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"
}
}
56 changes: 28 additions & 28 deletions src/commands/setUp.js → old/src/commands/setUp.js
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))
})
}
36 changes: 18 additions & 18 deletions src/commands/sync.js → old/src/commands/sync.js
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))
})
}
21 changes: 21 additions & 0 deletions old/src/index.js
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()
18 changes: 18 additions & 0 deletions old/src/utils/addConfigToGitignore.js
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.'))
}
18 changes: 9 additions & 9 deletions src/utils/parseValue.js → old/src/utils/parseValue.js
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
}
Loading

0 comments on commit 8a64ae8

Please sign in to comment.