embark/site/source
Pascal Precht 40c3d98217 feat(plugins/scripts-runner): introduce exec command to run scripts
This commit introduces a new feature that enables users to run (migration) scripts.
Similar to deployment hooks, scripts are functions that may perform operations on newly
deployed Smart Contracts.

Therefore a script needs to export a function that has access to some dependencies:

```
// scripts/001-some-script.js

module.exports = async ({contracts, web3, logger}) => {
  ...
};
```

Where `contracts` is a map of newly deployed Smart Contract instances, `web3` a blockchain connector
instance and `logger` Embark's logger instance. Script functions can but don't have to be `async`.

To execute such a script users use the newly introduced `exec` command:

```
$ embark exec development scripts/001-some-script.js
```

In the example above, `development` defines the environment in which Smart Contracts are being
deployed to as well as where tracking data is stored.
Alternativey, users can also provide a directory in which case Embark will try to execute every
script living inside of it:

```
$ embark exec development scripts
```

Scripts can fail and therefore emit an error accordingly. When this happens, Embark will
abort the script execution (in case multiple are scheduled to run) and informs the user
about the original error:

```
.. 001_foo.js running....
Script '001_foo.js' failed to execute. Original error: Error: Some error
```

It's recommended for scripts to emit proper instances of `Error`.

(Migration) scripts can be tracked as well but there are a couple of rules to be aware of:

- Generally, tracking all scripts that have been executed by default is not a good thing because
  some scripts might be one-off operations.
- OTOH, there might be scripts that should always be tracked by default
- Therefore, we introduce a dedicated `migrations` directory in which scripts live that should be
  tracked by default
- Any other scripts that does not live in the specified `migrations` directory will not be tracked **unless**
- The new `--track` option was provided

For more information see: https://notes.status.im/h8XwB7xkR7GKnfNh6OnPMQ
2020-02-12 16:47:04 -06:00
..
_data feat(plugins/scripts-runner): introduce exec command to run scripts 2020-02-12 16:47:04 -06:00
_posts build(deps): bump web3[-*] from 1.2.4 to 1.2.6 2020-02-03 10:17:07 -06:00
assets/images article: add web3 intro article 2019-12-09 20:37:31 +01:00
chat chore: move embark site into mono repo 2019-04-29 13:00:58 +02:00
community chore: localize static sites 2019-06-20 10:49:26 +02:00
docs feat(plugins/scripts-runner): introduce exec command to run scripts 2020-02-12 16:47:04 -06:00
news chore: localize static sites 2019-06-20 10:49:26 +02:00
plugins chore: localize static sites 2019-06-20 10:49:26 +02:00
templates chore(@embark/site): Add `—template` deprecation notice. 2019-12-11 09:39:20 -05:00
tutorials chore: move embark site into mono repo 2019-04-29 13:00:58 +02:00
CNAME chore: update site urls 2020-01-28 12:07:17 -05:00
browserconfig.xml chore: move embark site into mono repo 2019-04-29 13:00:58 +02:00
coverage-files.png chore: move embark site into mono repo 2019-04-29 13:00:58 +02:00
coverage-report.png chore: move embark site into mono repo 2019-04-29 13:00:58 +02:00
embark-logo.svg chore: move embark site into mono repo 2019-04-29 13:00:58 +02:00
favicon.ico chore: move embark site into mono repo 2019-04-29 13:00:58 +02:00
index.md chore: localize static sites 2019-06-20 10:49:26 +02:00
robots.txt chore: move embark site into mono repo 2019-04-29 13:00:58 +02:00