repl.ts 846 B

1234567891011121314151617181920212223242526272829303132333435
  1. import type { REPLServer } from 'node:repl';
  2. import repl from 'node:repl';
  3. import mongoose from 'mongoose';
  4. import { getMongoUri, mongoOptions } from '~/server/util/mongoose-utils';
  5. import Crowi from './crowi';
  6. const setupMongoose = async (replServer: REPLServer) => {
  7. mongoose.Promise = global.Promise;
  8. await mongoose.connect(getMongoUri(), mongoOptions).then(() => {
  9. replServer.context.db = mongoose.connection.db;
  10. });
  11. replServer.context.mongoose = mongoose;
  12. };
  13. const setupCrowi = async (replServer: REPLServer) => {
  14. const crowi = new Crowi();
  15. await crowi.init();
  16. replServer.context.crowi = crowi;
  17. };
  18. const start = async () => {
  19. const replServer = repl.start({
  20. prompt: `${process.env.NODE_ENV} > `,
  21. ignoreUndefined: true,
  22. });
  23. await setupMongoose(replServer);
  24. await setupCrowi(replServer);
  25. };
  26. start();