track-cli 3.0.0-rc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +3 -0
- package/esm/_dnt.polyfills.d.ts +6 -0
- package/esm/_dnt.polyfills.js +1 -0
- package/esm/_dnt.shims.d.ts +19 -0
- package/esm/_dnt.shims.js +78 -0
- package/esm/deps/deno.land/std@0.170.0/fmt/colors.d.ts +270 -0
- package/esm/deps/deno.land/std@0.170.0/fmt/colors.js +473 -0
- package/esm/deps/deno.land/std@0.195.0/_util/os.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/_util/os.js +18 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert.js +8 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.js +12 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/_common.d.ts +50 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/_common.js +545 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/constants.d.ts +55 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/constants.js +57 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.d.ts +26 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.js +45 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/difference.d.ts +38 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/difference.js +93 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/format.d.ts +22 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/format.js +28 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.d.ts +49 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.js +60 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/mod.d.ts +43 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/mod.js +45 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/parse.d.ts +21 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/parse.js +29 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.d.ts +17 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.js +44 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.d.ts +13 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.js +38 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/colors.d.ts +270 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/colors.js +474 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/duration.d.ts +15 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/duration.js +96 -0
- package/esm/deps/deno.land/std@0.195.0/fs/_util.d.ts +35 -0
- package/esm/deps/deno.land/std@0.195.0/fs/_util.js +80 -0
- package/esm/deps/deno.land/std@0.195.0/fs/copy.d.ts +51 -0
- package/esm/deps/deno.land/std@0.195.0/fs/copy.js +244 -0
- package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.d.ts +31 -0
- package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.js +74 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.d.ts +27 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.js +55 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.d.ts +33 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.js +75 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.d.ts +31 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.js +43 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.d.ts +17 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.js +68 -0
- package/esm/deps/deno.land/std@0.195.0/fs/eol.d.ts +40 -0
- package/esm/deps/deno.land/std@0.195.0/fs/eol.js +53 -0
- package/esm/deps/deno.land/std@0.195.0/fs/exists.d.ts +102 -0
- package/esm/deps/deno.land/std@0.195.0/fs/exists.js +163 -0
- package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.d.ts +37 -0
- package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.js +216 -0
- package/esm/deps/deno.land/std@0.195.0/fs/mod.d.ts +16 -0
- package/esm/deps/deno.land/std@0.195.0/fs/mod.js +17 -0
- package/esm/deps/deno.land/std@0.195.0/fs/move.d.ts +29 -0
- package/esm/deps/deno.land/std@0.195.0/fs/move.js +88 -0
- package/esm/deps/deno.land/std@0.195.0/fs/walk.d.ts +40 -0
- package/esm/deps/deno.land/std@0.195.0/fs/walk.js +158 -0
- package/esm/deps/deno.land/std@0.195.0/path/_constants.d.ts +39 -0
- package/esm/deps/deno.land/std@0.195.0/path/_constants.js +46 -0
- package/esm/deps/deno.land/std@0.195.0/path/_interface.d.ts +26 -0
- package/esm/deps/deno.land/std@0.195.0/path/_interface.js +3 -0
- package/esm/deps/deno.land/std@0.195.0/path/_util.d.ts +11 -0
- package/esm/deps/deno.land/std@0.195.0/path/_util.js +161 -0
- package/esm/deps/deno.land/std@0.195.0/path/common.d.ts +13 -0
- package/esm/deps/deno.land/std@0.195.0/path/common.js +36 -0
- package/esm/deps/deno.land/std@0.195.0/path/glob.d.ts +83 -0
- package/esm/deps/deno.land/std@0.195.0/path/glob.js +361 -0
- package/esm/deps/deno.land/std@0.195.0/path/mod.d.ts +9 -0
- package/esm/deps/deno.land/std@0.195.0/path/mod.js +33 -0
- package/esm/deps/deno.land/std@0.195.0/path/posix.d.ts +86 -0
- package/esm/deps/deno.land/std@0.195.0/path/posix.js +442 -0
- package/esm/deps/deno.land/std@0.195.0/path/separator.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/path/separator.js +5 -0
- package/esm/deps/deno.land/std@0.195.0/path/win32.d.ts +91 -0
- package/esm/deps/deno.land/std@0.195.0/path/win32.js +909 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.js +26 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.d.ts +76 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.js +154 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.d.ts +32 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.js +105 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.d.ts +831 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.js +1701 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.d.ts +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.js +201 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.js +141 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.d.ts +21 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.js +285 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.d.ts +8 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.js +32 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.js +46 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.d.ts +45 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.js +2 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.d.ts +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.js +323 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.js +34 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.d.ts +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.js +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.d.ts +41 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.js +24 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.js +20 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.js +13 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.js +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.d.ts +10 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.js +29 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.d.ts +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.js +12 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.d.ts +118 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.js +2 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.d.ts +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.js +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.js +46 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.d.ts +26 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.js +118 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.js +55 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.d.ts +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.js +102 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.d.ts +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.js +75 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.d.ts +60 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.js +117 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.d.ts +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.js +106 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.d.ts +10 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.js +157 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.d.ts +24 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.d.ts +33 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.js +402 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.js +11 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.js +4 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.d.ts +59 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.d.ts +20 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.js +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.d.ts +78 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.js +128 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.d.ts +99 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.js +529 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.d.ts +49 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.js +74 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.d.ts +135 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.js +237 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.d.ts +13 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.js +60 -0
- package/esm/package.json +3 -0
- package/esm/src/action/add.d.ts +1 -0
- package/esm/src/action/add.js +57 -0
- package/esm/src/action/clone.d.ts +6 -0
- package/esm/src/action/clone.js +108 -0
- package/esm/src/action/lang.d.ts +1 -0
- package/esm/src/action/lang.js +40 -0
- package/esm/src/action/pull.d.ts +1 -0
- package/esm/src/action/pull.js +22 -0
- package/esm/src/action/remove.d.ts +4 -0
- package/esm/src/action/remove.js +67 -0
- package/esm/src/action/reset.d.ts +1 -0
- package/esm/src/action/reset.js +21 -0
- package/esm/src/action/run.d.ts +4 -0
- package/esm/src/action/run.js +163 -0
- package/esm/src/action/status.d.ts +1 -0
- package/esm/src/action/status.js +5 -0
- package/esm/src/main.d.ts +2 -0
- package/esm/src/main.js +96 -0
- package/esm/src/meta.d.ts +3 -0
- package/esm/src/meta.js +51 -0
- package/esm/src/orca/client.d.ts +20 -0
- package/esm/src/orca/client.js +152 -0
- package/esm/src/orca/types.d.ts +54 -0
- package/esm/src/orca/types.js +12 -0
- package/esm/src/shared/config.d.ts +24 -0
- package/esm/src/shared/config.js +24 -0
- package/esm/src/shared/errors.d.ts +82 -0
- package/esm/src/shared/errors.js +228 -0
- package/esm/src/shared/file.d.ts +30 -0
- package/esm/src/shared/file.js +110 -0
- package/esm/src/shared/mod.d.ts +40 -0
- package/esm/src/shared/mod.js +383 -0
- package/esm/src/shared/types.d.ts +12 -0
- package/esm/src/shared/types.js +1 -0
- package/esm/src/track/client.d.ts +60 -0
- package/esm/src/track/client.js +268 -0
- package/esm/src/track/types.d.ts +210 -0
- package/esm/src/track/types.js +40 -0
- package/package.json +35 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export interface CopyOptions {
|
|
3
|
+
/**
|
|
4
|
+
* overwrite existing file or directory.
|
|
5
|
+
* @default {false}
|
|
6
|
+
*/
|
|
7
|
+
overwrite?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* When `true`, will set last modification and access times to the ones of the
|
|
10
|
+
* original source files.
|
|
11
|
+
* When `false`, timestamp behavior is OS-dependent.
|
|
12
|
+
*
|
|
13
|
+
* @default {false}
|
|
14
|
+
*/
|
|
15
|
+
preserveTimestamps?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Copy a file or directory. The directory can have contents. Like `cp -r`.
|
|
19
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { copy } from "https://deno.land/std@$STD_VERSION/fs/copy.ts";
|
|
24
|
+
* copy("./foo", "./bar"); // returns a promise
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param src the file/directory path.
|
|
28
|
+
* Note that if `src` is a directory it will copy everything inside
|
|
29
|
+
* of this directory, not the entire directory itself
|
|
30
|
+
* @param dest the destination path. Note that if `src` is a file, `dest` cannot
|
|
31
|
+
* be a directory
|
|
32
|
+
* @param options
|
|
33
|
+
*/
|
|
34
|
+
export declare function copy(src: string | URL, dest: string | URL, options?: CopyOptions): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Copy a file or directory. The directory can have contents. Like `cp -r`.
|
|
37
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { copySync } from "https://deno.land/std@$STD_VERSION/fs/copy.ts";
|
|
42
|
+
* copySync("./foo", "./bar"); // void
|
|
43
|
+
* ```
|
|
44
|
+
* @param src the file/directory path.
|
|
45
|
+
* Note that if `src` is a directory it will copy everything inside
|
|
46
|
+
* of this directory, not the entire directory itself
|
|
47
|
+
* @param dest the destination path. Note that if `src` is a file, `dest` cannot
|
|
48
|
+
* be a directory
|
|
49
|
+
* @param options
|
|
50
|
+
*/
|
|
51
|
+
export declare function copySync(src: string | URL, dest: string | URL, options?: CopyOptions): void;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
3
|
+
// @ts-nocheck Bypass static errors for missing --unstable.
|
|
4
|
+
import * as path from "../path/mod.js";
|
|
5
|
+
import { ensureDir, ensureDirSync } from "./ensure_dir.js";
|
|
6
|
+
import { getFileInfoType, isSubdir, toPathString } from "./_util.js";
|
|
7
|
+
import { assert } from "../assert/assert.js";
|
|
8
|
+
import { isWindows } from "../_util/os.js";
|
|
9
|
+
async function ensureValidCopy(src, dest, options) {
|
|
10
|
+
let destStat;
|
|
11
|
+
try {
|
|
12
|
+
destStat = await dntShim.Deno.lstat(dest);
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
if (err instanceof dntShim.Deno.errors.NotFound) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
if (options.isFolder && !destStat.isDirectory) {
|
|
21
|
+
throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`);
|
|
22
|
+
}
|
|
23
|
+
if (!options.overwrite) {
|
|
24
|
+
throw new dntShim.Deno.errors.AlreadyExists(`'${dest}' already exists.`);
|
|
25
|
+
}
|
|
26
|
+
return destStat;
|
|
27
|
+
}
|
|
28
|
+
function ensureValidCopySync(src, dest, options) {
|
|
29
|
+
let destStat;
|
|
30
|
+
try {
|
|
31
|
+
destStat = dntShim.Deno.lstatSync(dest);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (err instanceof dntShim.Deno.errors.NotFound) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
if (options.isFolder && !destStat.isDirectory) {
|
|
40
|
+
throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`);
|
|
41
|
+
}
|
|
42
|
+
if (!options.overwrite) {
|
|
43
|
+
throw new dntShim.Deno.errors.AlreadyExists(`'${dest}' already exists.`);
|
|
44
|
+
}
|
|
45
|
+
return destStat;
|
|
46
|
+
}
|
|
47
|
+
/* copy file to dest */
|
|
48
|
+
async function copyFile(src, dest, options) {
|
|
49
|
+
await ensureValidCopy(src, dest, options);
|
|
50
|
+
await dntShim.Deno.copyFile(src, dest);
|
|
51
|
+
if (options.preserveTimestamps) {
|
|
52
|
+
const statInfo = await dntShim.Deno.stat(src);
|
|
53
|
+
assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`);
|
|
54
|
+
assert(statInfo.mtime instanceof Date, `statInfo.mtime is unavailable`);
|
|
55
|
+
await dntShim.Deno.utime(dest, statInfo.atime, statInfo.mtime);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/* copy file to dest synchronously */
|
|
59
|
+
function copyFileSync(src, dest, options) {
|
|
60
|
+
ensureValidCopySync(src, dest, options);
|
|
61
|
+
dntShim.Deno.copyFileSync(src, dest);
|
|
62
|
+
if (options.preserveTimestamps) {
|
|
63
|
+
const statInfo = dntShim.Deno.statSync(src);
|
|
64
|
+
assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`);
|
|
65
|
+
assert(statInfo.mtime instanceof Date, `statInfo.mtime is unavailable`);
|
|
66
|
+
dntShim.Deno.utimeSync(dest, statInfo.atime, statInfo.mtime);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/* copy symlink to dest */
|
|
70
|
+
async function copySymLink(src, dest, options) {
|
|
71
|
+
await ensureValidCopy(src, dest, options);
|
|
72
|
+
const originSrcFilePath = await dntShim.Deno.readLink(src);
|
|
73
|
+
const type = getFileInfoType(await dntShim.Deno.lstat(src));
|
|
74
|
+
if (isWindows) {
|
|
75
|
+
await dntShim.Deno.symlink(originSrcFilePath, dest, {
|
|
76
|
+
type: type === "dir" ? "dir" : "file",
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
await dntShim.Deno.symlink(originSrcFilePath, dest);
|
|
81
|
+
}
|
|
82
|
+
if (options.preserveTimestamps) {
|
|
83
|
+
const statInfo = await dntShim.Deno.lstat(src);
|
|
84
|
+
assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`);
|
|
85
|
+
assert(statInfo.mtime instanceof Date, `statInfo.mtime is unavailable`);
|
|
86
|
+
await dntShim.Deno.utime(dest, statInfo.atime, statInfo.mtime);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/* copy symlink to dest synchronously */
|
|
90
|
+
function copySymlinkSync(src, dest, options) {
|
|
91
|
+
ensureValidCopySync(src, dest, options);
|
|
92
|
+
const originSrcFilePath = dntShim.Deno.readLinkSync(src);
|
|
93
|
+
const type = getFileInfoType(dntShim.Deno.lstatSync(src));
|
|
94
|
+
if (isWindows) {
|
|
95
|
+
dntShim.Deno.symlinkSync(originSrcFilePath, dest, {
|
|
96
|
+
type: type === "dir" ? "dir" : "file",
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
dntShim.Deno.symlinkSync(originSrcFilePath, dest);
|
|
101
|
+
}
|
|
102
|
+
if (options.preserveTimestamps) {
|
|
103
|
+
const statInfo = dntShim.Deno.lstatSync(src);
|
|
104
|
+
assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`);
|
|
105
|
+
assert(statInfo.mtime instanceof Date, `statInfo.mtime is unavailable`);
|
|
106
|
+
dntShim.Deno.utimeSync(dest, statInfo.atime, statInfo.mtime);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/* copy folder from src to dest. */
|
|
110
|
+
async function copyDir(src, dest, options) {
|
|
111
|
+
const destStat = await ensureValidCopy(src, dest, {
|
|
112
|
+
...options,
|
|
113
|
+
isFolder: true,
|
|
114
|
+
});
|
|
115
|
+
if (!destStat) {
|
|
116
|
+
await ensureDir(dest);
|
|
117
|
+
}
|
|
118
|
+
if (options.preserveTimestamps) {
|
|
119
|
+
const srcStatInfo = await dntShim.Deno.stat(src);
|
|
120
|
+
assert(srcStatInfo.atime instanceof Date, `statInfo.atime is unavailable`);
|
|
121
|
+
assert(srcStatInfo.mtime instanceof Date, `statInfo.mtime is unavailable`);
|
|
122
|
+
await dntShim.Deno.utime(dest, srcStatInfo.atime, srcStatInfo.mtime);
|
|
123
|
+
}
|
|
124
|
+
src = toPathString(src);
|
|
125
|
+
dest = toPathString(dest);
|
|
126
|
+
for await (const entry of dntShim.Deno.readDir(src)) {
|
|
127
|
+
const srcPath = path.join(src, entry.name);
|
|
128
|
+
const destPath = path.join(dest, path.basename(srcPath));
|
|
129
|
+
if (entry.isSymlink) {
|
|
130
|
+
await copySymLink(srcPath, destPath, options);
|
|
131
|
+
}
|
|
132
|
+
else if (entry.isDirectory) {
|
|
133
|
+
await copyDir(srcPath, destPath, options);
|
|
134
|
+
}
|
|
135
|
+
else if (entry.isFile) {
|
|
136
|
+
await copyFile(srcPath, destPath, options);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/* copy folder from src to dest synchronously */
|
|
141
|
+
function copyDirSync(src, dest, options) {
|
|
142
|
+
const destStat = ensureValidCopySync(src, dest, {
|
|
143
|
+
...options,
|
|
144
|
+
isFolder: true,
|
|
145
|
+
});
|
|
146
|
+
if (!destStat) {
|
|
147
|
+
ensureDirSync(dest);
|
|
148
|
+
}
|
|
149
|
+
if (options.preserveTimestamps) {
|
|
150
|
+
const srcStatInfo = dntShim.Deno.statSync(src);
|
|
151
|
+
assert(srcStatInfo.atime instanceof Date, `statInfo.atime is unavailable`);
|
|
152
|
+
assert(srcStatInfo.mtime instanceof Date, `statInfo.mtime is unavailable`);
|
|
153
|
+
dntShim.Deno.utimeSync(dest, srcStatInfo.atime, srcStatInfo.mtime);
|
|
154
|
+
}
|
|
155
|
+
src = toPathString(src);
|
|
156
|
+
dest = toPathString(dest);
|
|
157
|
+
for (const entry of dntShim.Deno.readDirSync(src)) {
|
|
158
|
+
assert(entry.name != null, "file.name must be set");
|
|
159
|
+
const srcPath = path.join(src, entry.name);
|
|
160
|
+
const destPath = path.join(dest, path.basename(srcPath));
|
|
161
|
+
if (entry.isSymlink) {
|
|
162
|
+
copySymlinkSync(srcPath, destPath, options);
|
|
163
|
+
}
|
|
164
|
+
else if (entry.isDirectory) {
|
|
165
|
+
copyDirSync(srcPath, destPath, options);
|
|
166
|
+
}
|
|
167
|
+
else if (entry.isFile) {
|
|
168
|
+
copyFileSync(srcPath, destPath, options);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Copy a file or directory. The directory can have contents. Like `cp -r`.
|
|
174
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* import { copy } from "https://deno.land/std@$STD_VERSION/fs/copy.ts";
|
|
179
|
+
* copy("./foo", "./bar"); // returns a promise
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
* @param src the file/directory path.
|
|
183
|
+
* Note that if `src` is a directory it will copy everything inside
|
|
184
|
+
* of this directory, not the entire directory itself
|
|
185
|
+
* @param dest the destination path. Note that if `src` is a file, `dest` cannot
|
|
186
|
+
* be a directory
|
|
187
|
+
* @param options
|
|
188
|
+
*/
|
|
189
|
+
export async function copy(src, dest, options = {}) {
|
|
190
|
+
src = path.resolve(toPathString(src));
|
|
191
|
+
dest = path.resolve(toPathString(dest));
|
|
192
|
+
if (src === dest) {
|
|
193
|
+
throw new Error("Source and destination cannot be the same.");
|
|
194
|
+
}
|
|
195
|
+
const srcStat = await dntShim.Deno.lstat(src);
|
|
196
|
+
if (srcStat.isDirectory && isSubdir(src, dest)) {
|
|
197
|
+
throw new Error(`Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`);
|
|
198
|
+
}
|
|
199
|
+
if (srcStat.isSymlink) {
|
|
200
|
+
await copySymLink(src, dest, options);
|
|
201
|
+
}
|
|
202
|
+
else if (srcStat.isDirectory) {
|
|
203
|
+
await copyDir(src, dest, options);
|
|
204
|
+
}
|
|
205
|
+
else if (srcStat.isFile) {
|
|
206
|
+
await copyFile(src, dest, options);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Copy a file or directory. The directory can have contents. Like `cp -r`.
|
|
211
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* import { copySync } from "https://deno.land/std@$STD_VERSION/fs/copy.ts";
|
|
216
|
+
* copySync("./foo", "./bar"); // void
|
|
217
|
+
* ```
|
|
218
|
+
* @param src the file/directory path.
|
|
219
|
+
* Note that if `src` is a directory it will copy everything inside
|
|
220
|
+
* of this directory, not the entire directory itself
|
|
221
|
+
* @param dest the destination path. Note that if `src` is a file, `dest` cannot
|
|
222
|
+
* be a directory
|
|
223
|
+
* @param options
|
|
224
|
+
*/
|
|
225
|
+
export function copySync(src, dest, options = {}) {
|
|
226
|
+
src = path.resolve(toPathString(src));
|
|
227
|
+
dest = path.resolve(toPathString(dest));
|
|
228
|
+
if (src === dest) {
|
|
229
|
+
throw new Error("Source and destination cannot be the same.");
|
|
230
|
+
}
|
|
231
|
+
const srcStat = dntShim.Deno.lstatSync(src);
|
|
232
|
+
if (srcStat.isDirectory && isSubdir(src, dest)) {
|
|
233
|
+
throw new Error(`Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`);
|
|
234
|
+
}
|
|
235
|
+
if (srcStat.isSymlink) {
|
|
236
|
+
copySymlinkSync(src, dest, options);
|
|
237
|
+
}
|
|
238
|
+
else if (srcStat.isDirectory) {
|
|
239
|
+
copyDirSync(src, dest, options);
|
|
240
|
+
}
|
|
241
|
+
else if (srcStat.isFile) {
|
|
242
|
+
copyFileSync(src, dest, options);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Ensures that a directory is empty.
|
|
4
|
+
* Deletes directory contents if the directory is not empty.
|
|
5
|
+
* If the directory does not exist, it is created.
|
|
6
|
+
* The directory itself is not deleted.
|
|
7
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { emptyDir } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
12
|
+
*
|
|
13
|
+
* emptyDir("./foo"); // returns a promise
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function emptyDir(dir: string | URL): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Ensures that a directory is empty.
|
|
19
|
+
* Deletes directory contents if the directory is not empty.
|
|
20
|
+
* If the directory does not exist, it is created.
|
|
21
|
+
* The directory itself is not deleted.
|
|
22
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { emptyDirSync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
27
|
+
*
|
|
28
|
+
* emptyDirSync("./foo"); // void
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function emptyDirSync(dir: string | URL): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
3
|
+
import { join } from "../path/mod.js";
|
|
4
|
+
import { toPathString } from "./_util.js";
|
|
5
|
+
/**
|
|
6
|
+
* Ensures that a directory is empty.
|
|
7
|
+
* Deletes directory contents if the directory is not empty.
|
|
8
|
+
* If the directory does not exist, it is created.
|
|
9
|
+
* The directory itself is not deleted.
|
|
10
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { emptyDir } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
15
|
+
*
|
|
16
|
+
* emptyDir("./foo"); // returns a promise
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export async function emptyDir(dir) {
|
|
20
|
+
try {
|
|
21
|
+
const items = [];
|
|
22
|
+
for await (const dirEntry of dntShim.Deno.readDir(dir)) {
|
|
23
|
+
items.push(dirEntry);
|
|
24
|
+
}
|
|
25
|
+
while (items.length) {
|
|
26
|
+
const item = items.shift();
|
|
27
|
+
if (item && item.name) {
|
|
28
|
+
const filepath = join(toPathString(dir), item.name);
|
|
29
|
+
await dntShim.Deno.remove(filepath, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (!(err instanceof dntShim.Deno.errors.NotFound)) {
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
// if not exist. then create it
|
|
38
|
+
await dntShim.Deno.mkdir(dir, { recursive: true });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Ensures that a directory is empty.
|
|
43
|
+
* Deletes directory contents if the directory is not empty.
|
|
44
|
+
* If the directory does not exist, it is created.
|
|
45
|
+
* The directory itself is not deleted.
|
|
46
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { emptyDirSync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
51
|
+
*
|
|
52
|
+
* emptyDirSync("./foo"); // void
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function emptyDirSync(dir) {
|
|
56
|
+
try {
|
|
57
|
+
const items = [...dntShim.Deno.readDirSync(dir)];
|
|
58
|
+
// If the directory exists, remove all entries inside it.
|
|
59
|
+
while (items.length) {
|
|
60
|
+
const item = items.shift();
|
|
61
|
+
if (item && item.name) {
|
|
62
|
+
const filepath = join(toPathString(dir), item.name);
|
|
63
|
+
dntShim.Deno.removeSync(filepath, { recursive: true });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
if (!(err instanceof dntShim.Deno.errors.NotFound)) {
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
// if not exist. then create it
|
|
72
|
+
dntShim.Deno.mkdirSync(dir, { recursive: true });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Ensures that the directory exists.
|
|
4
|
+
* If the directory structure does not exist, it is created. Like mkdir -p.
|
|
5
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { ensureDir } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
10
|
+
*
|
|
11
|
+
* ensureDir("./bar"); // returns a promise
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function ensureDir(dir: string | URL): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Ensures that the directory exists.
|
|
17
|
+
* If the directory structure does not exist, it is created. Like mkdir -p.
|
|
18
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { ensureDirSync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
23
|
+
*
|
|
24
|
+
* ensureDirSync("./ensureDirSync"); // void
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function ensureDirSync(dir: string | URL): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
3
|
+
import { getFileInfoType } from "./_util.js";
|
|
4
|
+
/**
|
|
5
|
+
* Ensures that the directory exists.
|
|
6
|
+
* If the directory structure does not exist, it is created. Like mkdir -p.
|
|
7
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { ensureDir } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
12
|
+
*
|
|
13
|
+
* ensureDir("./bar"); // returns a promise
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export async function ensureDir(dir) {
|
|
17
|
+
try {
|
|
18
|
+
await dntShim.Deno.mkdir(dir, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
if (!(err instanceof dntShim.Deno.errors.AlreadyExists)) {
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
const fileInfo = await dntShim.Deno.lstat(dir);
|
|
25
|
+
if (!fileInfo.isDirectory) {
|
|
26
|
+
throw new Error(`Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Ensures that the directory exists.
|
|
32
|
+
* If the directory structure does not exist, it is created. Like mkdir -p.
|
|
33
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { ensureDirSync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
38
|
+
*
|
|
39
|
+
* ensureDirSync("./ensureDirSync"); // void
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function ensureDirSync(dir) {
|
|
43
|
+
try {
|
|
44
|
+
dntShim.Deno.mkdirSync(dir, { recursive: true });
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
if (!(err instanceof dntShim.Deno.errors.AlreadyExists)) {
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
const fileInfo = dntShim.Deno.lstatSync(dir);
|
|
51
|
+
if (!fileInfo.isDirectory) {
|
|
52
|
+
throw new Error(`Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Ensures that the file exists.
|
|
4
|
+
* If the file that is requested to be created is in directories that do not
|
|
5
|
+
* exist.
|
|
6
|
+
* these directories are created. If the file already exists,
|
|
7
|
+
* it is NOTMODIFIED.
|
|
8
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { ensureFile } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
13
|
+
*
|
|
14
|
+
* ensureFile("./folder/targetFile.dat"); // returns promise
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function ensureFile(filePath: string | URL): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Ensures that the file exists.
|
|
20
|
+
* If the file that is requested to be created is in directories that do not
|
|
21
|
+
* exist,
|
|
22
|
+
* these directories are created. If the file already exists,
|
|
23
|
+
* it is NOT MODIFIED.
|
|
24
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { ensureFileSync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
29
|
+
*
|
|
30
|
+
* ensureFileSync("./folder/targetFile.dat"); // void
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function ensureFileSync(filePath: string | URL): void;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
3
|
+
import * as path from "../path/mod.js";
|
|
4
|
+
import { ensureDir, ensureDirSync } from "./ensure_dir.js";
|
|
5
|
+
import { getFileInfoType, toPathString } from "./_util.js";
|
|
6
|
+
/**
|
|
7
|
+
* Ensures that the file exists.
|
|
8
|
+
* If the file that is requested to be created is in directories that do not
|
|
9
|
+
* exist.
|
|
10
|
+
* these directories are created. If the file already exists,
|
|
11
|
+
* it is NOTMODIFIED.
|
|
12
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { ensureFile } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
17
|
+
*
|
|
18
|
+
* ensureFile("./folder/targetFile.dat"); // returns promise
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export async function ensureFile(filePath) {
|
|
22
|
+
try {
|
|
23
|
+
// if file exists
|
|
24
|
+
const stat = await dntShim.Deno.lstat(filePath);
|
|
25
|
+
if (!stat.isFile) {
|
|
26
|
+
throw new Error(`Ensure path exists, expected 'file', got '${getFileInfoType(stat)}'`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
// if file not exists
|
|
31
|
+
if (err instanceof dntShim.Deno.errors.NotFound) {
|
|
32
|
+
// ensure dir exists
|
|
33
|
+
await ensureDir(path.dirname(toPathString(filePath)));
|
|
34
|
+
// create file
|
|
35
|
+
await dntShim.Deno.writeFile(filePath, new Uint8Array());
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Ensures that the file exists.
|
|
43
|
+
* If the file that is requested to be created is in directories that do not
|
|
44
|
+
* exist,
|
|
45
|
+
* these directories are created. If the file already exists,
|
|
46
|
+
* it is NOT MODIFIED.
|
|
47
|
+
* Requires the `--allow-read` and `--allow-write` flag.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { ensureFileSync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
52
|
+
*
|
|
53
|
+
* ensureFileSync("./folder/targetFile.dat"); // void
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export function ensureFileSync(filePath) {
|
|
57
|
+
try {
|
|
58
|
+
// if file exists
|
|
59
|
+
const stat = dntShim.Deno.lstatSync(filePath);
|
|
60
|
+
if (!stat.isFile) {
|
|
61
|
+
throw new Error(`Ensure path exists, expected 'file', got '${getFileInfoType(stat)}'`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
// if file not exists
|
|
66
|
+
if (err instanceof dntShim.Deno.errors.NotFound) {
|
|
67
|
+
// ensure dir exists
|
|
68
|
+
ensureDirSync(path.dirname(toPathString(filePath)));
|
|
69
|
+
// create file
|
|
70
|
+
dntShim.Deno.writeFileSync(filePath, new Uint8Array());
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Ensures that the hard link exists.
|
|
4
|
+
* If the directory structure does not exist, it is created.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { ensureSymlink } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
9
|
+
*
|
|
10
|
+
* ensureSymlink("./folder/targetFile.dat", "./folder/targetFile.link.dat"); // returns promise
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param src the source file path. Directory hard links are not allowed.
|
|
14
|
+
* @param dest the destination link path
|
|
15
|
+
*/
|
|
16
|
+
export declare function ensureLink(src: string | URL, dest: string | URL): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Ensures that the hard link exists.
|
|
19
|
+
* If the directory structure does not exist, it is created.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { ensureSymlinkSync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
24
|
+
*
|
|
25
|
+
* ensureSymlinkSync("./folder/targetFile.dat", "./folder/targetFile.link.dat"); // void
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param src the source file path. Directory hard links are not allowed.
|
|
29
|
+
* @param dest the destination link path
|
|
30
|
+
*/
|
|
31
|
+
export declare function ensureLinkSync(src: string | URL, dest: string | URL): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
3
|
+
import * as path from "../path/mod.js";
|
|
4
|
+
import { ensureDir, ensureDirSync } from "./ensure_dir.js";
|
|
5
|
+
import { toPathString } from "./_util.js";
|
|
6
|
+
/**
|
|
7
|
+
* Ensures that the hard link exists.
|
|
8
|
+
* If the directory structure does not exist, it is created.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { ensureSymlink } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
13
|
+
*
|
|
14
|
+
* ensureSymlink("./folder/targetFile.dat", "./folder/targetFile.link.dat"); // returns promise
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param src the source file path. Directory hard links are not allowed.
|
|
18
|
+
* @param dest the destination link path
|
|
19
|
+
*/
|
|
20
|
+
export async function ensureLink(src, dest) {
|
|
21
|
+
dest = toPathString(dest);
|
|
22
|
+
await ensureDir(path.dirname(dest));
|
|
23
|
+
await dntShim.Deno.link(toPathString(src), dest);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Ensures that the hard link exists.
|
|
27
|
+
* If the directory structure does not exist, it is created.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { ensureSymlinkSync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";
|
|
32
|
+
*
|
|
33
|
+
* ensureSymlinkSync("./folder/targetFile.dat", "./folder/targetFile.link.dat"); // void
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param src the source file path. Directory hard links are not allowed.
|
|
37
|
+
* @param dest the destination link path
|
|
38
|
+
*/
|
|
39
|
+
export function ensureLinkSync(src, dest) {
|
|
40
|
+
dest = toPathString(dest);
|
|
41
|
+
ensureDirSync(path.dirname(dest));
|
|
42
|
+
dntShim.Deno.linkSync(toPathString(src), dest);
|
|
43
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Ensures that the link exists, and points to a valid file.
|
|
4
|
+
* If the directory structure does not exist, it is created.
|
|
5
|
+
*
|
|
6
|
+
* @param target the source file path
|
|
7
|
+
* @param linkName the destination link path
|
|
8
|
+
*/
|
|
9
|
+
export declare function ensureSymlink(target: string | URL, linkName: string | URL): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Ensures that the link exists, and points to a valid file.
|
|
12
|
+
* If the directory structure does not exist, it is created.
|
|
13
|
+
*
|
|
14
|
+
* @param target the source file path
|
|
15
|
+
* @param linkName the destination link path
|
|
16
|
+
*/
|
|
17
|
+
export declare function ensureSymlinkSync(target: string | URL, linkName: string | URL): void;
|