Skip to content

Commit dcbeb37

Browse files
author
Yang Zhen
committed
Add build workstation
1 parent d8c953c commit dcbeb37

File tree

13 files changed

+818
-6
lines changed

13 files changed

+818
-6
lines changed

app/styles/lib.styl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@import 'normalize';
2+
@import 'ui-variables';
3+
@import "mixins";
4+
@import 'scaffolding';
5+
6+
@import "core-ui"
7+
8+
.hidden {display: none !important;}
9+
10+
.ide-container {
11+
width: 100%;
12+
height: 100%;
13+
display: flex;
14+
flex-direction: column;
15+
align-items: stretch;
16+
}
17+
18+
.utilities-container {
19+
isolation: isolate;
20+
z-index: z(utilities-container);
21+
}

app/workstation/api.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { request } from '../utils'
2+
import config from '../config'
3+
4+
export function findSpaceKey({ ownerName, projectName }) {
5+
return request.get(`/ws/find/coding/${ownerName}/${projectName}`, null,
6+
{ headers: { Accept: '*/*' } }
7+
).then(res => res.data);
8+
}
9+
10+
export function getDefaultWorkspace() {
11+
return request.get('/workspaces?default');
12+
}
13+
14+
export function setupWorkspace() {
15+
return request.post(`/workspaces/${config.spaceKey}`).catch(err => err.response.data);
16+
}
17+
18+
export function setupWorkspace2() {
19+
return request.post(`/workspaces/${config.spaceKey}`).catch(err => err.response.data);
20+
}
21+
22+
export function getUserProfile() {
23+
// @fixme: initialize2 requires removing .then(res => res.data)
24+
return request.get('/user/current', null,
25+
{ headers: { Accept: '*/*' } }
26+
).then(res => res);
27+
}
28+
29+
export function fetchRequestState() {
30+
return request.get(`/workspaces/${config.spaceKey}/collaborator/request`);
31+
}
32+
33+
// Switch back to old version
34+
export function switchVersion() {
35+
return request.put('/versions')
36+
.then((res) => {
37+
window.location.reload();
38+
});
39+
}
40+
41+
export function fetchProjectType() {
42+
return request.get(`/ws/${config.spaceKey}/type`)
43+
.then((res) => {
44+
config.estimatedMap.replace(res);
45+
});
46+
}
47+
48+
export function getWorkspaceList() {
49+
return request.get('/workspaces?page=0&size=5&sort=lastModifiedDate,desc');
50+
}
51+
52+
export function getHardwares() {
53+
return request.get('/workspaces/hardwares');
54+
}
55+
56+
export function postAdjust(options) {
57+
return request.post(`/workspaces/${config.spaceKey}/adjust`, options);
58+
}
59+
60+
export function getStaticServingToken() {
61+
return request.get(`/workspaces/${config.spaceKey}/static_serving_token`);
62+
}

app/workstation/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import WorkStation from './workstation'
2+
3+
4+
export default WorkStation

app/workstation/initialize.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/* eslint-disable no-await-in-loop */
2+
import React from 'react'
3+
import { isFunction, isBoolean, isString } from 'utils/is'
4+
import config from '../config'
5+
import api from '../backendAPI'
6+
import { stepFactory } from '../utils'
7+
import i18n from 'utils/createI18n'
8+
import { loadPackagesByType, mountPackagesByType } from '../components/Plugins/actions'
9+
import CodingSDK from '../CodingSDK'
10+
import state from './state'
11+
import { persistTask } from '../mobxStore'
12+
13+
function closestTo (arr, key, isPrev) {
14+
const offsetIndex = isPrev ? -1 : 1
15+
const current = arr.indexOf(key)
16+
return arr[current + offsetIndex]
17+
}
18+
19+
function checkEnable (enable) {
20+
if (enable === undefined) {
21+
return true
22+
}
23+
if (isFunction(enable)) {
24+
return enable(config)
25+
}
26+
return Boolean(enable)
27+
}
28+
29+
async function initialize () {
30+
const step = stepFactory()
31+
let stepNum = 2
32+
await step('[0] prepare data', async () => {
33+
window.CodingSDK = CodingSDK
34+
window.React = React
35+
window.i18n = i18n
36+
window.extension = f => null
37+
window.refs = {}
38+
window.config = config
39+
return true
40+
})
41+
42+
// await step('[1] load required package', async() => {
43+
// try {
44+
// await loadPackagesByType('Required', state, true)
45+
// } catch (err) {
46+
// return true
47+
// }
48+
// return true
49+
// })
50+
51+
await step('=== Run steps in stepCache ===', async() => {
52+
/*async function goto (key, hasNext = true) {
53+
if (!hasNext) {
54+
return true
55+
}
56+
const nextKey = await step(`[${stepNum++}] ${state.get(key).desc}`, state.get(key).func)
57+
if (nextKey === undefined || isBoolean(nextKey)) {
58+
const next = closestTo(state.keys(), key)
59+
return nextKey && goto(next, !!next)
60+
}
61+
if (isString(nextKey)) {
62+
return goto(nextKey)
63+
}
64+
}
65+
return goto(state.keys()[0])*/
66+
for (const value of state.values()) {
67+
console.log('== value ==', value.desc)
68+
if (checkEnable(value.enable)) {
69+
await step(`[${stepNum++}] ${value.desc}`, value.func)
70+
}
71+
}
72+
console.log('=== End running stepCache ===')
73+
return true
74+
})
75+
76+
77+
await step(`[${stepNum++}] mount required package`, () => {
78+
mountPackagesByType('Required')
79+
return true
80+
})
81+
82+
await step(`[${stepNum++}] persist Store`, () => {
83+
persistTask()
84+
return true
85+
})
86+
87+
if (config.packageDev) {
88+
await step(`[${stepNum++}] enable package server hotreload`,
89+
() => {
90+
const ports = __PACKAGE_PORTS__
91+
if (ports && ports.length) {
92+
ports.forEach((port) => {
93+
const url = `http://ide.test:${port}`
94+
api.enablePackageHotReload(url)
95+
})
96+
} else {
97+
api.enablePackageHotReload()
98+
}
99+
return true
100+
})
101+
}
102+
103+
return step
104+
}
105+
106+
export default initialize

0 commit comments

Comments
 (0)