From 247c794e57e8eba4aec2529e14f41b7cc94573b8 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Thu, 23 Mar 2023 14:47:33 +0000 Subject: [PATCH] feat: use generated index to exclude from coverage Breaking Change Not really, but it feels like a good thing to draw a line under --- .github/workflows/validate.yml | 3 +++ .gitignore | 3 ++- package.json | 1 + scripts/build.cjs | 31 ++++++++++++++++++++++++++ src/classes/bit-mask.spec.ts | 2 +- src/classes/logger.spec.ts | 2 +- src/functions/address-object.spec.ts | 2 +- src/functions/array-move.spec.ts | 2 +- src/functions/array-selectors.spec.ts | 2 +- src/functions/async-for-each.spec.ts | 2 +- src/functions/async-map.spec.ts | 2 +- src/functions/cache-for.spec.ts | 2 +- src/functions/clamp.spec.ts | 2 +- src/functions/create-map.spec.ts | 2 +- src/functions/css.spec.ts | 2 +- src/functions/dates.spec.ts | 8 +++---- src/functions/deep-includes.spec.ts | 2 +- src/functions/defaults.spec.ts | 2 +- src/functions/diff-array.spec.ts | 2 +- src/functions/diff-object.spec.ts | 2 +- src/functions/grouped-by.spec.ts | 2 +- src/functions/if-fn.spec.ts | 2 +- src/functions/increment.spec.ts | 2 +- src/functions/indexed-by.spec.ts | 2 +- src/functions/invariant.spec.ts | 2 +- src/functions/is-env.spec.ts | 2 +- src/functions/keys.spec.ts | 2 +- src/functions/map-property.spec.ts | 2 +- src/functions/network.spec.ts | 2 +- src/functions/nl2br.spec.ts | 2 +- src/functions/parameterize.spec.ts | 2 +- src/functions/pick.spec.ts | 2 +- src/functions/range-as-string.spec.ts | 2 +- src/functions/reduce.spec.ts | 2 +- src/functions/replace-property.spec.ts | 2 +- src/functions/selectors.spec.ts | 2 +- src/functions/time.spec.ts | 2 +- src/functions/times.spec.ts | 2 +- src/functions/unique.spec.ts | 2 +- src/functions/value-or.spec.ts | 2 +- src/functions/wait-for.spec.ts | 2 +- 41 files changed, 77 insertions(+), 41 deletions(-) create mode 100644 scripts/build.cjs diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 25ffd11..fdbcbe4 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -84,6 +84,9 @@ jobs: path: lib key: lib-${{github.sha}} + - name: 🧙‍♂️ Build Index + run: npm run build:index + - name: 🏗 TypeScript run: npm run build diff --git a/.gitignore b/.gitignore index 539c0c1..ced4711 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ coverage/ node_modules/ -lib/ \ No newline at end of file +lib/ +src/index.ts \ No newline at end of file diff --git a/package.json b/package.json index 4d9bf1d..9dbfca2 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "test": "cross-env NODE_OPTIONS=--experimental-vm-modules kcd-scripts test --runInBand --detectOpenHandles", "lint": "kcd-scripts lint", "build": "tsc", + "build:index": "node ./scripts/build.cjs", "document": "typedoc --out ./docs --entryPoints src/index.ts --name Utils --readme Readme.md && echo utils.arcath.net > ./docs/CNAME", "validate": "kcd-scripts validate", "format": "kcd-scripts format" diff --git a/scripts/build.cjs b/scripts/build.cjs new file mode 100644 index 0000000..13006a9 --- /dev/null +++ b/scripts/build.cjs @@ -0,0 +1,31 @@ +const path = require('path') +const fs = require('fs') + +const FUNCTIONS = path.join(__dirname, '..', 'src', 'functions') +const CLASSES = path.join(__dirname, '..', 'src', 'classes') + +const INDEX = path.join(__dirname, '..', 'src', 'index.ts') + +const lines = [`// Automatically generated by ./scripts/build.cjs`, ''] + +fs.readdir(FUNCTIONS, (err, files) => { + files.forEach(file => { + if (file.match(`\.spec\.`)) { + return + } + + lines.push(`export * from './functions/${file.replace('.ts', '')}'`) + }) + + fs.readdir(CLASSES, (err, files) => { + files.forEach(file => { + if (file.match(`\.spec\.`)) { + return + } + + lines.push(`export * from './classes/${file.replace('.ts', '')}'`) + }) + + fs.writeFile(INDEX, lines.join(`\r\n`), err => {}) + }) +}) diff --git a/src/classes/bit-mask.spec.ts b/src/classes/bit-mask.spec.ts index 586202c..5f12d8b 100644 --- a/src/classes/bit-mask.spec.ts +++ b/src/classes/bit-mask.spec.ts @@ -1,4 +1,4 @@ -import {BitMask} from '../' +import {BitMask} from './bit-mask' const READ = 'read' const WRITE = 'write' diff --git a/src/classes/logger.spec.ts b/src/classes/logger.spec.ts index 9c5466f..677d440 100644 --- a/src/classes/logger.spec.ts +++ b/src/classes/logger.spec.ts @@ -2,7 +2,7 @@ // eslint-disable-next-line import {jest} from '@jest/globals' -import {Logger} from '../' +import {Logger} from './logger' describe('Logger', () => { it('should log messages', () => { diff --git a/src/functions/address-object.spec.ts b/src/functions/address-object.spec.ts index e6d140e..b354e1b 100644 --- a/src/functions/address-object.spec.ts +++ b/src/functions/address-object.spec.ts @@ -1,4 +1,4 @@ -import {addressObject, testObjectAddress} from '../' +import {addressObject, testObjectAddress} from './address-object' describe('Address Object', () => { it('should address an object', () => { diff --git a/src/functions/array-move.spec.ts b/src/functions/array-move.spec.ts index 2e9dd0e..dbe45d8 100644 --- a/src/functions/array-move.spec.ts +++ b/src/functions/array-move.spec.ts @@ -1,4 +1,4 @@ -import {arrayMove} from '../index' +import {arrayMove} from './array-move' describe('Array Move', () => { it('should move objects in an array', () => { diff --git a/src/functions/array-selectors.spec.ts b/src/functions/array-selectors.spec.ts index 065e608..c5994a7 100644 --- a/src/functions/array-selectors.spec.ts +++ b/src/functions/array-selectors.spec.ts @@ -1,4 +1,4 @@ -import {randomEntry} from '../' +import {randomEntry} from './array-selectors' describe('Array Selectors', () => { it('should select a random entry', () => { diff --git a/src/functions/async-for-each.spec.ts b/src/functions/async-for-each.spec.ts index d882711..9182d7d 100644 --- a/src/functions/async-for-each.spec.ts +++ b/src/functions/async-for-each.spec.ts @@ -1,4 +1,4 @@ -import {asyncForEach} from '../' +import {asyncForEach} from './async-for-each' describe('Async For Each (in sequence)', () => { it('should work async', async () => { diff --git a/src/functions/async-map.spec.ts b/src/functions/async-map.spec.ts index 6e39e6d..65c85c2 100644 --- a/src/functions/async-map.spec.ts +++ b/src/functions/async-map.spec.ts @@ -1,4 +1,4 @@ -import {asyncMap} from '../' +import {asyncMap} from './async-map' describe('Async Map', () => { it('should work async', async () => { diff --git a/src/functions/cache-for.spec.ts b/src/functions/cache-for.spec.ts index 4f139ce..abb60f2 100644 --- a/src/functions/cache-for.spec.ts +++ b/src/functions/cache-for.spec.ts @@ -8,7 +8,7 @@ import { cacheKey, resetCache, cacheKeyExists -} from '../' +} from './cache-for' jest.setTimeout(20000) diff --git a/src/functions/clamp.spec.ts b/src/functions/clamp.spec.ts index 33ab4c3..382579f 100644 --- a/src/functions/clamp.spec.ts +++ b/src/functions/clamp.spec.ts @@ -1,4 +1,4 @@ -import {clamp} from '../' +import {clamp} from './clamp' describe('clamp', () => { it('should clamp values', () => { diff --git a/src/functions/create-map.spec.ts b/src/functions/create-map.spec.ts index 98a8a5d..20cf034 100644 --- a/src/functions/create-map.spec.ts +++ b/src/functions/create-map.spec.ts @@ -1,4 +1,4 @@ -import {createMap} from '../' +import {createMap} from './create-map' describe('Create Map', () => { it('should create a map', () => { diff --git a/src/functions/css.spec.ts b/src/functions/css.spec.ts index 36d446f..aaf1e1d 100644 --- a/src/functions/css.spec.ts +++ b/src/functions/css.spec.ts @@ -9,7 +9,7 @@ import { numberToRem, numberToVh, numberToVw -} from '../' +} from './css' describe('CSS', () => { it('should conver units to numbers', () => { diff --git a/src/functions/dates.spec.ts b/src/functions/dates.spec.ts index eeab7c5..7af5d56 100644 --- a/src/functions/dates.spec.ts +++ b/src/functions/dates.spec.ts @@ -1,11 +1,11 @@ -import {lastModifiedHeaderDate} from '../index' +import {lastModifiedHeaderDate} from './dates' describe('Dates', () => { - it('should generate a last modified date', () => { - const timeString = "Wed Apr 6 2022 09:38:39 GMT+0100 (British Summer Time)" + it('should generate a last modified date', () => { + const timeString = 'Wed Apr 6 2022 09:38:39 GMT+0100 (British Summer Time)' const lastModified = lastModifiedHeaderDate(timeString) expect(lastModified).toBe('Wed, 06 Apr 2022 08:38:39 GMT') }) -}) \ No newline at end of file +}) diff --git a/src/functions/deep-includes.spec.ts b/src/functions/deep-includes.spec.ts index 58d83d4..01c1fb1 100644 --- a/src/functions/deep-includes.spec.ts +++ b/src/functions/deep-includes.spec.ts @@ -1,4 +1,4 @@ -import {deepIncludesArray} from '../index' +import {deepIncludesArray} from './deep-includes' describe('Deep Includes', () => { test('it should return the correct value', () => { diff --git a/src/functions/defaults.spec.ts b/src/functions/defaults.spec.ts index 5ab4698..0245eff 100644 --- a/src/functions/defaults.spec.ts +++ b/src/functions/defaults.spec.ts @@ -1,4 +1,4 @@ -import {defaults} from '../' +import {defaults} from './defaults' describe('Defaults', () => { it('should set defaults', () => { diff --git a/src/functions/diff-array.spec.ts b/src/functions/diff-array.spec.ts index 23b7308..b952b5e 100644 --- a/src/functions/diff-array.spec.ts +++ b/src/functions/diff-array.spec.ts @@ -1,4 +1,4 @@ -import {diffArray} from '../' +import {diffArray} from './diff-array' describe('diffArray', () => { it('should diff arrays', () => { diff --git a/src/functions/diff-object.spec.ts b/src/functions/diff-object.spec.ts index 26f8429..3be22b0 100644 --- a/src/functions/diff-object.spec.ts +++ b/src/functions/diff-object.spec.ts @@ -1,4 +1,4 @@ -import {diffObject} from '../' +import {diffObject} from './diff-object' describe('Diff Object', () => { it('should diff two objects', () => { diff --git a/src/functions/grouped-by.spec.ts b/src/functions/grouped-by.spec.ts index 9c3de69..2d0df48 100644 --- a/src/functions/grouped-by.spec.ts +++ b/src/functions/grouped-by.spec.ts @@ -1,4 +1,4 @@ -import {groupedBy} from '../' +import {groupedBy} from './grouped-by' describe('Grouped By', () => { it('should group items', () => { diff --git a/src/functions/if-fn.spec.ts b/src/functions/if-fn.spec.ts index 7ee182f..6c36c9a 100644 --- a/src/functions/if-fn.spec.ts +++ b/src/functions/if-fn.spec.ts @@ -1,4 +1,4 @@ -import {ifFn} from '../index' +import {ifFn} from './if-fn' import {hasDevDependency} from './package' describe('If FN', () => { diff --git a/src/functions/increment.spec.ts b/src/functions/increment.spec.ts index 3c04882..3ad514d 100644 --- a/src/functions/increment.spec.ts +++ b/src/functions/increment.spec.ts @@ -1,4 +1,4 @@ -import {increment, decrement} from '../index' +import {increment, decrement} from './increment' describe('Increment', () => { it('should increment', () => { diff --git a/src/functions/indexed-by.spec.ts b/src/functions/indexed-by.spec.ts index a048c93..cb1af23 100644 --- a/src/functions/indexed-by.spec.ts +++ b/src/functions/indexed-by.spec.ts @@ -1,4 +1,4 @@ -import {indexedBy} from '../' +import {indexedBy} from './indexed-by' describe('Indexed By', () => { it('should produce an index', () => { diff --git a/src/functions/invariant.spec.ts b/src/functions/invariant.spec.ts index 9cea004..d6ff911 100644 --- a/src/functions/invariant.spec.ts +++ b/src/functions/invariant.spec.ts @@ -1,6 +1,6 @@ import {expectTypeOf} from 'expect-type' -import {invariant} from '../' +import {invariant} from './invariant' describe('invariant', () => { it('should throw errors', () => { diff --git a/src/functions/is-env.spec.ts b/src/functions/is-env.spec.ts index 6fc0c3b..79b5ec0 100644 --- a/src/functions/is-env.spec.ts +++ b/src/functions/is-env.spec.ts @@ -1,4 +1,4 @@ -import {isEnv} from '../' +import {isEnv} from './is-env' describe('isEnv', () => { it('should get the env', () => { diff --git a/src/functions/keys.spec.ts b/src/functions/keys.spec.ts index b8f7010..503f14b 100644 --- a/src/functions/keys.spec.ts +++ b/src/functions/keys.spec.ts @@ -1,4 +1,4 @@ -import {keys, keyValue} from '../' +import {keys, keyValue} from './keys' describe('Keys', () => { it('should return an array of keys', () => { diff --git a/src/functions/map-property.spec.ts b/src/functions/map-property.spec.ts index 9a30c87..e302c48 100644 --- a/src/functions/map-property.spec.ts +++ b/src/functions/map-property.spec.ts @@ -1,4 +1,4 @@ -import {mapProperty} from '../' +import {mapProperty} from './map-property' describe('Map Property', () => { it('should map properties', () => { diff --git a/src/functions/network.spec.ts b/src/functions/network.spec.ts index 3cce6d0..d8fa24f 100644 --- a/src/functions/network.spec.ts +++ b/src/functions/network.spec.ts @@ -1,4 +1,4 @@ -import {parseCDIR} from '../index' +import {parseCDIR} from './network' describe('Network', () => { it('should parse', () => { diff --git a/src/functions/nl2br.spec.ts b/src/functions/nl2br.spec.ts index ea9cfc4..80db8e2 100644 --- a/src/functions/nl2br.spec.ts +++ b/src/functions/nl2br.spec.ts @@ -1,4 +1,4 @@ -import {nl2br} from '../' +import {nl2br} from './nl2br' describe('NL2BR', () => { it('should add line breaks', () => { diff --git a/src/functions/parameterize.spec.ts b/src/functions/parameterize.spec.ts index 121f4d5..3997c1d 100644 --- a/src/functions/parameterize.spec.ts +++ b/src/functions/parameterize.spec.ts @@ -1,4 +1,4 @@ -import {parameterize} from '../' +import {parameterize} from './parameterize' describe('Parameterize', () => { it('should make strings safe for urls', () => { diff --git a/src/functions/pick.spec.ts b/src/functions/pick.spec.ts index 17450e6..d659903 100644 --- a/src/functions/pick.spec.ts +++ b/src/functions/pick.spec.ts @@ -1,4 +1,4 @@ -import {pick, omit} from '../' +import {pick, omit} from './pick' describe('Pick & Omit', () => { it('should pick elements', () => { diff --git a/src/functions/range-as-string.spec.ts b/src/functions/range-as-string.spec.ts index bbe7a88..dae874f 100644 --- a/src/functions/range-as-string.spec.ts +++ b/src/functions/range-as-string.spec.ts @@ -1,4 +1,4 @@ -import {rangeAsString, rangeAsArray} from '../' +import {rangeAsString, rangeAsArray} from './range-as-string' describe('Range As String', () => { it('should create strings', () => { diff --git a/src/functions/reduce.spec.ts b/src/functions/reduce.spec.ts index cac2e0d..5634d34 100644 --- a/src/functions/reduce.spec.ts +++ b/src/functions/reduce.spec.ts @@ -1,7 +1,7 @@ // eslint-disable-next-line import {jest} from '@jest/globals' -import {reduceTruthy, reduceFalsy, reducio} from '../index' +import {reduceTruthy, reduceFalsy, reducio} from './reduce' describe('Reduce Functions', () => { it('should reduce truthy', () => { diff --git a/src/functions/replace-property.spec.ts b/src/functions/replace-property.spec.ts index 17da8f4..3beed8f 100644 --- a/src/functions/replace-property.spec.ts +++ b/src/functions/replace-property.spec.ts @@ -1,4 +1,4 @@ -import {replaceProperty} from '../index' +import {replaceProperty} from './replace-property' describe('Replace Property', () => { it('should replace a property', () => { diff --git a/src/functions/selectors.spec.ts b/src/functions/selectors.spec.ts index 84d8ae7..bf27a0c 100644 --- a/src/functions/selectors.spec.ts +++ b/src/functions/selectors.spec.ts @@ -1,4 +1,4 @@ -import {propIs, propIsNot} from '../' +import {propIs, propIsNot} from './selectors' describe('Selectors', () => { it('should select items', () => { diff --git a/src/functions/time.spec.ts b/src/functions/time.spec.ts index 92a2e85..cb29945 100644 --- a/src/functions/time.spec.ts +++ b/src/functions/time.spec.ts @@ -17,7 +17,7 @@ import { HOUR_IN_MINUTES, HOUR_IN_SECONDS, HOUR_IN_MS -} from '../' +} from './time' describe('Time FNS', () => { it('should calculate values', () => { diff --git a/src/functions/times.spec.ts b/src/functions/times.spec.ts index ee4364e..84d8e94 100644 --- a/src/functions/times.spec.ts +++ b/src/functions/times.spec.ts @@ -1,4 +1,4 @@ -import {times, asyncTimes} from '../' +import {times, asyncTimes} from './times' describe('Times', () => { it('should interate', () => { diff --git a/src/functions/unique.spec.ts b/src/functions/unique.spec.ts index 12a194c..7713fd0 100644 --- a/src/functions/unique.spec.ts +++ b/src/functions/unique.spec.ts @@ -1,4 +1,4 @@ -import {unique} from '../' +import {unique} from './unique' describe('Unique', () => { it('should find unique values', () => { diff --git a/src/functions/value-or.spec.ts b/src/functions/value-or.spec.ts index 18e1826..12fc8ec 100644 --- a/src/functions/value-or.spec.ts +++ b/src/functions/value-or.spec.ts @@ -1,4 +1,4 @@ -import {valueOr} from '../' +import {valueOr} from './value-or' describe('ValueOr', () => { it('should work', () => { diff --git a/src/functions/wait-for.spec.ts b/src/functions/wait-for.spec.ts index d2c21d9..1b4afdf 100644 --- a/src/functions/wait-for.spec.ts +++ b/src/functions/wait-for.spec.ts @@ -1,4 +1,4 @@ -import {waitFor} from '../' +import {waitFor} from './wait-for' describe('waitFor', () => { it('should return T', async () => {