module:flitter-flap/FlapHelper
Get an object containing some helper functions to be used by migrations. These functions will run in non-modification mode if dry_run is true.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dry_run |
boolean |
<optional> |
true | If true, the helper function that are returned will print their changes to the console rather than actually modifying files. |
- Source:
Members
(inner, constant) dry_run :boolean
If true, the user has requested that migrations print their changes to the console, rather than modifying files. This is set so that any custom migrations that don't use the provided helper functions can honor dry mode.
- boolean
- Source:
Methods
(inner) copy(from, to) → {Promise.<void>}
Copy a file or folder from one place to another. If dry mode, just print the fully-qualified paths of the source and destination.
Name | Type | Description |
---|---|---|
from |
string | path to the file/directory to be copied |
to |
string | path to the destination |
- Source:
- Type
- Promise.<void>
(inner) count(string, regex) → {number}
Count the number of times the provided regex is matched in a string.
Name | Type | Description |
---|---|---|
string |
string | string to be searched |
regex |
RegExp | Regular expression to match against |
- Source:
- the number of times the string matches the regex
- Type
- number
(inner) delete(file) → {Promise.<void>}
Delete the file/directory at the specified path. If dry mode, print the path to be deleted. If dry mode, print the fully-qualified path of the resource to be deleted.
Name | Type | Description |
---|---|---|
file |
string | path to the file/directory to be deleted. accepts globs. |
- Source:
- Type
- Promise.<void>
(inner) delete_line(file, to_find_line) → {Promise.<void>}
Delete a line that is matched by the search string from the provided file. This will delete ONLY the first line it matches. The line must contain the search query, which can be either a string or regex value. If dry mode, print the fully-qualified path of the file, as well as the contents and number of the line to be deleted.
Name | Type | Description |
---|---|---|
file |
string | path of the file from which the line should be deleted |
to_find_line |
string | RegExp | search query used to match the line |
- Source:
- Type
- Promise.<void>
(inner) exists(dir) → {Promise.<boolean>}
Check if a file or directory exists. If it does, resolve true. If not, resolve false.
Name | Type | Description |
---|---|---|
dir |
string | path to check existence of |
- Source:
- resolves true or false if the resource exists or not respectively
- Type
- Promise.<boolean>
(inner) find_replace(file, to_find, replace_with, allopt) → {Promise.<void>}
Find and replace instances of the search query in the specified file. The specified query is applied once per line. This means that if the search query is a string, it will only replace the first instance of the string on each line. Regex is allowed to compensate for this. If the 'all' toggle is false, the search will stop after the first line matching the search string is found. If dry run, print the fully-qualified path of the file to be modified, as well as the numbers, before, and after contents of each line to be modified.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
file |
string | path of the file to be modified |
||
to_find |
string | RegExp | search query of text to be replaced |
||
replace_with |
string | text to be inserted |
||
all |
boolean |
<optional> |
true | if true, then the search will be performed on each line of the file. Otherwise, stop after the first match. |
- Source:
- Type
- Promise.<void>
(inner) find_replace_file(file, to_find, replace_with, replace_handleropt, reformatopt) → {Promise.<void>}
Find and replace instances of the search query in the specified file. The specified query is applied once to the entire file. Regex or a string are allowed as search criteria. Optionally, a replace_handler function can be provided to alter the replacements before they are inserted.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
file |
string | path of the file to be modified |
||
to_find |
string | RegExp | search query of text to be replaced |
||
replace_with |
string | text to be inserted |
||
replace_handler |
function |
<optional> |
(m) => m | handler called on each match to alter before insert. must return a string. |
reformat |
boolean |
<optional> |
true | if true, the file will be reformatted before write |
- Source:
- Type
- Promise.<void>
(inner) insert_line(file, to_find_line_before, to_insert, search_insert_beforeopt) → {Promise.<void>}
Insert a line into the specified file after the line matched by the search query. This function will insert the specified text after the first instance of a line that contains the search query, whether it be a string or regex value. If dry mode, print the fully-qualified path of the file to be modified, as well as the content and numbers of the existing and new lines.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
file |
string | path of the file in which the line should be inserted |
||
to_find_line_before |
string | RegExp | search query used to find the line under which the new line should be inserted |
||
to_insert |
string | line to be inserted in the file |
||
search_insert_before |
boolean |
<optional> |
false | if true, will insert the string BEFORE the found line |
- Source:
- Type
- Promise.<void>
(inner) mkdir(dir) → {Promise.<void>}
Create the provided directory recursively. Any super-directories needed will be created as well. If dry mode, print the fully-qualified path of the directory to be created.
Name | Type | Description |
---|---|---|
dir |
string | path of the directory to be created |
- Source:
- Type
- Promise.<void>
(inner) touch(file) → {Promise.<void>}
Create the specified file if it doesn't exist. Otherwise, update its timestamp. The file's directory must exist for this to work. If dry mode, print the fully-qualified path of the file to be created.
Name | Type | Description |
---|---|---|
file |
string | path of the file to be created. |
- Source:
- Type
- Promise.<void>
(inner) write_file(file, contents) → {Promise.<void>}
Write the contents to the file at the specified path. If it doesn't exist, the file will be created. The directory of the file must exist for this to work. If dry mode, print the fully-qualified path of the file to be written, as well as the contents.
Name | Type | Description |
---|---|---|
file |
string | path of the file to be written |
contents |
string | contents to write to the file |
- Source:
- Type
- Promise.<void>