2021-02-14 13:09:20 -05:00
|
|
|
import { identity } from 'lodash';
|
2018-03-20 10:12:48 -04:00
|
|
|
import Vue from 'vue';
|
2018-05-29 06:06:00 -04:00
|
|
|
import { mapActions } from 'vuex';
|
2021-06-14 20:10:11 -04:00
|
|
|
import { DEFAULT_BRANCH } from '~/ide/constants';
|
2020-11-18 13:09:08 -05:00
|
|
|
import PerformancePlugin from '~/performance/vue_performance_plugin';
|
2021-02-14 13:09:20 -05:00
|
|
|
import Translate from '~/vue_shared/translate';
|
2021-02-01 10:08:56 -05:00
|
|
|
import { parseBoolean } from '../lib/utils/common_utils';
|
|
|
|
import { resetServiceWorkersPublicPath } from '../lib/utils/webpack';
|
2018-03-20 10:12:48 -04:00
|
|
|
import ide from './components/ide.vue';
|
2020-06-04 20:08:38 -04:00
|
|
|
import { createRouter } from './ide_router';
|
2020-02-15 16:08:49 -05:00
|
|
|
import { DEFAULT_THEME } from './lib/themes';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { createStore } from './stores';
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2018-05-03 12:16:56 -04:00
|
|
|
Vue.use(Translate);
|
|
|
|
|
2020-11-18 13:09:08 -05:00
|
|
|
Vue.use(PerformancePlugin, {
|
|
|
|
components: ['FileTree'],
|
|
|
|
});
|
|
|
|
|
2019-01-14 16:46:21 -05:00
|
|
|
/**
|
|
|
|
* Function that receives the default store and returns an extended one.
|
|
|
|
* @callback extendStoreCallback
|
|
|
|
* @param {Vuex.Store} store
|
|
|
|
* @param {Element} el
|
|
|
|
*/
|
|
|
|
|
2018-09-24 17:37:04 -04: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-26 23:59:02 -04:00
|
|
|
* @param {Component} options.rootComponent -
|
|
|
|
* Component that overrides the root component.
|
2019-01-14 16:46:21 -05:00
|
|
|
* @param {extendStoreCallback} options.extendStore -
|
2018-12-03 13:00:03 -05:00
|
|
|
* Function that receives the default store and returns an extended one.
|
2018-09-24 17:37:04 -04:00
|
|
|
*/
|
2021-12-15 16:11:32 -05:00
|
|
|
export const initIde = (el, options = {}) => {
|
2018-03-20 10:12:48 -04:00
|
|
|
if (!el) return null;
|
|
|
|
|
2020-03-24 14:07:55 -04:00
|
|
|
const { rootComponent = ide, extendStore = identity } = options;
|
2021-12-15 16:11:32 -05:00
|
|
|
|
2020-07-21 05:09:34 -04:00
|
|
|
const store = createStore();
|
2021-12-15 16:11:32 -05: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-14 20:10:11 -04:00
|
|
|
const router = createRouter(store, el.dataset.defaultBranch || DEFAULT_BRANCH);
|
2018-09-24 17:37:04 -04:00
|
|
|
|
2018-03-20 10:12:48 -04:00
|
|
|
return new Vue({
|
|
|
|
el,
|
2018-12-03 13:00:03 -05:00
|
|
|
store: extendStore(store, el),
|
2018-03-20 10:12:48 -04:00
|
|
|
router,
|
2018-04-16 11:29:34 -04:00
|
|
|
created() {
|
2018-05-29 06:06:00 -04:00
|
|
|
this.setEmptyStateSvgs({
|
2018-04-16 11:29:34 -04:00
|
|
|
emptyStateSvgPath: el.dataset.emptyStateSvgPath,
|
|
|
|
noChangesStateSvgPath: el.dataset.noChangesStateSvgPath,
|
|
|
|
committedStateSvgPath: el.dataset.committedStateSvgPath,
|
2018-05-29 05:35:13 -04:00
|
|
|
pipelinesEmptyStateSvgPath: el.dataset.pipelinesEmptyStateSvgPath,
|
2018-06-13 12:06:35 -04:00
|
|
|
promotionSvgPath: el.dataset.promotionSvgPath,
|
2018-04-16 11:29:34 -04:00
|
|
|
});
|
2018-05-29 06:06:00 -04:00
|
|
|
this.setLinks({
|
2018-06-13 12:06:35 -04:00
|
|
|
webIDEHelpPagePath: el.dataset.webIdeHelpPagePath,
|
2021-03-22 20:09:09 -04:00
|
|
|
forkInfo: el.dataset.forkInfo ? JSON.parse(el.dataset.forkInfo) : null,
|
2018-06-13 12:06:35 -04:00
|
|
|
});
|
2021-05-07 17:10:34 -04:00
|
|
|
this.init({
|
2018-11-21 10:13:04 -05:00
|
|
|
clientsidePreviewEnabled: parseBoolean(el.dataset.clientsidePreviewEnabled),
|
2020-01-06 10:07:26 -05:00
|
|
|
renderWhitespaceInCode: parseBoolean(el.dataset.renderWhitespaceInCode),
|
2020-02-15 16:08:49 -05:00
|
|
|
editorTheme: window.gon?.user_color_scheme || DEFAULT_THEME,
|
2020-03-12 17:09:45 -04:00
|
|
|
codesandboxBundlerUrl: el.dataset.codesandboxBundlerUrl,
|
2021-05-07 17:10:34 -04:00
|
|
|
environmentsGuidanceAlertDismissed: !parseBoolean(el.dataset.enableEnvironmentsGuidance),
|
2021-08-24 11:10:36 -04:00
|
|
|
previewMarkdownPath: el.dataset.previewMarkdownPath,
|
2018-05-29 06:06:00 -04:00
|
|
|
});
|
|
|
|
},
|
2021-01-13 22:10:47 -05: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 06:06:00 -04:00
|
|
|
methods: {
|
2021-05-07 17:10:34 -04:00
|
|
|
...mapActions(['setEmptyStateSvgs', 'setLinks', 'init']),
|
2018-04-16 11:29:34 -04:00
|
|
|
},
|
2018-03-20 10:12:48 -04:00
|
|
|
render(createElement) {
|
2018-09-26 23:59:02 -04:00
|
|
|
return createElement(rootComponent);
|
2018-03-20 10:12:48 -04:00
|
|
|
},
|
|
|
|
});
|
2021-12-15 16:11:32 -05:00
|
|
|
};
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2018-09-24 17:37:04 -04:00
|
|
|
/**
|
|
|
|
* Start the IDE.
|
|
|
|
*
|
|
|
|
* @param {Objects} options - Extra options for the IDE (Used by EE).
|
|
|
|
*/
|
|
|
|
export function startIde(options) {
|
2020-10-19 08:09:20 -04:00
|
|
|
const ideElement = document.getElementById('ide');
|
|
|
|
if (ideElement) {
|
|
|
|
resetServiceWorkersPublicPath();
|
|
|
|
initIde(ideElement, options);
|
|
|
|
}
|
2018-09-24 17:37:04 -04:00
|
|
|
}
|