Skip to content

Commit

Permalink
Moved code into src folder. Added build for component library.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Aug 21, 2023
1 parent 7a7233e commit ede6587
Show file tree
Hide file tree
Showing 490 changed files with 750 additions and 443 deletions.
17 changes: 8 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@
"plugin:@typescript-eslint/recommended",
"next"
],

"plugins": ["@typescript-eslint", "prettier"],
"settings": {
"import/resolver": {
"alias": {
"map": [
["assets", "./assets"],
["components", "./components"],
["assets", "./src/assets"],
["components", "./src/components"],
["db", "./db"],
["hooks", "./hooks"],
["lang", "./lang"],
["lib", "./lib"],
["hooks", "./src/components/hooks"],
["lang", "./src/lang"],
["lib", "./src/lib"],
["public", "./public"],
["queries", "./queries"],
["store", "./store"],
["styles", "./styles"]
["queries", "./src/queries"],
["store", "./src/store"],
["styles", "./src/styles"]
],
"extensions": [".ts", ".tsx", ".js", ".jsx", ".json"]
}
Expand Down
4 changes: 2 additions & 2 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"compilerOptions": {
"baseUrl": "."
"baseUrl": "./src"
}
}
}
10 changes: 10 additions & 0 deletions package.components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@umami/components",
"version": "0.1.0",
"description": "Umami React components.",
"author": "Mike Cao <[email protected]>",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts"
}
25 changes: 15 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"start-env": "node scripts/start-env.js",
"start-server": "node server.js",
"build-app": "next build",
"build-tracker": "rollup -c rollup.tracker.config.js",
"build-components": "rollup -c rollup.components.config.mjs",
"build-tracker": "rollup -c rollup.tracker.config.mjs",
"build-db": "npm-run-all copy-db-files build-db-client",
"build-lang": "npm-run-all format-lang compile-lang download-country-names download-language-names",
"build-geo": "node scripts/build-geo.js",
Expand Down Expand Up @@ -115,13 +116,16 @@
"@formatjs/cli": "^4.2.29",
"@netlify/plugin-nextjs": "^4.27.3",
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-commonjs": "^24.1.0",
"@rollup/plugin-buble": "^1.0.2",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-replace": "^4.0.0",
"@svgr/rollup": "^7.0.0",
"@rollup/plugin-node-resolve": "^15.2.0",
"@rollup/plugin-replace": "^5.0.2",
"@svgr/rollup": "^8.1.0",
"@svgr/webpack": "^6.2.1",
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.8",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"cross-env": "^7.0.3",
Expand All @@ -143,11 +147,12 @@
"prettier": "^2.6.2",
"prisma": "5.0.0",
"prompts": "2.4.2",
"rollup": "^2.70.1",
"rollup": "^3.28.0",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-dts": "^5.3.0",
"rollup-plugin-dts": "^6.0.0",
"rollup-plugin-esbuild": "^5.0.0",
"rollup-plugin-node-externals": "^5.1.2",
"rollup-plugin-node-externals": "^6.1.1",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-terser": "^7.0.2",
"stylelint": "^15.10.1",
Expand All @@ -156,6 +161,6 @@
"stylelint-config-recommended": "^9.0.0",
"tar": "^6.1.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
"typescript": "^5.1.6"
}
}
99 changes: 99 additions & 0 deletions rollup.components.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import path from 'path';
import crypto from 'crypto';
import resolve from '@rollup/plugin-node-resolve';
import alias from '@rollup/plugin-alias';
import json from '@rollup/plugin-json';
import postcss from 'rollup-plugin-postcss';
import copy from 'rollup-plugin-copy';
import del from 'rollup-plugin-delete';
import nodeExternals from 'rollup-plugin-node-externals';
import esbuild from 'rollup-plugin-esbuild';
import dts from 'rollup-plugin-dts';
import svgr from '@svgr/rollup';

const md5 = str => crypto.createHash('md5').update(str).digest('hex');

const customResolver = resolve({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
});

const aliasConfig = {
entries: [
{ find: /^components/, replacement: path.resolve('./src/components') },
{ find: /^hooks/, replacement: path.resolve('./src/hooks') },
{ find: /^lib/, replacement: path.resolve('./src/lib') },
{ find: /^store/, replacement: path.resolve('./src/store') },
{ find: /^public/, replacement: path.resolve('./public') },
{ find: /^assets/, replacement: path.resolve('./src/assets') },
],
customResolver,
};

const external = [
'react',
'react-dom',
'react/jsx-runtime',
'react-intl',
'react-basics',
'classnames',
'next',
];

const jsBundle = {
input: 'src/index.ts',
output: [
{
file: 'dist/index.js',
format: 'cjs',
sourcemap: true,
},
{
file: 'dist/index.mjs',
format: 'es',
sourcemap: true,
},
],
plugins: [
del({ targets: 'dist/*', runOnce: true }),
copy({ targets: [{ src: './package.components.json', dest: 'dist', rename: 'package.json' }] }),
postcss({
config: false,
extract: 'styles.css',
sourceMap: true,
minimize: true,
modules: {
generateScopedName: function (name, filename, css) {
const file = path.basename(filename, '.css').replace('.module', '');
const hash = Buffer.from(md5(`${name}:${filename}:${css}`))
.toString('base64')
.substring(0, 5);

return `${file}-${name}--${hash}`;
},
},
}),
svgr({ icon: true }),
nodeExternals(),
json(),
alias(aliasConfig),
esbuild({
target: 'es6',
jsx: 'transform',
loaders: {
'.js': 'jsx',
},
}),
],
};

const dtsBundle = {
input: 'src/index.ts',
output: {
file: 'dist/index.d.ts',
format: 'es',
},
plugins: [alias(aliasConfig), nodeExternals(), json(), dts()],
external: [/\.css/],
};

export default [jsBundle, dtsBundle];
2 changes: 1 addition & 1 deletion rollup.tracker.config.js → rollup.tracker.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import replace from '@rollup/plugin-replace';
import { terser } from 'rollup-plugin-terser';

export default {
input: 'tracker/index.js',
input: 'src/tracker/index.js',
output: {
file: 'public/script.js',
format: 'iife',
Expand Down
2 changes: 1 addition & 1 deletion scripts/check-lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const messages = require('../lang/en-US.json');
const messages = require('../src/lang/en-US.json');
const ignore = require('../lang-ignore.json');

const dir = path.resolve(__dirname, '../lang');
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';
import { Button, LoadingButton, Form, FormButtons } from 'react-basics';
import useMessages from 'hooks/useMessages';
import useMessages from 'components/hooks/useMessages';

export function ConfirmDeleteForm({ name, onConfirm, onClose }) {
const [loading, setLoading] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import classNames from 'classnames';
import styles from './Empty.module.css';
import useMessages from 'hooks/useMessages';
import useMessages from 'components/hooks/useMessages';

export function Empty({ message, className }) {
const { formatMessage, messages } = useMessages();
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import { ErrorBoundary as Boundary } from 'react-error-boundary';
import { Button } from 'react-basics';
import useMessages from 'hooks/useMessages';
import useMessages from 'components/hooks/useMessages';
import styles from './ErrorBoundry.module.css';

const logError = (error, info) => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Icon, Icons, Text } from 'react-basics';
import styles from './ErrorMessage.module.css';
import useMessages from 'hooks/useMessages';
import useMessages from 'components/hooks/useMessages';

export function ErrorMessage() {
const { formatMessage, messages } = useMessages();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Icon, Icons } from 'react-basics';
import classNames from 'classnames';
import Link from 'next/link';
import { safeDecodeURI } from 'next-basics';
import usePageQuery from 'hooks/usePageQuery';
import useMessages from 'hooks/useMessages';
import usePageQuery from 'components/hooks/usePageQuery';
import useMessages from 'components/hooks/useMessages';
import styles from './FilterLink.module.css';

export function FilterLink({ id, value, label, externalUrl, children, className }) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Button, Icon } from 'react-basics';
import { useState } from 'react';
import MobileMenu from './MobileMenu';
import Icons from 'components/icons';
import useMessages from 'hooks/useMessages';
import useConfig from 'hooks/useConfig';
import useMessages from 'components/hooks/useMessages';
import useConfig from 'components/hooks/useConfig';

export function HamburgerButton() {
const { formatMessage, labels } = useMessages();
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import Link from 'next/link';
import { Icon, Icons, Text } from 'react-basics';
import styles from './LinkButton.module.css';

export default function LinkButton({ href, icon, children }) {
export function LinkButton({ href, icon, children }) {
return (
<Link className={styles.button} href={href}>
<Icon>{icon || <Icons.ArrowRight />}</Icon>
<Text>{children}</Text>
</Link>
);
}

export default LinkButton;
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styles from './Pager.module.css';
import { Button, Flexbox, Icon, Icons } from 'react-basics';
import useMessages from 'hooks/useMessages';
import useMessages from 'components/hooks/useMessages';

export function Pager({ page, pageSize, count, onPageChange }) {
const { formatMessage, labels } = useMessages();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Empty from 'components/common/Empty';
import useMessages from 'hooks/useMessages';
import useMessages from 'components/hooks/useMessages';
import { useState } from 'react';
import {
SearchField,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { setItem } from 'next-basics';
import useStore, { checkVersion } from 'store/version';
import { REPO_URL, VERSION_CHECK } from 'lib/constants';
import styles from './UpdateNotice.module.css';
import useMessages from 'hooks/useMessages';
import useMessages from 'components/hooks/useMessages';
import { useRouter } from 'next/router';

export function UpdateNotice({ user, config }) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import classNames from 'classnames';
import { colord } from 'colord';
import HoverTooltip from 'components/common/HoverTooltip';
import { ISO_COUNTRIES, MAP_FILE } from 'lib/constants';
import useTheme from 'hooks/useTheme';
import useCountryNames from 'hooks/useCountryNames';
import useLocale from 'hooks/useLocale';
import useTheme from 'components/hooks/useTheme';
import useCountryNames from 'components/hooks/useCountryNames';
import useLocale from 'components/hooks/useLocale';
import { formatLongNumber } from 'lib/format';
import { percentFilter } from 'lib/filters';
import styles from './WorldMap.module.css';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion hooks/useConfig.js → src/components/hooks/useConfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from 'react';
import useStore, { setConfig } from 'store/app';
import useApi from 'hooks/useApi';
import useApi from 'components/hooks/useApi';

let loading = false;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion hooks/useFilters.js → src/components/hooks/useFilters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMessages } from 'hooks';
import { useMessages } from './useMessages';
import { OPERATORS } from 'lib/constants';

export function useFilters() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion hooks/useLocale.js → src/components/hooks/useLocale.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { httpGet, setItem } from 'next-basics';
import { LOCALE_CONFIG } from 'lib/constants';
import { getDateLocale, getTextDirection } from 'lib/lang';
import useStore, { setLocale } from 'store/app';
import useForceUpdate from 'hooks/useForceUpdate';
import useForceUpdate from 'components/hooks/useForceUpdate';
import enUS from 'public/intl/messages/en-US.json';

const messages = {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion hooks/useReports.js → src/components/hooks/useReports.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';
import useApi from './useApi';
import useApiFilter from 'hooks/useApiFilter';
import useApiFilter from 'components/hooks/useApiFilter';

export function useReports() {
const [modified, setModified] = useState(Date.now());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect } from 'react';
import { useRouter } from 'next/router';
import useApi from 'hooks/useApi';
import useUser from 'hooks/useUser';
import useApi from 'components/hooks/useApi';
import useUser from 'components/hooks/useUser';

export function useRequireLogin() {
const router = useRouter();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';
import useApi from './useApi';
import useApiFilter from 'hooks/useApiFilter';
import useApiFilter from 'components/hooks/useApiFilter';

export function useWebsiteReports(websiteId) {
const [modified, setModified] = useState(Date.now());
Expand Down
2 changes: 1 addition & 1 deletion components/icons.ts → src/components/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import User from 'assets/user.svg';
import Users from 'assets/users.svg';
import Visitor from 'assets/visitor.svg';

const icons = {
const icons: any = {
...Icons,
AddUser,
Bars,
Expand Down
Loading

0 comments on commit ede6587

Please sign in to comment.