Skip to content

Commit 6be6ee0

Browse files
committed
style: standardize code formatting and add husky pre-commit hooks
1 parent 4827f45 commit 6be6ee0

File tree

9 files changed

+54
-33
lines changed

9 files changed

+54
-33
lines changed

.vscode/settings.json

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
2-
"editor.tabSize": 2,
3-
"typescript.preferences.importModuleSpecifier": "relative",
4-
"prettier.bracketSpacing": false,
5-
"editor.formatOnSave": true,
6-
"editor.formatOnSaveMode": "file",
7-
"editor.codeActionsOnSave": {
8-
"source.addMissingImports.ts": "always",
9-
"source.fixAll.eslint": "always",
10-
"source.organizeImports": "always"
11-
},
12-
"typescript.tsdk": "node_modules/typescript/lib"
13-
}
14-
2+
"editor.tabSize": 2,
3+
"typescript.preferences.importModuleSpecifier": "relative",
4+
"prettier.bracketSpacing": false,
5+
"editor.formatOnSave": true,
6+
"editor.formatOnSaveMode": "file",
7+
"editor.codeActionsOnSave": {
8+
"source.addMissingImports.ts": "always",
9+
"source.fixAll.eslint": "always",
10+
"source.organizeImports": "always"
11+
},
12+
"typescript.tsdk": "node_modules/typescript/lib"
13+
}

admin/src/translations/en.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const en = {
1111
success: 'Successfully imported {successful} of {total} files',
1212
warning: 'Import completed with warnings: {message}',
1313
complete: 'Import process failed',
14-
error: 'Error importing files: {message} {details}'
15-
}
16-
}
14+
error: 'Error importing files: {message} {details}',
15+
},
16+
},
1717
},
1818
settings: {
1919
state: {

admin/src/utils/url.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
export function removeTrailingSlash(str: string) {
2-
if (typeof str == "string" && str[str.length - 1] == "/") {
2+
if (typeof str == 'string' && str[str.length - 1] == '/') {
33
str = str.substring(0, str.length - 1);
44
}
55
return str;
66
}
77

88
export function removeLeadingSlash(str: string) {
9-
if (typeof str == "string" && str[0] == "/") {
9+
if (typeof str == 'string' && str[0] == '/') {
1010
str = str.slice(1);
1111
}
1212
return str;

common/pluginId.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import * as pluginPkg from '../package.json';
2-
3-
export const PLUGIN_ID = pluginPkg.strapi.name;
1+
export const PLUGIN_ID = 'imagekit';

common/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"include": ["./src", "./custom.d.ts"],
44
"compilerOptions": {
55
"rootDir": "../",
6-
"baseUrl": "."
6+
"baseUrl": ".",
7+
"resolveJsonModule": true
78
}
89
}

package.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@
2323
"dist"
2424
],
2525
"scripts": {
26-
"build": "strapi-plugin build",
26+
"prepare": "husky install",
27+
"publish:latest": "npm publish --tag latest",
28+
"publish:beta": "npm publish --tag beta",
29+
"build": "yarn clean && strapi-plugin build",
30+
"clean": "rm -rf dist",
31+
"lint": "prettier --check .",
32+
"format": "prettier --write .",
2733
"watch": "strapi-plugin watch",
2834
"watch:link": "strapi-plugin watch:link",
2935
"verify": "strapi-plugin verify",
@@ -48,6 +54,7 @@
4854
"@strapi/upload": "^5.13.0",
4955
"@types/react": "^19.1.3",
5056
"@types/react-dom": "^19.1.4",
57+
"husky": "^9.1.7",
5158
"prettier": "^3.5.3",
5259
"react": "^18.3.1",
5360
"react-dom": "^18.3.1",
@@ -88,5 +95,10 @@
8895
"email": "[email protected]"
8996
}
9097
],
91-
"packageManager": "[email protected]"
92-
}
98+
"packageManager": "[email protected]",
99+
"husky": {
100+
"hooks": {
101+
"pre-commit": "yarn format"
102+
}
103+
}
104+
}

server/src/controllers/webhook.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const webhookController = ({ strapi }: { strapi: Core.Strapi }) => ({
88
async handleWebhook(ctx: any) {
99
try {
1010
const { body } = ctx.request;
11-
11+
1212
// Validate the webhook payload
1313
if (!body || !body.eventType || !body.data || !Array.isArray(body.data)) {
1414
return ctx.badRequest({
@@ -17,7 +17,7 @@ const webhookController = ({ strapi }: { strapi: Core.Strapi }) => ({
1717
details: 'The webhook payload must contain eventType and an array of data items',
1818
});
1919
}
20-
20+
2121
if (body.data.length === 0) {
2222
return ctx.badRequest({
2323
status: 'error',
@@ -27,11 +27,8 @@ const webhookController = ({ strapi }: { strapi: Core.Strapi }) => ({
2727
}
2828

2929
// Process the webhook data
30-
const result = await strapi
31-
.plugin('imagekit')
32-
.service('webhook')
33-
.processWebhook(body);
34-
30+
const result = await strapi.plugin('imagekit').service('webhook').processWebhook(body);
31+
3532
// Check if we got any successful imports
3633
if (result && result.length > 0) {
3734
// Add statistics for successful imports vs attempted imports
@@ -61,7 +58,7 @@ const webhookController = ({ strapi }: { strapi: Core.Strapi }) => ({
6158
}
6259
} catch (error: any) {
6360
strapi.log.error('[ImageKit Webhook Controller] Error handling webhook:', error);
64-
61+
6562
// Return a structured error response
6663
return ctx.badRequest({
6764
status: 'error',

server/src/register.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { getService } from './utils/getService';
99
function toImageKitUrl(src: string, settings: Settings, client: ImageKit): string {
1010
const endpoint = settings.urlEndpoint;
1111

12+
if (!endpoint) {
13+
return src;
14+
}
15+
1216
if (src.startsWith(endpoint)) {
1317
return client.url({
1418
src,

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8460,6 +8460,15 @@ __metadata:
84608460
languageName: node
84618461
linkType: hard
84628462

8463+
"husky@npm:^9.1.7":
8464+
version: 9.1.7
8465+
resolution: "husky@npm:9.1.7"
8466+
bin:
8467+
husky: bin.js
8468+
checksum: 10c0/35bb110a71086c48906aa7cd3ed4913fb913823715359d65e32e0b964cb1e255593b0ae8014a5005c66a68e6fa66c38dcfa8056dbbdfb8b0187c0ffe7ee3a58f
8469+
languageName: node
8470+
linkType: hard
8471+
84638472
"iconv-lite@npm:0.4.13":
84648473
version: 0.4.13
84658474
resolution: "iconv-lite@npm:0.4.13"
@@ -13325,6 +13334,7 @@ __metadata:
1332513334
"@types/react": "npm:^19.1.3"
1332613335
"@types/react-dom": "npm:^19.1.4"
1332713336
formik: "npm:^2.4.6"
13337+
husky: "npm:^9.1.7"
1332813338
imagekit: "npm:^6.0.0"
1332913339
imagekit-media-library-widget: "npm:^2.1.1"
1333013340
lodash: "npm:^4.17.21"

0 commit comments

Comments
 (0)