@form8ion/javascript-core
Advanced tools
Comparing version 1.2.0 to 1.3.0-alpha.1
@@ -8,6 +8,24 @@ 'use strict'; | ||
var deepmerge = _interopDefault(require('deepmerge')); | ||
var mochaScaffolder = require('@form8ion/mocha-scaffolder'); | ||
var hoek = _interopDefault(require('@hapi/hoek')); | ||
var fs = require('fs'); | ||
var joi = require('@hapi/joi'); | ||
var inquirer = require('inquirer'); | ||
var overridablePrompts = require('@form8ion/overridable-prompts'); | ||
function scaffoldFrameworkChoice (choices, choice, options) { | ||
const type = choices[choice]; | ||
if (type) return type.scaffolder(options); | ||
return {scripts: {}, dependencies: [], devDependencies: [], vcsIgnore: {files: [], directories: []}}; | ||
} | ||
function validate (schema, options) { | ||
const {error, value} = schema.validate(options); | ||
hoek.assert(!error, error); | ||
return value; | ||
} | ||
async function scaffoldNyc ({projectRoot, vcs, visibility}) { | ||
@@ -39,5 +57,31 @@ await fs.promises.writeFile( | ||
async function unit ({projectRoot, visibility, vcs}) { | ||
const [mocha, nyc] = await Promise.all([mochaScaffolder.scaffold({projectRoot}), scaffoldNyc({projectRoot, vcs, visibility})]); | ||
const unitTestFrameworksSchema = joi.object().required().pattern(/^/, joi.object({ | ||
scaffolder: joi.func().arity(1).required() | ||
})); | ||
const questionNames = { | ||
UNIT_TEST_FRAMEWORK: 'unitTestFramework' | ||
}; | ||
async function chooseFramework ({frameworks, decisions}) { | ||
if (!Object.keys(frameworks).length) return 'Other'; | ||
const answers = await overridablePrompts.prompt([{ | ||
name: questionNames.UNIT_TEST_FRAMEWORK, | ||
type: 'list', | ||
message: 'Which type of unit testing framework should be used?', | ||
choices: [...Object.keys(frameworks), new inquirer.Separator(), 'Other'] | ||
}], decisions); | ||
return answers[questionNames.UNIT_TEST_FRAMEWORK]; | ||
} | ||
async function unit ({projectRoot, frameworks, decisions, visibility, vcs}) { | ||
const validatedFrameworks = validate(unitTestFrameworksSchema, frameworks); | ||
const [framework, nyc] = await Promise.all([ | ||
chooseFramework({frameworks: validatedFrameworks, decisions}) | ||
.then(chosenFramework => scaffoldFrameworkChoice(validatedFrameworks, chosenFramework, {projectRoot})), | ||
scaffoldNyc({projectRoot, vcs, visibility}) | ||
]); | ||
return deepmerge.all([ | ||
@@ -51,3 +95,3 @@ { | ||
}, | ||
mocha, | ||
framework, | ||
nyc | ||
@@ -57,17 +101,5 @@ ]); | ||
function choiceScaffolder (choices, choice, options) { | ||
const type = choices[choice]; | ||
if (type) return type.scaffolder(options); | ||
return {scripts: {}, dependencies: [], devDependencies: [], vcsIgnore: {files: [], directories: []}}; | ||
} | ||
const unitTesting = joi.object().required().pattern(/^/, joi.object({ | ||
scaffolder: joi.func().arity(1).required() | ||
})); | ||
exports.scaffoldChoice = choiceScaffolder; | ||
exports.scaffoldChoice = scaffoldFrameworkChoice; | ||
exports.scaffoldUnitTesting = unit; | ||
exports.unitTestFrameworksSchema = unitTesting; | ||
exports.unitTestFrameworksSchema = unitTestFrameworksSchema; | ||
//# sourceMappingURL=index.cjs.js.map |
import deepmerge from 'deepmerge'; | ||
import { scaffold } from '@form8ion/mocha-scaffolder'; | ||
import hoek from '@hapi/hoek'; | ||
import { promises } from 'fs'; | ||
import { object, func } from '@hapi/joi'; | ||
import { Separator } from 'inquirer'; | ||
import { prompt } from '@form8ion/overridable-prompts'; | ||
function scaffoldFrameworkChoice (choices, choice, options) { | ||
const type = choices[choice]; | ||
if (type) return type.scaffolder(options); | ||
return {scripts: {}, dependencies: [], devDependencies: [], vcsIgnore: {files: [], directories: []}}; | ||
} | ||
function validate (schema, options) { | ||
const {error, value} = schema.validate(options); | ||
hoek.assert(!error, error); | ||
return value; | ||
} | ||
async function scaffoldNyc ({projectRoot, vcs, visibility}) { | ||
@@ -32,5 +50,31 @@ await promises.writeFile( | ||
async function unit ({projectRoot, visibility, vcs}) { | ||
const [mocha, nyc] = await Promise.all([scaffold({projectRoot}), scaffoldNyc({projectRoot, vcs, visibility})]); | ||
const unitTestFrameworksSchema = object().required().pattern(/^/, object({ | ||
scaffolder: func().arity(1).required() | ||
})); | ||
const questionNames = { | ||
UNIT_TEST_FRAMEWORK: 'unitTestFramework' | ||
}; | ||
async function chooseFramework ({frameworks, decisions}) { | ||
if (!Object.keys(frameworks).length) return 'Other'; | ||
const answers = await prompt([{ | ||
name: questionNames.UNIT_TEST_FRAMEWORK, | ||
type: 'list', | ||
message: 'Which type of unit testing framework should be used?', | ||
choices: [...Object.keys(frameworks), new Separator(), 'Other'] | ||
}], decisions); | ||
return answers[questionNames.UNIT_TEST_FRAMEWORK]; | ||
} | ||
async function unit ({projectRoot, frameworks, decisions, visibility, vcs}) { | ||
const validatedFrameworks = validate(unitTestFrameworksSchema, frameworks); | ||
const [framework, nyc] = await Promise.all([ | ||
chooseFramework({frameworks: validatedFrameworks, decisions}) | ||
.then(chosenFramework => scaffoldFrameworkChoice(validatedFrameworks, chosenFramework, {projectRoot})), | ||
scaffoldNyc({projectRoot, vcs, visibility}) | ||
]); | ||
return deepmerge.all([ | ||
@@ -44,3 +88,3 @@ { | ||
}, | ||
mocha, | ||
framework, | ||
nyc | ||
@@ -50,15 +94,3 @@ ]); | ||
function choiceScaffolder (choices, choice, options) { | ||
const type = choices[choice]; | ||
if (type) return type.scaffolder(options); | ||
return {scripts: {}, dependencies: [], devDependencies: [], vcsIgnore: {files: [], directories: []}}; | ||
} | ||
const unitTesting = object().required().pattern(/^/, object({ | ||
scaffolder: func().arity(1).required() | ||
})); | ||
export { choiceScaffolder as scaffoldChoice, unit as scaffoldUnitTesting, unitTesting as unitTestFrameworksSchema }; | ||
export { scaffoldFrameworkChoice as scaffoldChoice, unit as scaffoldUnitTesting, unitTestFrameworksSchema }; | ||
//# sourceMappingURL=index.es.js.map |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "1.2.0", | ||
"version": "1.3.0-alpha.1", | ||
"files": [ | ||
@@ -8,0 +8,0 @@ "example.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
29337
178
1