Migrate color-picker plugin to ts

This commit is contained in:
Alexandre Bodin 2023-07-20 18:27:57 +02:00
parent 1da17e2621
commit 5b1ecac1fa
47 changed files with 251 additions and 47 deletions

View File

@ -22,7 +22,7 @@ module.exports = {
moduleNameMapper,
/* Tells jest to ignore duplicated manual mock files, such as index.js */
modulePathIgnorePatterns: ['.*__mocks__.*'],
testPathIgnorePatterns: ['node_modules/', '__tests__'],
testPathIgnorePatterns: ['node_modules/', '__tests__', 'dist/'],
globalSetup: '@strapi/admin-test-utils/global-setup',
setupFiles: ['@strapi/admin-test-utils/environment'],
setupFilesAfterEnv: ['@strapi/admin-test-utils/after-env'],

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -0,0 +1,16 @@
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[{package.json,*.yml}]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false

View File

@ -1,2 +1,3 @@
node_modules/
.eslintrc.js
dist/

View File

@ -2,12 +2,8 @@ module.exports = {
root: true,
overrides: [
{
files: ['admin/**/*'],
extends: ['custom/front'],
},
{
files: ['**/*'],
excludedFiles: ['admin/**/*'],
files: ['**'],
excludedFiles: ['admin/**/*', 'server/**/*'],
extends: ['custom/back'],
},
],

View File

@ -0,0 +1,98 @@
############################
# OS X
############################
.DS_Store
.AppleDouble
.LSOverride
Icon
.Spotlight-V100
.Trashes
._*
############################
# Linux
############################
*~
############################
# Windows
############################
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
*.cab
*.msi
*.msm
*.msp
############################
# Packages
############################
*.7z
*.csv
*.dat
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.com
*.class
*.dll
*.exe
*.o
*.seed
*.so
*.swo
*.swp
*.swn
*.swm
*.out
*.pid
############################
# Logs and databases
############################
.tmp
*.log
*.sql
*.sqlite
############################
# Misc.
############################
*#
.editorconfig
.idea
nbproject
############################
# Node.js
############################
lib-cov
lcov.info
pids
logs
results
build
node_modules
.node_history
############################
# Tests
############################
test
tests
__tests__
jest.config.js

View File

@ -0,0 +1,7 @@
module.exports = {
root: true,
extends: ['custom/front/typescript'],
parserOptions: {
project: ['./admin/tsconfig.eslint.json'],
},
};

View File

@ -0,0 +1,2 @@
declare module '@strapi/helper-plugin';
declare module '@strapi/design-system';

View File

@ -1,11 +1,11 @@
import { prefixPluginTranslations } from '@strapi/helper-plugin';
import ColorPickerIcon from './components/ColorPicker/ColorPickerIcon';
import pluginId from './pluginId';
import { pluginId } from './pluginId';
import getTrad from './utils/getTrad';
export default {
register(app) {
register(app: any) {
app.customFields.register({
name: 'color',
pluginId: 'color-picker',
@ -64,7 +64,7 @@ export default {
},
});
},
async registerTrads({ locales }) {
async registerTrads({ locales }: { locales: string[] }) {
const importedTrads = await Promise.all(
locales.map((locale) => {
return import(`./translations/${locale}.json`)

View File

@ -1,5 +0,0 @@
const pluginPkg = require('../../package.json');
const pluginId = pluginPkg.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, '');
module.exports = pluginId;

View File

@ -0,0 +1,3 @@
import pluginPkg from '../../package.json';
export const pluginId = pluginPkg.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, '');

View File

@ -1,4 +1,4 @@
import pluginId from '../pluginId';
import { pluginId } from '../pluginId';
const getTrad = (id) => `${pluginId}.${id}`;

View File

@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["src"],
"exclude": ["node_modules"]
}

View File

@ -0,0 +1,9 @@
{
"extends": "tsconfig/base.json",
"compilerOptions": {
"jsx": "react-jsx",
"noEmit": true
},
"include": ["src"],
"exclude": ["node_modules"]
}

View File

@ -2,5 +2,8 @@
module.exports = {
preset: '../../../jest-preset.front.js',
transform: {
'^.+\\.ts(x)?$': ['@swc/jest'],
},
displayName: 'Color picker plugin',
};

View File

@ -18,6 +18,7 @@
},
"devDependencies": {
"@testing-library/react": "14.0.0",
"@types/styled-components": "5.1.26",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "5.3.4",
@ -30,7 +31,18 @@
"react-router-dom": "5.3.4",
"styled-components": "5.3.3"
},
"files": [
"./dist",
"./admin",
"strapi-admin.js",
"strapi-server.js"
],
"scripts": {
"build": "run -T tsc -p server/tsconfig.json --outDir ./dist/server",
"build:ts": "run build",
"watch": "run -T tsc -w --preserveWatchOutput",
"clean": "run -T rimraf ./dist",
"prepublishOnly": "yarn clean && yarn build",
"test:front": "run -T cross-env IS_EE=true jest --config ./jest.config.front.js",
"test:front:watch": "run -T cross-env IS_EE=true jest --config ./jest.config.front.js --watchAll",
"test:front:ce": "run -T cross-env IS_EE=false jest --config ./jest.config.front.js",

View File

@ -0,0 +1,7 @@
module.exports = {
root: true,
extends: ['custom/back/typescript'],
parserOptions: {
project: ['./server/tsconfig.eslint.json'],
},
};

View File

@ -1,7 +0,0 @@
'use strict';
const register = require('./register');
module.exports = {
register,
};

View File

@ -0,0 +1,5 @@
import { register } from './register';
export default {
register,
};

View File

@ -1,6 +1,4 @@
'use strict';
module.exports = ({ strapi }) => {
export const register = ({ strapi }: any) => {
strapi.customFields.register({
name: 'color',
plugin: 'color-picker',

View File

@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["src"],
"exclude": ["node_modules"]
}

View File

@ -0,0 +1,5 @@
{
"extends": "tsconfig/base.json",
"include": ["src"],
"exclude": ["node_modules"]
}

View File

@ -1,3 +1,3 @@
'use strict';
module.exports = require('./admin/src').default;
module.exports = require('./admin/src/index.ts');

View File

@ -1,3 +1,3 @@
'use strict';
module.exports = require('./server');
module.exports = require('./dist/server');

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -14,7 +14,7 @@ module.exports = {
strapi: false,
},
rules: {
...require('./back').rules,
...require('../back').rules,
'node/no-unsupported-features/es-syntax': 'off',
'node/no-missing-import': 'off',
// TODO: The following rules from @strapi/eslint-config/typescript are disabled because they're causing problems we need to solve or fix

View File

@ -0,0 +1,26 @@
const path = require('path');
module.exports = {
root: true,
// TODO: create a front typescript config in eslint-config and use it here
extends: [
'airbnb-typescript/base',
'../front',
'plugin:@typescript-eslint/recommended',
/*'plugin:@typescript-eslint/recommended-requiring-type-checking'*/
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
project: ['./tsconfig.eslint.json'],
},
rules: {
'react/jsx-filename-extension': [
1,
{
extensions: ['tsx'],
},
],
'import/extensions': 'off',
},
};

View File

@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['custom/typescript'],
extends: ['custom/back/typescript'],
};

View File

@ -7864,6 +7864,7 @@ __metadata:
"@strapi/helper-plugin": 4.11.7
"@strapi/icons": 1.8.2
"@testing-library/react": 14.0.0
"@types/styled-components": 5.1.26
prop-types: ^15.8.1
react: ^18.2.0
react-colorful: 5.6.1
@ -8970,7 +8971,7 @@ __metadata:
languageName: node
linkType: hard
"@types/hoist-non-react-statics@npm:^3.3.1":
"@types/hoist-non-react-statics@npm:*, @types/hoist-non-react-statics@npm:^3.3.1":
version: 3.3.1
resolution: "@types/hoist-non-react-statics@npm:3.3.1"
dependencies:
@ -9531,6 +9532,17 @@ __metadata:
languageName: node
linkType: hard
"@types/styled-components@npm:5.1.26":
version: 5.1.26
resolution: "@types/styled-components@npm:5.1.26"
dependencies:
"@types/hoist-non-react-statics": "*"
"@types/react": "*"
csstype: ^3.0.2
checksum: 84f53b3101739b20d1731554fb7735bc2f3f5d050a8b392e9845403c8c8bbd729737d033978649f9195a97b557875b010d46e35a4538564a2d0dbcce661dbf76
languageName: node
linkType: hard
"@types/tapable@npm:^1, @types/tapable@npm:^1.0.5":
version: 1.0.8
resolution: "@types/tapable@npm:1.0.8"