repl.ts 855 B

123456789101112131415161718192021222324252627282930313233343536373839
  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)
  9. .then(() => {
  10. replServer.context.db = mongoose.connection.db;
  11. });
  12. replServer.context.mongoose = mongoose;
  13. };
  14. const setupCrowi = async(replServer: REPLServer) => {
  15. const crowi = new Crowi();
  16. await crowi.init();
  17. replServer.context.crowi = crowi;
  18. };
  19. const start = async() => {
  20. const replServer = repl.start({
  21. prompt: `${process.env.NODE_ENV} > `,
  22. ignoreUndefined: true,
  23. });
  24. await setupMongoose(replServer);
  25. await setupCrowi(replServer);
  26. };
  27. start();