"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get shell () {
        return shell;
    },
    get shellCommand () {
        return shellCommand;
    }
});
const _repl = /*#__PURE__*/ _interop_require_default(require("repl"));
const _os = require("os");
const _path = require("path");
const _commander = require("commander");
const _logging = require("@tamanu/shared/services/logging");
const _ApplicationContext = require("../ApplicationContext");
const _packagejson = /*#__PURE__*/ _interop_require_default(require("../../package.json"));
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const shell = async ({ skipMigrationCheck })=>{
    _logging.log.info(`Starting shell in Central Server ${_packagejson.default.version}!`);
    const context = await new _ApplicationContext.ApplicationContext().init();
    const { store } = context;
    await store.sequelize.assertUpToDate({
        skipMigrationCheck
    });
    const replServer = await new Promise((resolve, reject)=>{
        _repl.default.start().setupHistory((0, _path.join)((0, _os.homedir)(), '.tamanu_repl_history'), (err, srv)=>{
            if (err) reject(err);
            else resolve(srv);
        });
    });
    Object.assign(replServer.context, {
        context,
        store,
        models: store.models
    });
    return new Promise((resolve)=>{
        replServer.on('exit', ()=>resolve());
    });
};
const shellCommand = new _commander.Command('shell').description('Start a Node.js shell').action(shell);

//# sourceMappingURL=shell.js.map