Giter VIP home page Giter VIP logo

seneca-maintain's Introduction

Seneca

Run standardisation tests on your Seneca.js plugin.

seneca-maintain

Voxgig This open source module is sponsored and supported by Voxgig.

This module is designed for contributors to the Seneca family of plugins. If you wish, you may make use of this to scan your own plugin prior to publishing to see if it meets our standardisation specifications.

If you're using this module, and need help, you can:

If you are new to Seneca in general, please take a look at senecajs.org. We have everything from tutorials to sample apps to help get you up and running quickly.

Install

npm install -D @seneca/maintain

Run the above command from your plugin's root directory to install this tool. The -D flag (alternatively --save-dev) marks it as a devDependency - meaning it is used during development and not as part of production.

Check out the official docs on dependencies and devDependencies here.

Quick Example

const { Maintain } = require('@seneca/maintain')

Maintain()

This maintenance tool can be run alongside existing tests, by including the above code snippet within your test script (usually index.test.js or similar).

Run the script with Jest (see More Examples below), or simply with node and the path to your test file:

$ node <index.test.js>

On success, nothing will be printed to console, and the script will continue as normal. On a fail, the script will throw a custom error with details of what went wrong.

More Examples

Return pass/fail boolean

If you're only looking for a simplified output in the form of a boolean (all checks pass/at least one check has failed), then you only need to set the returnBool parameter to false.

let maintainBool = await Maintain({returnBool:true})

Specify path to run checks on

If for example you need to run the maintain tool on one directory from another, it's possible to specify a root path. This should be the top level of the local package to test, ie. where the package.json and README.md files reside. Note that it is possible to step up levels from the current path using the .. syntax. A forward slash must preceed any path.

await Maintain({runPath:'/../path/to/package'})

If this optional parameter is not defined, the tool will default to running from the directory it was launched from (process.cwd()).

Running Custom Check List

It is possible to run only a select few checks, or to exclude certain ones, by making use of the optional parameters for the Maintain() function - an include array and an exclude array.

include - If checks are denoted in this array, they will be the only checks run.

exclude - Any checks denoted in this array will be excluded from the run.

To make use of these functionalities, simply include an object as the argument for the Maintain function - the key being the name of the array, and the value being the array of check names itself.

// to only run the Code of Conduct checks
Maintain({ include: ['exist_codeconduct', 'version_codeconduct'] })

// to exclude the default branch check, but run every other check
Maintain({ exclude: ['check_default'] })

Using Jest testing framework

Using the standard tool as a test suite for Jest is simple - a one line addition to your test file is all you need. In order to make use of the custom include and exclude lists however, the function call must be wrapped in an async/await block.

import { Maintain } from '@seneca/maintain'

// Standard run
test('maintain', Maintain)

// With parameters
test('maintain', async () => {
  await Maintain({
    exclude: ['exist_codeconduct', 'version_codeconduct'],
  })
})

Configurations

Configurations are used to run additional checks based on the architecture of your specific plugin. At the moment, there are three configs - Base, JavaScript, and TypeScript. The base configuration is run by default, and the tool will apply language-specific configurations based on the language of your plugin. No action on your part is necessary.

CLI Tool (coming soon)

$ cli-maintain

Sample output :

Total checks for this configuration: 8

Failed checks: 2
  exist_codeconduct (why: file not found)
  version_codeconduct (why: file not found)

Please refer to the README.md document for descriptions of all checks.
https://github.com/senecajs/seneca-maintain/blob/main/README.md

Check Descriptions

Name Description
check_default Your default branch should be named main, and not master.
content_readme Your README.md file should contain the word "Voxgig" somewhere in it. Voxgig are the sponsors and supporters of many Seneca modules and plugins.
content_gitignore Your .gitignore file should contain the string package-lock.json, as this file should not be shipped with production.
exist_codeconduct Your plugin should contain a CODE_OF_CONDUCT.md file at the top level. Please refer to Contributor Covenant for further details.
exist_dist This is a TypeScript configuration check. Your plugin should contain a top-level file named <plugin>.ts, where <plugin> matches "main": "dist/<plugin>.js" in your package.json. For example - a file named maintain.ts and a (package.json) main value of dist/maintain.js. Instances where <plugin> is equal to "index" are not accepted.
exist_entry This is a JavaScript configuration check. Your plugin should contain a top-level file named <plugin>.js, where <plugin> matches "main": "<plugin>.js" in your package.json. For example - a file named maintain.js and a (package.json) main value of maintain.js. Instances where <plugin> is equal to "index" are not accepted.
exist_license Your plugin should include a license file at the top level, simply named LICENSE - no file extension.
exist_pkgjson Your plugin should include a package.json file, at the top level. This check simply scans for its existence.
exist_readme Your plugin should contain a README.md file at the top level, named exactly README.md.
readme_title Your README.md file should contain a H1-level heading (denoted by a single hash (#) in Markdown), the value of which should be <package.name>, where <package.name> is the name taken from the "name" value in the package.json file.
readme_headings Your README.md file should contain at least eight H2-level headings (denoted by a double-hash (##) in Markdown). The names of these H2 headings should be the following (order need not be conserved): Install, Quick Example, More Examples, Motivation, Support, API, Contributing, Background.
scoped_package If your plugin is an official Seneca plugin and grouped under the SenecaJS GitHub organisation, then it must be scoped as such. For example - this module named senecajs/seneca-maintain is scoped as @seneca/maintain in the package.json file.
test_pkgjson Your package.json file should include a scripts.test key (a key named "test" nested within the "scripts" value). The value of this key is up to you.
version_codeconduct Your CODE_OF_CONDUCT.md file should contain the latest version of Contributor Covenant's Code of Conduct, as denoted here.

Motivation

Support

Check out our sponsors and supporters, Voxgig, on their website here.

API

No API functionality is currently shipped with this tool.

Contributing

The SenecaJS org encourages participation. If you feel you can help in any way, be it with bug reporting, documentation, examples, extra testing, or new features, feel free to create an issue, or better yet - submit a Pull Request. For more information on contribution, please see our Contributing Guide.

Background

Check out the SenecaJS roadmap here!

License

Licensed under MIT.

seneca-maintain's People

Contributors

rionastokes avatar rjrodger avatar beallaround avatar

Stargazers

 avatar

Watchers

James Cloos avatar seneca-bot avatar  avatar

seneca-maintain's Issues

Build fail - check_default failed (branch incorrect)

Hey @stokesriona,

In the repo all my tests passed, only the maintain one failed.

When I check to see the error, it says:

FAIL test/refer.test.ts
  refer
    ✓ happy (280 ms)
    ✓ basic.messages (577 ms)
    ✕ maintain (1075 ms)

  ● refer › maintain

    Failed Checks:

    check_default failed (branch incorrect)

      at runChecks (node_modules/@seneca/maintain/maintain.js:78:15)

However, looking into the seneca-maintain docs, it should't fail, right? As my default branch is named "main" and not "master".

Please, could you help me debug this?

`depth(0)` ignores `/dist` directory

There are going to be plugins where the main js file isn't at the top level dir. For example, if we have dist/notion-provider.js Seneca Maintain is gonna throw "entry not found" even though the file is there. This is because it doesn't actually see it because of the depth(0).

This also happens with Typescript source files in /src

Here is a suggested solution:

here: https://github.com/senecajs/seneca-maintain/blob/main/maintain.js#L133

use: .paths(process.cwd(), process.cwd() + '/dist', process.cwd() + '/src')

No need to set depth to 1 - that would be bug-prone.

here is some sort of pseudocode

subDirs = [ process.cwd() + '/dist', process.cwd() + '/src' ]
subDirs = subDirs.filter(dir => exists(dir) )

then
.paths(process.cwd(), ...subDirs )

Only runs from test directory

Module only runs correctly and as expected if node maintain.test.js is run from within a subdirectory (commonly a test dir)

  • node test/maintain.test.js as run from the top level directory causes the checks to run in the wrong directory (higher level dir)

Configs should be in function?

Should the definition of the configuration use function parameters in the maintain.test.js file as opposed to command line arguments when running node maintain.test.js <config>?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.