Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
imcotton committed Aug 9, 2024
1 parent ae348d2 commit 45a141a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Input source is reading from `stdin`.

### Built-in Presets

- `--all`
- `--lodash`: pkg naming starts by `lodash.` or equals to `lodash`
- `--nolyfill`: list of names from https://github.com/SukkaW/nolyfill (**1.0.34**)
- `--relief`: list of names from https://github.com/es-tooling/module-replacements (**2.3.2**)
Expand Down
2 changes: 2 additions & 0 deletions src/cli/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Usage:
Builtin Presets:
--all
--lodash
--nolyfill (via SukkaW/nolyfill v1.0.34)
Expand Down
4 changes: 4 additions & 0 deletions src/cli/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export function parse (args: Iterable<string>): Flags {
short: 'v',
},

all: {
type: 'boolean',
},

// presets

lodash: {
Expand Down
2 changes: 2 additions & 0 deletions src/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface Flags {

invert?: boolean;

all?: boolean;

lodash?: boolean;

nolyfill?: boolean;
Expand Down
22 changes: 18 additions & 4 deletions src/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export { nolyfill };
import * as relief from './relief.ts';
export { relief };

import type { Predicate } from '../common.ts';
import { type Predicate, or } from '../common.ts';



Expand All @@ -17,6 +17,8 @@ export type Param = Partial<Readonly<Record<Toggle, boolean | undefined>>>;

export type Toggle =

| 'all'

| 'lodash'
| 'nolyfill'

Expand All @@ -31,21 +33,33 @@ export type Toggle =



const on = (t: Toggle) => (p: Param) => p[t] === true;

const on_all = on('all');

const all_OR_lodash = or(on_all, on('lodash'));
const all_OR_nolyfill = or(on_all, on('nolyfill'));
const all_OR_relief = or(on_all, on('relief'));





export function * gen_presets (

param: Param,

): Iterable<Predicate<string>> {

if (param.lodash === true) {
if (all_OR_lodash(param)) {
yield lodash.check;
}

if (param.nolyfill === true) {
if (all_OR_nolyfill(param)) {
yield nolyfill.check;
}

if (param.relief === true) {
if (all_OR_relief(param)) {

yield * [
relief.native_check,
Expand Down
16 changes: 16 additions & 0 deletions tests/presets/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { lookup, make_predicate } from '../../src/common.ts';
import {

gen_presets,
lodash,
nolyfill,
relief,

} from '../../src/presets/index.ts';
Expand All @@ -20,6 +22,20 @@ describe('presets', function () {

describe('gen_presets', function () {

it(`gens all`, function () {

const presets = Array.from(gen_presets({ all: true }));

asserts.assertEquals(presets, [
lodash.check,
nolyfill.check,
relief.native_check,
relief.micro_check,
relief.preferred_check,
]);

});

it(`gens all reliefs`, function () {

const all = Array.of(
Expand Down

0 comments on commit 45a141a

Please sign in to comment.