Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better publish #11

Merged
merged 1 commit into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## v2.0.0

### Features:

- Generalized Discriminant field
- Using Mapped returns in matchers for better inference
- Partial matching (`matchP`/`matchPI`) courtesy of @rjdestigter
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
"version": "1.0.1",
"author": "Paul Gray <pfbgray@gmail.com>",
"description": "An Algebraic Data Type generator for Typescript",
"main": "lib/ADT.js",
"types": "lib/ADT.d.ts",
"main": "ADT.js",
"types": "ADT.d.ts",
"license": "MIT",
"scripts": {
"build": "tsc",
"build": "tsc && ts-node ./scripts/build",
"prepublish": "tsc",
"test": "ava"
},
"devDependencies": {
"@types/glob": "^7.1.3",
"ava": "^3.13.0",
"fp-ts": "^2.9.0",
"glob": "^7.1.6",
"ts-node": "^9.1.0",
"tsd": "^0.14.0",
"typescript": "3.9"
Expand Down
51 changes: 51 additions & 0 deletions scripts/FileSystem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as TE from "fp-ts/lib/TaskEither";
import { flow } from "fp-ts/lib/function";
import * as fs from "fs";
import * as G from "glob";

export interface FileSystem {
readonly readFile: (path: string) => TE.TaskEither<Error, string>;
readonly writeFile: (
path: string,
content: string
) => TE.TaskEither<Error, void>;
readonly copyFile: (from: string, to: string) => TE.TaskEither<Error, void>;
readonly glob: (
pattern: string
) => TE.TaskEither<Error, ReadonlyArray<string>>;
readonly mkdir: (path: string) => TE.TaskEither<Error, void>;
readonly moveFile: (from: string, to: string) => TE.TaskEither<Error, void>;
}

const readFile = TE.taskify<fs.PathLike, string, NodeJS.ErrnoException, string>(
fs.readFile
);
const writeFile = TE.taskify<fs.PathLike, string, NodeJS.ErrnoException, void>(
fs.writeFile
);
const copyFile = TE.taskify<
fs.PathLike,
fs.PathLike,
NodeJS.ErrnoException,
void
>(fs.copyFile);
const glob = TE.taskify<string, Error, ReadonlyArray<string>>(G);
const mkdirTE = TE.taskify(fs.mkdir);
const moveFile = TE.taskify<
fs.PathLike,
fs.PathLike,
NodeJS.ErrnoException,
void
>(fs.rename);

export const fileSystem: FileSystem = {
readFile: (path) => readFile(path, "utf8"),
writeFile,
copyFile,
glob,
mkdir: flow(
mkdirTE,
TE.map(() => undefined)
),
moveFile,
};
59 changes: 59 additions & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as path from "path";
import * as E from "fp-ts/lib/Either";
import { pipe } from "fp-ts/lib/function";
import * as RTE from "fp-ts/lib/ReaderTaskEither";
import * as A from "fp-ts/lib/ReadonlyArray";
import * as TE from "fp-ts/lib/TaskEither";
import { FileSystem, fileSystem } from "./FileSystem";
import { run } from "./run";

interface Build<A> extends RTE.ReaderTaskEither<FileSystem, Error, A> {}

const OUTPUT_FOLDER = "lib";
const PKG = "package.json";

export const copyPackageJson: Build<void> = (C) =>
pipe(
C.readFile(PKG),
TE.chain((s) => TE.fromEither(E.parseJSON(s, E.toError))),
TE.map((v) => {
const clone = Object.assign({}, v as any);

delete clone.scripts;
delete clone.files;
delete clone.devDependencies;

return clone;
}),
TE.chain((json) =>
C.writeFile(path.join(OUTPUT_FOLDER, PKG), JSON.stringify(json, null, 2))
)
);

export const FILES: ReadonlyArray<string> = [
"CHANGELOG.md",
"LICENSE",
"README.md",
];

export const copyFiles: Build<void> = (C) =>
pipe(
FILES,
A.traverse(TE.taskEither)((from) =>
C.copyFile(from, path.resolve(OUTPUT_FOLDER, from))
),
TE.map(() => {})
);

const traverse = A.traverse(TE.taskEither);

const main: Build<void> = pipe(
copyPackageJson,
RTE.chain(() => copyFiles)
);

run(
main({
...fileSystem,
})
);
21 changes: 21 additions & 0 deletions scripts/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { fold } from "fp-ts/lib/Either";
import { TaskEither } from "fp-ts/lib/TaskEither";

export function run<A>(eff: TaskEither<Error, A>): void {
eff()
.then(
fold(
(e) => {
throw e;
},
(_) => {
process.exitCode = 0;
}
)
)
.catch((e) => {
console.error(e); // tslint:disable-line no-console

process.exitCode = 1;
});
}
Loading