Skip to content

Commit

Permalink
feat: add platform template
Browse files Browse the repository at this point in the history
  • Loading branch information
xiejay97 committed Sep 14, 2022
1 parent 2d76ade commit 308bdf0
Show file tree
Hide file tree
Showing 205 changed files with 4,468 additions and 1,857 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"sourceTag": "scope:ui",
"onlyDependOnLibsWithTags": ["scope:shared", "scope:icons", "scope:ui"]
},
{
"sourceTag": "scope:platform",
"onlyDependOnLibsWithTags": ["scope:shared", "scope:icons", "scope:ui", "scope:platform"]
},
{
"sourceTag": "scope:site",
"onlyDependOnLibsWithTags": ["scope:shared", "scope:icons", "scope:ui", "scope:site"]
Expand Down
78 changes: 40 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,67 @@
"homepage": "https://github.com/DevCloudFE/react-devui",
"license": "MIT",
"scripts": {
"build:affected": "nx affected --target=build --parallel=5",
"build:affected": "nx affected --target=build --parallel=7",
"build:icons": "ts-node -P ./tools/tsconfig.json ./tools/ui-icons.ts",
"build:vscode-extension": "nx build vscode-extension && cd dist/packages/vscode-extension && yarn install && vsce package --yarn",
"lint:affected": "nx affected --target=lint --parallel=5",
"lint:affected": "nx affected --target=lint --parallel=7",
"lint:style": "stylelint **/*.{css,scss,html,md}",
"lint:style:fix": "yarn lint:style --fix",
"prepare": "husky install && chmod ug+x .husky/*",
"prepublishOnly": "nx run-many --target=build --parallel=5 --exclude=site,vscode-extension",
"prepublishOnly": "yarn util:update-dependencies && nx run-many --target=build --parallel=7 --exclude=site,vscode-extension",
"publish:vscode-extension": "yarn build:vscode-extension && cd dist/packages/vscode-extension && vsce publish --yarn",
"serve:site": "nx serve site",
"test:affected": "nx affected --target=test --parallel=5",
"test:affected": "nx affected --target=test --parallel=7",
"util:check-update": "yarn upgrade-interactive --latest",
"util:sort-package-json": "npx sort-package-json 'package.json' 'packages/*/package.json'",
"version": "npx prettier lerna.json --write"
"util:sort-package-json": "sort-package-json 'package.json' 'packages/*/package.json'",
"util:update-dependencies": "ts-node -P ./tools/tsconfig.json ./tools/update-dependencies.ts",
"version": "prettier lerna.json --write"
},
"devDependencies": {
"@ant-design/icons-svg": "^4.2.1",
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@nrwl/cli": "14.5.6",
"@nrwl/cypress": "14.5.6",
"@nrwl/eslint-plugin-nx": "14.5.6",
"@nrwl/jest": "14.5.6",
"@nrwl/linter": "14.5.6",
"@nrwl/nx-cloud": "14.3.0",
"@nrwl/react": "14.5.6",
"@nrwl/tao": "14.5.6",
"@nrwl/web": "14.5.6",
"@nrwl/workspace": "14.5.6",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@nrwl/cli": "14.6.5",
"@nrwl/eslint-plugin-nx": "14.6.5",
"@nrwl/jest": "14.6.5",
"@nrwl/linter": "14.6.5",
"@nrwl/nx-cloud": "14.6.2",
"@nrwl/react": "14.6.5",
"@nrwl/tao": "14.6.5",
"@nrwl/web": "14.6.5",
"@nrwl/workspace": "14.6.5",
"@stackblitz/sdk": "^1.8.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.3.0",
"@testing-library/react": "^13.4.0",
"@types/fs-extra": "^9.0.13",
"@types/glob": "^7.2.0",
"@types/glob": "^8.0.0",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.182",
"@types/marked": "^4.0.3",
"@types/marked": "^4.0.7",
"@types/mocha": "^9.1.1",
"@types/node": "^18.7.3",
"@types/react": "^18.0.17",
"@types/node": "^18.7.16",
"@types/react": "^18.0.18",
"@types/react-dom": "^18.0.6",
"@types/vscode": "^1.70.0",
"@types/vscode": "^1.71.0",
"@types/yaml-front-matter": "^4.1.0",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"@typescript-eslint/eslint-plugin": "^5.36.2",
"@typescript-eslint/parser": "^5.36.2",
"@vscode/test-electron": "^2.1.5",
"axios": "^0.27.2",
"axios-mock-adapter": "^1.21.2",
"babel-jest": "^27.5.1",
"codesandbox": "^2.2.3",
"core-js": "^3.24.1",
"cypress": "^10.2.0",
"colors": "^1.4.0",
"core-js": "^3.25.1",
"dayjs": "^1.11.5",
"eslint": "^8.22.0",
"eslint": "^8.23.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-cypress": "^2.10.3",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^39.3.6",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react": "^7.31.8",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-tsdoc": "^0.2.16",
"fs-extra": "^10.1.0",
Expand All @@ -76,36 +75,39 @@
"husky": "^8.0.1",
"i18next": "^21.9.0",
"immer": "^9.0.15",
"is-builtin-module": "^3.2.0",
"jest": "^27.5.1",
"lerna": "^5.4.2",
"lerna": "^5.5.0",
"lodash": "^4.17.21",
"marked": "^4.0.18",
"marked": "^4.1.0",
"mocha": "^10.0.0",
"nx": "14.5.6",
"nx": "14.6.5",
"postcss-html": "^1.5.0",
"postcss-markdown": "^1.2.0",
"prettier": "^2.7.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^11.18.3",
"react-i18next": "^11.18.5",
"react-router-dom": "^6.3.0",
"react-test-renderer": "^18.2.0",
"regenerator-runtime": "^0.13.9",
"rfs": "^9.0.6",
"rxjs": "^7.5.6",
"rxjs-for-await": "^1.0.0",
"sass": "^1.54.4",
"sass": "^1.54.9",
"sort-package-json": "^1.57.0",
"stylelint": "^14.10.0",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-recess-order": "^3.0.0",
"stylelint-config-recommended-scss": "^7.0.0",
"stylelint-config-standard": "^27.0.0",
"stylelint-config-standard": "^28.0.0",
"stylelint-scss": "^4.3.0",
"swiper": "^8.3.2",
"table": "^6.8.0",
"ts-jest": "^27.1.4",
"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"typescript": "~4.7.4",
"typescript": "~4.8.3",
"yaml-front-matter": "^4.1.1"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { createGlobalState } from './createGlobalState';
export { useAsync } from './useAsync';
export { useBreakpoints } from './useBreakpoints';
export { useEvent } from './useEvent';
export { useEventCallback } from './useEventCallback';
export { useElement } from './useElement';
Expand All @@ -9,7 +10,6 @@ export { useForceUpdate } from './useForceUpdate';
export { useForkRef } from './useForkRef';
export { useImmer } from './useImmer';
export { useLockScroll } from './useLockScroll';
export { useMediaMatch } from './useMediaMatch';
export { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
export { useLocalStorage } from './useLocalStorage';
export { useMount } from './useMount';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ import { isSimpleArrayEqual } from '@react-devui/utils';
import { useEvent } from './useEvent';
import { useForceUpdate } from './useForceUpdate';

function getMediaMatch<P>(breakpoints: Map<P, number>) {
const mediaMatch: P[] = [];
function matchBreakpoints<P>(breakpoints: Map<P, number>) {
const match: P[] = [];
for (const [breakpoint, num] of Array.from(breakpoints).sort((a, b) => a[1] - b[1])) {
if (window.matchMedia(`(min-width: ${num}px)`).matches) {
mediaMatch.push(breakpoint);
match.push(breakpoint);
}
}
return mediaMatch;
return match;
}

export function useMediaMatch<P>(breakpoints: Map<P, number>) {
const mediaMatch = useRef<P[]>([]);
export function useBreakpoints<P>(breakpoints: Map<P, number>) {
const match = useRef<P[]>([]);
if (typeof window !== 'undefined') {
mediaMatch.current = getMediaMatch(breakpoints);
match.current = matchBreakpoints(breakpoints);
}

const forceUpdate = useForceUpdate();

useEvent(window, 'resize', () => {
const currentMediaMatch = getMediaMatch(breakpoints);
if (!isSimpleArrayEqual(currentMediaMatch, mediaMatch.current)) {
const currentMediaMatch = matchBreakpoints(breakpoints);
if (!isSimpleArrayEqual(currentMediaMatch, match.current)) {
forceUpdate();
}
});

return mediaMatch.current;
return match.current;
}
2 changes: 1 addition & 1 deletion packages/icons/src/useIconProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useContext } from 'react';

import { DIconContext } from './Icon';

export function useIconProps<T>(props: T): T {
export function useIconProps<T extends object>(props: T): T {
const context = useContext(DIconContext);
const gProps = context.props ?? {};
const noUndefinedProps: any = {};
Expand Down
11 changes: 11 additions & 0 deletions packages/platform/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
[
"@nrwl/react/babel",
{
"runtime": "automatic"
}
]
],
"plugins": []
}
16 changes: 16 additions & 0 deletions packages/platform/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is used by:
# 1. autoprefixer to adjust CSS to support the below specified browsers
# 2. babel preset-env to adjust included polyfills
#
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
#
# If you need to support different browsers in production, you may tweak the list below.

last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major version
last 2 iOS major versions
Firefox ESR
not IE 9-11 # For IE 9-11 support, remove 'not'.
18 changes: 18 additions & 0 deletions packages/platform/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nrwl/nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
10 changes: 10 additions & 0 deletions packages/platform/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
displayName: 'platform',
preset: '../../jest.preset.js',
transform: {
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest',
'^.+\\.[tj]sx?$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/packages/platform',
};
38 changes: 38 additions & 0 deletions packages/platform/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "platform",
"version": "0.0.1",
"private": true,
"description": "An out-of-box solution for enterprise applications as a React boilerplate",
"keywords": [
"react",
"devui",
"platform"
],
"homepage": "https://github.com/DevCloudFE/react-devui/tree/main/packages/platform#readme",
"bugs": {
"url": "https://github.com/DevCloudFE/react-devui/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/DevCloudFE/react-devui.git"
},
"license": "MIT",
"author": "Xie Jay <xiejay97@gmail.com>",
"dependencies": {
"@react-devui/hooks": "file:../hooks",
"@react-devui/icons": "file:../icons",
"@react-devui/ui": "file:../ui",
"@react-devui/utils": "file:../utils",
"axios": "^0.27.2",
"axios-mock-adapter": "^1.21.2",
"core-js": "^3.25.1",
"i18next": "^21.9.0",
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^11.18.5",
"react-router-dom": "^6.3.0",
"regenerator-runtime": "^0.13.9",
"rxjs": "^7.5.6"
}
}
64 changes: 64 additions & 0 deletions packages/platform/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/platform/src",
"projectType": "application",
"tags": ["scope:platform"],
"targets": {
"build": {
"executor": "@nrwl/web:webpack",
"outputs": ["{options.outputPath}"],
"options": {
"compiler": "babel",
"deployUrl": "/",
"outputPath": "dist/packages/platform",
"index": "packages/platform/src/index.html",
"main": "packages/platform/src/main.tsx",
"polyfills": "packages/platform/src/polyfills.ts",
"tsConfig": "packages/platform/tsconfig.app.json",
"assets": ["packages/platform/src/assets"],
"styles": ["packages/platform/src/styles.scss"],
"scripts": [],
"webpackConfig": "@nrwl/react/plugins/webpack"
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "packages/platform/src/environments/environment.ts",
"with": "packages/platform/src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false
}
}
},
"serve": {
"executor": "@nrwl/web:dev-server",
"options": {
"buildTarget": "platform:build",
"port": 4310,
"open": true
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/platform/**/*.{ts,tsx,js,jsx,md}"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/packages/platform"],
"options": {
"jestConfig": "packages/platform/jest.config.js",
"passWithNoTests": true
}
}
}
}
Loading

0 comments on commit 308bdf0

Please sign in to comment.