Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b04cfcb
Showing
10 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.* | ||
!.gitignore | ||
/dist | ||
/node_modules | ||
/result | ||
/ts-refined-v*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Refinements for node paths | ||
|
||
## Tags | ||
|
||
`Path`, `Dir`, and `File` perform no checks. Use to tag after checking. | ||
|
||
## Refinements | ||
`Abs` and `Rel` check using node's `path.isAbsolute`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env nix-build | ||
|
||
{ pkgs ? import <nixpkgs> {} }: | ||
|
||
pkgs.callPackage ./derivation.nix { pname = "ts-refined-path"; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env nix-build | ||
|
||
{ pkgs ? import <nixpkgs> {}, pname }: | ||
|
||
with pkgs; | ||
with builtins; | ||
let | ||
copy = {echo ? false}: paths: runCommand "copy" {} | ||
( ''mkdir -p "$out" | ||
'' | ||
+ | ||
( concatStringsSep "\n" | ||
( map (p: | ||
let | ||
from = elemAt p 0; | ||
to = ''$out/${elemAt p 1}''; | ||
cmd = ''cp -r "${from}" "${to}"''; | ||
echo-cmd = '' | ||
echo ${cmd} | ||
''; | ||
run-cmd = '' | ||
mkdir -p "$(dirname "${to}")" | ||
${cmd} | ||
''; | ||
in | ||
if echo | ||
then echo-cmd + run-cmd | ||
else run-cmd | ||
) paths | ||
) | ||
) | ||
); | ||
|
||
node-modules = pkgs.stdenv.mkDerivation { | ||
name = "${pname}-node-modules"; | ||
src = copy {} [ | ||
[./package.json "package.json"] | ||
[./yarn.lock "yarn.lock"] | ||
]; | ||
phases = "unpackPhase buildPhase"; | ||
buildInputs = [yarn]; | ||
buildPhase = '' | ||
mkdir "$out" | ||
export HOME="$out/.yarn-home" | ||
exec yarn --pure-lockfile --modules-folder "$out" | ||
''; | ||
}; | ||
|
||
dist = pkgs.stdenv.mkDerivation { | ||
name = pname; | ||
src = copy {} [ | ||
[./src "src"] | ||
[./tsconfig.json "tsconfig.json"] | ||
[./package.json "package.json"] | ||
[./yarn.lock "yarn.lock"] | ||
[./README.md "README.md"] | ||
[node-modules "node_modules"] | ||
]; | ||
buildInputs = [nodejs]; | ||
phases = "unpackPhase buildPhase"; | ||
buildPhase = '' | ||
mkdir "$out" | ||
export NODE_PATH=./node_modules | ||
"./node_modules/.bin/tsc" --outDir "$out" | ||
cp package.json yarn.lock README.md "$out" | ||
''; | ||
}; | ||
|
||
in | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "ts-refined-path", | ||
"version": "0.1.0", | ||
"description": "Refined path types for Typescript", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"repository": "git@github.com:jedahu/ts-refined-path.git", | ||
"author": "Jeremy Hughes <jedahu@gmail.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@types/node": "^8.0.23", | ||
"ts-refined": "^0.4.0" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^2.4.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bash | ||
|
||
cmd="$1" | ||
|
||
shift | ||
|
||
run-usage() { | ||
echo "run <cmd> [cmd args...]" | ||
echo " build [nix-build args...] : build package" | ||
echo " pack [yarn package args...] : pack package" | ||
echo " publish [yarn publish args...] : publish package" | ||
echo " name : print package name" | ||
echo " version : print package version" | ||
echo " usage : print this message" | ||
} | ||
|
||
run-build() { | ||
nix-build "$@" && rsync -aL --delete --chmod +w result/ dist | ||
} | ||
|
||
run-pack() { | ||
local name=$(run-name) | ||
local ver=$(run-version) | ||
run-build && (cd dist && yarn pack -f "../$name-v$ver.tgz" "$@") | ||
} | ||
|
||
run-publish() { | ||
local ver=$(run-version) | ||
run-build && ( | ||
cd dist && \ | ||
yarn publish \ | ||
--new-version "$ver" \ | ||
--no-git-tag-version \ | ||
--non-interactive \ | ||
"$@" | ||
) | ||
} | ||
|
||
run-name() { | ||
node -e 'console.log(require("./package.json").name);' | ||
} | ||
|
||
run-version() { | ||
node -e 'console.log(require("./package.json").version);' | ||
} | ||
|
||
case "$cmd" in | ||
build|pack|publish|version) | ||
run-"$cmd" "$@" | ||
;; | ||
*) | ||
echo "No such command: $cmd" | ||
run-usage | ||
exit 1 | ||
;; | ||
esac | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
|
||
with pkgs; | ||
stdenv.mkDerivation { | ||
name = "env"; | ||
buildInputs = [ | ||
gitAndTools.git | ||
nodejs | ||
rsync | ||
yarn | ||
]; | ||
shellHook = '' | ||
export PATH="$(yarn bin):$PATH" | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// #+TITLE: Refinements for paths | ||
|
||
import {Refinement, Tagged} from "ts-refined"; | ||
import * as p from "path"; | ||
|
||
|
||
// ** Tags | ||
|
||
export class Path extends Tagged<string> { | ||
"@nominal" : "de222c7d-3565-435e-9bfc-1750a7d07838"; | ||
} | ||
|
||
export class Dir extends Tagged<string> { | ||
"@nominal" : "c9174b4e-a8c1-48b3-adfb-c84341137f1a"; | ||
} | ||
|
||
export class File extends Tagged<string> { | ||
"@nominal" : "6b7615c1-5d02-4e1a-9921-381fa3a8585e"; | ||
} | ||
|
||
|
||
// ** Refinements | ||
|
||
export class Abs implements Refinement<string> { | ||
"@nominal" : "1a88d9e9-522c-4de1-96c0-7e5257705ca4"; | ||
test = (s : string) => p.isAbsolute(s); | ||
} | ||
|
||
export class Rel implements Refinement<string> { | ||
"@nominal" : "5bed8e96-5562-444c-b42a-9bcb35a77448"; | ||
test = (s : string) => !p.isAbsolute(s); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"alwaysStrict": true, | ||
"newLine": "lf", | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noUnusedLocals": true, | ||
"strictNullChecks": true, | ||
"declaration": true, | ||
"outDir": "./dist", | ||
"target": "es6", | ||
"moduleResolution": "node" | ||
}, | ||
"include": ["./src/*.ts"], | ||
"exclude": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@types/node@^8.0.23": | ||
version "8.0.23" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.23.tgz#c746697004782346594a0d755c34425bbf3014d2" | ||
|
||
ts-refined@^0.4.0: | ||
version "0.4.2" | ||
resolved "https://registry.yarnpkg.com/ts-refined/-/ts-refined-0.4.2.tgz#d6ebff42b58e73404eefc319d79bb55ddc2c5f83" | ||
|
||
typescript@^2.4.2: | ||
version "2.4.2" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.2.tgz#f8395f85d459276067c988aa41837a8f82870844" |