Skip to content

Commit

Permalink
add tools/sync-nolyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
imcotton committed Jul 12, 2024
1 parent c502c91 commit f2e1173
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions tools/sync-nolyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env -S deno run --allow-read=./src/presets/nolyfill.ts --allow-write=./src/presets/nolyfill.ts

import { allPackages } from 'https://esm.sh/gh/SukkaW/[email protected]/packages/tools/cli/src/all-packages.ts';

import type { Fn } from '../src/common.ts';





async function main ({

path = './src/presets/nolyfill.ts',
up = 'Array.of(',
down = ');',

} = {}) {

const total = await Deno.readTextFile(path);

const [ top, bottom ] = split({ up, down, total });

const middle = JSON.stringify(allPackages, null, 4)
.slice(2, -2)
.concat(',')
.replaceAll(`"`, `'`)
;

const updated = Array.of(top, middle, bottom).join('\n\n');

await Deno.writeTextFile(path, updated, { create: false });

}





function split ({ up, down, total }: {

up: string,
down: string,
total: string,

}) {

const top = begin(up);
const bottom = end(down);

return [ top(total), bottom(total) ] as const;

}





const index: (part: string, whole: string) => number
= (part, whole) => whole.indexOf(part) + part.length;





const begin: Fn<string, Fn<string, string>>
= part => whole => whole.slice(0, index(part, whole));





const end: Fn<string, Fn<string, string>>
= part => whole => whole.slice(index(part, whole) - part.length);





if (import.meta.main) {

await main();

}

0 comments on commit f2e1173

Please sign in to comment.