Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@form8ion/javascript-core

Package Overview
Dependencies
Maintainers
2
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@form8ion/javascript-core - npm Package Compare versions

Comparing version 3.1.0 to 4.0.0

19

example.js

@@ -8,9 +8,3 @@ // #### Import

const {
scaffoldUnitTesting,
scaffoldChoice,
installDependencies,
PROD_DEPENDENCY_TYPE,
questionNames
} = require('./lib/index.cjs');
const {scaffoldChoice, installDependencies, PROD_DEPENDENCY_TYPE} = require('./lib/index.cjs');

@@ -23,13 +17,2 @@ // remark-usage-ignore-next

(async () => {
await scaffoldUnitTesting({
projectRoot: process.cwd(),
frameworks: {
Mocha: {scaffolder: options => options},
Jest: {scaffolder: options => options}
},
visibility: 'Public',
vcs: {host: 'GitHub', owner: 'foo', name: 'bar'},
decisions: {[questionNames.UNIT_TEST_FRAMEWORK]: 'Mocha'}
});
await scaffoldChoice(

@@ -36,0 +19,0 @@ {foo: {scaffolder: options => options}},

@@ -5,37 +5,12 @@ 'use strict';

var deepmerge = require('deepmerge');
var hoek = require('@hapi/hoek');
var fs = require('fs');
var joi = require('@hapi/joi');
var inquirer = require('inquirer');
var overridablePrompts = require('@form8ion/overridable-prompts');
var cliMessages = require('@travi/cli-messages');
var execa = require('execa');
var hoek = require('@hapi/hoek');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var deepmerge__default = /*#__PURE__*/_interopDefaultLegacy(deepmerge);
var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
var hoek__default = /*#__PURE__*/_interopDefaultLegacy(hoek);
var joi__namespace = /*#__PURE__*/_interopNamespace(joi);
var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
function scaffoldFrameworkChoice (choices, choice, options) {
function choiceScaffolder (choices, choice, options) {
const type = choices[choice];

@@ -54,172 +29,2 @@ if (type) return type.scaffolder(options);

function validate (schema, options) {
const {
error,
value
} = schema.validate(options);
hoek__default["default"].assert(!error, error);
return value;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function scaffold({
vcs,
visibility
}) {
if ('Public' !== visibility) {
return {};
}
return _objectSpread2({
devDependencies: ['codecov'],
scripts: {
'coverage:report': 'nyc report --reporter=text-lcov > coverage.lcov && codecov'
}
}, ['github', 'gitlab', 'bitbucket'].includes(vcs === null || vcs === void 0 ? void 0 : vcs.host) && {
badges: {
status: {
coverage: {
img: `https://img.shields.io/codecov/c/${vcs.host}/${vcs.owner}/${vcs.name}.svg`,
link: `https://codecov.io/${vcs.host}/${vcs.owner}/${vcs.name}`,
text: 'Codecov'
}
}
}
});
}
async function scaffoldNyc ({
projectRoot
}) {
await fs.promises.writeFile(`${projectRoot}/.nycrc`, JSON.stringify({
extends: '@istanbuljs/nyc-config-babel',
reporter: ['lcov', 'text-summary', 'html'],
exclude: ['src/**/*-test.js', 'test/', 'thirdparty-wrappers/', 'vendor/']
}));
return {
devDependencies: ['cross-env', 'nyc', '@istanbuljs/nyc-config-babel'],
vcsIgnore: {
files: [],
directories: ['/coverage/', '/.nyc_output/']
},
eslint: {
ignore: {
directories: ['/coverage/']
}
}
};
}
async function scaffoldCoverage ({
projectRoot,
vcs,
visibility
}) {
return deepmerge__default["default"](await scaffoldNyc({
projectRoot
}), scaffold({
vcs,
visibility
}));
}
const unitTestFrameworksSchema = joi__namespace.object().required().pattern(/^/, joi__namespace.object({
scaffolder: joi__namespace.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, coverage] = await Promise.all([chooseFramework({
frameworks: validatedFrameworks,
decisions
}).then(chosenFramework => scaffoldFrameworkChoice(validatedFrameworks, chosenFramework, {
projectRoot
})), scaffoldCoverage({
projectRoot,
vcs,
visibility
})]);
return deepmerge__default["default"].all([{
scripts: {
'test:unit': 'cross-env NODE_ENV=test nyc run-s test:unit:base'
}
}, framework, coverage]);
}
const DEV_DEPENDENCY_TYPE = 'dev';

@@ -272,2 +77,11 @@ const PROD_DEPENDENCY_TYPE = 'prod';

function optionsValidator (schema, options) {
const {
error,
value
} = schema.validate(options);
hoek__default["default"].assert(!error, error);
return value;
}
const projectTypes = {

@@ -284,6 +98,2 @@ APPLICATION: 'Application',

function shouldBeReported(visibility, tests) {
return 'Public' === visibility && tests.unit;
}
var dialects = {

@@ -298,3 +108,2 @@ COMMON_JS: 'common-js',

exports.PROD_DEPENDENCY_TYPE = PROD_DEPENDENCY_TYPE;
exports.coverageShouldBeReported = shouldBeReported;
exports.dialects = dialects;

@@ -305,7 +114,4 @@ exports.installDependencies = install;

exports.projectTypes = projectTypes;
exports.questionNames = questionNames;
exports.scaffoldChoice = scaffoldFrameworkChoice;
exports.scaffoldUnitTesting = unit;
exports.unitTestFrameworksSchema = unitTestFrameworksSchema;
exports.validateOptions = validate;
exports.scaffoldChoice = choiceScaffolder;
exports.validateOptions = optionsValidator;
//# sourceMappingURL=index.cjs.js.map

@@ -1,11 +0,6 @@

import deepmerge from 'deepmerge';
import hoek from '@hapi/hoek';
import { promises } from 'fs';
import * as joi from '@hapi/joi';
import { Separator } from 'inquirer';
import { prompt } from '@form8ion/overridable-prompts';
import { info, warn } from '@travi/cli-messages';
import execa from 'execa';
import hoek from '@hapi/hoek';
function scaffoldFrameworkChoice (choices, choice, options) {
function choiceScaffolder (choices, choice, options) {
const type = choices[choice];

@@ -24,172 +19,2 @@ if (type) return type.scaffolder(options);

function validate (schema, options) {
const {
error,
value
} = schema.validate(options);
hoek.assert(!error, error);
return value;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function scaffold({
vcs,
visibility
}) {
if ('Public' !== visibility) {
return {};
}
return _objectSpread2({
devDependencies: ['codecov'],
scripts: {
'coverage:report': 'nyc report --reporter=text-lcov > coverage.lcov && codecov'
}
}, ['github', 'gitlab', 'bitbucket'].includes(vcs === null || vcs === void 0 ? void 0 : vcs.host) && {
badges: {
status: {
coverage: {
img: `https://img.shields.io/codecov/c/${vcs.host}/${vcs.owner}/${vcs.name}.svg`,
link: `https://codecov.io/${vcs.host}/${vcs.owner}/${vcs.name}`,
text: 'Codecov'
}
}
}
});
}
async function scaffoldNyc ({
projectRoot
}) {
await promises.writeFile(`${projectRoot}/.nycrc`, JSON.stringify({
extends: '@istanbuljs/nyc-config-babel',
reporter: ['lcov', 'text-summary', 'html'],
exclude: ['src/**/*-test.js', 'test/', 'thirdparty-wrappers/', 'vendor/']
}));
return {
devDependencies: ['cross-env', 'nyc', '@istanbuljs/nyc-config-babel'],
vcsIgnore: {
files: [],
directories: ['/coverage/', '/.nyc_output/']
},
eslint: {
ignore: {
directories: ['/coverage/']
}
}
};
}
async function scaffoldCoverage ({
projectRoot,
vcs,
visibility
}) {
return deepmerge(await scaffoldNyc({
projectRoot
}), scaffold({
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 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, coverage] = await Promise.all([chooseFramework({
frameworks: validatedFrameworks,
decisions
}).then(chosenFramework => scaffoldFrameworkChoice(validatedFrameworks, chosenFramework, {
projectRoot
})), scaffoldCoverage({
projectRoot,
vcs,
visibility
})]);
return deepmerge.all([{
scripts: {
'test:unit': 'cross-env NODE_ENV=test nyc run-s test:unit:base'
}
}, framework, coverage]);
}
const DEV_DEPENDENCY_TYPE = 'dev';

@@ -242,2 +67,11 @@ const PROD_DEPENDENCY_TYPE = 'prod';

function optionsValidator (schema, options) {
const {
error,
value
} = schema.validate(options);
hoek.assert(!error, error);
return value;
}
const projectTypes = {

@@ -254,6 +88,2 @@ APPLICATION: 'Application',

function shouldBeReported(visibility, tests) {
return 'Public' === visibility && tests.unit;
}
var dialects = {

@@ -266,3 +96,3 @@ COMMON_JS: 'common-js',

export { DEV_DEPENDENCY_TYPE, PROD_DEPENDENCY_TYPE, shouldBeReported as coverageShouldBeReported, dialects, install as installDependencies, packageManagers, shouldBePublished as projectTypeShouldBePublished, projectTypes, questionNames, scaffoldFrameworkChoice as scaffoldChoice, unit as scaffoldUnitTesting, unitTestFrameworksSchema, validate as validateOptions };
export { DEV_DEPENDENCY_TYPE, PROD_DEPENDENCY_TYPE, dialects, install as installDependencies, packageManagers, shouldBePublished as projectTypeShouldBePublished, projectTypes, choiceScaffolder as scaffoldChoice, optionsValidator as validateOptions };
//# sourceMappingURL=index.es.js.map

8

package.json

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "3.1.0",
"version": "4.0.0",
"files": [

@@ -48,3 +48,3 @@ "example.js",

"@form8ion/babel-preset": "1.6.71",
"@form8ion/commitlint-config": "1.0.21",
"@form8ion/commitlint-config": "1.0.22",
"@form8ion/eslint-config": "1.8.5",

@@ -69,6 +69,6 @@ "@form8ion/eslint-config-mocha": "1.2.12",

"rimraf": "3.0.2",
"rollup": "2.58.3",
"rollup": "2.59.0",
"rollup-plugin-auto-external": "2.0.0",
"sinon": "11.1.2",
"testdouble": "3.16.2"
"testdouble": "3.16.3"
},

@@ -75,0 +75,0 @@ "dependencies": {

@@ -1,2 +0,2 @@

# javascript-core
coverageShouldBeReported# javascript-core

@@ -25,9 +25,5 @@ core logic for form8ion tools related to JavaScript, like

* [`options` __object__ (_optional_)](#options-object-optional)
* [`scaffoldUnitTesting`](#scaffoldunittesting)
* [`projectRoot` __string__ (_required_)](#projectroot-string-required)
* [`frameworks` __object__ (_required_)](#frameworks-object-required)
* [`decisions` __object__ (_optional_)](#decisions-object-optional)
* [`visibility` __string__ (_required_)](#visibility-string-required)
* [`vcs` __object__ (_required_)](#vcs-object-required)
* [`unitTestFrameworksSchema`](#unittestframeworksschema)
* [`validateOptions`](#validateoptions)
* [`schema` (_required_)](#schema-required)
* [`options` (_required_)](#options-required)
* [`installDependencies`](#installdependencies)

@@ -39,3 +35,2 @@ * [`dependencies` __list of strings__ (_required_)](#dependencies-list-of-strings-required)

* [Dependency-types Constants](#dependency-types-constants)
* [`questionNames`](#questionnames)
* [`projectTypes`](#projecttypes)

@@ -46,3 +41,3 @@ * [`packageManagers`](#packagemanagers)

* [`coverageShouldBeReported`](#coverageshouldbereported)
* [`visibility` __string__ (_required_)](#visibility-string-required-1)
* [`visibility` __string__ (_required_)](#visibility-string-required)
* [`tests` __object__ (_required_)](#tests-object-required)

@@ -75,9 +70,3 @@ * [Contributing](#contributing)

```javascript
const {
scaffoldUnitTesting,
scaffoldChoice,
installDependencies,
PROD_DEPENDENCY_TYPE,
questionNames
} = require('./lib/index.cjs');
const {scaffoldChoice, installDependencies, PROD_DEPENDENCY_TYPE} = require('./lib/index.cjs');
```

@@ -89,13 +78,2 @@

(async () => {
await scaffoldUnitTesting({
projectRoot: process.cwd(),
frameworks: {
Mocha: {scaffolder: options => options},
Jest: {scaffolder: options => options}
},
visibility: 'Public',
vcs: {host: 'GitHub', owner: 'foo', name: 'bar'},
decisions: {[questionNames.UNIT_TEST_FRAMEWORK]: 'Mocha'}
});
await scaffoldChoice(

@@ -146,43 +124,2 @@ {foo: {scaffolder: options => options}},

#### `scaffoldUnitTesting`
Scaffolder for enabling unit-testing in a project with the ability to choose a
desired framework from provided options.
Takes a single options object as an argument, containing:
##### `projectRoot` __string__ (_required_)
path to the root of the project
##### `frameworks` __object__ (_required_)
A [`choices` object](#choices-object-required) for defining
[unit-testing framework options](https://github.com/form8ion/awesome#unit-testing-frameworks)
##### `decisions` __object__ (_optional_)
Answers for prompt questions so that the prompt is skipped at execution time
* keys: __string__ Name of the prompt question
* values: Hard-coded answer for the prompt question
##### `visibility` __string__ (_required_)
visibility of the project (`Public` or `Private`)
##### `vcs` __object__ (_required_)
* `host` __string__ (_required_)
VCS hosting service
* `owner` __string__ (_required_)
account name on the host service for the repository
* `name` __string__ (_required_)
repository name
#### `unitTestFrameworksSchema`
[joi](https://hapi.dev/module/joi/) schema for the choices required for the
[unit-testing scaffolder](#scaffoldunittesting)
#### `installDependencies`

@@ -220,7 +157,2 @@

#### `questionNames`
Constants defining the question names for the prompts implemented in this
package
#### `projectTypes`

@@ -227,0 +159,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc