setup-crowi.js 590 B

1234567891011121314151617181920212223242526272829303132
  1. const helpers = require('@commons/util/helpers');
  2. const Crowi = require('@server/crowi');
  3. let _instance = null;
  4. async function createInstance() {
  5. const crowi = new Crowi(helpers.root());
  6. await crowi.initForTest();
  7. // init DB
  8. const appService = crowi.appService;
  9. await appService.initDB();
  10. return crowi;
  11. }
  12. async function getInstance(isNewInstance) {
  13. if (isNewInstance) {
  14. return createInstance();
  15. }
  16. // initialize singleton instance
  17. if (_instance == null) {
  18. _instance = await createInstance();
  19. }
  20. return _instance;
  21. }
  22. module.exports = {
  23. getInstance,
  24. };