Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.

Commit

Permalink
feat: get config from private repo
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmeinke committed Sep 24, 2018
1 parent 6203031 commit 8594038
Show file tree
Hide file tree
Showing 12 changed files with 11,416 additions and 6,377 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
/node_modules
/yarn-error.log
/npm-debug.log
/yarn.lock
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ npm install -g @serieseight/cli
```
s8 hello
```

## Development

Clone the repository at https://github.com/serieseight/cli.

Install dependencies with `npm install` (avoid yarn this time, as
internals use npm).
35 changes: 19 additions & 16 deletions commands/hello.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
const chalk = require('chalk')
const inquirer = require('inquirer')
const { team } = require('../config')

module.exports = () => {
inquirer
.prompt([
{
type: 'list',
name: 'user',
message: 'Who the heck are you?',
choices: team.map(({ name }) => name)
}
])
.then(({ user }) => {
console.log(
`Yay, it's ${chalk.bold.green(user)}! My favourite team member.`
)
})
module.exports = team => {
if (team.length) {
inquirer
.prompt([
{
type: 'list',
name: 'user',
message: 'Who the heck are you?',
choices: team.map(({ name }) => name)
}
])
.then(({ user }) => {
console.log(
`Yay, it's ${chalk.bold.green(user)}! My favourite team member.`
)
})
} else {
console.log(`Hello!`)
}
}
7 changes: 5 additions & 2 deletions commands/help.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const chalk = require('chalk')

module.exports = () => {
console.log(`Usage: s8 <command>
console.log(`${chalk.green('Usage:')} ${chalk.bold('s8 <command>')}
Where <command> is one of:
Where ${chalk.bold('<command>')} is one of:
hello
install
setup
team
upgrade`)
}
22 changes: 22 additions & 0 deletions commands/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const chalk = require('chalk')
const { exec } = require('child_process')
const { promisify } = require('util')

const execAsync = promisify(exec)

module.exports = (hasSetup) => {
if (hasSetup) {
console.log(`${chalk.green(`You've already successfully ran ${chalk.bold('s8 setup')}!`)}
You only have to run this command once.
After that please use ${chalk.bold('s8 upgrade')} to upgrade ${chalk.bold('s8')} and all of its dependencies.
`)
} else {
console.log(chalk.dim('Installing private dependencies...'))

execAsync('npm i --no-save git+ssh://[email protected]:serieseight/config.git#master')
.then(() => console.log('Private dependencies installed!'))
.then(() => console.log(chalk.bold.green('Setup complete!')))
.catch(err => console.error(err))
}
}
7 changes: 4 additions & 3 deletions commands/team.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const chalk = require('chalk')
const { team } = require('../config')

module.exports = ([cmd]) => {
module.exports = (team, [cmd]) => {
switch (cmd) {
case 'list':
case undefined:
team.map(({ name, email }) => console.log(`${name} - ${email}`))
team.length
? team.map(({ name, email }) => console.log(`${chalk.bold.green(name)} - ${email}`))
: console.log(`${chalk.bold.red('No team members.')}`)
break

default:
Expand Down
22 changes: 12 additions & 10 deletions commands/upgrade.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const chalk = require('chalk')
const { exec } = require('child_process')
const { name } = require('../package.json')
const { promisify } = require('util')

module.exports = () => {
console.log('Upgrading...')

exec(`npm i -g ${name}`, (err, stdout, stderr) => {
if (err) {
console.error(err)
const execAsync = promisify(exec)

return
}
module.exports = () => {
console.log(chalk.dim(`Upgrading ${chalk.bold('s8')}...`))

console.log('Upgrade complete. Go forth and build things.')
})
execAsync(`npm i -g ${name}`)
.then(() => console.log(`${chalk.bold('s8')} upgraded!`))
.then(() => console.log(chalk.dim('Upgrading private dependencies...')))
.then(() => execAsync('npm i --no-save git+ssh://[email protected]:serieseight/config.git#master'))
.then(() => console.log('Private dependencies upgraded!'))
.then(() => console.log(chalk.bold.green('Upgrade complete!')))
.catch(err => console.error(err))
}
5 changes: 4 additions & 1 deletion commands/version.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const chalk = require('chalk')
const { version } = require('../package.json')

module.exports = () => console.log(version)
module.exports = () => {
console.log(`${chalk.green('Version:')} ${chalk.bold(version)}`)
}
19 changes: 0 additions & 19 deletions config.js

This file was deleted.

32 changes: 24 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ const chalk = require('chalk')
const helloCmd = require('./commands/hello')
const helpCmd = require('./commands/help')
const installCmd = require('./commands/install')
const setupCmd = require('./commands/setup')
const teamCmd = require('./commands/team')
const upgradeCmd = require('./commands/upgrade')
const versionCmd = require('./commands/version')

const [cmd, ...args] = process.argv.slice(2)

let config = { email: [], team: [] }
let hasSetup = false

try {
config = require('@serieseight/config')
hasSetup = true
} catch (err) {
console.log(`${chalk.yellow(`You still need to run ${chalk.bold('s8 setup')} to complete installation.
Currently ${chalk.bold('s8')} does not have all the data it requires to function.`)}\n`)
}

switch(cmd) {
case '--help':
case '-h':
Expand All @@ -22,20 +34,24 @@ switch(cmd) {
versionCmd()
break

case 'team':
teamCmd(args)
break

case 'upgrade':
upgradeCmd()
case 'hello':
helloCmd(config.team)
break

case 'install':
installCmd(args)
break

case 'hello':
helloCmd()
case 'setup':
setupCmd(hasSetup)
break

case 'team':
teamCmd(config.team, args)
break

case 'upgrade':
upgradeCmd()
break

default:
Expand Down
Loading

0 comments on commit 8594038

Please sign in to comment.