From ecf897688adcfe5e8eef3a16dee7a70e8e5637a9 Mon Sep 17 00:00:00 2001 From: wkj <278599135@qq.com> Date: Mon, 25 Jul 2022 11:24:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20server=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/babel-plugin/router.js | 2 +- lib/template.js | 2 ++ scripts/locales/copy-mp-locales.js | 2 +- src/template.ts | 2 ++ template/configuration/mysql.json | 8 ++++++ template/configuration/server.json | 5 ++++ template/scripts/cleanDtsAndJs.ts | 28 +++++++++++++++++++ template/scripts/initServer.ts | 12 ++++++++ template/scripts/startServer.ts | 8 ++++++ .../{RunningContext.ts => RuntimeContext.ts} | 20 +++++++------ 10 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 template/configuration/mysql.json create mode 100644 template/configuration/server.json create mode 100644 template/scripts/cleanDtsAndJs.ts create mode 100644 template/scripts/initServer.ts create mode 100644 template/scripts/startServer.ts rename template/src/{RunningContext.ts => RuntimeContext.ts} (61%) diff --git a/config/babel-plugin/router.js b/config/babel-plugin/router.js index b67d5bc..d21cb14 100644 --- a/config/babel-plugin/router.js +++ b/config/babel-plugin/router.js @@ -28,7 +28,7 @@ module.exports = () => { const { navigationBarTitleText } = require(`${relPath}.json`); const pagePath = ele.slice(ele.indexOf('pages/') + 6, ele.length - 6); return t.objectExpression([ - t.objectProperty(t.identifier('title'), t.stringLiteral(navigationBarTitleText)), + t.objectProperty(t.identifier('title'), t.stringLiteral(navigationBarTitleText || '')), t.objectProperty(t.identifier('path'), t.stringLiteral(pagePath)), t.objectProperty(t.identifier('element'), t.callExpression( t.identifier('LazyLoad'), diff --git a/lib/template.js b/lib/template.js index cfe621d..33085e7 100644 --- a/lib/template.js +++ b/lib/template.js @@ -5,6 +5,7 @@ function packageJsonContent({ name, version, description, cliversion, cliname, i let oakPackageStr; if (isDev) { oakPackageStr = `"${cliname}": "file:../${cliname}", + "oak-common-aspect": "file:../oak-common-aspect", "oak-domain": "file:../oak-domain", "oak-frontend-base": "file:../oak-frontend-base", "oak_external-sdk": "file:../oak-external-sdk", @@ -13,6 +14,7 @@ function packageJsonContent({ name, version, description, cliversion, cliname, i } else { oakPackageStr = `"${cliname}": "^${cliversion}", + "oak-common-aspect": "^1.0.0", "oak-domain": "^1.0.0", "oak-frontend-base": "^1.0.0", "oak-general-business": "^1.0.0", diff --git a/scripts/locales/copy-mp-locales.js b/scripts/locales/copy-mp-locales.js index 407eb6b..70e997e 100644 --- a/scripts/locales/copy-mp-locales.js +++ b/scripts/locales/copy-mp-locales.js @@ -11,7 +11,7 @@ const Locales = 'locales'; function copyLocaleFiles() { //build locales - consola.start(`${chalk.blueBright('读取locales,生成json数据')}`); + consola.success(`${chalk.blueBright('读取locales,生成json数据')}`); // locales到mp/dist下 const buildPath = Path.resolve(paths.appBuild, Locales); const json = buildLocales({ diff --git a/src/template.ts b/src/template.ts index ca02b22..61111a5 100644 --- a/src/template.ts +++ b/src/template.ts @@ -10,6 +10,7 @@ export function packageJsonContent({ let oakPackageStr; if (isDev) { oakPackageStr = `"${cliname}": "file:../${cliname}", + "oak-common-aspect": "file:../oak-common-aspect", "oak-domain": "file:../oak-domain", "oak-frontend-base": "file:../oak-frontend-base", "oak_external-sdk": "file:../oak-external-sdk", @@ -18,6 +19,7 @@ export function packageJsonContent({ } else { oakPackageStr = `"${cliname}": "^${cliversion}", + "oak-common-aspect": "^1.0.0", "oak-domain": "^1.0.0", "oak-frontend-base": "^1.0.0", "oak-general-business": "^1.0.0", diff --git a/template/configuration/mysql.json b/template/configuration/mysql.json new file mode 100644 index 0000000..1b12147 --- /dev/null +++ b/template/configuration/mysql.json @@ -0,0 +1,8 @@ +{ + "host": "localhost", + "user": "root", + "password": "", + "database": "bangzuxia", + "charset": "utf8mb4_general_ci", + "connectionLimit": 5 +} \ No newline at end of file diff --git a/template/configuration/server.json b/template/configuration/server.json new file mode 100644 index 0000000..560aaec --- /dev/null +++ b/template/configuration/server.json @@ -0,0 +1,5 @@ +{ + "port": 3001, + "serverUrl": "http://localhost", + "serverEndpoint": "/aspect" +} \ No newline at end of file diff --git a/template/scripts/cleanDtsAndJs.ts b/template/scripts/cleanDtsAndJs.ts new file mode 100644 index 0000000..8e2a8b1 --- /dev/null +++ b/template/scripts/cleanDtsAndJs.ts @@ -0,0 +1,28 @@ +import { removeSync, readdirSync, statSync } from 'fs-extra'; +import { join } from 'path'; + +function removeDts(path: string) { + const files = readdirSync(path); + + files.forEach( + (file) => { + const stat = statSync(join(path, file)); + if (stat.isDirectory() && !['types', 'typings', 'lin-ui'].includes(file)) { + removeDts(join(path, file)); + } + else if ((file.endsWith('.d.ts') || file.endsWith('.js')) && file !== 'react-app-env.d.ts') { + removeSync(join(path, file)); + console.log(`remove ${join(path, file)}`); + } + } + ); +} + +if (process.argv[2]) { + console.log(`清理${process.argv[2]}路径下的d.ts和js文件`); + removeDts(join(process.cwd(), process.argv[2])); +} +else { + console.log('请输入路径名'); +} + diff --git a/template/scripts/initServer.ts b/template/scripts/initServer.ts new file mode 100644 index 0000000..eddcca9 --- /dev/null +++ b/template/scripts/initServer.ts @@ -0,0 +1,12 @@ +import { initialize } from 'oak-cli/lib/server/initialize'; +import { RuntimeContext } from '../src/RuntimeContext'; + +const pwd = process.cwd(); + +const dropIfExists = process.argv[2]; +console.log(dropIfExists); + +initialize(pwd, RuntimeContext.FromCxtStr, !!dropIfExists) + .then( + () => process.exit(0) + ); \ No newline at end of file diff --git a/template/scripts/startServer.ts b/template/scripts/startServer.ts new file mode 100644 index 0000000..dafaea0 --- /dev/null +++ b/template/scripts/startServer.ts @@ -0,0 +1,8 @@ +import { startup } from 'oak-cli/lib/server/start'; +import { RuntimeContext } from '../src/RuntimeContext'; +import { makeException } from '../src/types/Exception'; +import { SimpleConnector } from 'oak-domain/lib/utils/SimpleConnector'; +const pwd = process.cwd(); + +const connector = new SimpleConnector('', makeException, RuntimeContext.FromCxtStr); +startup(pwd, RuntimeContext.FromCxtStr, connector); \ No newline at end of file diff --git a/template/src/RunningContext.ts b/template/src/RuntimeContext.ts similarity index 61% rename from template/src/RunningContext.ts rename to template/src/RuntimeContext.ts index 26eadde..cb0b5ab 100644 --- a/template/src/RunningContext.ts +++ b/template/src/RuntimeContext.ts @@ -3,14 +3,16 @@ import { EntityDict } from 'oak-app-domain'; import { RowStore } from 'oak-domain/lib/types'; export class RuntimeContext extends GeneralRuntimeContext { - static FromCxtStr(cxtStr?: string) { - const { token, applicationId, scene } = cxtStr - ? GeneralRuntimeContext.fromString(cxtStr) - : { - token: undefined, - applicationId: undefined, - scene: undefined, - }; + static FromCxtStr(cxtStr?: string){ + const { + token, + applicationId, + scene + } = cxtStr ? GeneralRuntimeContext.fromString(cxtStr) : { + token: undefined, + applicationId: undefined, + scene: undefined, + }; return (store: RowStore) => { const context = new RuntimeContext(store, applicationId); context.setScene(scene); @@ -18,4 +20,4 @@ export class RuntimeContext extends GeneralRuntimeContext { return context; }; } -} +} \ No newline at end of file