oneRepo API: file
File manipulation functions.
Type Aliases
Section titled Type AliasesOptions
Section titled OptionsGeneric options for file functions
Type declaration
Section titled Type declarationstep?
Section titled step?Avoid creating a new step in output for each function. Pass a Logger Step to pipe all logs and output to that instead.
Defined in: modules/file/src/index.ts
ReadJsonOptions
Section titled ReadJsonOptionsType declaration
Section titled Type declarationjsonc?
Section titled jsonc?Parse the file as JSONC (JSON with comments).
Defined in: modules/file/src/index.ts
ReadSafeOptions
Section titled ReadSafeOptionsType declaration
Section titled Type declarationsentinel?
Section titled sentinel?Unique string to use as a start and end sentinel for the contents
step?
Section titled step?Avoid creating a new step in output for each function. Pass a Logger Step to pipe all logs and output to that instead.
Defined in: modules/file/src/index.ts
SigningStatus
Section titled SigningStatusDefined in: modules/file/src/signing.ts
WriteOptions
Section titled WriteOptionsType declaration
Section titled Type declarationsign?
Section titled sign?Optionally sign the contents for future verification.
step?
Section titled step?Avoid creating a new step in output for each function. Pass a Logger Step to pipe all logs and output to that instead.
Defined in: modules/file/src/index.ts
WriteSafeOptions
Section titled WriteSafeOptionsType declaration
Section titled Type declarationsentinel?
Section titled sentinel?Unique string to use as a start and end sentinel for the contents
sign?
Section titled sign?Optionally sign the contents for future verification.
step?
Section titled step?Avoid creating a new step in output for each function. Pass a Logger Step to pipe all logs and output to that instead.
Defined in: modules/file/src/index.ts
Functions
Section titled Functionschmod()
Section titled chmod()Change file permissions
Parameters:
Parameter | Type |
---|---|
filename | string |
mode | string | number |
options ? | Options |
Returns: Promise
<void
>
Defined in: modules/file/src/index.ts
copy()
Section titled copy()Copy a file from one location to another.
If --dry-run
or process.env.ONEREPO_DRY_RUN
is true, no files will be modified.
Parameters:
Parameter | Type |
---|---|
input | string |
output | string |
options ? | Options |
Returns: Promise
<void
>
Defined in: modules/file/src/index.ts
exists()
Section titled exists()Step-wrapped fs.existsSync
implementation.
Parameters:
Parameter | Type |
---|---|
filename | string |
options ? | Options |
Returns: Promise
<boolean
>
Defined in: modules/file/src/index.ts
isSigned()
Section titled isSigned()Checks whether a file is signed without verifying the signature.
Parameters:
Parameter | Type |
---|---|
contents | string |
Returns: boolean
Defined in: modules/file/src/signing.ts
lstat()
Section titled lstat()Step-wrapped fs.lstat
implementation. See the node.js fs.Stats documentation for more on how to use the return data.
Parameters:
Parameter | Type |
---|---|
filename | string |
options ? | Options |
Returns: Promise
<Stats
| null
>
If the filename
does not exist, null
will be returned instead of a Stats object.
Defined in: modules/file/src/index.ts
makeTempDir()
Section titled makeTempDir()Create a tmp directory in the os tmpdir.
Parameters:
Parameter | Type |
---|---|
prefix | string |
options ? | Options |
Returns: Promise
<string
>
Defined in: modules/file/src/index.ts
mkdirp()
Section titled mkdirp()Recursively create a directory.
Parameters:
Parameter | Type |
---|---|
pathname | string |
options ? | Options |
Returns: Promise
<void
>
Defined in: modules/file/src/index.ts
read()
Section titled read()Read the contents of a file.
Parameters:
Parameter | Type |
---|---|
filename | string |
flag ? | OpenMode |
options ? | Options |
Returns: Promise
<string
>
Defined in: modules/file/src/index.ts
readJson()
Section titled readJson()Read and parse a JSON files.
Compatible with jsonc by stripping comments before running JSON.parse()
. Pass jsonc: true
to the options to enable jsonc.
Type Parameters
Section titled Type ParametersType Parameter |
---|
T extends Record <string , unknown > |
Parameters:
Parameter | Type |
---|---|
filename | string |
flag ? | OpenMode |
options ? | ReadJsonOptions |
Returns: Promise
<T
>
Defined in: modules/file/src/index.ts
readSafe()
Section titled readSafe()Read a sentinel-wrapped portion of a file that was previously written with writeSafe and return both the wrapped portion as well as the full contents of the file.
Parameters:
Parameter | Type |
---|---|
filename | string |
options ? | ReadSafeOptions |
Returns: Promise
<[string
| null
, string
]>
Defined in: modules/file/src/index.ts
remove()
Section titled remove()Remove files and folders at a given path. Equivalent to rm -rf {pathname}
Parameters:
Parameter | Type |
---|---|
pathname | string |
options ? | Options |
Returns: Promise
<void
>
Defined in: modules/file/src/index.ts
signContents()
Section titled signContents()Sign the contents for a given file without writing out. This function is typically useful for manually comparing signed file contents.
Parameters:
Parameter | Type |
---|---|
filename | string |
contents | string |
options ? | Options |
Returns: Promise
<any
>
Defined in: modules/file/src/index.ts
verifySignature()
Section titled verifySignature()Verify the signature in a signed file.
Parameters:
Parameter | Type |
---|---|
contents | string |
Returns: SigningStatus
Defined in: modules/file/src/signing.ts
write()
Section titled write()Write to a file. This will attempt use Prettier to format the contents based on the filename
given. If Prettier does not understand the file’s extension, no changes will be made.
If --dry-run
or process.env.ONEREPO_DRY_RUN
is true, no files will be modified.
Parameters:
Parameter | Type |
---|---|
filename | string |
contents | string |
options ? | WriteOptions |
Returns: Promise
<void
>
Defined in: modules/file/src/index.ts
writeSafe()
Section titled writeSafe()Safely write contents to a file, wrapped in a start and end sentinel. This allows writing to a file without overwriting the current content of the file – other than that which falls between the start and end sentinel.
Write to /path/to/out/
between a section denoted by the sentinel 'some-unique-string'
while leaving the rest of the file intact.
Write to a section of the file as signed content for verifying later.
Parameters:
Parameter | Type |
---|---|
filename | string |
contents | string |
options ? | WriteSafeOptions |
Returns: Promise
<void
>
Defined in: modules/file/src/index.ts