Skip to content

Commit cdf2ea9

Browse files
committed
Initial commit
0 parents  commit cdf2ea9

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# ember-cli-deploy-plugin
2+
3+
This NPM module exposes a base class that can be used by ember-cli-deploy plugins to streamline
4+
implementation of a plugin.
5+
6+
## Usage
7+
8+
In your plugin's directory:
9+
10+
`npm install ember-cli-deploy-plugin --save`
11+
12+
In your plugin's `index.js` file:
13+
14+
```js
15+
/* jshint node: true */
16+
'use strict';
17+
18+
var DeployPluginBase = require('ember-cli-deploy-plugin');
19+
20+
module.exports = {
21+
name: 'ember-cli-deploy-awesomeness',
22+
23+
createDeployPlugin: function(options) {
24+
var DeployPlugin = DeployPluginBase.extend({
25+
name: options.name,
26+
27+
// note: most plugins can simply implement these next two properties and use
28+
// the base class' implementation of the `configure` hook
29+
defaultConfig: {
30+
someKey: 'defaultValue',
31+
anotherKey: function(context) {
32+
return context.anotherKey; // to use data added to the context by another plugin
33+
}
34+
},
35+
requiredConfig: ['awesomeApiKey'], // throw an error if this is not configured
36+
37+
// implement any hooks appropriate for your plugin
38+
willUpload: function(context) {
39+
// Use the `readConfig` method for uniform access to this plugin's config,
40+
// whether via a dynamic function or a configured value
41+
var someValue = this.readConfig('someKey');
42+
var anotherValue = this.readConfig('anotherKey');
43+
var awesomeApiKey = this.readConfig('awesomeApiKey');
44+
45+
// Use the `log` method to generate output consistent with the tree style
46+
// of ember-cli-deploy
47+
this.log('unleashing awesomeness');
48+
49+
// Need to do something async? You can return a promise.
50+
// Need to fail out? Throw an error or return a promise which becomes rejected
51+
return Promise.resolve();
52+
},
53+
});
54+
return new DeployPlugin();
55+
}
56+
};
57+
58+
## TODO
59+
60+
Tests

index.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var CoreObject = require('core-object');
2+
var chalk = require('chalk');
3+
var blue = chalk.blue;
4+
5+
var DeployPluginBase = CoreObject.extend({
6+
context: null,
7+
ui: null,
8+
project: null,
9+
pluginConfig: null,
10+
defaultConfig: {},
11+
configure: function(context) {
12+
this.log('validating config');
13+
var defaultProps = Object.keys(this.defaultConfig || {});
14+
defaultProps.forEach(this.applyDefaultConfigProperty.bind(this));
15+
var requiredProps = this.requiredConfig || [];
16+
requiredProps.forEach(this.ensureConfigPropertySet.bind(this));
17+
this.log('config ok');
18+
},
19+
applyDefaultConfigProperty: function(propertyName){
20+
if (!this.pluginConfig[propertyName]) {
21+
var value = this.defaultConfig[propertyName];
22+
this.pluginConfig[propertyName] = value;
23+
var description = value;
24+
if (typeof description === "function") {
25+
description = "[Function]";
26+
}
27+
this.log('Missing config: `' + propertyName + '`, using default: `' + description + '`', { color: 'yellow' });
28+
}
29+
},
30+
ensureConfigPropertySet: function(propertyName){
31+
if (!this.pluginConfig[propertyName]) {
32+
var message = 'Missing required config: `' + propertyName + '`';
33+
this.log(message, { color: 'red' });
34+
throw new Error(message);
35+
}
36+
},
37+
readConfig: function(property){
38+
var configuredValue = this.pluginConfig[property];
39+
if (typeof configuredValue === 'function') {
40+
return configuredValue(this.context);
41+
}
42+
return configuredValue;
43+
},
44+
log: function(message, opts) {
45+
opts = opts || { color: 'blue' }
46+
opts['color'] = opts['color'] || 'blue';
47+
48+
this.ui.write(blue('| '));
49+
var chalkColor = chalk[opts.color];
50+
this.ui.writeLine(chalkColor('- ' + message));
51+
}
52+
});
53+
54+
module.exports = DeployPluginBase;

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "ember-cli-deploy-plugin",
3+
"version": "0.1.0",
4+
"description": "For building plugins for ember-cli-deploy",
5+
"repository": "https://github.com/lukemelia/ember-cli-deploy-plugin",
6+
"engines": {
7+
"node": ">= 0.10.0"
8+
},
9+
"author": "Luke Melia",
10+
"license": "MIT",
11+
"devDependencies": {
12+
},
13+
"dependencies": {
14+
"chalk": "^1.0.0",
15+
"core-object": "0.0.2"
16+
}
17+
}

0 commit comments

Comments
 (0)