初始化时处理dependency
This commit is contained in:
parent
9f217284a1
commit
04a2d1147d
|
|
@ -2,6 +2,9 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.update = exports.create = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const ts = tslib_1.__importStar(require("typescript"));
|
||||
const fs_1 = require("fs");
|
||||
const { factory } = ts;
|
||||
const file_handle_1 = require("./file-handle");
|
||||
const enum_1 = require("./enum");
|
||||
const config_1 = require("./config");
|
||||
|
|
@ -12,6 +15,7 @@ const axios_1 = tslib_1.__importDefault(require("axios"));
|
|||
const tip_style_1 = require("./tip-style");
|
||||
const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
|
||||
const rename_1 = require("./rename");
|
||||
const assert_1 = tslib_1.__importDefault(require("assert"));
|
||||
const DEFAULT_PROJECT_NAME = 'oak_template';
|
||||
const DEFAULT_PROJECT_TITLE = 'oak template project';
|
||||
const prompt = [
|
||||
|
|
@ -32,6 +36,30 @@ const prompt = [
|
|||
message: 'description',
|
||||
},
|
||||
];
|
||||
/**
|
||||
* 将项目的依赖关系加入
|
||||
*/
|
||||
function addDependencies(dependencies) {
|
||||
const dependencyFile = (0, path_1.join)(process.cwd(), 'src', 'configuration', 'dependency.ts');
|
||||
const program = ts.createProgram([
|
||||
dependencyFile,
|
||||
], {});
|
||||
const sourceFile = program.getSourceFile(dependencyFile);
|
||||
const { statements } = sourceFile;
|
||||
const stmt1 = statements[1];
|
||||
(0, assert_1.default)(ts.isVariableStatement(stmt1));
|
||||
const { declarationList: { declarations: [vd] } } = stmt1;
|
||||
const { name, initializer } = vd;
|
||||
(0, assert_1.default)(ts.isIdentifier(name) && name.text === 'dependencyConfiguration');
|
||||
(0, assert_1.default)(ts.isArrayLiteralExpression(initializer));
|
||||
Object.assign(initializer, {
|
||||
elements: dependencies.map(ele => factory.createStringLiteral(ele))
|
||||
});
|
||||
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
||||
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), sourceFile);
|
||||
(0, fs_1.writeFileSync)(dependencyFile, result, { flag: 'w' });
|
||||
(0, tip_style_1.Success)((0, tip_style_1.success)(`${dependencyFile} has been built.`));
|
||||
}
|
||||
/**
|
||||
* @name 检查项目名是否已存在
|
||||
* @param dirName
|
||||
|
|
@ -60,12 +88,18 @@ async function getOakCliVersion() {
|
|||
* @returns
|
||||
*/
|
||||
async function getMiniVersion() {
|
||||
const res = await axios_1.default.get(config_1.MINI_VERSION_URL);
|
||||
const versions = JSON.parse(res.data['json_data'])['total'];
|
||||
const versionsSort = versions.sort((a, b) => {
|
||||
return b['percentage'] - a['percentage'];
|
||||
});
|
||||
return versionsSort[0]['sdkVer'];
|
||||
try {
|
||||
const res = await axios_1.default.get(config_1.MINI_VERSION_URL);
|
||||
const versions = JSON.parse(res.data['json_data'])['total'];
|
||||
const versionsSort = versions.sort((a, b) => {
|
||||
return b['percentage'] - a['percentage'];
|
||||
});
|
||||
return versionsSort[0]['sdkVer'];
|
||||
}
|
||||
catch (err) {
|
||||
(0, tip_style_1.Warn)((0, tip_style_1.warn)(`can't access a-o-s weixin mini version, using 3.4.1`));
|
||||
return '3.4.1';
|
||||
}
|
||||
}
|
||||
async function createWechatMpBoilplate(dir, isDev, isUpdate) {
|
||||
// 获取微信小程序稳定基础版本库
|
||||
|
|
@ -176,6 +210,29 @@ async function create(dirName, cmd) {
|
|||
shell.cd(dirName).exec('npm install'); */
|
||||
(0, rename_1.renameProject)(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE);
|
||||
(0, tip_style_1.Success)(`${(0, tip_style_1.success)(`Successfully created project ${(0, tip_style_1.primary)(name)}, directory name is ${(0, tip_style_1.primary)(dirName)}`)}`);
|
||||
const { useOgb, moreDeps } = await inquirer_1.default.prompt([{
|
||||
name: 'useOgb',
|
||||
type: 'confirm',
|
||||
message: 'add oak-general-business into dependency?',
|
||||
default: true,
|
||||
}, {
|
||||
name: 'moreDeps',
|
||||
type: 'input',
|
||||
message: 'do you have more dependent oak-family libraries? type their names, use comma as separator.',
|
||||
default: '',
|
||||
}]);
|
||||
const deps = [];
|
||||
if (useOgb) {
|
||||
deps.push('oak-general-business');
|
||||
}
|
||||
if (moreDeps) {
|
||||
deps.push(...(moreDeps.split(',').map(ele => ele.trim()).filter(ele => !!ele)));
|
||||
}
|
||||
if (deps.length > 0) {
|
||||
shelljs_1.default.cd(dirName);
|
||||
addDependencies(deps);
|
||||
}
|
||||
(0, tip_style_1.Success)(`${(0, tip_style_1.success)(`Ok, type 'npm install' to install libs, then start!`)}`);
|
||||
}
|
||||
catch (err) {
|
||||
(0, tip_style_1.Error)((0, tip_style_1.error)('create error'));
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
import * as ts from 'typescript';
|
||||
import { writeFileSync } from 'fs';
|
||||
const { factory } = ts;
|
||||
|
||||
import {
|
||||
copyFolder,
|
||||
checkFileExistsAndCreate,
|
||||
|
|
@ -39,8 +43,9 @@ import {
|
|||
warn,
|
||||
Warn,
|
||||
} from './tip-style';
|
||||
import shell from 'shelljs';
|
||||
import shell, { cat } from 'shelljs';
|
||||
import { renameProject } from './rename';
|
||||
import assert from 'assert';
|
||||
const DEFAULT_PROJECT_NAME = 'oak_template';
|
||||
const DEFAULT_PROJECT_TITLE = 'oak template project';
|
||||
|
||||
|
|
@ -63,6 +68,41 @@ const prompt = [
|
|||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* 将项目的依赖关系加入
|
||||
*/
|
||||
function addDependencies(dependencies: string[]) {
|
||||
const dependencyFile = join(process.cwd(), 'src', 'configuration', 'dependency.ts');
|
||||
const program = ts.createProgram([
|
||||
dependencyFile,
|
||||
], {});
|
||||
|
||||
const sourceFile = program.getSourceFile(dependencyFile);
|
||||
|
||||
const { statements } = sourceFile!;
|
||||
|
||||
const stmt1 = statements[1];
|
||||
assert(ts.isVariableStatement(stmt1));
|
||||
const { declarationList: { declarations: [ vd ]}} = stmt1;
|
||||
const { name, initializer } = vd;
|
||||
assert(ts.isIdentifier(name) && name.text === 'dependencyConfiguration');
|
||||
assert(ts.isArrayLiteralExpression(initializer!));
|
||||
Object.assign(initializer, {
|
||||
elements: dependencies.map(
|
||||
ele => factory.createStringLiteral(ele)
|
||||
)
|
||||
});
|
||||
|
||||
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
||||
const result = printer.printList(
|
||||
ts.ListFormat.SourceFileStatements,
|
||||
factory.createNodeArray(statements),
|
||||
sourceFile!);
|
||||
|
||||
writeFileSync(dependencyFile, result, { flag: 'w' });
|
||||
Success(success(`${dependencyFile} has been built.`));
|
||||
}
|
||||
|
||||
/**
|
||||
* @name 检查项目名是否已存在
|
||||
* @param dirName
|
||||
|
|
@ -95,12 +135,18 @@ async function getOakCliVersion() {
|
|||
* @returns
|
||||
*/
|
||||
async function getMiniVersion() {
|
||||
const res = await axios.get(MINI_VERSION_URL);
|
||||
const versions: Array<any> = JSON.parse(res.data['json_data'])['total'];
|
||||
const versionsSort = versions.sort((a: any, b: any) => {
|
||||
return b['percentage'] - a['percentage'];
|
||||
});
|
||||
return versionsSort[0]['sdkVer'];
|
||||
try {
|
||||
const res = await axios.get(MINI_VERSION_URL);
|
||||
const versions: Array<any> = JSON.parse(res.data['json_data'])['total'];
|
||||
const versionsSort = versions.sort((a: any, b: any) => {
|
||||
return b['percentage'] - a['percentage'];
|
||||
});
|
||||
return versionsSort[0]['sdkVer'];
|
||||
}
|
||||
catch (err) {
|
||||
Warn(warn(`can't access a-o-s weixin mini version, using 3.4.1`));
|
||||
return '3.4.1';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -277,11 +323,13 @@ export async function create(dirName: string, cmd: any) {
|
|||
Warn(warn('Sorry, this script requires npm! Please install npm!'));
|
||||
shell.exit(1);
|
||||
}
|
||||
|
||||
/* Success(`${success(`Waiting...`)}`);
|
||||
Success(`${success(`Dependencies are now being installed`)}`);
|
||||
shell.cd(dirName).exec('npm install'); */
|
||||
|
||||
renameProject(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE);
|
||||
|
||||
Success(
|
||||
`${success(
|
||||
`Successfully created project ${primary(
|
||||
|
|
@ -289,6 +337,41 @@ export async function create(dirName: string, cmd: any) {
|
|||
)}, directory name is ${primary(dirName)}`
|
||||
)}`
|
||||
);
|
||||
|
||||
const { useOgb, moreDeps } = await inquirer.prompt([{
|
||||
name: 'useOgb',
|
||||
type: 'confirm',
|
||||
message: 'add oak-general-business into dependency?',
|
||||
default: true,
|
||||
}, {
|
||||
name: 'moreDeps',
|
||||
type: 'input',
|
||||
message: 'do you have more dependent oak-family libraries? type their names, use comma as separator.',
|
||||
default: '',
|
||||
}]);
|
||||
const deps = [] as string[];
|
||||
if (useOgb) {
|
||||
deps.push('oak-general-business');
|
||||
}
|
||||
if (moreDeps) {
|
||||
deps.push(
|
||||
...((<string>moreDeps).split(',').map(
|
||||
ele => ele.trim()
|
||||
).filter(
|
||||
ele => !!ele
|
||||
))
|
||||
);
|
||||
}
|
||||
if (deps.length > 0) {
|
||||
shell.cd(dirName);
|
||||
addDependencies(deps);
|
||||
}
|
||||
|
||||
Success(
|
||||
`${success(
|
||||
`Ok, type 'npm install' to install libs, then start!`
|
||||
)}`
|
||||
);
|
||||
} catch (err) {
|
||||
Error(error('create error'));
|
||||
Error(error(err));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { DependencyConfiguration } from 'oak-domain/lib/types/Configuration';
|
||||
|
||||
const dependencyConfiguration: DependencyConfiguration = ['oak-general-business'];
|
||||
const dependencyConfiguration: DependencyConfiguration = [];
|
||||
|
||||
export default dependencyConfiguration;
|
||||
|
|
|
|||
|
|
@ -10,4 +10,10 @@ export const selectFreeEntities = [
|
|||
];
|
||||
|
||||
export const updateFreeDict: UpdateFreeDict<EntityDict> = {
|
||||
};
|
||||
|
||||
export default {
|
||||
authDeduceRelationMap,
|
||||
selectFreeEntities,
|
||||
updateFreeDict,
|
||||
};
|
||||
|
|
@ -6,16 +6,16 @@ import {
|
|||
SingleGeo,
|
||||
} from 'oak-domain/lib/types/DataType';
|
||||
import { ActionDef, EntityDesc } from 'oak-domain/lib/types';
|
||||
import { Schema as Area } from 'oak-general-business/lib/entities/Area';
|
||||
import { Schema as ExtraFile } from 'oak-general-business/lib/entities/ExtraFile';
|
||||
// import { Schema as Area } from 'oak-general-business/lib/entities/Area';
|
||||
// import { Schema as ExtraFile } from 'oak-general-business/lib/entities/ExtraFile';
|
||||
import { EntityShape } from 'oak-domain/lib/types/Entity';
|
||||
|
||||
export interface Schema extends EntityShape {
|
||||
coordinate: SingleGeo; //坐标
|
||||
area: Area; //地区
|
||||
// area: Area; //地区
|
||||
name: String<32>; //名称
|
||||
addrDetail: String<32>; //地址详情
|
||||
files: Array<ExtraFile>; //封面图
|
||||
// files: Array<ExtraFile>; //封面图
|
||||
}
|
||||
|
||||
type IAction = 'online' | 'offline' | 'disable';
|
||||
|
|
@ -58,10 +58,10 @@ const entityDesc: EntityDesc<
|
|||
name: '门店',
|
||||
attr: {
|
||||
coordinate: '位置',
|
||||
area: '地区',
|
||||
// area: '地区',
|
||||
name: '名称',
|
||||
addrDetail: '地址详情',
|
||||
files: '照片',
|
||||
// files: '照片',
|
||||
iState: '状态',
|
||||
},
|
||||
action: {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,3 @@
|
|||
import {
|
||||
OakTokenExpiredException,
|
||||
OakMobileUnsetException,
|
||||
OakUserInfoUncompletedException,
|
||||
OakUserInfoLoadingException,
|
||||
} from 'oak-general-business';
|
||||
import {
|
||||
OakException,
|
||||
OakUnloggedInException,
|
||||
|
|
@ -35,42 +29,7 @@ export const handler = async (reason: any, features: AFD) => {
|
|||
{ isGoBack: true },
|
||||
true
|
||||
);
|
||||
} else if (reason instanceof OakTokenExpiredException) {
|
||||
await features.token.logout();
|
||||
features.navigator.navigateTo(
|
||||
{
|
||||
url: '/login',
|
||||
},
|
||||
{ isGoBack: true },
|
||||
true
|
||||
);
|
||||
} /* else if (reason instanceof OakUserUnpermittedException) {
|
||||
features.navigator.redirectTo(
|
||||
{
|
||||
url: '/result/403',
|
||||
},
|
||||
undefined,
|
||||
true
|
||||
);
|
||||
} */ else if (reason instanceof OakMobileUnsetException) {
|
||||
features.navigator.navigateTo(
|
||||
{
|
||||
url: '/mobile/me',
|
||||
},
|
||||
undefined,
|
||||
true
|
||||
);
|
||||
} else if (reason instanceof OakUserInfoUncompletedException) {
|
||||
const userId = features.token.getUserId();
|
||||
features.navigator.navigateTo(
|
||||
{
|
||||
url: '/user/manager/upsert',
|
||||
oakId: userId,
|
||||
},
|
||||
undefined,
|
||||
true
|
||||
);
|
||||
} else if (reason instanceof OakInputIllegalException) {
|
||||
} else if (reason instanceof OakInputIllegalException) {
|
||||
features.message.setMessage({
|
||||
content: reason.message,
|
||||
type: 'error',
|
||||
|
|
@ -80,9 +39,6 @@ export const handler = async (reason: any, features: AFD) => {
|
|||
content: reason.message,
|
||||
type: 'error',
|
||||
});
|
||||
} else if (reason instanceof OakUserInfoLoadingException) {
|
||||
// 暂不处理,在oak-general-business的page的生命周期里,等token加载完成了会刷新页面的
|
||||
console.warn(reason);
|
||||
} else if (reason instanceof ExampleException) {
|
||||
console.log('在此处理ExampleException');
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -7,10 +7,9 @@ import {
|
|||
OakNetworkException,
|
||||
OakServerProxyException,
|
||||
} from 'oak-domain/lib/types/Exception';
|
||||
import { OakTokenExpiredException } from 'oak-general-business';
|
||||
import { ECode } from 'oak-general-business/es/types/ErrorPage';
|
||||
import { ECode } from 'oak-frontend-base/es/types/ErrorPage';
|
||||
const ErrorPage = lazy(
|
||||
() => import('oak-general-business/es/components/common/errorPage')
|
||||
() => import('oak-frontend-base/es/components/errorPage')
|
||||
);
|
||||
|
||||
interface ErrorProps {
|
||||
|
|
@ -21,27 +20,6 @@ function Error(props: ErrorProps) {
|
|||
const { error } = props;
|
||||
|
||||
if (error instanceof OakException) {
|
||||
if (error instanceof OakTokenExpiredException) {
|
||||
return (
|
||||
<ErrorPage
|
||||
code={ECode.error}
|
||||
title="登录失效"
|
||||
desc="抱歉,登录信息失效,请点击【重新加载】"
|
||||
>
|
||||
<Space>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={async () => {
|
||||
(global as any).features.token.removeToken();
|
||||
window.location.reload();
|
||||
}}
|
||||
>
|
||||
重新加载
|
||||
</Button>
|
||||
</Space>
|
||||
</ErrorPage>
|
||||
);
|
||||
}
|
||||
if (error instanceof OakNetworkException) {
|
||||
// 网络中断出现的异常
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"theme": {
|
||||
}
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ type RoutePath = string | undefined | null;
|
|||
type IsFirst = boolean;
|
||||
|
||||
// 项目路径别名
|
||||
export type Project = '@project' | '@oak-general-business' | '@oak-frontend-base';
|
||||
export type Project = '@project';
|
||||
|
||||
|
||||
// [项目别名, 文件path,[嵌套路由顶层path],设置根路由, 路由path]
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
import {
|
||||
String,
|
||||
Text,
|
||||
Price
|
||||
} from 'oak-domain/lib/types/DataType';
|
||||
import { EntityShape } from 'oak-domain/lib/types/Entity';
|
||||
import { Schema as System } from 'oak-general-business/lib/entities/System';
|
||||
import { Schema as ArticleMenu } from 'oak-general-business/lib/entities/ArticleMenu';
|
||||
import { EntityDesc } from 'oak-domain/lib/types';
|
||||
|
||||
export interface Schema extends EntityShape {
|
||||
name: String<32>;
|
||||
system: System;
|
||||
systems?: System[];
|
||||
articleMenus?: ArticleMenu[];
|
||||
};
|
||||
|
||||
export type Relation = 'owner' | 'manager';
|
||||
|
||||
const entityDesc: EntityDesc<Schema, '', Relation> = {
|
||||
locales: {
|
||||
zh_CN: {
|
||||
name: '系统供应商',
|
||||
attr: {
|
||||
name: '名称',
|
||||
system: '系统',
|
||||
systems: '系统',
|
||||
articleMenus: '文章分类',
|
||||
},
|
||||
r: {
|
||||
owner: '所有者',
|
||||
manager: '管理员',
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue