0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-30 09:08:00 -04:00
Original: 7a3c70e74b
This commit is contained in:
chiefbiiko 2019-01-01 23:45:41 +00:00 committed by Ryan Dahl
parent 02c3c97ddd
commit 2db683e47e
8 changed files with 80 additions and 5 deletions

View file

@ -5,4 +5,4 @@ install:
- export PATH="$HOME/.deno/bin:$PATH" - export PATH="$HOME/.deno/bin:$PATH"
script: script:
- deno test.ts --allow-run --allow-net - deno test.ts --allow-run --allow-net --allow-write

View file

@ -12,6 +12,7 @@ for Deno.
| [path](./path/) | File path manipulation. | | [path](./path/) | File path manipulation. |
| [flags](./flags/) | Command line arguments parser. | | [flags](./flags/) | Command line arguments parser. |
| [logging](./logging/) | Command line logging | | [logging](./logging/) | Command line logging |
| [mkdirp](./mkdirp/) | Make directory branches. |
--- ---

View file

@ -9,7 +9,7 @@ jobs:
steps: steps:
- script: curl -L https://deno.land/x/install/install.py | python - $(DENO_VERSION) - script: curl -L https://deno.land/x/install/install.py | python - $(DENO_VERSION)
- script: echo '##vso[task.prependpath]$(HOME)/.deno/bin/' - script: echo '##vso[task.prependpath]$(HOME)/.deno/bin/'
- script: deno test.ts --allow-run --allow-net - script: deno test.ts --allow-run --allow-net --allow-write
- job: 'Mac' - job: 'Mac'
pool: pool:
@ -17,7 +17,7 @@ jobs:
steps: steps:
- script: curl -L https://deno.land/x/install/install.py | python - $(DENO_VERSION) - script: curl -L https://deno.land/x/install/install.py | python - $(DENO_VERSION)
- script: echo '##vso[task.prependpath]$(HOME)/.deno/bin/' - script: echo '##vso[task.prependpath]$(HOME)/.deno/bin/'
- script: deno test.ts --allow-run --allow-net - script: deno test.ts --allow-run --allow-net --allow-write
# TODO Windows is broken on a bug: https://github.com/denoland/deno/issues/1384 # TODO Windows is broken on a bug: https://github.com/denoland/deno/issues/1384
#- job: 'Windows' #- job: 'Windows'

24
mkdirp/mkdirp.ts Normal file
View file

@ -0,0 +1,24 @@
import { ErrorKind, FileInfo, lstat, mkdir, platform } from "deno";
const PATH_SEPARATOR: string = platform.os === "win" ? "\\" : "/";
export async function mkdirp(path: string, mode?: number): Promise<void> {
for (
let parts: string[] = path.split(/\/|\\/),
parts_len: number = parts.length,
level: string,
info: FileInfo,
i: number = 0;
i < parts_len;
i++
) {
level = parts.slice(0, i + 1).join(PATH_SEPARATOR);
try {
info = await lstat(level);
if (!info.isDirectory()) throw Error(`${level} is not a directory`);
} catch (err) {
if (err.kind !== ErrorKind.NotFound) throw err;
await mkdir(level, mode);
}
}
}

17
mkdirp/readme.md Normal file
View file

@ -0,0 +1,17 @@
# deno-mkdirp
`mkdir -p` 4 `deno`.
## Import
```ts
import { mkdirp } from "https://deno.land/x/std/mkdirp/mkdirp.ts";
```
## API
Same as [`deno.mkdir`](https://deno.land/typedoc/index.html#mkdir).
### `mkdirp(path: string, mode?: number) : Promise<void>`
Creates directories if they do not already exist and makes parent directories as needed.

30
mkdirp/test.ts Normal file
View file

@ -0,0 +1,30 @@
import { cwd, lstat, makeTempDirSync, removeAll, FileInfo } from "deno";
import { test, assert } from "https://deno.land/x/testing/testing.ts";
import { mkdirp } from "./mkdirp.ts";
let root: string = `${cwd()}/${Date.now()}`; //makeTempDirSync();
test(async function createsNestedDirs(): Promise<void> {
const leaf: string = `${root}/levelx/levely`;
await mkdirp(leaf);
const info: FileInfo = await lstat(leaf);
assert(info.isDirectory());
await removeAll(root);
});
test(async function handlesAnyPathSeparator(): Promise<void> {
const leaf: string = `${root}\\levelx\\levely`;
await mkdirp(leaf);
const info: FileInfo = await lstat(leaf.replace(/\\/g, "/"));
assert(info.isDirectory());
await removeAll(root);
});
test(async function failsNonDir(): Promise<void> {
try {
await mkdirp("./test.ts/fest.fs");
} catch (err) {
// TODO: assert caught DenoError of kind NOT_A_DIRECTORY or similar
assert(err);
}
});

View file

@ -177,7 +177,7 @@ function guessContentType(filename: string): string {
return contentType; return contentType;
} }
return extensionsMap['']; return extensionsMap[""];
} }
async function serveFile(req: ServerRequest, filename: string) { async function serveFile(req: ServerRequest, filename: string) {

View file

@ -1,4 +1,4 @@
#!/usr/bin/env deno --allow-run --allow-net #!/usr/bin/env deno --allow-run --allow-net --allow-write
import { run } from "deno"; import { run } from "deno";
// colors tests // colors tests
@ -32,6 +32,9 @@ import "path/relative_test.ts";
import "path/resolve_test.ts"; import "path/resolve_test.ts";
import "path/zero_length_strings_test.ts"; import "path/zero_length_strings_test.ts";
// mkdirp tests
import "mkdirp/test.ts";
// I am also too lazy to do this properly LOL // I am also too lazy to do this properly LOL
runTests(new Promise(res => setTimeout(res, 5000))); runTests(new Promise(res => setTimeout(res, 5000)));
(async () => { (async () => {