Easy file operations between node.js modules and auto logging to help building zero-config boilerplates, postinstall and other scripts.
npm install intermodularSee documentation at https://intermodular.ozum.net.
Easy file operations between node.js modules and auto logging to help building zero-config boilerplates, postinstall and other scripts.
- Installation
- Synopsis
- API
- intermodular
- Type aliases
- CopyFilterFunction
- DependencyType
- PackageManager
- PredicateFileOperation
- StdioOption
- Variables
- Const ALL_DEPENDENCIES
- swc
- Classes
- Class: Intermodular
- Hierarchy
- Properties
- Readonly config
- Readonly logger
- Readonly sourceModule
- Readonly targetModule
- Methods
- areEquivalentFiles
- command
- copy
- execute
- log
- Static isEnvSet
- Static new
- Static parseEnv
- Class: Module
- Hierarchy
- Properties
- Readonly isTypeScript
- Readonly package
- Readonly packageManager
- Readonly root
- Accessors
- name
- nameWithoutUser
- Methods
- cloneWithSharedManager
- command
- createDirectory
- execute
- exists
- getDependencyVersion
- hasAnyDependency
- ifAnyDependency
- install
- isDirectory
- isEqual
- pathOf
- read
- readData
- readRaw
- relativePathOf
- remove
- removeEmptyDirs
- rename
- saveAll
- uninstall
- write
- Static new
- Interfaces
- Interface: CopyOptions
- Hierarchy
- Properties
- Optional dereference
- Optional errorOnExist
- Optional excludeDirFromReturn
- Optional filter
- Optional overwrite
- Optional preserveTimestamps
- Optional recursive
- Interface: ExecuteOptions ‹EncodingType›
- Type parameters
- Hierarchy
- Properties
- Optional Readonly all
- Optional Readonly argv0
- Optional Readonly buffer
- Optional Readonly cleanup
- Optional Readonly cwd
- Optional Readonly detached
- Optional Readonly encoding
- Optional Readonly env
- Optional Readonly execPath
- Optional exitOnProcessFailure
- Optional Readonly extendEnv
- Optional Readonly gid
- Optional Readonly input
- Optional Readonly killSignal
- Optional Readonly localDir
- Optional Readonly maxBuffer
- Optional Readonly preferLocal
- Optional Readonly reject
- Optional Readonly serialization
- Optional Readonly shell
- Optional Readonly stderr
- Optional Readonly stdin
- Optional stdio
- Optional Readonly stdout
- Optional Readonly stripFinalNewline
- Optional Readonly timeout
- Optional Readonly uid
- Optional Readonly windowsHide
- Optional Readonly windowsVerbatimArguments
``sh`
npm install intermodular
`ts
import Intermodular from "intermodular";
const intermodular = await Intermodular.new();
const targetModule = intermodular.targetModule;
// Copy all files from my-boilerplate/config/ to my-project/
await intermodular.copy("config", ".");
// Update project's package.json.My awesome project of ${targetModule.name}
targetModule.package.set("description", );
// Get some deep data from cosmiconfig compatible config file from my-project/.my-boilerplaterc or any cosmiconfig compatible way automatically.tsc ${buildFlags}
const buildFlags = intermodular.config.get("build.flags");
targetModule.package.set("scripts.build": );
// Read and update target eslint configuration.
const eslintConfig = await targetModule.read("eslint", { cosmiconfig: true });
eslintConfig.set("rules.lines-between-class-members", ["warn", "always", { exceptAfterSingleLine: true }]);
await targetModule.saveAll();
await targetModule.install("lodash");
await targetModule.execute("tsc", ["-b"]);
`
Ƭ CopyFilterFunction: _function_
_Defined in src/util/types.ts:22_
Type for function to filter copied files.
#### Type declaration:
▸ (fullSourcePath: string, fullTargetPath: string, isSourceDirectory: boolean, isTargetDirectory: boolean, sourceContent?: string | DataFile, targetContent?: string | DataFile): _boolean | Promise‹boolean›_
Sync callback function to filter copied files.
Parameters:
| Name | Type | Description |
| ------------------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| fullSourcePath | string | path of source file. |fullTargetPath
| | string | path of target file. |isSourceDirectory
| | boolean | is whether source path is a directory. |isTargetDirectory
| | boolean | is whether target path is a directory. |sourceContent?
| | string | DataFile | is string content or {@link DataFile https://www.npmjs.com/package/edit-config} instance if content of source file is parseble object. If file does not exist or is a directory, this is undefined. |targetContent?
| | string | DataFile | is string content or {@link DataFile https://www.npmjs.com/package/edit-config} instance if content of target file is parseble object. If file does not exist or is a directory, this is undefined. |
---
Ƭ DependencyType: _"dependencies" | "devDependencies" | "peerDependencies" | "optionalDependencies"_
_Defined in src/util/types.ts:9_
Dependency types for Node.js modules.
---
Ƭ PackageManager: _"npm" | "yarn"_
_Defined in src/util/types.ts:6_
Package manager
---
Ƭ PredicateFileOperation: _function_
_Defined in src/util/types.ts:12_
Type of callback function to test whether related file operation should be done.
#### Type declaration:
▸ (fileContent?: string | DataFile): _Promise‹boolean› | boolean_
Callback function to test whether related file operation should be done.
Parameters:
| Name | Type |
| -------------- | ---------------------- |
| fileContent? | string | DataFile |
---
Ƭ StdioOption: _"pipe" | "ignore" | "inherit" | Array‹"pipe" | "ipc" | "ignore" | "inherit" | Stream | number | undefined›_
_Defined in src/util/types.ts:70_
• ALL_DEPENDENCIES: _string[]_ = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]
_Defined in src/module.ts:11_
---
• swc: _"/Users/ozum/Development/intermodular/node_modules/@swc/core/index"_
_Defined in src/intermodular.ts:12_
- Intermodular
• config: _DataFile_
_Defined in src/intermodular.ts:22_
Configuration for source module in target module as a DataFile instance.
---
• logger: _Logger_
_Defined in src/intermodular.ts:25_
Winston compatible logger.
---
• sourceModule: _Module_
_Defined in src/intermodular.ts:16_
Module instance of node module which is used as source for modification operations such as copy, update.
---
• targetModule: _Module_
_Defined in src/intermodular.ts:19_
Module instance of node module which is used as target for modification operations such as copy, update.
▸ areEquivalentFiles(sourceModuleFilePath: string, targetModuleFilePath: string): _Promise‹boolean›_
_Defined in src/intermodular.ts:211_
Returns whether given files from source module and target module are equal using method described below:
- For data files such as JSON or YAML, returns whether they are deeply equal. (Objects does not have to have same key order.).js
- For and .ts files, files are transpiled and minified then copmpared. (To overcome comment and simple format changes.)
- For other files returns whether their string content are equal.
#### Example
`typescript`
intermodular("module-files/src/address.js", "src/address.js");
intermodular("module-files/config/.eslintrc", ".eslintrc");
intermodular("module-files/some.txt", "some.txt");
Parameters:
| Name | Type | Default | Description |
| ---------------------- | ------ | -------------------- | ------------------------------------------------------------------------------------------------------------------- |
| sourceModuleFilePath | string | - | is the file path relative to source module root. |targetModuleFilePath
| | string | sourceModuleFilePath | is the file path relative to target module root. If not provided uses same relative path as sourceModuleFilePath. |
Returns: _Promise‹boolean›_
whether given files are equivalent.
---
▸ command(cmd: string, options?: ExecuteOptions): _Promise‹ExecaReturnValue›_
_Defined in src/intermodular.ts:190_
Executes given command using execa.command with cwd as target module's root. Additionally adds source module's node_modules/.bin to path.
#### Example
`typescriptls
intermodular.command("ls"); // Run .ls -al
intermodular.command("ls -al", { stdio: "inherit" }); // Run .`
Parameters:
| Name | Type | Description |
| ---------- | --------------------------------------------- | ----------------------------------------------------------- |
| cmd | string | is command to execute. |options?
| | ExecuteOptions | are passed to Execa. |
Returns: _Promise‹ExecaReturnValue›_
[[ExecaReturnValue]] instance.
▸ command(cmd: string, options?: ExecuteOptions‹null›): _Promise‹ExecaReturnValue‹Buffer››_
_Defined in src/intermodular.ts:191_
Parameters:
| Name | Type |
| ---------- | --------------------------------------------------- |
| cmd | string |options?
| | ExecuteOptions‹null› |
Returns: _Promise‹ExecaReturnValue‹Buffer››_
---
▸ copy(sourcePath: string, targetPath: string, copyOptions: CopyOptions): _Promise‹string[]›_
_Defined in src/intermodular.ts:124_
Copies a file or directory from pathInSourceModule relative to source module root to pathInTargetModulerelative to
target module root. The directory can have contents. Like cp -r.
IMPORTANT: Note that if source is a directory it will copy everything inside of this directory, not the entire directory itself.
#### Example
`typescript/path/to/project/node_modules/module-a/src/config/
// Copy everything in to /path/to/project/`
const copiedPaths = copySync("src/config", ".");
const copiedFiles = copySync("src/config", ".", { excludeDirFromReturn: true });
Parameters:
| Name | Type | Default | Description |
| ------------- | --------------------------------------- | ---------- | ------------------------------------------------- |
| sourcePath | string | - | is source to copy from. |targetPath
| | string | sourcePath | is destination to copy to. Cannot be a directory. |copyOptions
| | CopyOptions | {} | - |
Returns: _Promise‹string[]›_
copied files and directories. Directories can be optionally excluded.
---
▸ execute(bin: string, args?: string[], options?: ExecuteOptions): _Promise‹ExecaReturnValue›_
_Defined in src/intermodular.ts:154_
Executes given command using execa with given arguments and options with cwd as target module's root. Applies sensible default options.node_modules/.bin
Additionally adds source module's to path.
#### Example
`typescriptls
intermodular.execute("ls"); // Run .ls -al
intermodular.execute("ls", ["-al"], { stdio: "inherit" }); // Run .`
Parameters:
| Name | Type | Description |
| ---------- | --------------------------------------------- | ----------------------------------------------------------- |
| bin | string | is binary file to execute. |args?
| | string[] | are arguments to pass to executable. |options?
| | ExecuteOptions | are passed to Execa. |
Returns: _Promise‹ExecaReturnValue›_
[[ExecaReturnValue]] instance.
▸ execute(bin: string, args?: string[], options?: ExecuteOptions‹null›): _Promise‹ExecaReturnValue‹Buffer››_
_Defined in src/intermodular.ts:155_
Parameters:
| Name | Type |
| ---------- | --------------------------------------------------- |
| bin | string |args?
| | string[] |options?
| | ExecuteOptions‹null› |
Returns: _Promise‹ExecaReturnValue‹Buffer››_
▸ execute(bin: string, options?: ExecuteOptions): _Promise‹ExecaReturnValue›_
_Defined in src/intermodular.ts:168_
Executes given command using execa with given arguments and options with cwd as target module's root. Applies sensible default options.node_modules/.bin
Additionally adds source module's to path.
#### Example
`typescriptls
intermodular.execute("ls"); // Run .ls
intermodular.execute("ls", { stdio: "inherit" }); // Run .`
Parameters:
| Name | Type | Description |
| ---------- | --------------------------------------------- | ----------------------------------------------------------- |
| bin | string | is binary file to execute. |options?
| | ExecuteOptions | are passed to Execa. |
Returns: _Promise‹ExecaReturnValue›_
[[ExecaReturnValue]] instance.
▸ execute(bin: string, options?: ExecuteOptions‹null›): _Promise‹ExecaReturnValue‹Buffer››_
_Defined in src/intermodular.ts:169_
Parameters:
| Name | Type |
| ---------- | --------------------------------------------------- |
| bin | string |options?
| | ExecuteOptions‹null› |
Returns: _Promise‹ExecaReturnValue‹Buffer››_
---
▸ log(logLevel: LogLevel, message: string): _void_
_Defined in src/intermodular.ts:40_
Logs given message with required level using logger provided during object construction.
Parameters:
| Name | Type | Description |
| ---------- | -------- | ---------------------------- |
| logLevel | LogLevel | is the level to log message. |message
| | string | is the message to log. |
Returns: _void_
---
▸ isEnvSet(variable: string): _boolean_
_Defined in src/intermodular.ts:285_
Returns whether variable is set in environment variables and not empty.
Parameters:
| Name | Type | Description |
| ---------- | ------ | --------------------------------------------- |
| variable | string | is name of the environment variable to check. |
Returns: _boolean_
whether given environment variable is set and not empty.
---
▸ new(__namedParameters: object): _Promise‹Intermodular›_
_Defined in src/intermodular.ts:242_
Creates and returns Intermodular instance.
Parameters:
▪Default value \_\_namedParameters: _object_= {}
are options
| Name | Type | Description |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| commandStdio | undefined | "pipe" | "ignore" | "inherit" | undefined | number | "pipe" | "ignore" | "inherit" | internal‹› | "ipc"[] | - |logger
| | undefined | Logger | is Winston compatible logger or console. |overwrite
| | undefined | false | true | is whether to overwrite files by default. |source
| | undefined | string | Module‹› | is the source module or a path in source module. By default immediate parent's root dir is used. Immediate parent is the file which calls this method. |target
| | undefined | string | Module‹› | is the target module or a path in target module. By default process.env.INIT_CWD or process.env.CWD is used whichever is first available. |
Returns: _Promise‹Intermodular›_
Intermodular instance.
---
▸ parseEnv‹T›(variable: string, defaultValue?: T): _string | number | Record‹string, any› | T | undefined_
_Defined in src/intermodular.ts:299_
Parses and returns variable environment variable. If value is JSON object, parses using JSON5 and returns it as a JavaScript object.defaultValue
Otherwise returns .
Type parameters:
▪ T
Parameters:
| Name | Type | Description |
| --------------- | ------ | ----------------------------------------------------------------- |
| variable | string | is Name of the environment variable |defaultValue?
| | T | is value to return if no environment variable is set or is empty. |
Returns: _string | number | Record‹string, any› | T | undefined_
environment variable (if possible as an object) or default value.
Class which provides information and modification methods for a module.
- Module
• isTypeScript: _boolean_
_Defined in src/module.ts:32_
Whether module is a TypeScript project.
---
• package: _DataFile_
_Defined in src/module.ts:29_
DataFile instance of package.json.
---
• packageManager: _PackageManager_
_Defined in src/module.ts:26_
Package manager of the module.
---
• root: _string_
_Defined in src/module.ts:23_
Absolute path of the module's root directory, where package.json is located.
• get name(): _string_
_Defined in src/module.ts:77_
Name of the module as defined in package.json.
Returns: _string_
---
• get nameWithoutUser(): _string_
_Defined in src/module.ts:82_
Name of the module without user name. For example: typescript for @microsoft/typescript.
Returns: _string_
▸ cloneWithSharedManager(__namedParameters: object): _Module_
_Defined in src/module.ts:66_
Creates a new Module instance from current instance, which shares
Data File Manager with current Module.
Multiple instance work over same files efficiently and without collision.
Parameters:
▪Default value \_\_namedParameters: _object_= {}
| Name | Type |
| ----------- | ---------------------------------- |
| logger | undefined | Logger |overwrite
| | undefined | false | true |
Returns: _Module_
Module instance.
---
▸ command(cmd: string, options?: ExecuteOptions): _Promise‹ExecaReturnValue›_
_Defined in src/module.ts:408_
Executes given command using execa.command with given options. Applies sensible default options.
#### Example
`typescriptls
module.command("ls"); // Run .ls -al
module.command("ls -al", { stdio: "inherit" }); // Run .`
Parameters:
| Name | Type | Description |
| ---------- | --------------------------------------------- | ----------------------------------------------------------- |
| cmd | string | is command to execute. |options?
| | ExecuteOptions | are passed to Execa. |
Returns: _Promise‹ExecaReturnValue›_
[[ExecaReturnValue]] instance.
▸ command(cmd: string, options?: ExecuteOptions‹null›): _Promise‹ExecaReturnValue‹Buffer››_
_Defined in src/module.ts:409_
Parameters:
| Name | Type |
| ---------- | --------------------------------------------------- |
| cmd | string |options?
| | ExecuteOptions‹null› |
Returns: _Promise‹ExecaReturnValue‹Buffer››_
---
▸ createDirectory(path: string): _Promise‹void›_
_Defined in src/module.ts:308_
Ensures that the directory exists. If the directory structure does not exist, it is created similar to mkdir -p.
Parameters:
| Name | Type | Description |
| ------ | ------ | -------------------------------------------------------- |
| path | string | is the path relative to module root or an absolute path. |
Returns: _Promise‹void›_
---
▸ execute(bin: string, args?: string[], options?: ExecuteOptions): _Promise‹ExecaReturnValue›_
_Defined in src/module.ts:364_
Executes given command using execa with given arguments and options. Applies sensible default options.
#### Example
`typescriptls
module.execute("ls"); // Run .ls -al
module.execute("ls", ["-al"], { stdio: "inherit" }); // Run .`
Parameters:
| Name | Type | Description |
| ---------- | --------------------------------------------- | ----------------------------------------------------------- |
| bin | string | is binary file to execute. |args?
| | string[] | are arguments to pass to executable. |options?
| | ExecuteOptions | are passed to Execa. |
Returns: _Promise‹ExecaReturnValue›_
[[ExecaReturnValue]] instance.
▸ execute(bin: string, args?: string[], options?: ExecuteOptions‹null›): _Promise‹ExecaReturnValue‹Buffer››_
_Defined in src/module.ts:365_
Parameters:
| Name | Type |
| ---------- | --------------------------------------------------- |
| bin | string |args?
| | string[] |options?
| | ExecuteOptions‹null› |
Returns: _Promise‹ExecaReturnValue‹Buffer››_
▸ execute(bin: string, options?: ExecuteOptions): _Promise‹ExecaReturnValue›_
_Defined in src/module.ts:377_
Executes given command using execa with given arguments and options. Applies sensible default options.
#### Example
`typescriptls
module.execute("ls"); // Run .ls
module.execute("ls", { stdio: "inherit" }); // Run .`
Parameters:
| Name | Type | Description |
| ---------- | --------------------------------------------- | ----------------------------------------------------------- |
| bin | string | is binary file to execute. |options?
| | ExecuteOptions | are passed to Execa. |
Returns: _Promise‹ExecaReturnValue›_
[[ExecaReturnValue]] instance.
▸ execute(bin: string, options?: ExecuteOptions‹null›): _Promise‹ExecaReturnValue‹Buffer››_
_Defined in src/module.ts:378_
Parameters:
| Name | Type |
| ---------- | --------------------------------------------------- |
| bin | string |options?
| | ExecuteOptions‹null› |
Returns: _Promise‹ExecaReturnValue‹Buffer››_
---
▸ exists(path: string): _Promise‹boolean›_
_Defined in src/module.ts:283_
Checks whether given path exists.
Parameters:
| Name | Type | Description |
| ------ | ------ | -------------------------------------------------------- |
| path | string | is the path relative to module root or an absolute path. |
Returns: _Promise‹boolean›_
whether given path exists.
---
▸ getDependencyVersion(moduleName: string, dependencyTypes: string[]): _string | undefined_
_Defined in src/module.ts:93_
Fetches a dependent module's version from given dependency types.
Parameters:
| Name | Type | Default | Description |
| ----------------- | -------- | ---------------- | -------------------------------------------------- |
| moduleName | string | - | is the name of the module to get version of. |dependencyTypes
| | string[] | ALL_DEPENDENCIES | are array of dependency types to search module in. |
Returns: _string | undefined_
version of the moduleName || undefined.
---
▸ hasAnyDependency(moduleNames: string | string[], dependencyTypes: string[]): _boolean_
_Defined in src/module.ts:105_
Checks whether given module or any of the modules exist in given dependency types.
Parameters:
| Name | Type | Default | Description |
| ----------------- | ---------------------- | ---------------- | -------------------------------------------------- |
| moduleNames | string | string[] | - | are the name of the module to search for. |dependencyTypes
| | string[] | ALL_DEPENDENCIES | are array of dependency types to search module in. |
Returns: _boolean_
whether moduleName exists in one of the dependency types.
---
▸ ifAnyDependency‹T, F›(moduleNames: string | string[]): _boolean_
_Defined in src/module.ts:109_
Checks single or multiple module's existence in any of the package.json dependencies.
Type parameters:
▪ T
▪ F
Parameters:
| Name | Type | Description |
| ------------- | ---------------------- | ---------------------------------------------------------------------- |
| moduleNames | string | string[] | are Module or modules to check whether this module has any dependency. |
Returns: _boolean_
trueValue if module depends on any of the moduleNames. Otherwise returns falseValue.
▸ ifAnyDependency‹T, F›(moduleNames: string | string[], t: T): _T | false_
_Defined in src/module.ts:110_
Checks single or multiple module's existence in any of the package.json dependencies.
Type parameters:
▪ T
▪ F
Parameters:
| Name | Type |
| ------------- | ---------------------- |
| moduleNames | string | string[] |t
| | T |
Returns: _T | false_
trueValue if module depends on any of the moduleNames. Otherwise returns falseValue.
▸ ifAnyDependency‹T, F›(moduleNames: string | string[], t: T, f: F, dependencyTypes?: DependencyType[]): _T | F_
_Defined in src/module.ts:111_
Checks single or multiple module's existence in any of the package.json dependencies.
Type parameters:
▪ T
▪ F
Parameters:
| Name | Type |
| ------------------ | ----------------------------------- |
| moduleNames | string | string[] |t
| | T |f
| | F |dependencyTypes?
| | DependencyType[] |
Returns: _T | F_
trueValue if module depends on any of the moduleNames. Otherwise returns falseValue.
---
▸ install(packageNames: string | string[], __namedParameters: object): _Promise‹void›_
_Defined in src/module.ts:435_
Installs node modules using specified package manager.
Parameters:
▪Default value packageNames: _string | string[]_= []
are package name or array of package names.
▪Default value \_\_namedParameters: _object_= {}
| Name | Type | Default | Description |
| ------ | ----------------------------------------------------------------------------------------------- | -------------------------------- | --------------------------------------------------------------------- |
| type | "dependencies" | "devDependencies" | "peerDependencies" | "optionalDependencies" | "dependencies" as DependencyType | is the dependency type of the package. dev, peer, optional etc. |
Returns: _Promise‹void›_
---
▸ isDirectory(path: string): _Promise‹boolean›_
_Defined in src/module.ts:293_
Returns whether given path is a directory.
Parameters:
| Name | Type | Description |
| ------ | ------ | -------------------------------------------------------- |
| path | string | is the path relative to module root or an absolute path. |
Returns: _Promise‹boolean›_
whether given path is a directory.
---
▸ isEqual(path: string, content: string | Record‹string, any›): _Promise‹boolean›_
_Defined in src/module.ts:347_
Checks whether content of pathInModule file is equal to data by making string comparison (for strings)
or deep comparison (for objects).
#### Example
`typescript`
const isConfigEqual = module.isEqual("config.json", { someData: 4 });
const textEqual = module.isEqual("some.txt", "content");
Parameters:
| Name | Type | Description |
| --------- | --------------------------------- | ------------------------------------------------------------ |
| path | string | is the path relative to module root or an absolute path. |content
| | string | Record‹string, any› | is string or JavaScript object to compare to file's content. |
Returns: _Promise‹boolean›_
whether the file is equal to given content.
---
▸ pathOf(...parts: string[]): _string_
_Defined in src/module.ts:135_
Returns absolute path for given relative path to module root. If given path is an absolute path, returns it directly.
#### Example
`typescript`
module.pathOf("images", "photo.jpg"); // -> /path/to/root/images/photo.jpg
module.pathOf("/usr", "bin"); // -> /usr/bin
Parameters:
| Name | Type | Description |
| ---------- | -------- | -------------------------------- |
| ...parts | string[] | are path or array of path parts. |
Returns: _string_
absolute path to given destination.
---
▸ read(path: string, options?: ManagerLoadOptions): _Promise‹DataFile | string | undefined›_
_Defined in src/module.ts:185_
Reads and if possible returns DataFile otherwise file content. If file does not exist returns undefined.options.defaultData
If is true, file will be created using options.defaultData if it does not exist.
see Module.readData, Module.readRaw
throws if given path is a directory.
Parameters:
| Name | Type | Description |
| ---------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
| path | string | is the path relative to module root or an absolute path. |options?
| | ManagerLoadOptions | are options passed to Manager.load of edit-config. See here. |
Returns: _Promise‹DataFile | string | undefined›_
DataFile instance, file content or undefined.
---
▸ readData(path: string, options?: ManagerLoadOptions): _Promise‹DataFile›_
_Defined in src/module.ts:171_
Reads file and creates DataFile instance using Manager.
Parameters:
| Name | Type | Description |
| ---------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
| path | string | is the path relative to module root or an absolute path. |options?
| | ManagerLoadOptions | are options passed to Manager.load of edit-config. See here. |
Returns: _Promise‹DataFile›_
---
▸ readRaw(path: string): _Promise‹string›_
_Defined in src/module.ts:161_
Asynchronously reads the entire contents of a file using utf8 encoding.
Parameters:
| Name | Type | Description |
| ------ | ------ | -------------------------------------------------------- |
| path | string | is the path relative to module root or an absolute path. |
Returns: _Promise‹string›_
file contents.
---
▸ relativePathOf(...parts: string[]): _string_
_Defined in src/module.ts:150_
Returns relative path to module root for given absolute path. If given path is a relative path, returns it directly.
#### Example
`typescript`
module.relativePathOf("/path/to/module/src/my-file.js"); // -> src/my-file.js
module.relativePathOf("src/my-file.js"); // -> src/my-file.js
Parameters:
| Name | Type | Description |
| ---------- | -------- | -------------------------------- |
| ...parts | string[] | are path or array of path parts. |
Returns: _string_
path relative to module's root.
---
▸ remove(path: string, __namedParameters: object): _Promise‹string | undefined›_
_Defined in src/module.ts:258_
Removes file or directory relative to module's root. Removes directory even it has files in it.
If the path does not exist, silently does nothing.
Parameters:
▪ path: _string_
is the path relative to module root or an absolute path.
▪Default value \_\_namedParameters: _object_= {}
| Name | Type |
| ----------- | ------------------------- |
| condition | undefined | function |
Returns: _Promise‹string | undefined›_
file path relative to module root if file is removed, undefined otherwise.
---
▸ removeEmptyDirs(path: string): _Promise‹string[]›_
_Defined in src/module.ts:271_
Removes empty directories recursively for given path relative to module root.
Parameters:
| Name | Type | Description |
| ------ | ------ | -------------------------------------------------------- |
| path | string | is the path relative to module root or an absolute path. |
Returns: _Promise‹string[]›_
array of deleted directories.
---
▸ rename(oldPath: string, newPath: string, __namedParameters: object): _Promise‹boolean›_
_Defined in src/module.ts:320_
Renames given path.
Parameters:
▪ oldPath: _string_
is the old path relative to module root or an absolute path.
▪ newPath: _string_
is the new path relative to module root or an absolute path.
▪Default value \_\_namedParameters: _object_= {}
| Name | Type | Default | Description |
| ----------- | ------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| overwrite | boolean | this.#overwrite | is whether to allow rename operation if target path already exists. Silently ignores operation if overwrite is not allowed and target path exists. |
Returns: _Promise‹boolean›_
whether file is renamed.
---
▸ saveAll(): _Promise‹void›_
_Defined in src/module.ts:424_
Saves all read data files.
Returns: _Promise‹void›_
---
▸ uninstall(packageNames: string | string[]): _Promise‹void›_
_Defined in src/module.ts:455_
Uninstalls node modules using specified package manager.
Parameters:
| Name | Type | Default | Description |
| -------------- | ---------------------- | ------- | ------------------------------------------- |
| packageNames | string | string[] | [] | are package name or array of package names. |
Returns: _Promise‹void›_
---
▸ write(path: string, content: object | string, __namedParameters: object): _Promise‹string | DataFile | undefined›_
_Defined in src/module.ts:222_
Writes given content to file. If content is an object, it is serialized.
If prettier configuration and module is available and content is formatted using prettier.
Parameters:
▪ path: _string_
is the path relative to module root or an absolute path.
▪Default value content: _object | string_= ""
is the content to write to file.
▪Default value \_\_namedParameters: _object_= {}
| Name | Type | Default | Description |
| --------------- | ------------------------- | --------------- | --------------------------------------------------------------------------------------- |
| condition | undefined | function | - | - |defaultFormat
| | "json" | "yaml" | "json" | is the format to be used in serialization if file does not exist and content is object. |overwrite
| | boolean | this.#overwrite | is whether to overwrite existing file. |
Returns: _Promise‹string | DataFile | undefined›_
written content or [[DataFile]] if file is written, undefined otherwise.
---
▸ new(options: object): _Promise‹Module›_
_Defined in src/module.ts:482_
Creates and returns a Module instance.
Parameters:
▪Default value options: _object_= {}
are options.
| Name | Type | Description |
| ----------------- | ---------------------------------- | ------------------------------------------------------------------------------ |
| commandStdio? | StdioOption | is the default stdio option to be used with command and execute methods. |cwd?
| | undefined | string | is starting directory to start search for module root from. |logger?
| | Logger | is Winston compatible Logger to be used when logging. |overwrite?
| | undefined | false | true | is whether to overwrite files by default. |packageManager?
| | PackageManager | is package manager used by module. |
Returns: _Promise‹Module›_
Module instance.
Copy options based on fs-extra copy options.
- CopyOptions
• dereference? : _undefined | false | true_
_Defined in src/util/types.ts:46_
Dereference symlinks, default is false.
---
• errorOnExist? : _undefined | false | true_
_Defined in src/util/types.ts:52_
When overwrite is false and the destination exists, throw an error. Default is false.
---
• excludeDirFromReturn? : _undefined | false | true_
_Defined in src/util/types.ts:58_
Whether to exclude directories from return value. If this is true only paths of copied files returned but not directories.
---
• filter? : _CopyFilterFunction_
_Defined in src/util/types.ts:54_
Function to filter copied files. Return true to include, false to exclude. Can also return a Promise that resolves to true or false (or pass in an async function)
---
• overwrite? : _undefined | false | true_
_Defined in src/util/types.ts:48_
Overwrite existing file or directory, default is true. Note that the copy operation will silently fail if you set this to false and the destination exists. Use the errorOnExist option to change this behavior.
---
• preserveTimestamps? : _undefined | false | true_
_Defined in src/util/types.ts:50_
When true, will set last modification and access times to the ones of the original source files. When false, timestamp behavior is OS-dependent. Default is false.
---
• recursive? : _undefined | false | true_
_Defined in src/util/types.ts:56_
fs-extra.copy recursive option.
Extended options for module.execute and module.command
▪ EncodingType
- Options‹EncodingType›
↳ ExecuteOptions
• all? : _undefined | false | true_
_Inherited from ExecuteOptions.all_
Defined in node_modules/execa/index.d.ts:96
Add an .all property on the promise and the resolved value. The property contains the output of the process with stdout and stderr interleaved.
default false
---
• argv0? : _undefined | string_
_Inherited from ExecuteOptions.argv0_
Defined in node_modules/execa/index.d.ts:129
Explicitly set the value of argv[0] sent to the child process. This will be set to command or file if not specified.
---
• buffer? : _undefined | false | true_
_Inherited from ExecuteOptions.buffer_
Defined in node_modules/execa/index.d.ts:61
Buffer the output from the spawned process. When set to false, you must read the output of stdout and stderr (or all if the all option is true). Otherwise the returned promise will not be resolved/rejected.
If the spawned process fails, error.stdout, error.stderr, and error.all will contain the buffered data.
default true
---
• cleanup? : _undefined | false | true_
_Inherited from ExecuteOptions.cleanup_
Defined in node_modules/execa/index.d.ts:23
Kill the spawned process when the parent process exits unless either:
- the spawned process is detached
- the parent process is terminated abruptly, for example, with SIGKILL as opposed to SIGTERM or a normal exit
default true
---
• cwd? : _undefined | string_
_Inherited from ExecuteOptions.cwd_
Defined in node_modules/execa/index.d.ts:117
Current working directory of the child process.
default process.cwd()
---
• detached? : _undefined | false | true_
_Inherited from ExecuteOptions.detached_
Defined in node_modules/execa/index.d.ts:156
Prepare child to run independently of its parent process. Specific behavior depends on the platform.
default false
---
• encoding? : _EncodingType_
_Inherited from ExecuteOptions.encoding_
Defined in node_modules/execa/index.d.ts:185
Specify the character encoding used to decode the stdout and stderr output. If set to null, then stdout and stderr will be a Buffer instead of a string.
default 'utf8'
---
• env? : _NodeJS.ProcessEnv_
_Inherited from ExecuteOptions.env_
Defined in node_modules/execa/index.d.ts:124
Environment key-value pairs. Extends automatically from process.env. Set extendEnv to false if you don't want this.
default process.env
---
• execPath? : _undefined | string_
_Inherited from ExecuteOptions.execPath_
Defined in node_modules/execa/index.d.ts:52
Path to the Node.js executable to use in child processes.
This can be either an absolute path or a path relative to the cwd option.
Requires preferLocal to be true.
For example, this can be used together with get-node to run a specific Node.js version in a child process.
default process.execPath
---
• exitOnProcessFailure? : _undefined | false | true_
_Defined in src/util/types.ts:64_
Exits using process.exit(errCode) if error is originated from shell. Otherwise throws as usual. Errors originated from node.js always throw.
---
• extendEnv? : _undefined | false | true_
_Inherited from ExecuteOptions.extendEnv_
Defined in node_modules/execa/index.d.ts:110
Set to false if you don't want to extend the environment variables when providing the env property.
default true
---
• gid? : _undefined | number_
_Inherited from ExecuteOptions.gid_
Defined in node_modules/execa/index.d.ts:166
Sets the group identity of the process.
---
• input? : _string | Buffer | ReadableStream_
_Inherited from ExecuteOptions.input_
Defined in node_modules/execa/index.d.ts:227
Write some input to the stdin of your binary.
---
• killSignal? : _string | number_
_Inherited from ExecuteOptions.killSignal_
Defined in node_modules/execa/index.d.ts:206
Signal value to be used when the spawned process will be killed.
default 'SIGTERM'
---
• localDir? : _undefined | string_
_Inherited from ExecuteOptions.localDir_
Defined in node_modules/execa/index.d.ts:39
Preferred path to find locally installed binaries in (use with preferLocal).
default process.cwd()
---
• maxBuffer? : _undefined | number_
_Inherited from ExecuteOptions.maxBuffer_
Defined in node_modules/execa/index.d.ts:199
Largest amount of data in bytes allowed on stdout or stderr. Default: 100 MB.
default 100_000_000
---
• preferLocal? : _undefined | false | true_
_Inherited from ExecuteOptions.preferLocal_
Defined in node_modules/execa/index.d.ts:32
Prefer locally installed binaries when looking for a binary to execute.
If you $ npm install foo, you can then execa('foo').
default false
---
• reject? : _undefined | false | true_
_Inherited from ExecuteOptions.reject_
Defined in node_modules/execa/index.d.ts:89
Setting this to false resolves the promise with the error instead of rejecting it.
default true
---
• serialization? : _"json" | "advanced"_
_Inherited from ExecuteOptions.serialization_
Defined in node_modules/execa/index.d.ts:149
Specify the kind of serialization used for sending messages between processes when using the stdio: 'ipc' option or execa.node():
- json: Uses JSON.stringify() and JSON.parse().advanced
- : Uses v8.serialize()
Requires Node.js 13.2.0 or later.
default 'json'
---
• shell? : _boolean | string_
_Inherited from ExecuteOptions.shell_
Defined in node_modules/execa/index.d.ts:178
If true, runs command inside of a shell. Uses /bin/sh on UNIX and cmd.exe on Windows. A different shell can be specified as a string. The shell should understand the -c switch on UNIX or /d /s /c on Windows.
We recommend against using this option since it is:
- not cross-platform, encouraging shell-specific syntax.
- slower, because of the additional shell interpretation.
- unsafe, potentially allowing command injection.
default false
---
• stderr? : _StdioOption_
_Inherited from ExecuteOptions.stderr_
Defined in node_modules/execa/index.d.ts:82
Same options as stdio.
default 'pipe'
---
• stdin? : _StdioOption_
_Inherited from ExecuteOptions.stdin_
Defined in node_modules/execa/index.d.ts:68
Same options as stdio.
default 'pipe'
---
• stdio? : _StdioOption_
_Overrides void_
_Defined in src/util/types.ts:66_
The options.stdio option is used to configure the pipes that are established between the parent and child process.
---
• stdout? : _StdioOption_
_Inherited from ExecuteOptions.stdout_
Defined in node_modules/execa/index.d.ts:75
Same options as stdio.
default 'pipe'
---
• stripFinalNewline? : _undefined | false | true_
_Inherited from ExecuteOptions.stripFinalNewline_
Defined in node_modules/execa/index.d.ts:103
Strip the final newline character from the output.
default true
---
• timeout? : _undefined | number_
_Inherited from ExecuteOptions.timeout_
Defined in node_modules/execa/index.d.ts:192
If timeout is greater than 0, the parent will send the signal identified by the killSignal property (the default is SIGTERM) if the child runs longer than timeout milliseconds.
**def