From ee102dc12175d537f770f78b60fdc6598f295c56 Mon Sep 17 00:00:00 2001 From: David Chambers Date: Fri, 11 Aug 2017 14:56:58 +0200 Subject: [PATCH] derive index.js and index.d.ts from canonical list of method names --- CONTRIBUTING.md | 7 +++++++ index.d.ts | 22 ++++++++++++++++++++++ names | 22 ++++++++++++++++++++++ package.json | 4 ++++ scripts/generate-js | 21 +++++++++++++++++++++ scripts/generate-ts | 4 ++++ scripts/lint | 7 +++++++ 7 files changed, 87 insertions(+) create mode 100644 index.d.ts create mode 100644 names create mode 100755 scripts/generate-js create mode 100755 scripts/generate-ts create mode 100755 scripts/lint diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4e6450b..5434cf0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,3 +2,10 @@ Additions and modifications to the specification are best proposed in issues. If there is support for a proposal, the next step is to submit a pull request. + +When adding a type class to __README.md__, please update __names__ then run: + +```console +$ npm run generate-js +$ npm run generate-ts +``` diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..81e3abe --- /dev/null +++ b/index.d.ts @@ -0,0 +1,22 @@ +export const equals: 'fantasy-land/equals'; +export const lte: 'fantasy-land/lte'; +export const compose: 'fantasy-land/compose'; +export const id: 'fantasy-land/id'; +export const concat: 'fantasy-land/concat'; +export const empty: 'fantasy-land/empty'; +export const invert: 'fantasy-land/invert'; +export const filter: 'fantasy-land/filter'; +export const map: 'fantasy-land/map'; +export const contramap: 'fantasy-land/contramap'; +export const ap: 'fantasy-land/ap'; +export const of: 'fantasy-land/of'; +export const alt: 'fantasy-land/alt'; +export const zero: 'fantasy-land/zero'; +export const reduce: 'fantasy-land/reduce'; +export const traverse: 'fantasy-land/traverse'; +export const chain: 'fantasy-land/chain'; +export const chainRec: 'fantasy-land/chainRec'; +export const extend: 'fantasy-land/extend'; +export const extract: 'fantasy-land/extract'; +export const bimap: 'fantasy-land/bimap'; +export const promap: 'fantasy-land/promap'; diff --git a/names b/names new file mode 100644 index 0000000..5419268 --- /dev/null +++ b/names @@ -0,0 +1,22 @@ +equals +lte +compose +id +concat +empty +invert +filter +map +contramap +ap +of +alt +zero +reduce +traverse +chain +chainRec +extend +extract +bimap +promap diff --git a/package.json b/package.json index 35995a9..07df67d 100644 --- a/package.json +++ b/package.json @@ -29,12 +29,16 @@ "files": [ "/LICENSE", "/README.md", + "/index.d.ts", "/index.js", "/package.json" ], "main": "index.js", + "types": "index.d.ts", "scripts": { "doctest": "sanctuary-doctest", + "generate-js": "scripts/generate-js", + "generate-ts": "scripts/generate-ts", "lint": "sanctuary-lint", "release": "sanctuary-release", "test": "npm run lint && sanctuary-test && npm run doctest" diff --git a/scripts/generate-js b/scripts/generate-js new file mode 100755 index 0000000..0bbfa71 --- /dev/null +++ b/scripts/generate-js @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euf -o pipefail + +cat >index.js < 1 ? ",\n " : "") $0 ": \047fantasy-land/" $0 "\047" }' names) + }; + + /* istanbul ignore else */ + if (typeof module === 'object' && typeof module.exports === 'object') { + module.exports = mapping; + } else { + self.FantasyLand = mapping; + } + +} ()); +EOF diff --git a/scripts/generate-ts b/scripts/generate-ts new file mode 100755 index 0000000..b13fc93 --- /dev/null +++ b/scripts/generate-ts @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -euf -o pipefail + +awk '{ print "export const " $0 ": \047fantasy-land/" $0 "\047;" }' names >index.d.ts diff --git a/scripts/lint b/scripts/lint new file mode 100755 index 0000000..f2c01b8 --- /dev/null +++ b/scripts/lint @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euf -o pipefail + +node_modules/.bin/sanctuary-lint "$@" + +scripts/generate-js && git diff --exit-code index.js +scripts/generate-ts && git diff --exit-code index.d.ts