Skip to content

Commit 3412fef

Browse files
committed
Reconfigure the project
1 parent 564448f commit 3412fef

20 files changed

+488
-70
lines changed

.eslintignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
vendor
2-
node_modules
31
build
2+
dist
3+
4+
./vendor
5+
./node_modules
46

57
.psalm
68
.github
79

810
./coverage
9-
./sources/server

.eslintrc.json

+14-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@
44
"es2023": true
55
},
66
"extends": [
7-
"eslint:recommended",
8-
"plugin:@typescript-eslint/recommended"
7+
"plugin:@wordpress/eslint-plugin/recommended"
98
],
10-
"parser": "@typescript-eslint/parser",
9+
"settings": {
10+
"import/resolver": "typescript"
11+
},
1112
"parserOptions": {
1213
"ecmaVersion": "latest",
1314
"sourceType": "module",
1415
"project": "./tsconfig.json"
1516
},
16-
"plugins": [
17-
"@typescript-eslint"
17+
"overrides": [
18+
{
19+
"files": ["webpack.config.js"],
20+
"env": {
21+
"node": true
22+
},
23+
"rules": {
24+
"@typescript-eslint/no-var-requires": "off"
25+
}
26+
}
1827
],
1928
"rules": {
2029
"consistent-return": "off",
@@ -51,7 +60,6 @@
5160
"@typescript-eslint/prefer-readonly": "error",
5261
"@typescript-eslint/prefer-readonly-parameter-types": "error",
5362
"@typescript-eslint/prefer-reduce-type-parameter": "error",
54-
"@typescript-eslint/consistent-return": "error",
5563
"@typescript-eslint/explicit-function-return-type": "error",
5664
"@typescript-eslint/explicit-module-boundary-types": "error",
5765
"@typescript-eslint/dot-notation": "error",

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/.psalm
22
/.idea
3-
/build/
3+
/sources/**/dist/
44
/coverage
55
/vendor/
66
/node_modules/

.phpstorm.meta.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace PHPSTORM_META {
4+
override(
5+
\Psr\Container\ContainerInterface::get(0),
6+
map(
7+
[
8+
'' => '@',
9+
]
10+
)
11+
);
12+
}

.prettierignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
build
2+
dist
3+
14
.psalm
25
.github
36

47
./coverage
58
./vendor
69
./node_modules
7-
./build
8-
./sources/server
10+

.scripts/make-aliases.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const path = require('path')
2+
3+
function makeAliases (externalAliases, tsConfig, basePath) {
4+
const aliases = {}
5+
6+
const paths = tsConfig?.compilerOptions?.paths ?? null
7+
if (typeof paths !== 'object') {
8+
return aliases
9+
}
10+
11+
for (const [key, values] of Object.entries(paths)) {
12+
if (!Array.isArray(values) || values[0] === undefined) {
13+
continue
14+
}
15+
if (key.includes('@wordpress')) {
16+
continue
17+
}
18+
19+
aliases[key] = path.resolve(basePath, values[0])
20+
}
21+
22+
return {
23+
...externalAliases,
24+
...aliases,
25+
}
26+
}
27+
28+
module.exports = makeAliases

@types/index.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from 'react';
2-
3-
export default Konomi;
1+
export = Konomi;
2+
export as namespace Konomi;
43

54
declare namespace Konomi {
6-
5+
type Configuration = Readonly< {
6+
} >;
77
}

@types/wp/index.d.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export = Wp;
2+
export as namespace Wp;
3+
4+
import type Konomi from '@konomi/types';
5+
6+
declare namespace Wp {
7+
type SiteConfiguration = Readonly< {
8+
konomi?: Konomi.Configuration;
9+
} >;
10+
11+
type Stores = Readonly< {
12+
core: {
13+
select: {
14+
getSite: () => SiteConfiguration;
15+
};
16+
};
17+
} >;
18+
}

@types/wp/modules/data.ts

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
declare module '@wordpress/data' {
2+
import type React from 'react';
3+
import type { WithoutInjectedProps } from '@wordpress/compose';
4+
import type Wp from '@konomi/wp-types';
5+
6+
type DataRegistry = Readonly< {
7+
select: select;
8+
dispatch: dispatch;
9+
} >;
10+
11+
type select = < S = Wp.Stores, SN extends keyof S = keyof S >(
12+
store: SN
13+
// TODO Double check Linting
14+
// @ts-expect-error
15+
) => S[ SN ][ 'select' ];
16+
17+
type dispatch = < S = Wp.Stores, SN extends keyof S = keyof S >(
18+
store: SN
19+
// TODO Double check Linting
20+
// @ts-expect-error
21+
) => S[ SN ][ 'dispatch' ];
22+
23+
type useSelect = < R = object >(
24+
fn: ( s: select ) => R,
25+
deps?: ReadonlyArray< unknown >
26+
) => R;
27+
28+
type useDispatch = dispatch;
29+
30+
type withSelect = < P = object, R = object >(
31+
fn: ( select: select, props: P, registry: DataRegistry ) => R
32+
) => < C >(
33+
// TODO Double check Linting
34+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
35+
Component: React.FC< C >
36+
) => React.FC< WithoutInjectedProps< React.FC< C >, R > >;
37+
38+
type withDispatch = < P = object, R = object >(
39+
fn: ( dispatch: dispatch, props: P, registry: DataRegistry ) => R
40+
) => < C >(
41+
// TODO Double check Linting
42+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
43+
Component: React.FC< C >
44+
) => React.FC< WithoutInjectedProps< React.FC< C >, R > >;
45+
46+
type subscribe = ( fn: () => void ) => void;
47+
48+
export const select: select;
49+
export const dispatch: dispatch;
50+
export const withSelect: withSelect;
51+
export const withDispatch: withDispatch;
52+
export const useSelect: useSelect;
53+
export const useDispatch: useDispatch;
54+
// eslint-disable-next-line @typescript-eslint/ban-types
55+
export const combineReducers: Function;
56+
export const subscribe: subscribe;
57+
// eslint-disable-next-line @typescript-eslint/ban-types
58+
export const createReduxStore: Function;
59+
// eslint-disable-next-line @typescript-eslint/ban-types
60+
export const register: Function;
61+
export const AsyncModeProvider: React.FC< {
62+
value: unknown;
63+
children: React.ReactNode;
64+
} >;
65+
}

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"autoload": {
2626
"psr-4": {
27-
"Widoz\\Wp\\Konomi\\": "sources/server/src/"
27+
"Widoz\\Wp\\Konomi\\": "sources/"
2828
}
2929
},
3030
"config": {

docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
name: konomi
2+
13
services:
24

35
php:

konomi.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,10 @@ function autoload(string $projectRoot): void
4646

4747
\add_action(
4848
'plugins_loaded',
49-
fn() => package()->boot()
49+
static function () {
50+
$package = package();
51+
$properties = $package->properties();
52+
53+
$package->boot();
54+
}
5055
);

package.json

+9-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"@testing-library/react": "^14.0.0",
1616
"@testing-library/user-event": "^14.5.1",
1717
"@total-typescript/shoehorn": "^0.1.0",
18+
"@types/react": "~18.2.0",
19+
"@wordpress/create-block": "^4.41.0",
1820
"@wordpress/dependency-extraction-webpack-plugin": "^4.8.0",
1921
"@wordpress/env": "^5.9.0",
2022
"@wordpress/scripts": "^26.0.0",
@@ -24,19 +26,20 @@
2426
"ts-jest": "^29.0.5",
2527
"ts-loader": "^9.4.2",
2628
"ts-node": "^10.9.1",
27-
"typescript": "~5.1.0",
29+
"typescript": "~5.3.0",
30+
"typescript-eslint": "^7.10.0",
2831
"yarn": "^1.22.19"
2932
},
3033
"dependencies": {
3134
"react": "~18.2.0"
3235
},
3336
"scripts": {
3437
"wp-env": "wp-env",
35-
"build": "wp-scripts build --webpack-src-dir=./sources/client/src",
36-
"build:dev": "wp-scripts start --webpack--devtool=inline-source-map --webpack-src-dir=./sources/client/src",
37-
"cs:fix": "wp-scripts format ./sources/client",
38-
"lint:js": "wp-scripts lint-js ./sources/client",
39-
"lint:js:fix": "wp-scripts lint-js --fix ./sources/client",
38+
"build": "wp-scripts build --webpack-src-dir=./sources/Blocks/like",
39+
"build:dev": "wp-scripts start --webpack--devtool=inline-source-map --webpack-src-dir=./sources/Blocks/like",
40+
"cs:fix": "wp-scripts format ./sources ./@types",
41+
"lint:js": "wp-scripts lint-js ./sources ./@types",
42+
"lint:js:fix": "wp-scripts lint-js --fix ./sources ./@types",
4043
"test": "jest",
4144
"test:update-snapshots": "yarn test -u"
4245
}

phpcs.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<ruleset>
33
<file>./konomi.php</file>
4-
<file>./sources/server/</file>
5-
<file>./tests/</file>
4+
<file>./sources</file>
5+
<file>./tests</file>
66

77
<arg value="sp"/>
88
<arg name="colors"/>

psalm.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
>
1212
<projectFiles>
1313
<file name="konomi.php" />
14-
<directory name="sources/server/src" />
14+
<directory name="sources" />
1515
<ignoreFiles>
1616
<directory name="vendor" />
1717
<directory name="tests" />

sources/client/src/.gitkeep

Whitespace-only changes.

sources/server/src/.gitkeep

Whitespace-only changes.

tsconfig.json

+30-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"compilerOptions": {
33
"target": "ES2022",
4+
"checkJs": true,
5+
"allowJs": true,
46
"alwaysStrict": true,
57
"exactOptionalPropertyTypes": true,
68
"noFallthroughCasesInSwitch": true,
@@ -24,12 +26,34 @@
2426
"esModuleInterop": true,
2527
"baseUrl": ".",
2628
"module": "ESNext",
27-
"moduleResolution": "nodenext",
28-
"typeRoots": ["./node_modules/@types"],
29+
"moduleResolution": "NodeNext",
30+
"typeRoots": [
31+
"./node_modules/@types",
32+
"./@types"
33+
],
34+
"rootDir": "./",
2935
"paths": {
30-
"*": ["node_modules/*", "types/*"]
31-
},
32-
"rootDir": "./"
36+
"@konomi/wp-types": [
37+
"./@types/wp"
38+
],
39+
"@konomi/types": [
40+
"./@types"
41+
],
42+
"@konomi/configuration": [
43+
"./sources/Configuration/client"
44+
],
45+
"@wordpress/block-editor": [
46+
"./node_modules/@wordpress/block-editor/src"
47+
]
48+
}
3349
},
34-
"exclude": ["node_modules", "tests"]
50+
"include": [
51+
"./sources",
52+
"./@types"
53+
],
54+
"exclude": [
55+
"dist",
56+
"node_modules",
57+
"tests"
58+
]
3559
}

0 commit comments

Comments
 (0)