Skip to content

Commit

Permalink
starting check option
Browse files Browse the repository at this point in the history
  • Loading branch information
GantMan committed Aug 4, 2018
1 parent a73fdb0 commit 2d706fa
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 14 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ src/
coverage/
yarn.lock
*.log
check/
2 changes: 1 addition & 1 deletion __tests__/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ it('enforces required properties', () => {

test('check solidarity create with no parameter', async () => {
await createCommand.run(mockContext)
expect(mockContext.print.error.mock.calls).toEqual([['Missing what to create'], ['solidarity create <wut?>']])
expect(mockContext.print.error.mock.calls).toEqual([['Missing what to create'], ['$ solidarity create <wut?>']])
expect(mockContext.print.info.mock.calls.length).toBe(1)
})

Expand Down
2 changes: 1 addition & 1 deletion __tests__/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test('Calls print items several times', () => {
expect(context.print.success.mock.calls.length).toBe(0)
expect(context.print.colors.magenta.mock.calls.length).toBe(0)
helpCommand.run(context)
expect(context.print.info.mock.calls.length).toBe(8)
expect(context.print.info.mock.calls.length).toBe(9)
expect(context.print.printCommands.mock.calls.length).toBe(1)
expect(context.print.success.mock.calls.length).toBe(2)
expect(context.print.colors.magenta.mock.calls.length).toBe(2)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
break
default:
print.error('Missing what to create')
print.error('solidarity create <wut?>')
print.error('$ solidarity create <wut?>')
print.info(`Things you can create: ${createables}`)
}
},
Expand Down
1 change: 1 addition & 0 deletions src/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
print.info(' --silent\t (-s) No output, just a return code of success/failure')
print.info(' --solidarityFile\t (-f) Use given path to solidarity file for settings')
print.info(' --module\t (-m) Search for a solidarity file in the given npm package')
print.info(' --check\t (-c) Use a known technology, and not the local file')

print.success(colors.magenta('\nSolidarity is open source - https://github.com/infinitered/solidarity'))
print.info(colors.magenta('If you need additional help, join our Slack at http://community.infinite.red'))
Expand Down
60 changes: 49 additions & 11 deletions src/commands/solidarity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,59 @@ namespace Solidarity {
// drop out fast in these situations
await checkForEscapeHatchFlags(context)

const { print, solidarity } = context
const { print, solidarity, parameters } = context
const { options } = parameters
const { checkRequirement, getSolidaritySettings } = solidarity

// get settings or error
let solidaritySettings
try {
solidaritySettings = getSolidaritySettings(context)
} catch (e) {
print.error(e)
print.info(
`Make sure you are in the correct folder or run ${print.colors.success(
'solidarity snapshot'
)} to take a snapshot of your environment and create a .solidarity file for this project.`
)
process.exit(3)
//////////
// Consider cleaing this up
const checkOption: string = options ? (options.check || options.c) : null
if (checkOption) {
const { http } = context
const checkSpinner = print.spin(`Running check on ${checkOption}`)
const api = http.create({
baseURL: 'https://api.github.com',
headers: { Accept: 'application/vnd.github.v3+json' },
})
try {
// Load check from web
const checkURL = `https:\/\/raw.githubusercontent.com/infinitered/solidarity/master/${checkOption}`
const result = await api.get(checkURL)
console.log(result)
if (result.ok) {
checkSpinner.succeed(checkURL)
// result.data
} else {
checkSpinner.fail(`Unable to find a known check for ${checkOption}`)
print.info(
`https://github.com/infinitered/solidarity/checks for options.`
)
process.exit(3)
}
} catch (e) {
checkSpinner.fail(e)
print.info(
`Check is meant to verify your environment based on known stacks
solidarity failed to do a proper check for ${print.colors.success(checkOption)}`
)
process.exit(3)
}
process.exit(1)
//////////////////////////////////////
} else {
try {
solidaritySettings = getSolidaritySettings(context)
} catch (e) {
print.error(e)
print.info(
`Make sure you are in the correct folder or run ${print.colors.success(
'solidarity snapshot'
)} to take a snapshot of your environment and create a .solidarity file for this project.`
)
process.exit(3)
}
}

context.outputMode = setOutputMode(context.parameters, solidaritySettings)
Expand Down

0 comments on commit 2d706fa

Please sign in to comment.