-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbarrelFlow.ts
executable file
·50 lines (42 loc) · 1.68 KB
/
barrelFlow.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import localization from "../../../localization";
import BarrelType from "../../../common/domain/barrel/BarrelType";
import * as configUtil from "../../config/util/configUtil";
import { showInEditor } from "../../../common/vscode/editor/editorUtil";
import { selectAndValidateConfig } from "../../common/flow/commonFlow";
import MessageBuilder from "../../../common/vscode/message/MessageBuilder";
import MessageType from "../../../common/vscode/message/MessageType";
import { pickBarrel } from "../../../common/domain/barrel/flow/barrelFlow";
function startAddProjectFlow() {
return startAddBarrelFlow(BarrelType.Project);
}
function startAddStyleguideFlow() {
return startAddBarrelFlow(BarrelType.Styleguide);
}
async function startAddBarrelFlow(type: BarrelType) {
const title = localization.common.barrel.add(type);
// Validate login and select config, fail if a modifiable config is not selected
const configPath = await selectAndValidateConfig(title);
if (!configPath) {
return;
}
// Picker barrel
const barrel = await pickBarrel(title, type);
// Fail if no barrel is selected
if (!barrel) {
return;
}
// Fail if config contains barrel
if (configUtil.containsBarrel(configPath, barrel)) {
MessageBuilder.with(localization.common.barrel.alreadyAdded(type)).show();
showInEditor(configPath, { text: barrel.id });
return;
}
// Add barrel
configUtil.addBarrel(configPath, barrel);
MessageBuilder.with(localization.coco.barrel.added(type)).setType(MessageType.Info).show();
showInEditor(configPath, { text: barrel.id, onAdd: true });
}
export {
startAddProjectFlow,
startAddStyleguideFlow
};