@cloudcannon/suite
Version:
A suite of gulp tools to manage static sites on CloudCannon
64 lines (53 loc) • 2.67 kB
Markdown
---
title: Setup
package: State
order_number: 2
subtasks:
- name: build
desc: Copies the JSON files from the reports directory to the build destination directory, along with an HTML template. This acts as a static site you can use to visualise dependencies.
code: gulp state:build
- name: clean
desc: Deletes everything in the build destination directory.
code: gulp state:clean
- name: dependencies
desc: Scans the compiled site for asset references, builds a dependency graph, and creates a JSON file report in the reports directory.
code: gulp state:dependencies
- name: dependents
desc: Reads the report generated by `state:dependencies`, builds a reversed graph, and creates a JSON file in the reports directory. Make sure to run `gulp state:dependencies` first, if you are running this subtask manually.
code: gulp state:dependents
- name: find-unused
desc: Scans the dependency tree and prints unused assets to the console. Make sure to run `gulp state:dependencies` first.
code: gulp state:find-unused
---
To use this package, add `suite.state(gulp)` to your Gulpfile:
```js
/* gulpfile.js */
const gulp = require("gulp");
const suite = require("@cloudcannon/suite");
suite.state(gulp);
```
Running `gulp state` will build a dependency graph and save it as JSON in your `reports/` directory. A local webserver will be started on port 9001, using the JSON file to create an interactive visualisation of the dependency graph.
> The state package needs to scan your compiled site - make sure you run `gulp dev:build` before `gulp state`.
{: .explainer}
```sh
$ gulp state
[] Using gulpfile ./gulpfile.js
[] Starting 'state'...
[] Starting 'state:get-filename-list'...
[] Finished 'state:get-filename-list' after 1.25 s
[] Starting 'state:dependencies'...
[] Finished 'state:dependencies' after 458 ms
[] Starting 'state:dependents'...
[] Finished 'state:dependents' after 2.43 ms
[] Starting 'state:clean'...
[] Finished 'state:clean' after 42 ms
[] Starting 'state:build'...
[] Finished 'state:build' after 14 ms
[] Starting 'state:serve'...
[] Finished 'state:serve' after 15 ms
[] Finished 'state' after 1.78 s
```
In the visualiser, you can toggle between viewing the dependencies of an asset, and viewing the dependants of an asset.
Running `gulp state:find-unused` will print a list of unused assets to the console. This uses the dependency graph in `reports/`, so make sure to run `gulp state:dependencies` or `gulp state` first.
{% include package-subtasks.md %}