2021-02-14 18:09:20 +00:00
|
|
|
import { identity } from 'lodash';
|
2018-03-20 14:12:48 +00:00
|
|
|
import Vue from 'vue';
|
2018-05-29 10:06:00 +00:00
|
|
|
import { mapActions } from 'vuex';
|
2021-06-15 00:10:11 +00:00
|
|
|
import { DEFAULT_BRANCH } from '~/ide/constants';
|
2020-11-18 18:09:08 +00:00
|
|
|
import PerformancePlugin from '~/performance/vue_performance_plugin';
|
2021-02-14 18:09:20 +00:00
|
|
|
import Translate from '~/vue_shared/translate';
|
2021-02-01 15:08:56 +00:00
|
|
|
import { parseBoolean } from '../lib/utils/common_utils';
|
|
|
|
import { resetServiceWorkersPublicPath } from '../lib/utils/webpack';
|
2018-03-20 14:12:48 +00:00
|
|
|
import ide from './components/ide.vue';
|
2020-06-05 00:08:38 +00:00
|
|
|
import { createRouter } from './ide_router';
|
2020-02-15 21:08:49 +00:00
|
|
|
import { DEFAULT_THEME } from './lib/themes';
|
2021-02-14 18:09:20 +00:00
|
|
|
import { createStore } from './stores';
|
2018-03-20 14:12:48 +00:00
|
|
|
|
2018-05-03 16:16:56 +00:00
|
|
|
Vue.use(Translate);
|
|
|
|
|
2020-11-18 18:09:08 +00:00
|
|
|
Vue.use(PerformancePlugin, {
|
|
|
|
components: ['FileTree'],
|
|
|
|
});
|
|
|
|
|
2019-01-14 21:46:21 +00:00
|
|
|
/**
|
|
|
|
* Function that receives the default store and returns an extended one.
|
|
|
|
* @callback extendStoreCallback
|
|
|
|
* @param {Vuex.Store} store
|
|
|
|
* @param {Element} el
|
|
|
|
*/
|
|
|
|
|
2018-09-24 21:37:04 +00:00
|
|
|
/**
|
|
|
|
* Initialize the IDE on the given element.
|
|
|
|
*
|
|
|
|
* @param {Element} el - The element that will contain the IDE.
|
|
|
|
* @param {Object} options - Extra options for the IDE (Used by EE).
|
2018-09-27 03:59:02 +00:00
|
|
|
* @param {Component} options.rootComponent -
|
|
|
|
* Component that overrides the root component.
|
2019-01-14 21:46:21 +00:00
|
|
|
* @param {extendStoreCallback} options.extendStore -
|
2018-12-03 18:00:03 +00:00
|
|
|
* Function that receives the default store and returns an extended one.
|
2018-09-24 21:37:04 +00:00
|
|
|
*/
|
2021-12-15 21:11:32 +00:00
|
|
|
export const initIde = (el, options = {}) => {
|
2018-03-20 14:12:48 +00:00
|
|
|
if (!el) return null;
|
|
|
|
|
2020-03-24 18:07:55 +00:00
|
|
|
const { rootComponent = ide, extendStore = identity } = options;
|
2021-12-15 21:11:32 +00:00
|
|
|
|
2020-07-21 09:09:34 +00:00
|
|
|
const store = createStore();
|
2021-12-15 21:11:32 +00:00
|
|
|
const project = JSON.parse(el.dataset.project);
|
|
|
|
store.dispatch('setProject', { project });
|
|
|
|
|
|
|
|
// fire and forget fetching non-critical project info
|
|
|
|
store.dispatch('fetchProjectPermissions');
|
|
|
|
|
2021-06-15 00:10:11 +00:00
|
|
|
const router = createRouter(store, el.dataset.defaultBranch || DEFAULT_BRANCH);
|
2018-09-24 21:37:04 +00:00
|
|
|
|
2018-03-20 14:12:48 +00:00
|
|
|
return new Vue({
|
|
|
|
el,
|
2018-12-03 18:00:03 +00:00
|
|
|
store: extendStore(store, el),
|
2018-03-20 14:12:48 +00:00
|
|
|
router,
|
2018-04-16 15:29:34 +00:00
|
|
|
created() {
|
2018-05-29 10:06:00 +00:00
|
|
|
this.setEmptyStateSvgs({
|
2018-04-16 15:29:34 +00:00
|
|
|
emptyStateSvgPath: el.dataset.emptyStateSvgPath,
|
|
|
|
noChangesStateSvgPath: el.dataset.noChangesStateSvgPath,
|
|
|
|
committedStateSvgPath: el.dataset.committedStateSvgPath,
|
2018-05-29 09:35:13 +00:00
|
|
|
pipelinesEmptyStateSvgPath: el.dataset.pipelinesEmptyStateSvgPath,
|
2018-06-13 16:06:35 +00:00
|
|
|
promotionSvgPath: el.dataset.promotionSvgPath,
|
2018-04-16 15:29:34 +00:00
|
|
|
});
|
2018-05-29 10:06:00 +00:00
|
|
|
this.setLinks({
|
2018-06-13 16:06:35 +00:00
|
|
|
webIDEHelpPagePath: el.dataset.webIdeHelpPagePath,
|
2021-03-23 00:09:09 +00:00
|
|
|
forkInfo: el.dataset.forkInfo ? JSON.parse(el.dataset.forkInfo) : null,
|
2018-06-13 16:06:35 +00:00
|
|
|
});
|
2021-05-07 21:10:34 +00:00
|
|
|
this.init({
|
2018-11-21 15:13:04 +00:00
|
|
|
clientsidePreviewEnabled: parseBoolean(el.dataset.clientsidePreviewEnabled),
|
2020-01-06 15:07:26 +00:00
|
|
|
renderWhitespaceInCode: parseBoolean(el.dataset.renderWhitespaceInCode),
|
2020-02-15 21:08:49 +00:00
|
|
|
editorTheme: window.gon?.user_color_scheme || DEFAULT_THEME,
|
2020-03-12 21:09:45 +00:00
|
|
|
codesandboxBundlerUrl: el.dataset.codesandboxBundlerUrl,
|
2021-05-07 21:10:34 +00:00
|
|
|
environmentsGuidanceAlertDismissed: !parseBoolean(el.dataset.enableEnvironmentsGuidance),
|
2021-08-24 15:10:36 +00:00
|
|
|
previewMarkdownPath: el.dataset.previewMarkdownPath,
|
2018-05-29 10:06:00 +00:00
|
|
|
});
|
|
|
|
},
|
2021-01-14 03:10:47 +00:00
|
|
|
beforeDestroy() {
|
|
|
|
// This helps tests do Singleton cleanups which we don't really have responsibility to know about here.
|
|
|
|
this.$emit('destroy');
|
|
|
|
},
|
2018-05-29 10:06:00 +00:00
|
|
|
methods: {
|
2021-05-07 21:10:34 +00:00
|
|
|
...mapActions(['setEmptyStateSvgs', 'setLinks', 'init']),
|
2018-04-16 15:29:34 +00:00
|
|
|
},
|
2018-03-20 14:12:48 +00:00
|
|
|
render(createElement) {
|
2018-09-27 03:59:02 +00:00
|
|
|
return createElement(rootComponent);
|
2018-03-20 14:12:48 +00:00
|
|
|
},
|
|
|
|
});
|
2021-12-15 21:11:32 +00:00
|
|
|
};
|
2018-03-20 14:12:48 +00:00
|
|
|
|
2018-09-24 21:37:04 +00:00
|
|
|
/**
|
|
|
|
* Start the IDE.
|
|
|
|
*
|
|
|
|
* @param {Objects} options - Extra options for the IDE (Used by EE).
|
|
|
|
*/
|
|
|
|
export function startIde(options) {
|
2020-10-19 12:09:20 +00:00
|
|
|
const ideElement = document.getElementById('ide');
|
|
|
|
if (ideElement) {
|
|
|
|
resetServiceWorkersPublicPath();
|
|
|
|
initIde(ideElement, options);
|
|
|
|
}
|
2018-09-24 21:37:04 +00:00
|
|
|
}
|