create-plugin

This commit is contained in:
Belen Curcio
2017-07-05 16:41:52 -03:00
parent b28902312d
commit 7c753ee518
8 changed files with 127 additions and 3 deletions
+50 -1
View File
@@ -8,13 +8,14 @@
// https://yarnpkg.com/
const program = require('./commander');
const inquirer = require('inquirer');
// Make things colorful!
require('colors');
const emoji = require('node-emoji');
const dir = process.cwd();
const fs = require('fs');
const fs = require('fs-extra');
const path = require('path');
const spawn = require('cross-spawn');
const semver = require('semver');
@@ -272,10 +273,58 @@ async function reconcilePluginDeps({skipLocal, skipRemote, dryRun, upgradeRemote
console.log(`✨ Done in ${totalTime}s.`);
}
async function createSeedPlugin() {
const pluginsDir = path.join(dir, 'plugins');
function pluginNameExists(pluginName) {
const pluginNames = fs.readdirSync(pluginsDir);
return !!pluginNames
.filter((pn) => pn === pluginName).length;
}
let answers = await inquirer.prompt([
{
type: 'input',
name: 'pluginName',
message: 'Plugin Name: i.e talk-plugin-permalink',
validate: (input) => {
if (pluginNameExists(input)) {
return 'Please, choose another name. That name already exists';
}
if (input && input.length > 0) {
return true;
}
return 'Plugin Name is required.';
}
}
]);
// Creating plugin seed
const seedTemplatePlugin = path.join(dir, 'scripts/templates/plugin');
const newPluginPath = path.join(pluginsDir, answers.pluginName);
try {
fs.copySync(seedTemplatePlugin, newPluginPath);
console.log('Success!');
} catch (err) {
console.error(err);
}
}
//==============================================================================
// Setting up the program command line arguments.
//==============================================================================
program
.command('create')
.description('creates a seed plugin')
.action(createSeedPlugin);
program
.command('list')
.description('')
+3 -2
View File
@@ -15,9 +15,9 @@ function getSlotComponents(slot) {
// Filter out components that have been disabled in `plugin_config`
return flatten(plugins
// Filter out components that have been disabled in `plugin_config`
.filter((o) => !pluginConfig || !pluginConfig[o.plugin] || !pluginConfig[o.plugin].disable_components)
.filter((o) => o.module.slots && (!pluginConfig || !pluginConfig[o.plugin] || !pluginConfig[o.plugin].disable_components))
.filter((o) => o.module.slots[slot])
.map((o) => o.module.slots[slot]));
@@ -78,6 +78,7 @@ export function getSlotsFragments(slots) {
}
const components = uniq(flattenDeep(slots.map((slot) => {
return plugins
.filter((o) => o.module.slots)
.filter((o) => o.module.slots[slot])
.map((o) => o.module.slots[slot]);
})));
+1
View File
@@ -78,6 +78,7 @@
"express": "^4.15.2",
"express-session": "^1.15.1",
"form-data": "^2.1.2",
"fs-extra": "^3.0.1",
"gql-merge": "^0.0.4",
"graphql": "^0.9.1",
"graphql-errors": "^2.1.0",
+14
View File
@@ -0,0 +1,14 @@
{
"presets": [
"es2015"
],
"plugins": [
"add-module-exports",
"transform-class-properties",
"transform-decorators-legacy",
"transform-object-assign",
"transform-object-rest-spread",
"transform-async-to-generator",
"transform-react-jsx"
]
}
@@ -0,0 +1,23 @@
{
"env": {
"browser": true,
"es6": true,
"mocha": true
},
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
}
},
"parser": "babel-eslint",
"plugins": [
"react"
],
"rules": {
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"no-console": ["warn", { "allow": ["warn", "error"] }]
}
}
+20
View File
@@ -0,0 +1,20 @@
/**
This is a client index example file and it should look like this:
```
import LoveButton from './components/LoveButton';
export default {
slots: {
commentReactions: [LoveButton]
},
reducer,
translations
};
```
To read more info on how to build client plugins. Please, go to: https://coralproject.github.io/talk/plugins-client.html
*/
export default {};
@@ -0,0 +1,15 @@
#
# This file is for translations and they should look like this:
#
#
# ```
# en:
# coral-plugin-respect:
# respect: Respect
# respected: Respected
# es:
# coral-plugin-respect:
# respect: Respetar
# respected: Respetado
# ```
#
+1
View File
@@ -0,0 +1 @@
module.exports = {};