effects-as-data-generate
Advanced tools
Comparing version 2.1.2 to 2.2.0
const c = require('case'); | ||
const actions = require('../actions'); | ||
const {getSettings} = require('./get-settings'); | ||
const {failure, isFailure, success} = require('effects-as-data'); | ||
const { getSettings } = require('./get-settings'); | ||
const { failure, isFailure, success } = require('effects-as-data'); | ||
const path = require('path'); | ||
const {replace, pipe, merge, toPairs, map, values} = require('ramda'); | ||
const { replace, pipe, merge, toPairs, map, values } = require('ramda'); | ||
function* newFn(fn) { | ||
if (!fn) return failure('A function name is required.'); | ||
const $settings = yield actions.call(getSettings); | ||
@@ -18,3 +19,3 @@ if (isFailure($settings)) return $settings; | ||
fileName, | ||
settings: $settings.payload, | ||
settings: $settings.payload | ||
}); | ||
@@ -27,3 +28,3 @@ if (isFailure($fnWriteResult)) return $fnWriteResult; | ||
fileName, | ||
settings: $settings.payload, | ||
settings: $settings.payload | ||
}); | ||
@@ -35,3 +36,3 @@ if (isFailure($specWriteResult)) return $specWriteResult; | ||
fileName, | ||
settings: $settings.payload, | ||
settings: $settings.payload | ||
}); | ||
@@ -41,10 +42,10 @@ if (isFailure($writeIndexResult)) return $writeIndexResult; | ||
return success({ | ||
message: `${fn}() has been created.\nPath: ${$settings.payload.functionsPath}/${fileName}.js`, | ||
message: `${fn}() has been created.\nPath: ${$settings.payload.functionsPath}/${fileName}.js` | ||
}); | ||
} | ||
function* writeFunction({nameCamel, fileName, settings}) { | ||
function* writeFunction({ nameCamel, fileName, settings }) { | ||
const $functionTemplate = yield actions.readFile( | ||
path.join(__dirname, '../../templates/fn.js.txt'), | ||
{encoding: 'utf8'} | ||
{ encoding: 'utf8' } | ||
); | ||
@@ -60,10 +61,10 @@ if (isFailure($functionTemplate)) return $functionTemplate; | ||
functionText, | ||
{encoding: 'utf8'} | ||
{ encoding: 'utf8' } | ||
); | ||
} | ||
function* writeSpec({nameCamel, namePascal, fileName, settings}) { | ||
function* writeSpec({ nameCamel, namePascal, fileName, settings }) { | ||
const $specTemplate = yield actions.readFile( | ||
path.join(__dirname, '../../templates/spec.js.txt'), | ||
{encoding: 'utf8'} | ||
{ encoding: 'utf8' } | ||
); | ||
@@ -79,9 +80,9 @@ if (isFailure($specTemplate)) return $specTemplate; | ||
specText, | ||
{encoding: 'utf8'} | ||
{ encoding: 'utf8' } | ||
); | ||
} | ||
function* writeIndex({fileName, fn, settings}) { | ||
function* writeIndex({ fileName, fn, settings }) { | ||
const indexPath = path.join(settings.functionsPath, '.eadindex'); | ||
const $index = yield actions.readFile(indexPath, {encoding: 'utf8'}); | ||
const $index = yield actions.readFile(indexPath, { encoding: 'utf8' }); | ||
if (isFailure($index)) return $index; | ||
@@ -91,7 +92,7 @@ const $functionsIndex = yield actions.jsonParse($index.payload); | ||
const updatedFunctionsIndex = merge($functionsIndex.payload, { | ||
[fileName]: fn, | ||
[fileName]: fn | ||
}); | ||
const indexString = JSON.stringify(updatedFunctionsIndex); | ||
const $writeResult = yield actions.writeFile(indexPath, indexString, { | ||
encoding: 'utf8', | ||
encoding: 'utf8' | ||
}); | ||
@@ -101,7 +102,7 @@ if (isFailure($writeResult)) return $writeResult; | ||
functionsPath: settings.functionsPath, | ||
functionsIndex: updatedFunctionsIndex, | ||
functionsIndex: updatedFunctionsIndex | ||
}); | ||
} | ||
function* writeFnIndex({functionsIndex, functionsPath}) { | ||
function* writeFnIndex({ functionsIndex, functionsPath }) { | ||
const pairs = toPairs(functionsIndex); | ||
@@ -120,3 +121,3 @@ const requires = map( | ||
{ | ||
encoding: 'utf8', | ||
encoding: 'utf8' | ||
} | ||
@@ -128,3 +129,3 @@ ); | ||
module.exports = { | ||
newFn, | ||
newFn | ||
}; |
const program = require('commander'); | ||
const fxns = require('./effects'); | ||
const chalk = require('chalk'); | ||
const {failure, isFailure} = require('effects-as-data'); | ||
const { failure, isFailure } = require('effects-as-data'); | ||
@@ -11,3 +11,4 @@ program.version('0.0.1').command('init').action(function() { | ||
program.version('0.0.1').command('fn').action(function(fn) { | ||
fxns.newFn(fn).then(printResult).catch(printFailure); | ||
const fnName = typeof fn === 'string' ? fn : null; | ||
fxns.newFn(fnName).then(printResult).catch(printFailure); | ||
}); | ||
@@ -14,0 +15,0 @@ |
{ | ||
"name": "effects-as-data-generate", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10651
21
267