Use hook prefix and rename

This commit is contained in:
Jim LAURIE 2018-07-11 16:23:14 +02:00
parent 2482d5488f
commit cf8184e223
58 changed files with 75 additions and 110 deletions

View File

@ -1,6 +1,6 @@
# Hooks
The hooks are modules that add functionality to the core. They are loaded during the server boot. For example, if your project needs to work with a SQL database, your will have to add the hook `strapi-bookshelf` to be able to connect your app with your database.
The hooks are modules that add functionality to the core. They are loaded during the server boot. For example, if your project needs to work with a SQL database, your will have to add the hook `strapi-hook-bookshelf` to be able to connect your app with your database.
**Path —** `./hooks/documentation/lib/index.js`.
```js
@ -76,13 +76,13 @@ The `index.js` is the entry point to your hook. It should look like the example
## Dependencies
It happens that a hook has a dependency to another one. For example, the `strapi-bookshelf` has a dependency to `strapi-knex`. Without it, the `strapi-bookshelf` can't work correctly. It also means that the `strapi-knex` hook has to be loaded before.
It happens that a hook has a dependency to another one. For example, the `strapi-hook-bookshelf` has a dependency to `strapi-hook-knex`. Without it, the `strapi-hook-bookshelf` can't work correctly. It also means that the `strapi-hook-knex` hook has to be loaded before.
To handle this case, you need to update the `package.json` at the root of your hook.
```json
{
"name": "strapi-bookshelf",
"name": "strapi-hook-bookshelf",
"version": "x.x.x",
"description": "Bookshelf hook for the Strapi framework",
"dependencies": {
@ -90,10 +90,10 @@ To handle this case, you need to update the `package.json` at the root of your h
},
"strapi": {
"dependencies": [
"strapi-knex"
"strapi-hook-knex"
]
}
}
}
```
## Custom hooks

View File

@ -13,7 +13,7 @@ Here is the list of the collected data and why we need them.
*Understand how the developers are using the different configurations? How many projects are started in production mode?*
- **Node modules names**
*Are developers integrating Strapi with Stripe? It means that we should develop a plugin to simplify the development process with Stripe.
Are developers using Strapi with strapi-bookshelf or strapi-mongoose? It helps us prioritize the issues.*
Are developers using Strapi with strapi-hook-bookshelf or strapi-hook-mongoose? It helps us prioritize the issues.*
- **OS**
*Is the community using Windows, Linux or Mac? It helps us prioritize the issues.*
- **Build configurations**

View File

@ -164,7 +164,7 @@ Most of the application's configurations are defined by environment. It means th
- `defaultConnection` (string): Connection by default for models which are not related to a specific `connection`. Default value: `default`.
- `connections` List of all available connections.
- `default`
- `connector` (string): Connector used by the current connection. Default value: `strapi-mongoose`.
- `connector` (string): Connector used by the current connection. Default value: `strapi-hook-mongoose`.
- `client` (string): Client used to store session. Default value: `cookie`.
- `key` (string): Cookie key name. Default value: `strapi.sid`
- `maxAge` (integer): Time in milliseconds before the session expire. Default value: `86400000`.
@ -192,7 +192,7 @@ Most of the application's configurations are defined by environment. It means th
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-mongoose",
"connector": "strapi-hook-mongoose",
"settings": {
"client": "mongo",
"host": "localhost",
@ -208,7 +208,7 @@ Most of the application's configurations are defined by environment. It means th
}
},
"postgres": {
"connector": "strapi-bookshelf",
"connector": "strapi-hook-bookshelf",
"settings": {
"client": "postgres",
"host": "localhost",
@ -223,7 +223,7 @@ Most of the application's configurations are defined by environment. It means th
}
},
"mysql": {
"connector": "strapi-bookshelf",
"connector": "strapi-hook-bookshelf",
"settings": {
"client": "mysql",
"host": "localhost",
@ -367,7 +367,7 @@ In any JSON configurations files in your project, you can inject dynamic values
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-mongoose",
"connector": "strapi-hook-mongoose",
"settings": {
"client": "mongo",
"uri": "${process.env.DATABASE_URI || ''}",

View File

@ -10,7 +10,7 @@
const _ = require('lodash');
// Strapi utilities.
const utils = require('strapi-bookshelf/lib/utils/');
const utils = require('strapi-hook-bookshelf/lib/utils/');
module.exports = {

View File

@ -2,7 +2,7 @@
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-mongoose",
"connector": "strapi-hook-mongoose",
"settings": {
"client": "mongo",
"uri": "${process.env.DATABASE_URI || ''}",

View File

@ -2,7 +2,7 @@
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-mongoose",
"connector": "strapi-hook-mongoose",
"settings": {
"client": "mongo",
"uri": "${process.env.DATABASE_URI || ''}",

View File

@ -69,14 +69,14 @@ module.exports = (scope, cb) => {
name: 'MongoDB (recommended)',
value: {
database: 'mongo',
connector: 'strapi-mongoose'
connector: 'strapi-hook-mongoose'
}
},
{
name: 'Postgres',
value: {
database: 'postgres',
connector: 'strapi-bookshelf',
connector: 'strapi-hook-bookshelf',
module: 'pg'
}
},
@ -84,7 +84,7 @@ module.exports = (scope, cb) => {
name: 'MySQL',
value: {
database: 'mysql',
connector: 'strapi-bookshelf',
connector: 'strapi-hook-bookshelf',
module: 'mysql'
}
}
@ -223,10 +223,10 @@ module.exports = (scope, cb) => {
cmd += ` ${scope.client.module}`;
}
if (scope.client.connector === 'strapi-bookshelf') {
cmd += ` strapi-knex@alpha`;
if (scope.client.connector === 'strapi-hook-bookshelf') {
cmd += ` strapi-hook-knex@alpha`;
scope.additionalsDependencies = ['strapi-knex', 'knex'];
scope.additionalsDependencies = ['strapi-hook-knex', 'knex'];
}
exec(cmd, () => {
@ -234,7 +234,7 @@ module.exports = (scope, cb) => {
const lock = require(path.join(`${scope.tmpPath}`,`/node_modules/`,`${scope.client.module}/package.json`));
scope.client.version = lock.version;
if (scope.developerMode === true && scope.client.connector === 'strapi-bookshelf') {
if (scope.developerMode === true && scope.client.connector === 'strapi-hook-bookshelf') {
const knexVersion = require(path.join(`${scope.tmpPath}`,`/node_modules/`,`knex/package.json`));
scope.additionalsDependencies[1] = `knex@${knexVersion.version || 'latest'}`;
}

View File

@ -1,12 +1,12 @@
# strapi-bookshelf
# strapi-boohook-kshelf
[![npm version](https://img.shields.io/npm/v/strapi-bookshelf.svg)](https://www.npmjs.org/package/strapi-bookshelf)
[![npm downloads](https://img.shields.io/npm/dm/strapi-bookshelf.svg)](https://www.npmjs.org/package/strapi-bookshelf)
[![npm dependencies](https://david-dm.org/strapi/strapi-bookshelf.svg)](https://david-dm.org/strapi/strapi-bookshelf)
[![Build status](https://travis-ci.org/strapi/strapi-bookshelf.svg?branch=master)](https://travis-ci.org/strapi/strapi-bookshelf)
[![npm version](https://img.shields.io/npm/v/strapi-hook-bookshelf.svg)](https://www.npmjs.org/package/strapi-hook-bookshelf)
[![npm downloads](https://img.shields.io/npm/dm/strapi-hook-bookshelf.svg)](https://www.npmjs.org/package/strapi-hook-bookshelf)
[![npm dependencies](https://david-dm.org/strapi/strapi-hook-bookshelf.svg)](https://david-dm.org/strapi/strapi-hook-bookshelf)
[![Build status](https://travis-ci.org/strapi/strapi-hook-bookshelf.svg?branch=master)](https://travis-ci.org/strapi/strapi-hook-bookshelf)
[![Slack status](http://strapi-slack.herokuapp.com/badge.svg)](http://slack.strapi.io)
This built-in hook allows you to use the [Bookshelf ORM](http://bookshelfjs.org/) using the `strapi-knex` hook.
This built-in hook allows you to use the [Bookshelf ORM](http://bookshelfjs.org/) using the `strapi-hook-knex` hook.
[Bookshelf ORM](http://bookshelfjs.org/) is a JavaScript ORM for Node.js, built on the [Knex node module](http://knexjs.org/) SQL query builder. Featuring both promise based and traditional callback interfaces, providing transaction support, eager/nested-eager relation loading, polymorphic associations, and support for one-to-one, one-to-many, and many-to-many relations.

View File

@ -45,7 +45,7 @@ module.exports = function(strapi) {
*/
initialize: async cb => {
const connections = _.pickBy(strapi.config.connections, { connector: 'strapi-bookshelf' });
const connections = _.pickBy(strapi.config.connections, { connector: 'strapi-hook-bookshelf' });
const databaseUpdate = [];

View File

@ -1,5 +1,5 @@
{
"name": "strapi-bookshelf",
"name": "strapi-hook-bookshelf",
"version": "3.0.0-alpha.12.7.1",
"description": "Bookshelf hook for the Strapi framework",
"homepage": "http://strapi.io",
@ -20,13 +20,12 @@
"inquirer": "^5.2.0",
"lodash": "^4.17.4",
"pluralize": "^6.0.0",
"strapi-knex": "3.0.0-alpha.12.7.1",
"strapi-hook-knex": "3.0.0-alpha.12.7.1",
"strapi-utils": "3.0.0-alpha.12.7.1"
},
"strapi": {
"isHook": true,
"dependencies": [
"strapi-knex"
"strapi-hook-knex"
]
},
"scripts": {

View File

@ -1,5 +1,5 @@
{
"name": "strapi-ejs",
"name": "strapi-hook-ejs",
"version": "3.0.0-alpha.12.7.1",
"description": "EJS hook for the Strapi framework",
"homepage": "http://strapi.io",
@ -16,9 +16,6 @@
"co": "^4.6.0",
"koa-ejs": "^4.1.0"
},
"strapi": {
"isHook": true
},
"scripts": {
"prepublishOnly": "npm prune"
},

View File

@ -1,9 +1,9 @@
# strapi-knex
# strapi-hook-knex
[![npm version](https://img.shields.io/npm/v/strapi-knex.svg)](https://www.npmjs.org/package/strapi-knex)
[![npm downloads](https://img.shields.io/npm/dm/strapi-knex.svg)](https://www.npmjs.org/package/strapi-knex)
[![npm dependencies](https://david-dm.org/strapi/strapi-knex.svg)](https://david-dm.org/strapi/strapi-knex)
[![Build status](https://travis-ci.org/strapi/strapi-knex.svg?branch=master)](https://travis-ci.org/strapi/strapi-knex)
[![npm version](https://img.shields.io/npm/v/strapi-hook-knex.svg)](https://www.npmjs.org/package/strapi-hook-knex)
[![npm downloads](https://img.shields.io/npm/dm/strapi-hook-knex.svg)](https://www.npmjs.org/package/strapi-hook-knex)
[![npm dependencies](https://david-dm.org/strapi/strapi-hook-knex.svg)](https://david-dm.org/strapi/strapi-hook-knex)
[![Build status](https://travis-ci.org/strapi/strapi-hook-knex.svg?branch=master)](https://travis-ci.org/strapi/strapi-hook-knex)
[![Slack status](http://strapi-slack.herokuapp.com/badge.svg)](http://slack.strapi.io)
This built-in hook allows you to directly make SQL queries from your Strapi connections to your databases thanks to the [Knex node module](http://knexjs.org/).

View File

@ -46,7 +46,7 @@ module.exports = strapi => {
initialize: cb => {
// For each connection in the config register a new Knex connection.
_.forEach(_.pickBy(strapi.config.connections, {connector: 'strapi-bookshelf'}), (connection, name) => {
_.forEach(_.pickBy(strapi.config.connections, {connector: 'strapi-hook-bookshelf'}), (connection, name) => {
// Make sure we use the client even if the typo is not the exact one.
switch (connection.settings.client) {

View File

@ -1,5 +1,5 @@
{
"name": "strapi-knex",
"name": "strapi-hook-knex",
"version": "3.0.0-alpha.12.7.1",
"description": "Knex hook for the Strapi framework",
"homepage": "http://strapi.io",
@ -19,9 +19,6 @@
"knex": "^0.13.0",
"lodash": "^4.17.4"
},
"strapi": {
"isHook": true
},
"author": {
"email": "hi@strapi.io",
"name": "Strapi team",

View File

@ -1,9 +1,9 @@
# strapi-mongoose
# strapi-hook-mongoose
[![npm version](https://img.shields.io/npm/v/strapi-mongoose.svg)](https://www.npmjs.org/package/strapi-mongoose)
[![npm downloads](https://img.shields.io/npm/dm/strapi-mongoose.svg)](https://www.npmjs.org/package/strapi-mongoose)
[![npm dependencies](https://david-dm.org/strapi/strapi-mongoose.svg)](https://david-dm.org/strapi/strapi-mongoose)
[![Build status](https://travis-ci.org/strapi/strapi-mongoose.svg?branch=master)](https://travis-ci.org/strapi/strapi-bookshelf)
[![npm version](https://img.shields.io/npm/v/strapi-hook-mongoose.svg)](https://www.npmjs.org/package/strapi-hook-mongoose)
[![npm downloads](https://img.shields.io/npm/dm/strapi-hook-mongoose.svg)](https://www.npmjs.org/package/strapi-hook-mongoose)
[![npm dependencies](https://david-dm.org/strapi/strapi-hook-mongoose.svg)](https://david-dm.org/strapi/strapi-hook-mongoose)
[![Build status](https://travis-ci.org/strapi/strapi-hook-mongoose.svg?branch=master)](https://travis-ci.org/strapi/strapi-hook-mongoose)
[![Slack status](http://strapi-slack.herokuapp.com/badge.svg)](http://slack.strapi.io)
This built-in hook allows you to use the [Mongoose ORM](http://mongoosejs.com/).

View File

@ -49,7 +49,7 @@ module.exports = function (strapi) {
*/
initialize: cb => {
_.forEach(_.pickBy(strapi.config.connections, {connector: 'strapi-mongoose'}), (connection, connectionName) => {
_.forEach(_.pickBy(strapi.config.connections, {connector: 'strapi-hook-mongoose'}), (connection, connectionName) => {
const instance = new Mongoose();
const { uri, host, port, username, password, database } = _.defaults(connection.settings, strapi.config.hook.settings.mongoose);
const uriOptions = uri ? url.parse(uri, true).query : {};

View File

@ -174,7 +174,7 @@ module.exports = {
strapi.models[_.toLower(obj.ref)].globalId;
// Define the object stored in database.
// The shape is this object is defined by the strapi-mongoose connector.
// The shape is this object is defined by the strapi-hook-mongoose connector.
return {
ref: obj.refId,
kind: globalId,

View File

@ -1,5 +1,5 @@
{
"name": "strapi-mongoose",
"name": "strapi-hook-mongoose",
"version": "3.0.0-alpha.12.7.1",
"description": "Mongoose hook for the Strapi framework",
"homepage": "http://strapi.io",
@ -21,9 +21,6 @@
"pluralize": "^6.0.0",
"strapi-utils": "3.0.0-alpha.12.7.1"
},
"strapi": {
"isHook": true
},
"author": {
"email": "hi@strapi.io",
"name": "Strapi team",

View File

@ -38,13 +38,13 @@ module.exports = function(strapi) {
initialize: cb => {
if (_.isEmpty(strapi.models) || !_.pickBy(strapi.config.connections, {
connector: 'strapi-redis'
connector: 'strapi-hook-redis'
})) {
return cb();
}
const connections = _.pickBy(strapi.config.connections, {
connector: 'strapi-redis'
connector: 'strapi-hook-redis'
});
if(_.size(connections) === 0) {

View File

@ -1,5 +1,5 @@
{
"name": "strapi-redis",
"name": "strapi-hook-redis",
"version": "3.0.0-alpha.12.7.1",
"description": "Redis hook for the Strapi framework",
"homepage": "http://strapi.io",
@ -20,9 +20,6 @@
"stack-trace": "0.0.10",
"strapi-utils": "3.0.0-alpha.12.7.1"
},
"strapi": {
"isHook": true
},
"author": {
"email": "hi@strapi.io",
"name": "Strapi team",

View File

@ -1,7 +1,7 @@
{
"name": "strapi-middleware-views",
"version": "3.0.0-alpha.12.7.1",
"description": "Views hook to enable server-side rendering for the Strapi framework",
"description": "Views middleware to enable server-side rendering for the Strapi framework",
"homepage": "http://strapi.io",
"keywords": [
"redis",
@ -19,9 +19,6 @@
"koa-views": "^6.1.1",
"lodash": "^4.17.4"
},
"strapi": {
"isHook": true
},
"author": {
"email": "hi@strapi.io",
"name": "Strapi team",

View File

@ -207,7 +207,7 @@ module.exports = {
return ctx.badRequest(null, [{ messages: [{ id: 'Connection doesn\'t exist' }] }]);
}
if (connector === 'strapi-bookshelf') {
if (connector === 'strapi-hook-bookshelf') {
try {
const tableExists = await strapi.connections[connection].schema.hasTable(model);

View File

@ -117,7 +117,7 @@ module.exports = {
},
generateAPI: (name, description, connection, collectionName, attributes) => {
const template = _.get(strapi.config.currentEnvironment, `database.connections.${connection}.connector`, 'strapi-mongoose').split('-')[1];
const template = _.get(strapi.config.currentEnvironment, `database.connections.${connection}.connector`, 'strapi-hook-mongoose').split('-')[1];
return new Promise((resolve, reject) => {
const scope = {

View File

@ -650,9 +650,9 @@ module.exports = {
const redisClients = ['redis'];
let connector;
if (_.indexOf(bookshelfClients, client) !== -1) connector = 'strapi-bookshelf';
if (_.indexOf(mongooseClients, client) !== -1) connector = 'strapi-mongoose';
if (_.indexOf(redisClients, client) !== -1) connector = 'strapi-redis';
if (_.indexOf(bookshelfClients, client) !== -1) connector = 'strapi-hook-bookshelf';
if (_.indexOf(mongooseClients, client) !== -1) connector = 'strapi-hook-mongoose';
if (_.indexOf(redisClients, client) !== -1) connector = 'strapi-hook-redis';
return connector;
},
@ -911,7 +911,7 @@ module.exports = {
},
cleanDependency: (env, config) => {
const availableConnectors = ['strapi-mongoose', 'strapi-bookshelf', 'strapi-redis'];
const availableConnectors = ['strapi-hook-mongoose', 'strapi-hook-bookshelf', 'strapi-hook-redis'];
let usedConnectors = [];
const errors = [];

View File

@ -21,10 +21,10 @@ module.exports = scope => {
// First, make sure the application we have access to
// the migration generator.
try {
require.resolve(path.resolve(scope.rootPath, 'node_modules', 'strapi-knex'));
require.resolve(path.resolve(scope.rootPath, 'node_modules', 'strapi-hook-knex'));
} catch (err) {
console.error('Impossible to call the Knex migration tool.');
console.error('You can install it with `$ npm install strapi-knex --save`.');
console.error('You can install it with `$ npm install strapi-hook-knex --save`.');
process.exit(1);
}

View File

@ -281,7 +281,7 @@ module.exports.app = async function() {
// Enable hooks and dependencies related to the connections.
for (let name in this.config.connections) {
const connection = this.config.connections[name];
const connector = connection.connector.replace('strapi-', '');
const connector = connection.connector.replace('strapi-hook-', '');
enableHookNestedDependencies.call(this, connector, flattenHooksConfig);
}
@ -333,7 +333,7 @@ module.exports.app = async function() {
const enableHookNestedDependencies = function (name, flattenHooksConfig, force = false) {
if (!this.hook[name]) {
this.log.warn(`(hook:${name}) \`strapi-${name}\` is missing in your dependencies. Please run \`npm install strapi-${name}\``);
this.log.warn(`(hook:${name}) \`strapi-hook-${name}\` is missing in your dependencies. Please run \`npm install strapi-hook-${name}\``);
}
// Couldn't find configurations for this hook.
@ -347,7 +347,7 @@ const enableHookNestedDependencies = function (name, flattenHooksConfig, force =
const connector = get(this.config.connections, models[model].connection, {}).connector;
if (connector) {
return connector.replace('strapi-', '') === name;
return connector.replace('strapi-hook-', '') === name;
}
return false;
@ -363,7 +363,7 @@ const enableHookNestedDependencies = function (name, flattenHooksConfig, force =
// Enabled dependencies.
if (get(this.hook, `${name}.dependencies`, []).length > 0) {
this.hook[name].dependencies.forEach(dependency => {
enableHookNestedDependencies.call(this, dependency.replace('strapi-', ''), flattenHooksConfig, true);
enableHookNestedDependencies.call(this, dependency.replace('strapi-hook-', ''), flattenHooksConfig, true);
});
}
}

View File

@ -15,18 +15,7 @@ module.exports = function() {
const cwd = '';
// Load configurations.
glob('./node_modules/strapi-*', {
ignore: [
'./node_modules/strapi-admin',
'./node_modules/strapi-utils',
'./node_modules/strapi-generate*',
'./node_modules/strapi-plugin-*',
'./node_modules/strapi-helper-*',
'./node_modules/strapi-middleware-*',
'./node_modules/strapi-upload-*',
'./node_modules/strapi-email-*',
'./node_modules/strapi-lint'
],
glob('./node_modules/strapi-hook-*', {
cwd: this.config.appPath
}, (err, files) => {
if (err) {
@ -71,17 +60,9 @@ const mountHooks = function (files, cwd, isPlugin) {
return (resolve, reject) =>
parallel(
files.map(p => cb => {
const extractStr = p
.split('/')
.pop()
.replace(/^strapi(-|\.)/, '')
.split('-');
const name = lowerFirst(
extractStr.length === 1
? extractStr[0]
: extractStr.map(p => upperFirst(p)).join('')
);
const folders = p.replace(/^.\/node_modules\/strapi-hook-/, './')
.split('/');
const name = isPlugin ? folders[folders.length - 2] : folders[1];
fs.readFile(path.resolve(this.config.appPath, cwd, p, 'package.json'), (err, content) => {
try {

View File

@ -83,7 +83,7 @@ module.exports = async function() {
}
// Initialize array.
let previousDependencies = this.hook[hook].dependencies.map(x => x.replace('strapi-', '')) || [];
let previousDependencies = this.hook[hook].dependencies.map(x => x.replace('strapi-hook', '')) || [];
// Add BEFORE middlewares to load and remove the current one
// to avoid that it waits itself.

View File

@ -99,17 +99,17 @@ shell.cd('../strapi-generate-new');
watcher('', 'npm install ../strapi-utils');
watcher('📦 Linking strapi-generate-new', 'npm link');
shell.cd('../strapi-mongoose');
shell.cd('../strapi-hook-mongoose');
watcher('', 'npm install ../strapi-utils');
watcher('📦 Linking strapi-mongoose...', 'npm link');
watcher('📦 Linking strapi-hook-mongoose...', 'npm link');
shell.cd('../strapi-knex');
watcher('📦 Linking strapi-knex...', 'npm link');
shell.cd('../strapi-hook-knex');
watcher('📦 Linking strapi-hook-knex...', 'npm link');
shell.cd('../strapi-bookshelf');
shell.cd('../strapi-hook-bookshelf');
watcher('', 'npm install ../strapi-utils');
watcher('', 'npm install ../strapi-knex');
watcher('📦 Linking strapi-bookshelf...', 'npm link');
watcher('', 'npm install ../strapi-hook-knex');
watcher('📦 Linking strapi-hook-bookshelf...', 'npm link');
shell.cd('../strapi');
watcher('', 'npm install ../strapi-generate ../strapi-generate-admin ../strapi-generate-api ../strapi-generate-new ../strapi-generate-plugin ../strapi-generate-policy ../strapi-generate-service ../strapi-utils');