Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #657 from ice-lab/release-next
Browse files Browse the repository at this point in the history
Release-rc.6
  • Loading branch information
ClarkXia authored Nov 7, 2022
2 parents d6d27af + e8ad84c commit 906c897
Show file tree
Hide file tree
Showing 168 changed files with 2,529 additions and 697 deletions.
2 changes: 0 additions & 2 deletions examples/basic-project/ice.config.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineConfig } from '@ice/app';
import SpeedMeasurePlugin from 'speed-measure-webpack-plugin';
import auth from '@ice/plugin-auth';
import custom from './plugin';

export default defineConfig({
Expand All @@ -23,7 +22,6 @@ export default defineConfig({
},
dropLogLevel: 'warn',
plugins: [
auth(),
custom,
],
eslint: true,
Expand Down
1 change: 0 additions & 1 deletion examples/basic-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"license": "MIT",
"dependencies": {
"@ice/app": "workspace:*",
"@ice/plugin-auth": "workspace:*",
"@ice/plugin-rax-compat": "workspace:*",
"@ice/runtime": "workspace:*",
"@uni/env": "^1.1.0",
Expand Down
14 changes: 1 addition & 13 deletions examples/basic-project/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { defineAppConfig } from 'ice';
import { defineAuthConfig } from '@ice/plugin-auth/esm/types';
import { isWeb, isNode } from '@uni/env';
import type { GetAppData } from 'ice';

Expand All @@ -11,6 +10,7 @@ console.log('__LOG__');
console.warn('__WARN__');
console.error('__ERROR__');
console.log('process.env.HAHA', process.env.HAHA);
console.log('process.env.undefinedEnv', process.env.undefinedEnv);

if (isWeb) {
console.error('__IS_WEB__');
Expand All @@ -20,15 +20,6 @@ if (isNode) {
console.error('__IS_NODE__');
}

export const auth = defineAuthConfig((data) => {
// fetch auth data
return {
initialAuth: {
admin: data?.auth?.admin,
},
};
});

export default defineAppConfig({
app: {
rootId: 'app',
Expand All @@ -39,9 +30,6 @@ export const getAppData: GetAppData = () => {
return new Promise((resolve) => {
resolve({
title: 'gogogogo',
auth: {
admin: true,
},
});
});
};
1 change: 0 additions & 1 deletion examples/basic-project/src/pages/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export function getConfig(): RouteConfig {
scripts: [{
src: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/lodash.min.js',
}],
auth: ['admin'],
};
}

Expand Down
1 change: 0 additions & 1 deletion examples/basic-project/src/pages/blog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ export default function Blog() {
export const getConfig = defineGetConfig(() => {
return {
title: 'Blog',
auth: ['guest'],
};
});
18 changes: 1 addition & 17 deletions examples/basic-project/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Suspense, lazy } from 'react';
import { Link, useData, useAppData, useConfig, ClientOnly, useMounted } from 'ice';
import { Link, useData, useAppData, useConfig } from 'ice';
// not recommended but works
import { useAppContext } from '@ice/runtime';
import { useRequest } from 'ahooks';
Expand All @@ -16,8 +16,6 @@ export default function Home(props) {
const appData = useAppData<AppData>();
const data = useData();
const config = useConfig();
const mounted = useMounted();

if (typeof window !== 'undefined') {
console.log('render Home', props);
console.log('get AppData', appData);
Expand All @@ -42,19 +40,6 @@ export default function Home(props) {
<div>userInfo: {JSON.stringify(userInfo)}</div>
<div>data from: <span id="data-from">{data.from}</span></div>
</div>
<p>
<div>{mounted ? 'Client' : 'Server'}</div>
<ClientOnly>
{() => {
const PageUrl = lazy(() => import('@/components/PageUrl'));
return (
<Suspense>
<PageUrl />
</Suspense>
);
}}
</ClientOnly>
</p>
</>
);
}
Expand All @@ -72,7 +57,6 @@ export function getConfig() {
content: '#f00',
},
],
auth: ['admin'],
};
}

Expand Down
5 changes: 2 additions & 3 deletions examples/basic-project/src/pages/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Outlet, useData, useConfig } from 'ice';

export default () => {
export default function Layout() {
const data = useData();
const config = useConfig();

Expand All @@ -12,7 +12,7 @@ export default () => {
<Outlet />
</div>
);
};
}

export function getConfig() {
return {
Expand All @@ -23,7 +23,6 @@ export function getConfig() {
content: '#f00',
},
],
auth: ['admin'],
};
}

Expand Down
1 change: 1 addition & 0 deletions examples/miniapp-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"@ice/app": "workspace:*",
"@ice/runtime": "workspace:*",
"@ice/miniapp-html-styles": "workspace:*",
"@ice/plugin-miniapp": "workspace:*",
"@ice/miniapp-runtime": "workspace:*",
"ahooks": "^3.3.8",
Expand Down
2 changes: 2 additions & 0 deletions examples/miniapp-project/src/global.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '@ice/miniapp-html-styles/html';

.global {
font-size: 14px;
}
8 changes: 8 additions & 0 deletions examples/with-auth/ice.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from '@ice/app';
import auth from '@ice/plugin-auth';

export default defineConfig({
plugins: [
auth(),
],
});
20 changes: 20 additions & 0 deletions examples/with-auth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "with-auth",
"version": "1.0.0",
"scripts": {
"start": "ice start",
"build": "ice build"
},
"license": "MIT",
"dependencies": {
"@ice/runtime": "workspace:*",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"@ice/app": "workspace:*",
"@ice/plugin-auth": "workspace:*",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0"
}
}
32 changes: 32 additions & 0 deletions examples/with-auth/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { defineAppConfig, Link } from 'ice';
import type { GetAppData } from 'ice';
import { defineAuthConfig } from '@ice/plugin-auth/esm/types';

export default defineAppConfig({});

export const auth = defineAuthConfig((data) => {
// fetch auth data
return {
initialAuth: {
admin: data?.auth?.admin,
},
NoAuthFallback: () => {
return (
<>
<div id="no-auth">无权限访问</div>
<Link to="/">Home</Link>
</>
);
},
};
});

export const getAppData: GetAppData = () => {
return new Promise((resolve) => {
resolve({
auth: {
admin: true,
},
});
});
};
16 changes: 16 additions & 0 deletions examples/with-auth/src/components/CustomAuth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useAuth } from 'ice';

function CustomAuth({ children, authKey, fallback }) {
const [auth] = useAuth();
// 判断是否有权限
const hasAuth = auth[authKey];
// 有权限时直接渲染内容
if (hasAuth) {
return children;
} else {
// 无权限时显示指定 UI
return fallback || (<>No Auth</>);
}
}

export default CustomAuth;
22 changes: 22 additions & 0 deletions examples/with-auth/src/document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Meta, Title, Links, Main, Scripts } from 'ice';

function Document() {
return (
<html>
<head>
<meta charSet="utf-8" />
<meta name="description" content="with-auth" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Title />
<Links />
</head>
<body>
<Main />
<Scripts />
</body>
</html>
);
}

export default Document;
17 changes: 17 additions & 0 deletions examples/with-auth/src/pages/blog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineGetConfig, Link } from 'ice';

export default function Blog() {
return (
<>
<h1>Blog</h1>
<Link to="/">Index</Link>
</>
);
}

export const getConfig = defineGetConfig(() => {
return {
title: 'Blog',
auth: ['guest'],
};
});
24 changes: 24 additions & 0 deletions examples/with-auth/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Link, useAuth, defineGetConfig } from 'ice';
import CustomAuth from '@/components/CustomAuth';

export default function Index() {
const [, setAuth] = useAuth();
return (
<>
<ul style={{ listStyleType: 'none' }}>
<li><Link to="blog">Blog</Link></li>
</ul>
<h1>Index</h1>
<CustomAuth authKey={'guest'} fallback={<><div onClick={() => setAuth({ guest: true })}>Set Guest Auth</div>No Auth</>}>
I am ice.js. My auth is guest.
</CustomAuth>
</>
);
}

export const getConfig = defineGetConfig(() => {
return {
title: 'Index',
auth: ['admin'],
};
});
25 changes: 25 additions & 0 deletions examples/with-auth/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"baseUrl": "./",
"module": "ESNext",
"target": "ESNext",
"lib": ["DOM", "ESNext", "DOM.Iterable"],
"jsx": "react-jsx",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": false,
"importHelpers": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./src/*"],
"ice": [".ice"]
}
},
"include": ["src", ".ice"],
"exclude": ["build"]
}
1 change: 0 additions & 1 deletion examples/with-plugin-request/ice.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { defineConfig } from '@ice/app';
import request from '@ice/plugin-request';

export default defineConfig({
dataLoader: false,
plugins: [
request(),
],
Expand Down
Binary file added examples/with-store/src/pages/ice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion examples/with-store/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Link } from 'ice';
import pageStore from './store';
import logo from './ice.png';
import appStore from '@/store';

function Home() {
Expand All @@ -10,12 +11,17 @@ function Home() {
<div id="username">
name: {userState.name}
</div>
<img src={logo} alt="logo" height="100" width="100" />
<div>
<button type="button" id="inc" onClick={() => countDispatcher.inc()}>+</button>
<span id="count">{countState.count}</span>
<button type="button" id="dec" onClick={() => countDispatcher.dec()}>-</button>
</div>
<Link to="/blog">Blog</Link>
<>
<Link to="/blog">Blog</Link>
<br />
<Link to="/login">Login</Link>
</>
</>
);
}
Expand Down
15 changes: 15 additions & 0 deletions examples/with-store/src/pages/login.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { history } from 'ice';
import store from '@/store';

export default function Login() {
const [, userDispatcher] = store.useModel('user');

function login() {
userDispatcher.setState({ name: 'Hello' });
history?.push('/');
}

return (
<div onClick={() => login()} id="login-click">Click Me to Login</div>
);
}
1 change: 1 addition & 0 deletions examples/with-store/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@ice/app/types" />
9 changes: 9 additions & 0 deletions examples/with-tailwindcss/ice.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from '@ice/app';

export default defineConfig({
postcss: {
plugins: [
'tailwindcss',
],
},
});
Loading

0 comments on commit 906c897

Please sign in to comment.