规范了initialize时的行为
This commit is contained in:
parent
8571458e97
commit
747c40eabe
|
|
@ -2,4 +2,4 @@
|
||||||
import { EntityDict } from 'oak-domain/lib/types';
|
import { EntityDict } from 'oak-domain/lib/types';
|
||||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||||
import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';
|
import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';
|
||||||
export declare function initialize<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>>(path: string): Promise<void>;
|
export declare function initialize<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>>(path: string, ifExists?: 'drop' | 'omit' | 'dropIfNotStatic'): Promise<void>;
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.initialize = void 0;
|
exports.initialize = void 0;
|
||||||
/// <reference path="../typings/polyfill.d.ts" />
|
/// <reference path="../typings/polyfill.d.ts" />
|
||||||
const oak_backend_base_1 = require("oak-backend-base");
|
const oak_backend_base_1 = require("oak-backend-base");
|
||||||
async function initialize(path) {
|
async function initialize(path, ifExists) {
|
||||||
const appLoader = new oak_backend_base_1.AppLoader(path);
|
const appLoader = new oak_backend_base_1.AppLoader(path);
|
||||||
await appLoader.mount(true);
|
await appLoader.mount(true);
|
||||||
await appLoader.initialize();
|
await appLoader.initialize(ifExists);
|
||||||
await appLoader.unmount();
|
await appLoader.unmount();
|
||||||
console.log('data initialized');
|
console.log('data initialized');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@ import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRunt
|
||||||
export async function initialize<
|
export async function initialize<
|
||||||
ED extends EntityDict & BaseEntityDict,
|
ED extends EntityDict & BaseEntityDict,
|
||||||
Cxt extends BackendRuntimeContext<ED>
|
Cxt extends BackendRuntimeContext<ED>
|
||||||
>(path: string) {
|
>(path: string, ifExists?: 'drop' | 'omit' | 'dropIfNotStatic') {
|
||||||
const appLoader = new AppLoader(path);
|
const appLoader = new AppLoader(path);
|
||||||
await appLoader.mount(true);
|
await appLoader.mount(true);
|
||||||
await appLoader.initialize();
|
await appLoader.initialize(ifExists);
|
||||||
await appLoader.unmount();
|
await appLoader.unmount();
|
||||||
console.log('data initialized');
|
console.log('data initialized');
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
const { initialize } = require('@xuchangzju/oak-cli/lib/server/initialize');
|
const { initialize } = require('@xuchangzju/oak-cli/lib/server/initialize');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
const pwd = process.cwd();
|
const pwd = process.cwd();
|
||||||
|
|
||||||
const dropIfExists = process.argv[2];
|
const ifExists = process.argv[2];
|
||||||
// console.log(dropIfExists);
|
assert(['drop' , 'omit' , 'dropIfNotStatic'].includes(ifExists), "第二个参数只能是'drop' | 'omit' | 'dropIfNotStatic'");
|
||||||
|
|
||||||
initialize(
|
initialize(
|
||||||
pwd,
|
pwd,
|
||||||
!!dropIfExists
|
ifExists
|
||||||
).then(() => process.exit(0));
|
).then(() => process.exit(0));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue