README
coverageShouldBeReported# javascript-core
core logic for form8ion tools related to JavaScript, like javascript-scaffolder and lift-javascript
Table of Contents
- Usage
- Contributing
Usage
Installation
$ npm install @form8ion/javascript-core --save-prod
Example
Import
const {scaffoldChoice, installDependencies, PROD_DEPENDENCY_TYPE} = require('./lib/index.cjs');
Execute
(async () => {
await scaffoldChoice(
{foo: {scaffolder: options => options}},
'foo',
{bar: 'baz'}
);
await installDependencies(['foo', 'bar'], PROD_DEPENDENCY_TYPE);
})();
API
scaffoldChoice
A generic function that executes the scaffolder
function from a provided map
of options based on the chosen option name.
Takes three unnamed arguments:
object (required) choices
- keys: string Name of the choice
- values: object
scaffolder
: function (required) scaffolds the choice options
string (required) choice
Name of the choice. SHOULD match a key from the choices
object.
object (optional) options
options object to be passed as the only argument to the chosen scaffolder
validateOptions
Validates provided options against a joi schema.
(required) schema
joi schema
(required) options
options to compare to the provided schema
installDependencies
A function that installs the provided package dependencies.
Takes four unnamed arguments:
list of strings (required) dependencies
The list of package names to be installed.
string (required) dependenciesType
Defines if the provided list of package names should be installed as prod or
dev dependencies. If "dev" is provided, the list will be installed with the
--save-exact
flag.
string (optional) projectRoot
Filesystem path to the root of the project
string (optional) packageManger
Specifies the name of the package manager to be used for dependency
installation. Defaults to npm
Dependency-types Constants
Constants to define the valid options for dependenciesType
PROD_DEPENDENCY_TYPE
DEV_DEPENDENCY_TYPE
projectTypes
Constants defining the types of possible JavaScript projects
APPLICATION
PACKAGE
CLI
packageManagers
Constants defining the available package managers
NPM
YARN
dialects
Constants defining the available JavaScript source dialects
COMMON_JS
BABEL
ESM
TYPESCRIPT
projectTypeShouldBePublished
Predicate function to determine if the project-type is one that should be published
Takes one argument:
string (required) projectType
Should be one of the project-type options
coverageShouldBeReported
Predicate function to determine if coverage should be reported
Takes two arguments:
string (required) visibility
visibility of the project (Public
or Private
)
object (required) tests
unit
boolean (optional) Whether the project will be unit-tested
Contributing
Dependencies
$ nvm install
$ npm install
Verification
$ npm test