2018-06-26 11:50:13 -04:00
|
|
|
import * as pathUtils from 'path';
|
2018-03-20 10:16:38 -04:00
|
|
|
import { decorateData } from '~/ide/stores/utils';
|
|
|
|
import state from '~/ide/stores/state';
|
|
|
|
import commitState from '~/ide/stores/modules/commit/state';
|
2018-05-11 06:36:34 -04:00
|
|
|
import mergeRequestsState from '~/ide/stores/modules/merge_requests/state';
|
2018-05-29 08:09:19 -04:00
|
|
|
import pipelinesState from '~/ide/stores/modules/pipelines/state';
|
2018-08-07 11:15:56 -04:00
|
|
|
import branchesState from '~/ide/stores/modules/branches/state';
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2018-03-20 10:16:38 -04:00
|
|
|
export const resetStore = store => {
|
2018-03-20 10:12:48 -04:00
|
|
|
const newState = {
|
|
|
|
...state(),
|
|
|
|
commit: commitState(),
|
2018-05-11 06:36:34 -04:00
|
|
|
mergeRequests: mergeRequestsState(),
|
2018-05-29 08:09:19 -04:00
|
|
|
pipelines: pipelinesState(),
|
2018-08-07 11:15:56 -04:00
|
|
|
branches: branchesState(),
|
2018-03-20 10:12:48 -04:00
|
|
|
};
|
|
|
|
store.replaceState(newState);
|
|
|
|
};
|
|
|
|
|
2018-06-26 11:50:13 -04:00
|
|
|
export const file = (name = 'name', id = name, type = '', parent = null) =>
|
2018-03-20 10:16:38 -04:00
|
|
|
decorateData({
|
|
|
|
id,
|
|
|
|
type,
|
|
|
|
icon: 'icon',
|
|
|
|
url: 'url',
|
|
|
|
name,
|
2018-06-26 11:50:13 -04:00
|
|
|
path: parent ? `${parent.path}/${name}` : name,
|
|
|
|
parentPath: parent ? parent.path : '',
|
2018-03-20 10:16:38 -04:00
|
|
|
lastCommit: {},
|
|
|
|
});
|
2018-06-26 11:50:13 -04:00
|
|
|
|
2018-06-26 12:18:56 -04:00
|
|
|
export const createEntriesFromPaths = paths =>
|
2018-06-26 11:50:13 -04:00
|
|
|
paths
|
|
|
|
.map(path => ({
|
|
|
|
name: pathUtils.basename(path),
|
|
|
|
dir: pathUtils.dirname(path),
|
|
|
|
ext: pathUtils.extname(path),
|
|
|
|
}))
|
|
|
|
.reduce((entries, path, idx) => {
|
2018-06-26 12:18:56 -04:00
|
|
|
const { name } = path;
|
2018-06-26 11:50:13 -04:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
}, {});
|