Skip to content

Commit

Permalink
Enable both staging + production client IDs based on local config
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanblock committed Apr 1, 2022
1 parent d2f8487 commit 4c2aac9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.nyc_output/
build
commit
client-id
client-ids.json
config.json
coverage/
node_modules/
Expand Down
8 changes: 5 additions & 3 deletions scripts/binary-config
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ if (DEPLOY === 'main') {
let appVersion = `main-${sha.toString().substr(0, 7)}`
let commitFile = join(__dirname, '..', 'commit')
writeFileSync(commitFile, appVersion)
let clientID = process.env.BEGIN_CLI_CLIENT_ID
let clientIDFile = join(__dirname, '..', 'client-id')
writeFileSync(clientIDFile, clientID)
let staging = process.env.BEGIN_CLI_CLIENT_ID_STAGING
let production = process.env.BEGIN_CLI_CLIENT_ID_PRODUCTION
let clientIDs = JSON.stringify({ staging, production })
let clientIDFile = join(__dirname, '..', 'client-ids.json')
writeFileSync(clientIDFile, clientIDs)
config.bin.cli = '../src/_main.js'
config.pkg.assets.push('../commit')
config.pkg.assets.push('../client-id')
Expand Down
6 changes: 3 additions & 3 deletions src/_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ let { join } = require('path')
let commitFile = join(__dirname, '..', 'commit')
let version = readFileSync(commitFile).toString()

let clientIDFile = join(__dirname, '..', 'client-id')
let clientID = readFileSync(clientIDFile).toString()
let clientIDFile = join(__dirname, '..', 'client-ids.json')
let clientIDs = JSON.parse(readFileSync(clientIDFile))

let begin = require('./')
begin({ version, clientID })
begin({ version, clientIDs })
3 changes: 2 additions & 1 deletion src/commands/login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
}

async function action (params) {
let { appVersion, cliDir, clientID, printer } = params
let { appVersion, cliDir, clientIDs, printer } = params
let { join } = require('path')
let { existsSync, readFileSync } = require('fs')
let writeFile = require('../../lib').writeFile(params)
Expand All @@ -36,6 +36,7 @@ async function action (params) {
else {
config = JSON.parse(readFileSync(configFile))
}
let clientID = config.stagingAPI ? clientIDs.staging : clientIDs.production
let domain = process.env.__BEGIN_TEST__
? 'http://localhost:3333'
: `https://${config.stagingAPI ? 'staging-' : ''}api.begin.com`
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let commands = require('./commands')
let _printer = require('./printer')

async function begin (params = {}) {
let { clientID, version } = params
let { clientIDs, version } = params
let alias = {
debug: 'd',
help: 'h',
Expand All @@ -17,9 +17,9 @@ async function begin (params = {}) {
let args = minimist(process.argv.slice(2), { alias })
if (process.env.DEBUG) args.debug = true
try {
if (!clientID) {
let clientIDFile = join(__dirname, '..', 'client-id')
if (existsSync(clientIDFile)) clientID = readFileSync(clientIDFile).toString().trim()
if (!clientIDs) {
let clientIDFile = join(__dirname, '..', 'client-ids.json')
if (existsSync(clientIDFile)) clientIDs = JSON.parse(readFileSync(clientIDFile))
}
if (!version) {
let pkg = join(__dirname, '..', 'package.json')
Expand All @@ -29,7 +29,7 @@ async function begin (params = {}) {
let lang = 'en' // This should / will be configurable
let printer = _printer(args)
let cliDir = process.env.BEGIN_INSTALL || join(homedir(), '.begin')
let params = { args, appVersion: version, cliDir, clientID, lang, printer }
let params = { args, appVersion: version, cliDir, clientIDs, lang, printer }
await commands(params)
}
catch (err) {
Expand Down

0 comments on commit 4c2aac9

Please sign in to comment.