-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·29 lines (23 loc) · 909 Bytes
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env node
const plist = require('plist')
const minimist = require('minimist')
const dotenv = require('dotenv')
const fs = require('fs')
const path = require('path')
// extracting arguments from CLI
const argv = minimist(process.argv.slice(2))
const env = (argv._.length === 2) ? argv._[0] : argv.e || argv.env
const dest = (argv._.length === 2) ? argv._[1] : argv.d || argv.destination
// loading env varibles from passed .env file
const variables = dotenv
.config({ path: env })
.parsed
// converting env variables to plist string
const plistContent = plist.build(variables)
// saving plist file to chosen destination
const destination = path.join(dest, `${path.basename(env)}.plist`)
fs.writeFile(destination, plist.build(variables), err => {
if (err)
return console.log(`react-native-dot-env: ${err}`)
console.log(`react-native-dot-env: ${env} converted to ${destination}`)
});