-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #886 from infinitered/project-plugins
Plugins that only live in your project.
- Loading branch information
Showing
8 changed files
with
174 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
# Ignite Documentation | ||
|
||
This is a list of documentation ideas. | ||
|
||
## Advanced Guides | ||
## Quick Start | ||
|
||
* Creating plugins from scratch | ||
* Creating plugins from an existing component | ||
* Sporking template (why and how) | ||
* How to test your plugin | ||
* Creating your own "extensions" (these are 'libraries' things that can be used by plugins - such as file patching) | ||
* Installing | ||
* [Getting started](./quick-start/getting-started.md) | ||
* [Ignite commands](./quick-start/ignite-commands.md) | ||
* [Using boilerplates](./quick-start/using-boilerplates.md) | ||
* Removing plugins | ||
* Spork! - tweaking 3rd-party generators | ||
|
||
## API | ||
## Advanced Guides | ||
|
||
## Quick Start | ||
* [Creating plugins](./advanced-guides/creating-plugins.md) | ||
* [Creating project plugins](./advanced-guides/creating-project-plugins.md) | ||
* Writing tests for plugins | ||
* Releasing plugins | ||
* Creating extensions | ||
|
||
* Using boilerplates | ||
* Removing plugins you don't like | ||
* Project plugins vs 3rd party plugins | ||
* Gluegun and its features | ||
* App structure | ||
* Use and adding Generators | ||
* Adding plugins | ||
* Editing generators and the templates they use | ||
* Ignite commands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Creating Project Plugins | ||
|
||
First read the [creating plugins guide](./creating-plugins.md). It covers the structure of plugins. | ||
|
||
Project-based plugins are plugins which stay within your repo. They're a great way to add some features to Ignite without going through the hassle or commitment of publishing to NPM. | ||
|
||
Some examples of this might be: | ||
|
||
* generators that make little sense outside your project | ||
* scripts that are a bit more complex than a one liner inside your `package.json` | ||
* a playground for exploring ignite | ||
* a proving arena for plugins you intend to build & release, but aren't quite ready yet | ||
|
||
## The ignite/plugins Directory | ||
|
||
You place your plugins in the `ignite/plugins` directory. Plugins are directories themselves, so begin by creating a `sample` directory there. | ||
|
||
In this directory, create a file called `ignite.json` and put this empty object inside: | ||
|
||
```json | ||
{} | ||
``` | ||
|
||
Next create a new text file in that directory, naming it `ignite.toml`. Inside, place this: | ||
|
||
```toml | ||
description = "🔥🔥🔥 It's plugin time!🔥🔥🔥" | ||
``` | ||
|
||
> Note! This will be replaced shortly with `ignite.json`. I just need to patch up gluegun to provide a post-load hook so ignite can do this. | ||
## Running Your Plugin | ||
|
||
Back in the project root, type: | ||
|
||
```sh | ||
ignite | ||
``` | ||
|
||
You should see your plugin appear. Now, let's list the commands that you've made: | ||
|
||
```sh | ||
ignite sample | ||
``` | ||
|
||
Empty. Let's make one by creating a new directory: `ignite/plugins/sample/commands`. In that directory place this `online.js`. | ||
|
||
```js | ||
// @cliDescription Let's gather some useful data on this mission! | ||
|
||
module.exports = context => { | ||
const { filesystem, print } = context | ||
const { colors } = print | ||
|
||
const pkg = filesystem.read('package.json', 'json') | ||
const depsCount = Object.keys(pkg.dependencies || {}).length | ||
print.info(`You have ${colors.bold(depsCount)} direct dependencies. And they are awesome.`) | ||
} | ||
|
||
``` | ||
|
||
```sh | ||
ignite sample | ||
``` | ||
|
||
Now you have one. Let's run it. | ||
|
||
```sh | ||
ignite sample online | ||
``` | ||
|
||
For more details on creating commands (including generators), check out [the guide to plugins](./creating-plugins.md) and the [context API guide](https://infinitered.github.io/gluegun/#/context-api). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 25 additions & 12 deletions
37
packages/ignite-cli/src/extensions/ignite/findIgnitePlugins.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
const { pipe, filter, propSatisfies, sortBy, prop } = require('ramda') | ||
const { | ||
contains, | ||
anyPass, | ||
pipe, | ||
filter, | ||
propSatisfies, | ||
sortBy, | ||
prop | ||
} = require('ramda') | ||
const { startsWith } = require('ramdasauce') | ||
|
||
module.exports = (plugin, command, context) => { | ||
// gluegun stuff | ||
const { runtime, filesystem: { separator } } = context | ||
|
||
// how to identify ignite plugins | ||
const ignitePrefixed = propSatisfies(startsWith('ignite-'), 'name') | ||
const isInRightLocation = contains(`ignite${separator}plugins`) | ||
const inProjectPlugins = propSatisfies(isInRightLocation, 'directory') | ||
const onlyIgnitePlugins = filter(anyPass([ignitePrefixed, inProjectPlugins])) | ||
const getIgnitePlugins = pipe(onlyIgnitePlugins, sortBy(prop('name'))) | ||
|
||
/** | ||
* Finds the gluegun plugins that are also ignite plugins. | ||
* Finds the gluegun plugins that are also ignite plugins. These are | ||
* plugins which have 1 of the following: | ||
* | ||
* - the name starts with "ignite-" | ||
* - the directory contains "ignite/plugins" | ||
* | ||
* @returns {Plugin[]} - an array of ignite plugins | ||
*/ | ||
function findIgnitePlugins () { | ||
const { runtime } = context | ||
|
||
return pipe( | ||
filter(propSatisfies(startsWith('ignite-'), 'name')), | ||
sortBy(prop('name')) | ||
)(runtime.plugins) | ||
} | ||
|
||
return findIgnitePlugins | ||
return () => getIgnitePlugins(runtime.plugins) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/ignite-cli/tests/extensions/findIgnitePlugins.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const test = require('ava') | ||
const extension = require('../../src/extensions/ignite/findIgnitePlugins') | ||
|
||
test('has the right interface', t => { | ||
t.is(typeof extension, 'function') | ||
const context = { filesystem: { separator: '/' } } | ||
const findIgnitePlugin = extension(null, null, context) | ||
t.is(typeof findIgnitePlugin, 'function') | ||
}) | ||
|
||
test('plugin-less', t => { | ||
const context = { | ||
filesystem: { separator: '/' }, | ||
runtime: { | ||
plugins: [] | ||
} | ||
} | ||
const findIgnitePlugin = extension(null, null, context) | ||
t.deepEqual(findIgnitePlugin(), []) | ||
}) | ||
|
||
test('skips non-ignite plugins', t => { | ||
const context = { | ||
filesystem: { separator: '/' }, | ||
runtime: { | ||
plugins: [{ name: 'x', directory: 'y' }] | ||
} | ||
} | ||
const findIgnitePlugin = extension(null, null, context) | ||
t.deepEqual(findIgnitePlugin(), []) | ||
}) | ||
|
||
test('finds ignite- prefixed plugins', t => { | ||
const context = { | ||
filesystem: { separator: '/' }, | ||
runtime: { | ||
plugins: [{ name: 'ignite-foo', directory: 'y' }] | ||
} | ||
} | ||
const findIgnitePlugin = extension(null, null, context) | ||
t.deepEqual(findIgnitePlugin(), [{ name: 'ignite-foo', directory: 'y' }]) | ||
}) | ||
|
||
test('finds project plugins', t => { | ||
const dir = `${process.cwd()}/ignite/plugins/y` | ||
const context = { | ||
filesystem: { separator: '/' }, | ||
runtime: { | ||
plugins: [{ name: 'x', directory: dir }] | ||
} | ||
} | ||
const findIgnitePlugin = extension(null, null, context) | ||
t.deepEqual(findIgnitePlugin(), [{ name: 'x', directory: dir }]) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters