Skip to content

Commit b6cffef

Browse files
committed
Refactor into unscoped packages
1 parent 53467a7 commit b6cffef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1971
-541
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"devDependencies": {
2626
"eslint-config-custom": "*",
2727
"prettier": "latest",
28-
"turbo": "1.10.7"
28+
"turbo": "1.10.12"
2929
},
3030
"engines": {
3131
"node": ">=14.0.0"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './types';

packages/strapi-plugin-search/package.json renamed to packages/strapi-plugin-search-index/package.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@rixw/strapi-plugin-search",
2+
"name": "strapi-plugin-search-index",
33
"version": "0.3.8",
44
"description": "Site search engine integration plugin for Strapi",
55
"keywords": [
@@ -21,15 +21,12 @@
2121
"url": "https://github.com/rixw"
2222
},
2323
"scripts": {
24-
"build": "tsc -p tsconfig.json",
25-
"prepare": "yarn clean && yarn build && node dist/setup-package.js",
24+
"build": "yarn clean && tsc -p tsconfig.json && node dist/setup-package.js",
2625
"clean": "rm -rf dist"
2726
},
2827
"peerDependencies": {
2928
"@strapi/strapi": "^4.11.4"
3029
},
31-
"main": "dist/index.js",
32-
"types": "dist/index.d.ts",
3330
"devDependencies": {
3431
"@strapi/typescript-utils": "^4.11.4",
3532
"strapi-typed": "^1.0.16",
@@ -40,9 +37,14 @@
4037
"directory": "dist"
4138
},
4239
"strapi": {
43-
"name": "strapi-plugin-search",
44-
"description": "Strapi plugin to interface with site search engines",
40+
"name": "search-index",
41+
"description": "Strapi plugin to index to site search engines",
4542
"kind": "plugin",
46-
"displayName": "Search"
47-
}
43+
"displayName": "Search Index"
44+
},
45+
"files": [
46+
"./dist"
47+
],
48+
"main": "./dist/index.js",
49+
"types": "./dist/index.d.ts"
4850
}

packages/strapi-plugin-search/server/bootstrap.ts renamed to packages/strapi-plugin-search-index/server/bootstrap.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { StrapiContext } from 'strapi-typed';
44
* Bootstraps search plugin
55
*/
66
const bootstrap = async ({ strapi }: StrapiContext) => {
7-
strapi.log.log('Search plugin bootstrapping...');
7+
strapi.log.log('Search Index plugin bootstrapping...');
88
try {
9-
const search = strapi.plugin('search');
9+
const search = strapi.plugin('search-index');
10+
console.log('search-index bootstrap search', search);
1011
await search.service('provider').loadProvider();
1112
await search.service('lifecycle').loadLifecycleMethods();
12-
strapi.log.log('Search plugin bootstrapped');
13+
strapi.log.log('Search Index plugin bootstrapped');
1314
} catch (error) {
14-
strapi.log.error(`Search plugin bootstrap failed. ${(error as Error).message}`);
15+
strapi.log.error(`Search Index plugin bootstrap failed. ${(error as Error).message}`);
1516
}
1617
};
1718

packages/strapi-plugin-search/server/config/index.ts renamed to packages/strapi-plugin-search-index/server/config/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Strapi } from '@strapi/strapi';
55

66
declare var strapi: Strapi;
77

8-
const config = {
8+
export default {
99
/**
1010
* Default plugin configuration
1111
*/
@@ -23,5 +23,3 @@ const config = {
2323
*/
2424
validator: (config: PluginConfig) => validateConfig(config),
2525
};
26-
27-
export default config;

packages/strapi-plugin-search/server/services/index.ts renamed to packages/strapi-plugin-search-index/server/services/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@
33
import lifecycle from './lifecycle';
44
import provider from './provider';
55

6-
export default {
7-
lifecycle,
8-
provider,
9-
};
6+
export default { lifecycle, provider };

packages/strapi-plugin-search/server/services/lifecycle.ts renamed to packages/strapi-plugin-search-index/server/services/lifecycle.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,27 @@ const lifecycle = (): Lifecycle =>
2525
* Load provider methods into lifecycles
2626
*/
2727
async loadLifecycleMethods() {
28-
const provider = strapi.plugin('search').provider;
28+
strapi.log.log('Loading lifecycle methods...');
29+
console.log('Loading lifecycle methods...');
30+
const provider = strapi.plugin('search-index').provider;
2931
const {
3032
excludedFields = [],
3133
prefix: indexPrefix = '',
3234
contentTypes,
33-
} = strapi.config.get('plugin.search') as PluginConfig;
35+
} = strapi.config.get('plugin.search-index') as PluginConfig;
3436

3537
// Loop over configured contentTypes in ./config/plugins.js
3638
contentTypes &&
3739
contentTypes.forEach((contentType) => {
40+
strapi.log.log('Loading lifecycle methods for content type:', contentType);
41+
console.log('Loading lifecycle methods for content type:', contentType);
3842
const { name, index, prefix: idPrefix = '', fields = [] } = contentType;
3943

4044
if (strapi.contentTypes[name]) {
4145
const indexName = indexPrefix + (index ? index : name);
4246

4347
const checkPublicationState = (event: AfterEvent) => {
48+
strapi.log.log('checkPublicationState', event);
4449
if (
4550
event.result &&
4651
has('publishedAt', event.result) &&
@@ -61,6 +66,7 @@ const lifecycle = (): Lifecycle =>
6166
models: [name],
6267

6368
async afterCreate(event: Event) {
69+
strapi.log.log('afterCreate', event);
6470
checkPublicationState(event as AfterEvent)
6571
? provider.create({
6672
indexName,
@@ -82,6 +88,7 @@ const lifecycle = (): Lifecycle =>
8288
// },
8389

8490
async afterUpdate(event) {
91+
strapi.log.log('afterUpdate', event);
8592
checkPublicationState(event as AfterEvent)
8693
? provider.create({
8794
indexName,
@@ -104,6 +111,7 @@ const lifecycle = (): Lifecycle =>
104111
// },
105112

106113
async afterDelete(event) {
114+
strapi.log.log('afterDelete', event);
107115
provider.delete({ indexName, id: idPrefix + (event as AfterEvent).result.id });
108116
},
109117

packages/strapi-plugin-search/server/services/provider.ts renamed to packages/strapi-plugin-search-index/server/services/provider.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const provider = () => ({
1717
* @param {string} [pluginConfig.resolve] - Path to provider
1818
*/
1919
async loadProvider(pluginConfig: PluginConfig): Promise<void> {
20-
pluginConfig = pluginConfig ? pluginConfig : strapi.config.get('plugin.search');
20+
strapi.log.log('loadProvider', pluginConfig);
21+
pluginConfig = pluginConfig ? pluginConfig : strapi.config.get('plugin.search-index');
2122

2223
try {
2324
// Todo implement v4 package loader logic
@@ -32,10 +33,10 @@ const provider = () => ({
3233
providerInstance.updateMany = wrapMethodWithError(providerInstance.updateMany);
3334
providerInstance.deleteMany = wrapMethodWithError(providerInstance.deleteMany);
3435
providerInstance.clear = wrapMethodWithError(providerInstance.clear);
35-
strapi.plugin('search').provider = providerInstance;
36+
strapi.plugin('search-index').provider = providerInstance;
3637
}
3738
} catch (error) {
38-
strapi.plugin('search').provider = null;
39+
strapi.plugin('search-index').provider = null;
3940
throw new Error(
4041
`Search plugin could not load provider '${pluginConfig.provider}': ${
4142
(error as Error).message
@@ -51,14 +52,15 @@ const provider = () => ({
5152
* @param {object} parameters - Parameters to pass to findMany
5253
*/
5354
async rebuild(specificTypes: string[], parameters: object) {
55+
strapi.log.log('rebuild', specificTypes, parameters);
5456
strapi.log.info('Rebuilding search indexes...');
5557
try {
5658
const {
5759
excludedFields = [],
5860
prefix: indexPrefix = '',
5961
contentTypes,
60-
} = strapi.config.get('plugin.search') as PluginConfig;
61-
const pluginInstance = strapi.plugin('search').provider;
62+
} = strapi.config.get('plugin.search-index') as PluginConfig;
63+
const pluginInstance = strapi.plugin('search-index').provider;
6264
const rebuildTypes = contentTypes.filter(
6365
(contentType) => !specificTypes || specificTypes.includes(contentType.name),
6466
);

packages/strapi-plugin-search/server/utils/validate.ts renamed to packages/strapi-plugin-search-index/server/utils/validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const validateConfig = (config: PluginConfig) => {
3737
.validateSync(config);
3838
} catch (error) {
3939
throw new Error(
40-
`Search plugin ConfigValidationError: ${(error as { errors: string[] }).errors}`,
40+
`Search Index plugin ConfigValidationError: ${(error as { errors: string[] }).errors}`,
4141
);
4242
}
4343
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import bootstrap from './server/bootstrap';
2+
import config from './server/config';
3+
import services from './server/services';
4+
5+
export = () => ({
6+
register: ({ strapi }) => {
7+
strapi.log.log('Top level register');
8+
},
9+
bootstrap: ({ strapi }) => {
10+
strapi.log.log('Top level bootstrap');
11+
},
12+
config,
13+
services,
14+
});

packages/strapi-plugin-search/tsconfig.json renamed to packages/strapi-plugin-search-index/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"./server/**/*",
1111
"./strapi-server.*",
1212
"./setup-package.ts",
13-
"types/index.d.ts",
13+
"./types/**/*",
1414
],
1515
"exclude": [
1616
"dist/**/*",

packages/strapi-plugin-search/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/strapi-plugin-search/server/index.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/strapi-plugin-search/strapi-server.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public/
2+
coverage/
3+
.circleci/
4+
.github/
5+
.nvmrc
6+
.eslintrc
7+
codecov.yml
8+
*.map
9+
*.spec.*
10+
setup-package.*
11+
**/__tests__/**
12+
**/__mocks__/**
13+
tsconfig.*

packages/strapi-provider-search-algolia/index.ts renamed to packages/strapi-provider-search-index-algolia/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
DeleteManyProps,
77
DeleteProps,
88
ProviderInstance,
9-
} from '@rixw/strapi-plugin-search';
9+
} from 'strapi-plugin-search-index';
1010

1111
declare var strapi: {
1212
log: {

packages/strapi-provider-search-algolia/package.json renamed to packages/strapi-provider-search-index-algolia/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "@rixw/strapi-provider-search-algolia",
3-
"version": "0.3.7",
3+
"version": "0.3.8",
44
"description": "This is the description of the plugin.",
55
"keywords": [
66
"strapi",
77
"search",
88
"algolia"
99
],
10-
"homepage": "https://github.com/rixw/strapi-utils/strapi-provider-search-algolia",
10+
"homepage": "https://github.com/rixw/strapi-utils/strapi-provider-search-index-algolia",
1111
"bugs": "https://github.com/rixw/strapi-utils/issues",
1212
"repository": {
1313
"type": "git",
@@ -24,12 +24,12 @@
2424
"types": "./dist/index.d.ts",
2525
"scripts": {
2626
"build": "tsc -p tsconfig.json",
27-
"prepare": "yarn clean && yarn build",
27+
"prebuild": "yarn clean",
2828
"clean": "rm -rf dist"
2929
},
3030
"dependencies": {
3131
"algoliasearch": "^4.17.0",
32-
"@rixw/strapi-plugin-search": "*"
32+
"strapi-plugin-search-index": "*"
3333
},
3434
"devDependencies": {
3535
"tsconfig": "*"
@@ -38,6 +38,8 @@
3838
"access": "public"
3939
},
4040
"strapi": {
41-
"isProvider": true
41+
"name": "algolia",
42+
"isProvider": true,
43+
"displayName": "Algolia Provider"
4244
}
4345
}

packages/test-project/.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[{package.json,*.yml}]
12+
indent_style = space
13+
indent_size = 2
14+
15+
[*.md]
16+
trim_trailing_whitespace = false

packages/test-project/.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
HOST=0.0.0.0
2+
PORT=1337
3+
APP_KEYS="toBeModified1,toBeModified2"
4+
API_TOKEN_SALT=tobemodified
5+
ADMIN_JWT_SECRET=tobemodified
6+
TRANSFER_TOKEN_SALT=tobemodified
7+
JWT_SECRET=tobemodified

packages/test-project/.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.cache
2+
build
3+
**/node_modules/**

packages/test-project/.eslintrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"parser": "babel-eslint",
3+
"extends": "eslint:recommended",
4+
"env": {
5+
"commonjs": true,
6+
"es6": true,
7+
"node": true,
8+
"browser": false
9+
},
10+
"parserOptions": {
11+
"ecmaFeatures": {
12+
"experimentalObjectRestSpread": true,
13+
"jsx": false
14+
},
15+
"sourceType": "module"
16+
},
17+
"globals": {
18+
"strapi": true
19+
},
20+
"rules": {
21+
"indent": ["error", 2, { "SwitchCase": 1 }],
22+
"linebreak-style": ["error", "unix"],
23+
"no-console": 0,
24+
"quotes": ["error", "single"],
25+
"semi": ["error", "always"]
26+
}
27+
}

0 commit comments

Comments
 (0)