diff --git a/lib/create.js b/lib/create.js index a9b1930..3fc1a84 100644 --- a/lib/create.js +++ b/lib/create.js @@ -121,7 +121,6 @@ async function create(dirName, cmd) { name: DEFAULT_PROJECT_NAME, version, description, - cliVersion: config_1.CLI_VERSION, cliName: config_1.CLI_NAME, cliBinName: config_1.CLI_BIN_NAME, isDev, diff --git a/lib/interface.d.ts b/lib/interface.d.ts index f187a29..ae17110 100644 --- a/lib/interface.d.ts +++ b/lib/interface.d.ts @@ -7,7 +7,6 @@ export interface PackageJsonInput { name: string; version?: string; description?: string; - cliVersion: string; cliName: string; cliBinName: string; isDev?: boolean; diff --git a/lib/template.d.ts b/lib/template.d.ts index b90475a..8e49e8b 100644 --- a/lib/template.d.ts +++ b/lib/template.d.ts @@ -1,5 +1,5 @@ import { PackageJsonInput } from './interface'; -export declare function packageJsonContent({ name, version, description, cliVersion, cliName, cliBinName, isDev, }: PackageJsonInput): string; +export declare function packageJsonContent({ name, version, description, cliName, cliBinName, isDev, }: PackageJsonInput): string; export declare function tsConfigJsonContent(): string; export declare function tsConfigBuildJsonContent(): string; export declare function tsConfigBuildPathsJsonContent(): string; diff --git a/lib/template.js b/lib/template.js index b9865bc..82ec562 100644 --- a/lib/template.js +++ b/lib/template.js @@ -1,7 +1,18 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.oakConfigContentWithWeb = exports.appJsonContentWithWeb = exports.oakConfigContentWithWeChatMp = exports.appJsonContentWithWeChatMp = exports.projectConfigContentWithWeChatMp = exports.tsConfigWebJsonContent = exports.tsConfigMpJsonContent = exports.tsConfigPathsJsonContent = exports.tsConfigBuildPathsJsonContent = exports.tsConfigBuildJsonContent = exports.tsConfigJsonContent = exports.packageJsonContent = void 0; -function packageJsonContent({ name, version, description, cliVersion, cliName, cliBinName, isDev, }) { +const child_process_1 = require("child_process"); +/** + * 利用npm info获得相应库的最新版本 + * @param name + * @returns + */ +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); +} +function packageJsonContent({ name, version, description, cliName, cliBinName, isDev, }) { let oakDependencyStr; let oakDevDependencyStr; if (isDev) { @@ -19,18 +30,18 @@ function packageJsonContent({ name, version, description, cliVersion, cliName, c else { // todo,这里从npmjs.org上获取最新版本 oakDependencyStr = ` - "oak-backend-base": "^3.2.0", - "oak-common-aspect": "^2.1.0", - "oak-db": "^2.1.1", - "oak-domain": "^2.1.0", - "oak-external-sdk": "^1.0.5", - "oak-frontend-base": "^2.1.0", - "oak-general-business": "^2.1.0", - "oak-memory-tree-store": "^2.1.0",`; - oakDevDependencyStr = `"${cliName}": "^${cliVersion}",`; + "oak-backend-base": "^${getPackageLatestVersion('oak-backend-base')}", + "oak-common-aspect": "^${getPackageLatestVersion('oak-common-aspect')}", + "oak-db": "^${getPackageLatestVersion('oak-db')}", + "oak-domain": "^${getPackageLatestVersion('oak-domain')}", + "oak-external-sdk": "^${getPackageLatestVersion('oak-external-sdk')}", + "oak-frontend-base": "^${getPackageLatestVersion('oak-frontend-base')}", + "oak-general-business": "^${getPackageLatestVersion('oak-general-business')}", + "oak-memory-tree-store": "^${getPackageLatestVersion('oak-memory-tree-store')}",`; + oakDevDependencyStr = `"${cliName}": "^${getPackageLatestVersion(cliName)}",`; } - const serverInitScript = isDev ? "cross-env OAK_PLATFORM=server ts-node scripts/initServer.js" : "cross-env OAK_PLATFORM=server ts-node scripts/initServer.js"; - const serverStartScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server ts-node scripts/startServer.js" : "cross-env OAK_PLATFORM=server ts-node scripts/startServer.js"; + 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"; return `{ "name": "${name}", "version": "${version}", @@ -65,11 +76,11 @@ function packageJsonContent({ name, version, description, cliVersion, cliName, c "dependencies": { "@ant-design/cssinjs": "^1.16.2", "@ant-design/icons": "^5.2.6", - "@react-native-async-storage/async-storage": "^1.19.8", - "@react-native-masked-view/masked-view": "^0.3.0", - "@react-navigation/bottom-tabs": "^6.5.11", - "@react-navigation/native": "^6.1.9", - "@react-navigation/stack": "^6.3.20", + "@react-native-async-storage/async-storage": "^1.19.8", + "@react-native-masked-view/masked-view": "^0.3.0", + "@react-navigation/bottom-tabs": "^6.5.11", + "@react-navigation/native": "^6.1.9", + "@react-navigation/stack": "^6.3.20", "@wangeditor/basic-modules": "^1.1.3", "@wangeditor/editor": "^5.1.14", "@wangeditor/editor-for-react": "^1.0.4", diff --git a/package.json b/package.json index b0447fb..8173d97 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "build": "tsc", "dev": "tsc --watch", - "test": "node test.js" + "test": "ts-node test.ts" }, "bin": { "oak-cli": "lib/index.js" @@ -34,8 +34,6 @@ "@types/uuid": "^8.3.4", "babel-plugin-module-resolver": "^5.0.0", "fork-ts-checker-webpack-plugin": "^8.0.0", - "node-watch": "^0.7.4", - "querystring-es3": "^0.2.1", "ts-node": "^10.9.1", "typescript": "^5.2.2" }, @@ -95,6 +93,7 @@ "loader-utils": "^3.2.0", "lodash": "^4.17.21", "mini-css-extract-plugin": "^2.5.3", + "node-watch": "^0.7.4", "oak-backend-base": "file:../oak-backend-base", "oak-domain": "file:../oak-domain", "oak-frontend-base": "file:../oak-frontend-base", @@ -106,6 +105,7 @@ "postcss-preset-env": "^7.0.1", "progress-bar-webpack-plugin": "^2.1.0", "prompts": "^2.4.2", + "querystring-es3": "^0.2.1", "react-app-polyfill": "^3.0.0", "react-dev-utils": "^12.0.1", "react-native": "^0.72.7", diff --git a/src/create.ts b/src/create.ts index c24af97..323dd1b 100644 --- a/src/create.ts +++ b/src/create.ts @@ -198,7 +198,6 @@ export async function create(dirName: string, cmd: any) { name: DEFAULT_PROJECT_NAME, // 后面再统一rename version, description, - cliVersion: CLI_VERSION, cliName: CLI_NAME, cliBinName: CLI_BIN_NAME, isDev, diff --git a/src/interface.ts b/src/interface.ts index faac799..64bc8da 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -9,7 +9,6 @@ export interface PackageJsonInput { name: string; version?: string; description?: string; - cliVersion: string; cliName: string; cliBinName: string; isDev?: boolean; diff --git a/src/template.ts b/src/template.ts index e3d734f..fff4bbb 100644 --- a/src/template.ts +++ b/src/template.ts @@ -1,9 +1,22 @@ -import { PackageJsonInput } from './interface' +import { execSync } from 'child_process'; +import { PackageJsonInput } from './interface'; + +/** + * 利用npm info获得相应库的最新版本 + * @param name + * @returns + */ +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); +} + + export function packageJsonContent({ name, version, description, - cliVersion, cliName, cliBinName, isDev, @@ -25,19 +38,19 @@ export function packageJsonContent({ else { // todo,这里从npmjs.org上获取最新版本 oakDependencyStr = ` - "oak-backend-base": "^3.2.0", - "oak-common-aspect": "^2.1.0", - "oak-db": "^2.1.1", - "oak-domain": "^2.1.0", - "oak-external-sdk": "^1.0.5", - "oak-frontend-base": "^2.1.0", - "oak-general-business": "^2.1.0", - "oak-memory-tree-store": "^2.1.0",`; - oakDevDependencyStr = `"${cliName}": "^${cliVersion}",` + "oak-backend-base": "^${getPackageLatestVersion('oak-backend-base')}", + "oak-common-aspect": "^${getPackageLatestVersion('oak-common-aspect')}", + "oak-db": "^${getPackageLatestVersion('oak-db')}", + "oak-domain": "^${getPackageLatestVersion('oak-domain')}", + "oak-external-sdk": "^${getPackageLatestVersion('oak-external-sdk')}", + "oak-frontend-base": "^${getPackageLatestVersion('oak-frontend-base')}", + "oak-general-business": "^${getPackageLatestVersion('oak-general-business')}", + "oak-memory-tree-store": "^${getPackageLatestVersion('oak-memory-tree-store')}",`; + oakDevDependencyStr = `"${cliName}": "^${getPackageLatestVersion(cliName)}",` } - const serverInitScript = isDev ? "cross-env OAK_PLATFORM=server ts-node scripts/initServer.js" : "cross-env OAK_PLATFORM=server ts-node scripts/initServer.js"; - const serverStartScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server ts-node scripts/startServer.js" : "cross-env OAK_PLATFORM=server ts-node scripts/startServer.js"; + 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"; return `{ "name": "${name}", "version": "${version}", @@ -72,11 +85,11 @@ export function packageJsonContent({ "dependencies": { "@ant-design/cssinjs": "^1.16.2", "@ant-design/icons": "^5.2.6", - "@react-native-async-storage/async-storage": "^1.19.8", - "@react-native-masked-view/masked-view": "^0.3.0", - "@react-navigation/bottom-tabs": "^6.5.11", - "@react-navigation/native": "^6.1.9", - "@react-navigation/stack": "^6.3.20", + "@react-native-async-storage/async-storage": "^1.19.8", + "@react-native-masked-view/masked-view": "^0.3.0", + "@react-navigation/bottom-tabs": "^6.5.11", + "@react-navigation/native": "^6.1.9", + "@react-navigation/stack": "^6.3.20", "@wangeditor/basic-modules": "^1.1.3", "@wangeditor/editor": "^5.1.14", "@wangeditor/editor-for-react": "^1.0.4", diff --git a/template/src/context/BackendRuntimeContext.ts b/template/src/context/BackendRuntimeContext.ts index afb3dae..035afd7 100644 --- a/template/src/context/BackendRuntimeContext.ts +++ b/template/src/context/BackendRuntimeContext.ts @@ -12,10 +12,9 @@ export class BackendRuntimeContext const data = str && JSON.parse(str); return async ( - store: AsyncRowStore, - headers?: IncomingHttpHeaders + store: AsyncRowStore ) => { - const context = new BackendRuntimeContext(store, headers); + const context = new BackendRuntimeContext(store); await context.initialize(data); return context; }; diff --git a/template/src/context/FrontendRuntimeContext.ts b/template/src/context/FrontendRuntimeContext.ts index 3392fac..2749637 100644 --- a/template/src/context/FrontendRuntimeContext.ts +++ b/template/src/context/FrontendRuntimeContext.ts @@ -3,7 +3,7 @@ import { FrontendRuntimeContext as GeneralFrontendRuntimeContext, GeneralAspectDict, } from 'oak-general-business'; -import { CommonAspectDict } from 'oak-common-aspect'; +import { CommonAspectDict } from 'oak-common-aspect/lib/AspectDict'; import { RuntimeContext } from './RuntimeContext'; import { AspectDict } from '../aspects/AspectDict'; import { BackendRuntimeContext } from './BackendRuntimeContext'; diff --git a/template/src/features/Sample.ts b/template/src/features/Sample.ts index b4a9369..93566ab 100644 --- a/template/src/features/Sample.ts +++ b/template/src/features/Sample.ts @@ -1,6 +1,6 @@ import { EntityDict } from '@oak-app-domain'; import { BasicFeatures, Feature } from 'oak-frontend-base'; -import { CommonAspectDict } from 'oak-common-aspect'; +import { CommonAspectDict } from 'oak-common-aspect/lib/AspectDict'; import { AspectDict } from '../aspects/AspectDict'; import { BackendRuntimeContext } from '@project/context/BackendRuntimeContext'; import { FrontendRuntimeContext } from '@project/context/FrontendRuntimeContext'; diff --git a/template/src/features/index.ts b/template/src/features/index.ts index 7b1a667..5ef0de8 100644 --- a/template/src/features/index.ts +++ b/template/src/features/index.ts @@ -1,7 +1,7 @@ import { EntityDict } from '@oak-app-domain'; import { BasicFeatures } from 'oak-frontend-base'; import { GeneralFeatures, GeneralAspectDict } from 'oak-general-business'; -import { CommonAspectDict } from 'oak-common-aspect'; +import { CommonAspectDict } from 'oak-common-aspect/lib/AspectDict'; import { AspectDict } from '../aspects/AspectDict'; import { BackendRuntimeContext } from '../context/BackendRuntimeContext'; import { FrontendRuntimeContext } from '../context/FrontendRuntimeContext'; diff --git a/template/src/hooks/useFeatures.ts b/template/src/hooks/useFeatures.ts index ec8cd86..33613e9 100644 --- a/template/src/hooks/useFeatures.ts +++ b/template/src/hooks/useFeatures.ts @@ -1,4 +1,4 @@ -import { useFeatures as useCommonFeatures } from '@oak-frontend-base/platforms/web'; +import { useFeatures as useCommonFeatures } from 'oak-frontend-base/es/platforms/web'; import { AFD } from '@project/types/RuntimeCxt'; // react 独有 diff --git a/template/src/routines/start.ts b/template/src/routines/start.ts index 2fde19b..286de5d 100644 --- a/template/src/routines/start.ts +++ b/template/src/routines/start.ts @@ -3,12 +3,24 @@ import { EntityDict } from '@oak-app-domain'; import { BackendRuntimeContext } from '../context/BackendRuntimeContext'; -const startRoutines: Array> = [ +const startRoutines: Array> = [ { name: '示例性routine', - fn: async (context) => { + entity: 'extraFile', + filter: { + uploadState: 'uploading', + }, + projection: { + id: 1, + uploadMeta: 1, + uploadState: 1, + entity: 1, + entityId: 1, + objectId: 1, + }, + fn: async (context, data) => { console.log('示例性routine执行,请在src/routine/start.ts中关闭'); - return '示例性routine执行完成'; + return context.opResult; }, }, ]; diff --git a/template/src/timers/index.ts b/template/src/timers/index.ts index 1ca2d8b..eface0d 100644 --- a/template/src/timers/index.ts +++ b/template/src/timers/index.ts @@ -2,17 +2,29 @@ import { Timer } from 'oak-domain/lib/types/Timer'; import { EntityDict } from '@oak-app-domain'; import { BackendRuntimeContext } from '../context/BackendRuntimeContext'; -const timers: Array> = [ - // { - // name: '示例timer', - // cron: '30 * * * * *', - // fn: async (context) => { - // console.log( - // '这是示例timer程序,每30秒执行一次,请在src/timer/index中关闭' - // ); - // return '示例timer完成了'; - // }, - // }, +const timers: Array> = [ + { + name: '示例timer', + cron: '30 * * * * *', + entity: 'extraFile', + filter: { + uploadState: 'uploading', + }, + projection: { + id: 1, + uploadMeta: 1, + uploadState: 1, + entity: 1, + entityId: 1, + objectId: 1, + }, + fn: async (context, data) => { + console.log( + '这是示例timer程序,每30秒执行一次,请在src/timer/index中关闭' + ); + return context.opResult; + }, + }, ]; export default timers; diff --git a/template/web/src/AppContainer.tsx b/template/web/src/AppContainer.tsx index 7807826..30a6d59 100644 --- a/template/web/src/AppContainer.tsx +++ b/template/web/src/AppContainer.tsx @@ -1,7 +1,7 @@ import React, { lazy } from 'react'; -const Message = lazy(() => import('@oak-general-business/components/message')); +const Message = lazy(() => import('oak-general-business/es/components/message')); const DebugPanel = lazy( - () => import('@oak-general-business/components/func/debugPanel') + () => import('oak-general-business/es/components/func/debugPanel') ); type AppContainerProps = { diff --git a/template/web/src/AppError.tsx b/template/web/src/AppError.tsx index 8f3dce1..9e32dcc 100644 --- a/template/web/src/AppError.tsx +++ b/template/web/src/AppError.tsx @@ -8,9 +8,9 @@ import { OakServerProxyException, } from 'oak-domain/lib/types/Exception'; import { OakTokenExpiredException } from 'oak-general-business'; -import { ECode } from '@oak-general-business/types/ErrorPage'; +import { ECode } from 'oak-general-business/es/types/ErrorPage'; const ErrorPage = lazy( - () => import('@oak-general-business/components/common/errorPage') + () => import('oak-general-business/es/components/common/errorPage') ); interface ErrorProps { diff --git a/template/web/src/index.tsx b/template/web/src/index.tsx index d768c05..6b5cbe8 100644 --- a/template/web/src/index.tsx +++ b/template/web/src/index.tsx @@ -15,7 +15,7 @@ import zhCN from 'antd/locale/zh_CN'; import { ResponsiveProvider, FeaturesProvider, -} from '@oak-frontend-base/platforms/web'; +} from 'oak-frontend-base/es/platforms/web'; import './index.less'; import App from './App'; import reportWebVitals from './reportWebVitals';