create时的细节修正,模板中web/namespace/console的修改
This commit is contained in:
parent
feb268dc67
commit
6a6b57d382
|
|
@ -232,7 +232,7 @@ async function create(dirName, cmd) {
|
|||
}
|
||||
// 获取package.json内容
|
||||
const packageJson = (0, template_1.packageJsonContent)({
|
||||
name: DEFAULT_PROJECT_NAME, // 后面再统一rename
|
||||
name: DEFAULT_PROJECT_NAME,
|
||||
version,
|
||||
description,
|
||||
cliName: config_1.CLI_NAME,
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ const path_1 = require("path");
|
|||
*/
|
||||
function getPackageLatestVersion(name) {
|
||||
const result = (0, child_process_1.execSync)(`npm info ${name}`).toString('utf-8');
|
||||
const data = result.match(/latest: \d\.\d\.\d\s*published/g);
|
||||
return data[0].slice(8, 13);
|
||||
const data = result.match(/latest: \d+\.\d+\.\d+\s*published/g);
|
||||
const versionStr = data[0];
|
||||
const version = versionStr.slice(8, versionStr.indexOf('published')).replace(/[^0-9.]/g, '');
|
||||
return version;
|
||||
}
|
||||
function packageJsonContent({ name, version, description, cliName, cliBinName, isDev, isModule, dependencies }) {
|
||||
let oakDependencyStr = '';
|
||||
|
|
@ -37,15 +39,15 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i
|
|||
else {
|
||||
// todo,这里从npmjs.org上获取最新版本
|
||||
oakDependencyStr = `
|
||||
"oak-domain": "^${getPackageLatestVersion('oak-domain')}",
|
||||
"oak-external-sdk": "^${getPackageLatestVersion('oak-external-sdk')}",
|
||||
"oak-frontend-base": "^${getPackageLatestVersion('oak-frontend-base')}",`;
|
||||
"oak-domain": "~${getPackageLatestVersion('oak-domain')}",
|
||||
"oak-external-sdk": "~${getPackageLatestVersion('oak-external-sdk')}",
|
||||
"oak-frontend-base": "~${getPackageLatestVersion('oak-frontend-base')}",`;
|
||||
if (dependencies?.length) {
|
||||
dependencies?.forEach((dep) => {
|
||||
oakDependencyStr += `\n"${dep}": "^${getPackageLatestVersion(dep)}"`;
|
||||
oakDependencyStr += `\n"${dep}": "~${getPackageLatestVersion(dep)}",`;
|
||||
});
|
||||
}
|
||||
oakDevDependencyStr = `"${cliName}": "^${getPackageLatestVersion(cliName)}",`;
|
||||
oakDevDependencyStr = `"${cliName}": "~${getPackageLatestVersion(cliName)}",`;
|
||||
}
|
||||
const serverInitScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node scripts/initServer.js" : "cross-env OAK_PLATFORM=server node scripts/initServer.js";
|
||||
const serverStartScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node scripts/startServer.js" : "cross-env OAK_PLATFORM=server node scripts/startServer.js";
|
||||
|
|
|
|||
|
|
@ -10,8 +10,11 @@ import { PackageJsonInput } from './interface';
|
|||
*/
|
||||
function getPackageLatestVersion(name: string) {
|
||||
const result = execSync(`npm info ${name}`).toString('utf-8');
|
||||
const data = result.match(/latest: \d\.\d\.\d\s*published/g);
|
||||
return data![0].slice(8, 13);
|
||||
const data = result.match(/latest: \d+\.\d+\.\d+\s*published/g);
|
||||
const versionStr = data![0];
|
||||
const version = versionStr.slice(8, versionStr.indexOf('published')).replace(/[^0-9.]/g, '');
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -50,17 +53,17 @@ export function packageJsonContent({
|
|||
else {
|
||||
// todo,这里从npmjs.org上获取最新版本
|
||||
oakDependencyStr = `
|
||||
"oak-domain": "^${getPackageLatestVersion('oak-domain')}",
|
||||
"oak-external-sdk": "^${getPackageLatestVersion('oak-external-sdk')}",
|
||||
"oak-frontend-base": "^${getPackageLatestVersion('oak-frontend-base')}",`;
|
||||
"oak-domain": "~${getPackageLatestVersion('oak-domain')}",
|
||||
"oak-external-sdk": "~${getPackageLatestVersion('oak-external-sdk')}",
|
||||
"oak-frontend-base": "~${getPackageLatestVersion('oak-frontend-base')}",`;
|
||||
if (dependencies?.length) {
|
||||
dependencies?.forEach(
|
||||
(dep) => {
|
||||
oakDependencyStr += `\n"${dep}": "^${getPackageLatestVersion(dep)}"`;
|
||||
oakDependencyStr += `\n"${dep}": "~${getPackageLatestVersion(dep)}",`;
|
||||
}
|
||||
);
|
||||
}
|
||||
oakDevDependencyStr = `"${cliName}": "^${getPackageLatestVersion(cliName)}",`
|
||||
oakDevDependencyStr = `"${cliName}": "~${getPackageLatestVersion(cliName)}",`
|
||||
}
|
||||
|
||||
const serverInitScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node scripts/initServer.js" : "cross-env OAK_PLATFORM=server node scripts/initServer.js";
|
||||
|
|
@ -70,11 +73,10 @@ export function packageJsonContent({
|
|||
"version": "${version}",
|
||||
"description": "${description}",
|
||||
"scripts": {
|
||||
"make:domain": "${
|
||||
isModule
|
||||
? `cross-env COMPLING_AS_LIB=yes ${cliBinName}`
|
||||
: cliBinName
|
||||
} make:domain",
|
||||
"make:domain": "${isModule
|
||||
? `cross-env COMPLING_AS_LIB=yes ${cliBinName}`
|
||||
: cliBinName
|
||||
} make:domain",
|
||||
"make:locale": "${cliBinName} make:locale ${isModule ? '-m' : ''}",
|
||||
"make:dep": "${cliBinName} make:dependency",
|
||||
"clean:cache": "rimraf node_modules/.cache",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
.footer {
|
||||
background: unset !important;
|
||||
}
|
||||
|
||||
.panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
/** 文本1 */
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
letter-spacing: 0px;
|
||||
line-height: 16.8px;
|
||||
color: rgba(165, 192, 203, 1);
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import React from 'react';
|
||||
import { Layout } from 'antd';
|
||||
import Style from './index.module.less';
|
||||
|
||||
const { Footer } = Layout;
|
||||
|
||||
export default function Render() {
|
||||
|
||||
return (
|
||||
<Footer className={Style.footer}>
|
||||
<div className={Style.panel}>
|
||||
<span>
|
||||
Copyright © {new Date().getFullYear()}{' '}
|
||||
浙江大学计算机创新技术研究院
|
||||
</span>
|
||||
</div>
|
||||
</Footer>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"copyright": "Oak Team & INSTITUTE OF COMPUTING INNOVATION, ZHEJIANG UNIVERSITY"
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
.mixPanel {
|
||||
height: 100% !important;
|
||||
background: var(--oak-bg-color-page) !important;
|
||||
min-height: unset !important;
|
||||
}
|
||||
|
||||
.mixMain {
|
||||
background: unset !important;
|
||||
flex-direction: row !important;
|
||||
flex: 1 !important;
|
||||
}
|
||||
|
||||
.mixLayout {
|
||||
background: unset !important;
|
||||
overflow: auto !important;
|
||||
min-height: unset !important;
|
||||
}
|
||||
|
||||
.mixContent {
|
||||
background: unset !important;
|
||||
min-height: unset !important;
|
||||
}
|
||||
|
||||
.login {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.loadingBox {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 1;
|
||||
}
|
||||
|
|
@ -1,69 +1,121 @@
|
|||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Routes, Route, Outlet, useLocation } from 'react-router-dom';
|
||||
import { Outlet, useLocation } from 'react-router-dom';
|
||||
import { Layout, Spin, Result, Button } from 'antd';
|
||||
import Styles from './index.pc.module.less';
|
||||
import Header from '../../components/header';
|
||||
import Styles from './web.pc.module.less';
|
||||
import Footer from '../../components/footer';
|
||||
import Login from 'oak-general-business/es/components/user/login';
|
||||
import useFeatures from '@project/hooks/useFeatures';
|
||||
// import Menu from '@project/components/console/menu';
|
||||
import { useWidth } from 'oak-frontend-base/es/platforms/web';
|
||||
// import Menu from '@project/components/menu';
|
||||
|
||||
import {
|
||||
OakTokenExpiredException,
|
||||
OakUserInfoLoadingException,
|
||||
} from 'oak-general-business';
|
||||
|
||||
import { OakUnloggedInException } from 'oak-domain/lib/types/Exception';
|
||||
|
||||
const { Content } = Layout;
|
||||
|
||||
type Status = 'waiting' | 'success' | 'fail';
|
||||
|
||||
function Console(props: { namespace: string }) {
|
||||
const { namespace } = props;
|
||||
const features = useFeatures();
|
||||
const [currentMenuPath, setCmp] = useState('');
|
||||
features.navigator.setNamespace(namespace);
|
||||
|
||||
const width = useWidth();
|
||||
const location = useLocation();
|
||||
const { pathname } = location;
|
||||
const path = pathname.slice(namespace.length);
|
||||
const showBack = currentMenuPath && currentMenuPath !== path;
|
||||
const isRoot = features.token.isRoot();
|
||||
// const mode = features.console.getMode(true);
|
||||
const [mode, setMode] = useState(features.console.getMode(true));
|
||||
const [userId, setUserId] = useState('');
|
||||
const [status, setStatus] = useState<Status>('waiting');
|
||||
|
||||
const init = async () => {
|
||||
try {
|
||||
const id = features.token.getUserId(true);
|
||||
if (id) {
|
||||
setUserId(id);
|
||||
} else {
|
||||
setUserId('');
|
||||
}
|
||||
setStatus('success');
|
||||
} catch (err) {
|
||||
if (err instanceof OakUserInfoLoadingException) {
|
||||
setStatus('waiting');
|
||||
return;
|
||||
}
|
||||
setStatus('fail');
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
features.navigator.setNamespace(namespace);
|
||||
features.console.initialize();
|
||||
const location = window.location;
|
||||
const { pathname } = location;
|
||||
const path2 = pathname.slice(namespace.length);
|
||||
setCmp(path2);
|
||||
const unModeSubscribe = features.console.subscribe(
|
||||
() => {
|
||||
const newMode = features.console.getMode();
|
||||
setMode(newMode);
|
||||
}
|
||||
)
|
||||
init();
|
||||
const unsub1 = features.token.subscribe(() => {
|
||||
init();
|
||||
});
|
||||
const unsub2 = features.locales.subscribe(() => {
|
||||
init();
|
||||
});
|
||||
return () => {
|
||||
unModeSubscribe();
|
||||
features.console.destroy();
|
||||
unsub1();
|
||||
unsub2();
|
||||
};
|
||||
}, []);
|
||||
|
||||
// const showOpenStoreBtn = !isRoot && !mode && pathname === '/console';
|
||||
const [showOpenStore, setShowOpenStore] = useState(true);
|
||||
useEffect(() => {
|
||||
if (mode || isRoot) {
|
||||
setShowOpenStore(false);
|
||||
} else {
|
||||
setShowOpenStore(true);
|
||||
}
|
||||
}, [mode, isRoot])
|
||||
return (
|
||||
<div className={Styles.container}>
|
||||
<div className={Styles.header}>
|
||||
<Header />
|
||||
const location = useLocation();
|
||||
const { pathname } = location;
|
||||
const isRoot = features.token.isRoot();
|
||||
|
||||
if (status === 'waiting') {
|
||||
return (
|
||||
<div className={Styles.loadingBox}>
|
||||
<Spin tip="Loading" />
|
||||
</div>
|
||||
<div className={Styles.body}>
|
||||
{/* <Menu
|
||||
pathname={path}
|
||||
onPathClicked={(path) => setCmp(path)}
|
||||
/> */}
|
||||
<div className={Styles.content}>
|
||||
<Outlet />
|
||||
);
|
||||
}
|
||||
|
||||
if (status === 'fail') {
|
||||
return (
|
||||
<Layout className={Styles.mixPanel}>
|
||||
<div className={Styles.login}>
|
||||
<Result
|
||||
status="error"
|
||||
title={features.locales.t('errorInLoading')}
|
||||
extra={[
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
window.location.reload();
|
||||
}}
|
||||
>
|
||||
{features.locales.t('reload')}
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
return (
|
||||
<Layout className={Styles.mixPanel}>
|
||||
<Header />
|
||||
<Layout className={Styles.mixMain}>
|
||||
{/* <Menu /> */}
|
||||
<Layout className={Styles.mixLayout}>
|
||||
<Content className={Styles.mixContent}>
|
||||
<Outlet />
|
||||
</Content>
|
||||
<Footer />
|
||||
</Layout>
|
||||
</Layout>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Layout className={Styles.mixPanel}>
|
||||
<div className={Styles.login}>
|
||||
<Login />
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"errorInLoading": "抱歉,页面加载出现错误!请稍后再试。",
|
||||
"reload": "重新加载"
|
||||
}
|
||||
Loading…
Reference in New Issue