2018-11-08 19:23:39 +05:30
|
|
|
import * as pathUtils from 'path';
|
2018-05-09 12:01:36 +05:30
|
|
|
import { decorateData } from '~/ide/stores/utils';
|
|
|
|
import state from '~/ide/stores/state';
|
|
|
|
import commitState from '~/ide/stores/modules/commit/state';
|
2018-11-08 19:23:39 +05:30
|
|
|
import mergeRequestsState from '~/ide/stores/modules/merge_requests/state';
|
|
|
|
import pipelinesState from '~/ide/stores/modules/pipelines/state';
|
2018-11-18 11:00:15 +05:30
|
|
|
import branchesState from '~/ide/stores/modules/branches/state';
|
2018-11-20 20:47:30 +05:30
|
|
|
import fileTemplatesState from '~/ide/stores/modules/file_templates/state';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
export const resetStore = store => {
|
|
|
|
const newState = {
|
|
|
|
...state(),
|
|
|
|
commit: commitState(),
|
2018-11-08 19:23:39 +05:30
|
|
|
mergeRequests: mergeRequestsState(),
|
|
|
|
pipelines: pipelinesState(),
|
2018-11-18 11:00:15 +05:30
|
|
|
branches: branchesState(),
|
2018-11-20 20:47:30 +05:30
|
|
|
fileTemplates: fileTemplatesState(),
|
2018-05-09 12:01:36 +05:30
|
|
|
};
|
|
|
|
store.replaceState(newState);
|
|
|
|
};
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
export const file = (name = 'name', id = name, type = '', parent = null) =>
|
2018-05-09 12:01:36 +05:30
|
|
|
decorateData({
|
|
|
|
id,
|
|
|
|
type,
|
|
|
|
icon: 'icon',
|
|
|
|
url: 'url',
|
|
|
|
name,
|
2018-11-08 19:23:39 +05:30
|
|
|
path: parent ? `${parent.path}/${name}` : name,
|
|
|
|
parentPath: parent ? parent.path : '',
|
2018-05-09 12:01:36 +05:30
|
|
|
lastCommit: {},
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
export const createEntriesFromPaths = paths =>
|
|
|
|
paths
|
|
|
|
.map(path => ({
|
|
|
|
name: pathUtils.basename(path),
|
|
|
|
dir: pathUtils.dirname(path),
|
|
|
|
ext: pathUtils.extname(path),
|
|
|
|
}))
|
|
|
|
.reduce((entries, path, idx) => {
|
|
|
|
const { name } = path;
|
|
|
|
const parent = path.dir ? entries[path.dir] : null;
|
|
|
|
const type = path.ext ? 'blob' : 'tree';
|
|
|
|
|
|
|
|
const entry = file(name, (idx + 1).toString(), type, parent);
|
|
|
|
|
|
|
|
return {
|
|
|
|
[entry.path]: entry,
|
|
|
|
...entries,
|
|
|
|
};
|
|
|
|
}, {});
|