Skip to content

Commit

Permalink
primed to move functionality down to function
Browse files Browse the repository at this point in the history
  • Loading branch information
GantMan committed Aug 4, 2018
1 parent 2d706fa commit 97b4460
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/commands/solidarity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Solidarity {
// get settings or error
let solidaritySettings
//////////
// Consider cleaing this up
// Consider cleaning this up
const checkOption: string = options ? (options.check || options.c) : null
if (checkOption) {
const { http } = context
Expand Down
64 changes: 42 additions & 22 deletions src/extensions/functions/getSolidaritySettings.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,58 @@
import { SolidarityRunContext, SolidaritySettings } from '../../types'
import { SolidarityRunContext, SolidaritySettings, solidarity } from '../../types'
import * as JSON5 from 'json5'
import * as path from 'path'

export const loadFile = (context, filePath) => {
const { filesystem } = context
if (filesystem.exists(filePath)) {
return JSON5.parse(filesystem.read('.solidarity'))
} else {
throw 'ERROR: There is no solidarity file at the given path'
}
}

export const loadModule = (context, moduleName) => {
const { filesystem } = context
// We will search that module
const filePath = path.join('node_modules', moduleName, '.solidarity')

if (filesystem.exists(filePath)) {
return JSON5.parse(filesystem.read(filePath))
} else if (filesystem.exists(filePath + '.json')) {
return JSON5.parse(filesystem.read(filePath + '.json'))
} else {
throw 'ERROR: There is no solidarity file found with the given module'
}
}

export const loadWebCheck = (context, checkStack) => {

}

export const loadDefault = () => {

}

module.exports = (context: SolidarityRunContext): SolidaritySettings => {
const { filesystem, parameters } = context
const options = parameters.options || {} // fix possibly undefined from gluegun
const demandedFile = options.solidarityFile || options.f
const demandedModule = options.module || options.m
const demandedCheck = options.check || options.c

/* for now only JSON and JSON5 support
* Summary:
* Looks for `.solidarity` or `.solidarity.json` files
* Unless you pass parameter options telling us to look
* in specific paths or node modules
* in specific paths, node modules, or websites
*/
let solidaritySettings
if (options.solidarityFile || options.f) {
// They are telling us where to go
const filePath = options.solidarityFile || options.f
if (filesystem.exists(filePath)) {
solidaritySettings = JSON5.parse(filesystem.read('.solidarity'))
} else {
throw 'ERROR: There is no solidarity file at the given path'
}
} else if (options.module || options.m) {
// We will search that module
const moduleName = options.module || options.m
const filePath = path.join('node_modules', moduleName, '.solidarity')

if (filesystem.exists(filePath)) {
solidaritySettings = JSON5.parse(filesystem.read(filePath))
} else if (filesystem.exists(filePath + '.json')) {
solidaritySettings = JSON5.parse(filesystem.read(filePath + '.json'))
} else {
throw 'ERROR: There is no solidarity file found with the given module'
}
if (demandedFile) {
solidaritySettings = loadFile(context, demandedFile)
} else if (demandedModule) {
solidaritySettings = loadModule(context, demandedModule)
} else if (demandedCheck) {
solidaritySettings = loadWebCheck(context, demandedCheck)
} else if (filesystem.exists('.solidarity')) {
solidaritySettings = JSON5.parse(filesystem.read('.solidarity'))
} else if (filesystem.exists('.solidarity.json')) {
Expand Down

0 comments on commit 97b4460

Please sign in to comment.