plan.ts
This file
Path
scripts/lib/import/plan.ts
383 lines · 7.4 KiB · TypeScript
Last changed by
Merge build/comments-ops into mainoscabrielbefore adoptione4c407e
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384import { ProjectKey, ProjectName, sourceNamespaceOf } from "@repo/protocol/ids";import { Option, Redacted } from "effect";
export interface ImportExample { readonly name: ProjectName; readonly key: ProjectKey; readonly url: string; readonly branch: string; readonly kind: string; readonly licence: string;}
const example = ( key: string, url: string, branch: string, kind: string, licence: string): ImportExample => ({ branch, key: ProjectKey.make(key), kind, licence, name: ProjectName.make(`${Option.getOrThrow(sourceNamespaceOf(url))}/${key}`), url,});
// anyhow first: it probes a `master` default and tags.export const examples: readonly ImportExample[] = [ example( "anyhow", "https://github.com/dtolnay/anyhow", "master", "Rust crate", "MIT OR Apache-2.0" ), example( "ky", "https://github.com/sindresorhus/ky", "main", "TypeScript library", "MIT" ), example( "gum", "https://github.com/charmbracelet/gum", "main", "Go CLI", "MIT" ), example( "click", "https://github.com/pallets/click", "main", "Python package", "BSD-3-Clause" ), example( "awesome", "https://github.com/sindresorhus/awesome", "main", "Markdown list", "CC0-1.0" ), example( "changesets", "https://github.com/changesets/changesets", "main", "TypeScript monorepo", "MIT" ), example( "stb", "https://github.com/nothings/stb", "master", "C single-file headers", "MIT OR Unlicense" ), example( "fuzzel", "https://codeberg.org/dnkl/fuzzel", "master", "C on Codeberg", "MIT" ), example( "hono", "https://github.com/honojs/hono", "main", "TypeScript web framework", "MIT" ), example( "express", "https://github.com/expressjs/express", "master", "JavaScript web framework", "MIT" ), example( "fastify", "https://github.com/fastify/fastify", "main", "JavaScript web framework", "MIT" ), example( "zustand", "https://github.com/pmndrs/zustand", "main", "TypeScript state library", "MIT" ), example( "immer", "https://github.com/immerjs/immer", "main", "JavaScript immutable state", "MIT" ), example( "nanoid", "https://github.com/ai/nanoid", "main", "JavaScript ID generator", "MIT" ), example( "commander", "https://github.com/tj/commander.js", "master", "JavaScript CLI parser", "MIT" ), example( "execa", "https://github.com/sindresorhus/execa", "main", "JavaScript process runner", "MIT" ), example( "chalk", "https://github.com/chalk/chalk", "main", "JavaScript terminal colours", "MIT" ), example( "mitt", "https://github.com/developit/mitt", "main", "TypeScript event emitter", "MIT" ), example( "clsx", "https://github.com/lukeed/clsx", "master", "JavaScript class names", "MIT" ), example( "ripgrep", "https://github.com/BurntSushi/ripgrep", "master", "Rust CLI", "Unlicense OR MIT" ), example( "serde", "https://github.com/serde-rs/serde", "master", "Rust serialization", "MIT OR Apache-2.0" ), example( "axum", "https://github.com/tokio-rs/axum", "main", "Rust web framework", "MIT" ), example( "fd", "https://github.com/sharkdp/fd", "master", "Rust CLI", "MIT OR Apache-2.0" ), example( "hyperfine", "https://github.com/sharkdp/hyperfine", "master", "Rust benchmarking CLI", "MIT OR Apache-2.0" ), example( "bubbletea", "https://github.com/charmbracelet/bubbletea", "main", "Go TUI framework", "MIT" ), example( "fzf", "https://github.com/junegunn/fzf", "master", "Go fuzzy finder", "MIT" ), example( "cobra", "https://github.com/spf13/cobra", "main", "Go CLI library", "Apache-2.0" ), example( "gin", "https://github.com/gin-gonic/gin", "master", "Go web framework", "MIT" ), example( "requests", "https://github.com/psf/requests", "main", "Python HTTP library", "Apache-2.0" ), example( "flask", "https://github.com/pallets/flask", "main", "Python web framework", "BSD-3-Clause" ), example( "httpx", "https://github.com/encode/httpx", "master", "Python HTTP client", "BSD-3-Clause" ), example( "typer", "https://github.com/fastapi/typer", "master", "Python CLI library", "MIT" ), example( "jinja", "https://github.com/pallets/jinja", "main", "Python templates", "BSD-3-Clause" ), example( "lua", "https://github.com/lua/lua", "master", "C language interpreter", "MIT" ), example( "jq", "https://github.com/jqlang/jq", "master", "C JSON processor", "MIT" ), example( "kilo", "https://github.com/antirez/kilo", "master", "C text editor", "BSD-2-Clause" ), example( "sinatra", "https://github.com/sinatra/sinatra", "main", "Ruby web framework", "MIT" ), example( "nvm", "https://github.com/nvm-sh/nvm", "master", "Shell version manager", "MIT" ),];
// A name the platform lists is never imported again, whatever repo it came from.export const planImports = ( all: readonly ImportExample[], listed: ReadonlySet<ProjectName>, only: Option.Option<ProjectName>): readonly ImportExample[] => all.filter( ({ name }) => Option.match(only, { onNone: () => true, onSome: (named) => named === name, }) && !listed.has(name) );
export const warmPaths = ( project: ProjectName, readme: Option.Option<string>): readonly string[] => [ `/${project}`, `/${project}/tree/main`, `/${project}/commits/main`, ...Option.match(readme, { onNone: () => [], onSome: (path) => [ `/${project}/blob/main/${path}`, `/${project}/why/main/${path}`, ], }),];
// Kept apart from the token so the URL can be shown.export interface RedactedUrl { readonly url: string; readonly token: Redacted.Redacted;}
// Its argv may be printed; its env values never are.export interface Command { readonly argv: readonly string[]; readonly env?: Readonly<Record<string, Redacted.Redacted>>;}
export const shownCommand = ({ argv }: Command) => argv.join(" ");
const TAGS = "refs/tags/*:refs/tags/*";
// The write token reaches git as an `Authorization` header through `GIT_CONFIG_*`,// so it is in no argument, URL or printed line. Only the tags are fetched: a// `clone --mirror` would bring every `refs/pull/*` GitHub keeps.export const tagBackfillCommands = (input: { readonly source: string; readonly mirror: string; readonly remote: RedactedUrl;}): readonly Command[] => [ { argv: ["git", "init", "--bare", "--quiet", input.mirror] }, { argv: [ "git", "--git-dir", input.mirror, "fetch", "--quiet", "--no-tags", input.source, TAGS, ], }, { argv: [ "git", "--git-dir", input.mirror, "push", "--quiet", input.remote.url, TAGS, ], env: { GIT_CONFIG_COUNT: Redacted.make("1"), GIT_CONFIG_KEY_0: Redacted.make("http.extraHeader"), GIT_CONFIG_VALUE_0: Redacted.make( `Authorization: Bearer ${Redacted.value(input.remote.token)}` ), }, },];