@teambit/workspace 0.0.551 → 0.0.556
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build-graph-from-fs.d.ts +30 -0
- package/dist/install.cmd.d.ts +17 -3
- package/dist/install.cmd.js.map +1 -1
- package/dist/link/link.cmd.d.ts +15 -1
- package/dist/types.d.ts +21 -0
- package/dist/ui/workspace/workspace-model.d.ts +32 -1
- package/dist/ui/workspace/workspace-provider.d.ts +9 -0
- package/dist/ui/workspace/workspace.d.ts +3 -0
- package/dist/watch/output-formatter.d.ts +6 -0
- package/dist/watch/watch.cmd.d.ts +22 -1
- package/dist/watch/watcher.d.ts +9 -0
- package/dist/workspace-component/component-status.d.ts +57 -1
- package/dist/workspace-component/workspace-component-loader.d.ts +7 -0
- package/dist/workspace-component/workspace-component.d.ts +36 -1
- package/dist/workspace.d.ts +236 -3
- package/dist/workspace.js +37 -5
- package/dist/workspace.js.map +1 -1
- package/dist/workspace.ui-root.d.ts +18 -1
- package/dist/workspace.ui.runtime.d.ts +32 -1
- package/package.json +58 -50
- package/build-graph-from-fs.ts +0 -160
- package/capsule.cmd.ts +0 -136
- package/component-config-file/component-config-file.ts +0 -98
- package/component-config-file/exceptions/already-exists.ts +0 -7
- package/component-config-file/exceptions/index.ts +0 -1
- package/component-config-file/index.ts +0 -2
- package/component-tree.widget.tsx +0 -16
- package/constants.ts +0 -1
- package/eject-conf.cmd.tsx +0 -62
- package/events/index.ts +0 -3
- package/events/on-component-add-event.ts +0 -14
- package/events/on-component-change-event.ts +0 -14
- package/events/on-component-removed-event.ts +0 -14
- package/exceptions/dependency-type-not-supported-in-policy.ts +0 -7
- package/exceptions/incorrect-env-aspect.ts +0 -8
- package/exceptions/index.ts +0 -1
- package/index.ts +0 -19
- package/install.cmd.tsx +0 -67
- package/link/component-list-links.ts +0 -50
- package/link/core-aspects-links.ts +0 -50
- package/link/get-package-name-from-target.ts +0 -5
- package/link/index.ts +0 -1
- package/link/link-row.ts +0 -20
- package/link/link-to-dir.ts +0 -13
- package/link/link.cmd.ts +0 -96
- package/link/nested-deps-in-nm-links.ts +0 -47
- package/link/rewire-row.ts +0 -17
- package/list.cmd.tsx +0 -30
- package/on-component-events.ts +0 -14
- package/package-tar/teambit-workspace-0.0.551.tgz +0 -0
- package/tag-cmd.ts +0 -247
- package/tsconfig.json +0 -35
- package/types/asset.d.ts +0 -29
- package/types/style.d.ts +0 -42
- package/types.ts +0 -40
- package/ui/index.ts +0 -1
- package/ui/workspace/default-component.ts +0 -7
- package/ui/workspace/index.ts +0 -1
- package/ui/workspace/use-workspace.ts +0 -193
- package/ui/workspace/workspace-context.tsx +0 -5
- package/ui/workspace/workspace-model.ts +0 -66
- package/ui/workspace/workspace-overview/index.ts +0 -1
- package/ui/workspace/workspace-overview/workspace-overview.module.scss +0 -6
- package/ui/workspace/workspace-overview/workspace-overview.tsx +0 -21
- package/ui/workspace/workspace-provider.tsx +0 -23
- package/ui/workspace/workspace.module.scss +0 -40
- package/ui/workspace/workspace.tsx +0 -99
- package/ui/workspace-components-drawer/index.ts +0 -1
- package/ui/workspace-components-drawer/workspace-components-drawer.module.scss +0 -4
- package/ui/workspace-components-drawer/workspace-components.drawer.tsx +0 -49
- package/watch/REFACTOR_GUIDE.md +0 -14
- package/watch/check-types.ts +0 -5
- package/watch/output-formatter.ts +0 -50
- package/watch/watch.cmd.tsx +0 -142
- package/watch/watcher.ts +0 -289
- package/workspace-component/component-status.ts +0 -67
- package/workspace-component/index.ts +0 -2
- package/workspace-component/workspace-component-loader.ts +0 -276
- package/workspace-component/workspace-component.ts +0 -51
- package/workspace-section.ts +0 -14
- package/workspace.aspect.ts +0 -9
- package/workspace.graphql.ts +0 -133
- package/workspace.main.runtime.ts +0 -50
- package/workspace.provider.ts +0 -218
- package/workspace.ts +0 -1517
- package/workspace.ui-root.ts +0 -64
- package/workspace.ui.runtime.tsx +0 -215
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import { ComponentGrid } from '@teambit/explorer.ui.gallery.component-grid';
|
|
3
|
-
import { EmptyWorkspace } from '@teambit/workspace.ui.empty-workspace';
|
|
4
|
-
import { WorkspaceComponentCard } from '@teambit/workspace.ui.workspace-component-card';
|
|
5
|
-
import { WorkspaceContext } from '../workspace-context';
|
|
6
|
-
import styles from './workspace-overview.module.scss';
|
|
7
|
-
|
|
8
|
-
export function WorkspaceOverview() {
|
|
9
|
-
const workspace = useContext(WorkspaceContext);
|
|
10
|
-
const { components } = workspace;
|
|
11
|
-
if (!components || components.length === 0) return <EmptyWorkspace name={workspace.name} />;
|
|
12
|
-
return (
|
|
13
|
-
<div className={styles.container}>
|
|
14
|
-
<ComponentGrid>
|
|
15
|
-
{components.map((component, index) => {
|
|
16
|
-
return <WorkspaceComponentCard key={index} component={component} />;
|
|
17
|
-
})}
|
|
18
|
-
</ComponentGrid>
|
|
19
|
-
</div>
|
|
20
|
-
);
|
|
21
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
import { WorkspaceContext } from './workspace-context';
|
|
4
|
-
import { Workspace } from './workspace-model';
|
|
5
|
-
|
|
6
|
-
export type WorkspaceProviderProps = {
|
|
7
|
-
/**
|
|
8
|
-
* workspace model.
|
|
9
|
-
*/
|
|
10
|
-
workspace: Workspace;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* react children.
|
|
14
|
-
*/
|
|
15
|
-
children: ReactNode;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* context provider of the workspace
|
|
20
|
-
*/
|
|
21
|
-
export function WorkspaceProvider({ workspace, children }: WorkspaceProviderProps) {
|
|
22
|
-
return <WorkspaceContext.Provider value={workspace}>{children}</WorkspaceContext.Provider>;
|
|
23
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
@import '~@teambit/ui-foundation.ui.constants.z-indexes/z-indexes.module.scss';
|
|
2
|
-
|
|
3
|
-
.emptyContainer {
|
|
4
|
-
height: 100vh;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
.workspaceWrapper {
|
|
8
|
-
display: flex;
|
|
9
|
-
flex-direction: column;
|
|
10
|
-
overflow: hidden; // TODO
|
|
11
|
-
height: 100vh;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.topbar {
|
|
15
|
-
flex: none;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.main {
|
|
19
|
-
flex: 1 1;
|
|
20
|
-
|
|
21
|
-
height: 100%;
|
|
22
|
-
overflow: hidden;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
.splitter {
|
|
26
|
-
position: relative;
|
|
27
|
-
|
|
28
|
-
> :first-child {
|
|
29
|
-
z-index: $nav-z-index + 1;
|
|
30
|
-
position: absolute;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.sidebar {
|
|
35
|
-
min-width: 100px;
|
|
36
|
-
max-width: 85%;
|
|
37
|
-
position: relative;
|
|
38
|
-
|
|
39
|
-
height: 100%;
|
|
40
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import 'reset-css';
|
|
2
|
-
import pluralize from 'pluralize';
|
|
3
|
-
import React, { useReducer, useMemo } from 'react';
|
|
4
|
-
import { Route } from 'react-router-dom';
|
|
5
|
-
import type { ComponentModel } from '@teambit/component';
|
|
6
|
-
import type { ComponentID } from '@teambit/component-id';
|
|
7
|
-
import { useNotifications } from '@teambit/ui-foundation.ui.notifications.notification-context';
|
|
8
|
-
import { RouteSlot, SlotRouter } from '@teambit/ui-foundation.ui.react-router.slot-router';
|
|
9
|
-
import { Corner } from '@teambit/ui-foundation.ui.corner';
|
|
10
|
-
import { Collapser } from '@teambit/ui-foundation.ui.buttons.collapser';
|
|
11
|
-
import { SplitPane, Pane, Layout } from '@teambit/base-ui.surfaces.split-pane.split-pane';
|
|
12
|
-
import { HoverSplitter } from '@teambit/base-ui.surfaces.split-pane.hover-splitter';
|
|
13
|
-
import { TopBar } from '@teambit/ui-foundation.ui.top-bar';
|
|
14
|
-
|
|
15
|
-
import { useWorkspace } from './use-workspace';
|
|
16
|
-
import { WorkspaceOverview } from './workspace-overview';
|
|
17
|
-
import { WorkspaceProvider } from './workspace-provider';
|
|
18
|
-
import styles from './workspace.module.scss';
|
|
19
|
-
import WorkspaceUI from '../../workspace.ui.runtime';
|
|
20
|
-
|
|
21
|
-
export type WorkspaceProps = {
|
|
22
|
-
routeSlot: RouteSlot;
|
|
23
|
-
menuSlot: RouteSlot;
|
|
24
|
-
sidebar: JSX.Element;
|
|
25
|
-
workspaceUI: WorkspaceUI;
|
|
26
|
-
onSidebarTogglerChange: (callback: () => void) => void;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* main workspace component.
|
|
31
|
-
*/
|
|
32
|
-
export function Workspace({ routeSlot, menuSlot, sidebar, workspaceUI, onSidebarTogglerChange }: WorkspaceProps) {
|
|
33
|
-
const reactions = useComponentNotifications();
|
|
34
|
-
const { workspace } = useWorkspace(reactions);
|
|
35
|
-
|
|
36
|
-
const [isSidebarOpen, handleSidebarToggle] = useReducer((x) => !x, true);
|
|
37
|
-
const sidebarOpenness = isSidebarOpen ? Layout.row : Layout.right;
|
|
38
|
-
|
|
39
|
-
onSidebarTogglerChange(handleSidebarToggle);
|
|
40
|
-
|
|
41
|
-
if (!workspace) {
|
|
42
|
-
return <div className={styles.emptyContainer}></div>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
workspaceUI.setComponents(workspace.components);
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
<WorkspaceProvider workspace={workspace}>
|
|
49
|
-
<div className={styles.workspaceWrapper}>
|
|
50
|
-
<TopBar
|
|
51
|
-
className={styles.topbar}
|
|
52
|
-
Corner={() => <Corner name={workspace.name} icon={workspace.icon} />}
|
|
53
|
-
menu={menuSlot}
|
|
54
|
-
/>
|
|
55
|
-
|
|
56
|
-
<SplitPane className={styles.main} size={264} layout={sidebarOpenness}>
|
|
57
|
-
<Pane className={styles.sidebar}>{sidebar}</Pane>
|
|
58
|
-
<HoverSplitter className={styles.splitter}>
|
|
59
|
-
<Collapser
|
|
60
|
-
isOpen={isSidebarOpen}
|
|
61
|
-
onMouseDown={(e) => e.stopPropagation()} // avoid split-pane drag
|
|
62
|
-
onClick={handleSidebarToggle}
|
|
63
|
-
tooltipContent={`${isSidebarOpen ? 'Hide' : 'Show'} side panel`}
|
|
64
|
-
/>
|
|
65
|
-
</HoverSplitter>
|
|
66
|
-
<Pane>
|
|
67
|
-
<SlotRouter slot={routeSlot} />
|
|
68
|
-
<Route exact path="/">
|
|
69
|
-
<WorkspaceOverview />
|
|
70
|
-
</Route>
|
|
71
|
-
</Pane>
|
|
72
|
-
</SplitPane>
|
|
73
|
-
</div>
|
|
74
|
-
</WorkspaceProvider>
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
function useComponentNotifications() {
|
|
78
|
-
const notifications = useNotifications();
|
|
79
|
-
|
|
80
|
-
// memo not really needed, but for peace of mind
|
|
81
|
-
return useMemo(
|
|
82
|
-
() => ({
|
|
83
|
-
onComponentAdded: (comps: ComponentModel[]) => {
|
|
84
|
-
const notificationId = notifications.log(
|
|
85
|
-
`added ${pluralize('component', comps.length)}: ${comps.map((comp) => comp.id.toString()).join(', ')}`
|
|
86
|
-
);
|
|
87
|
-
setTimeout(() => notifications.dismiss(notificationId), 12 * 1000);
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
onComponentRemoved: (ids: ComponentID[]) => {
|
|
91
|
-
const notificationId = notifications.log(
|
|
92
|
-
`removed ${pluralize('component', ids.length)} ${ids.map((id) => id.toString()).join(', ')}`
|
|
93
|
-
);
|
|
94
|
-
setTimeout(() => notifications.dismiss(notificationId), 12 * 1000);
|
|
95
|
-
},
|
|
96
|
-
}),
|
|
97
|
-
[notifications]
|
|
98
|
-
);
|
|
99
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { WorkspaceComponentsDrawer } from './workspace-components.drawer';
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { DrawerType } from '@teambit/ui-foundation.ui.tree.drawer';
|
|
2
|
-
import { FullLoader } from '@teambit/ui-foundation.ui.full-loader';
|
|
3
|
-
import {
|
|
4
|
-
ComponentTree,
|
|
5
|
-
PayloadType,
|
|
6
|
-
ComponentView,
|
|
7
|
-
ScopeTreeNode,
|
|
8
|
-
NamespaceTreeNode,
|
|
9
|
-
ScopePayload,
|
|
10
|
-
} from '@teambit/ui-foundation.ui.side-bar';
|
|
11
|
-
|
|
12
|
-
import type { TreeNodeProps } from '@teambit/base-ui.graph.tree.recursive-tree';
|
|
13
|
-
|
|
14
|
-
import React, { useCallback, useContext } from 'react';
|
|
15
|
-
import classNames from 'classnames';
|
|
16
|
-
import { ComponentTreeSlot } from '@teambit/component-tree';
|
|
17
|
-
import { mutedItalic } from '@teambit/design.ui.styles.muted-italic';
|
|
18
|
-
import { ellipsis } from '@teambit/design.ui.styles.ellipsis';
|
|
19
|
-
import { WorkspaceContext } from '../workspace/workspace-context';
|
|
20
|
-
import styles from './workspace-components-drawer.module.scss';
|
|
21
|
-
|
|
22
|
-
export class WorkspaceComponentsDrawer implements DrawerType {
|
|
23
|
-
constructor(private treeNodeSlot: ComponentTreeSlot) {}
|
|
24
|
-
|
|
25
|
-
name = 'COMPONENTS';
|
|
26
|
-
|
|
27
|
-
render = () => {
|
|
28
|
-
const workspace = useContext(WorkspaceContext);
|
|
29
|
-
const { treeNodeSlot } = this;
|
|
30
|
-
|
|
31
|
-
const TreeNodeRenderer = useCallback(
|
|
32
|
-
function TreeNode(props: TreeNodeProps<PayloadType>) {
|
|
33
|
-
const children = props.node.children;
|
|
34
|
-
|
|
35
|
-
if (!children) return <ComponentView {...props} treeNodeSlot={treeNodeSlot} />;
|
|
36
|
-
|
|
37
|
-
if (props.node.payload instanceof ScopePayload) return <ScopeTreeNode {...props} />;
|
|
38
|
-
|
|
39
|
-
return <NamespaceTreeNode {...props} />;
|
|
40
|
-
},
|
|
41
|
-
[treeNodeSlot]
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
if (!workspace) return <FullLoader />;
|
|
45
|
-
if (workspace.components.length === 0)
|
|
46
|
-
return <span className={classNames(mutedItalic, ellipsis, styles.emptyWorkspace)}>Workspace is empty</span>;
|
|
47
|
-
return <ComponentTree components={workspace.components} TreeNode={TreeNodeRenderer} />;
|
|
48
|
-
};
|
|
49
|
-
}
|
package/watch/REFACTOR_GUIDE.md
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
REFACTOR GUIDE FOR WATCHER EXTENSION.
|
|
2
|
-
|
|
3
|
-
- watcher should accept an array of file and handle watching for file changes.
|
|
4
|
-
- workspace should register a slot which listens to file changes and reload the component.
|
|
5
|
-
- workspace allow extension to register a slot which listens to component changes.
|
|
6
|
-
- workspace graphql should emit an event through subscription (onComponentChange) after reloading all changed components.
|
|
7
|
-
- hook should be exposed from components on load in which extension can register to add data.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
- more important events
|
|
11
|
-
- apply onComponentChange
|
|
12
|
-
- Scope
|
|
13
|
-
- onComponentChange
|
|
14
|
-
|
package/watch/check-types.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { OnComponentEventResult } from '../on-component-events';
|
|
3
|
-
|
|
4
|
-
const verboseComponentFilesArrayToString = (componentFiles) => {
|
|
5
|
-
return componentFiles.reduce((outputString, filePath) => `${outputString} \t - ${filePath}\n`, ``);
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const resultsForExtensionArrayToString = (resultsForExtension, verbose) => {
|
|
9
|
-
return resultsForExtension.reduce(
|
|
10
|
-
(outputString, resultForExtension) =>
|
|
11
|
-
`${outputString}${chalk.green('√')}SUCCESS\t${resultForExtension.component}\n
|
|
12
|
-
${verbose ? resultForExtension.componentFilesAsString : ''}\n`,
|
|
13
|
-
''
|
|
14
|
-
);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const formatWatchPathsSortByComponent = (trackDirs) => {
|
|
18
|
-
return Object.keys(trackDirs).reduce(
|
|
19
|
-
(outputString, watchPath) =>
|
|
20
|
-
`${outputString}
|
|
21
|
-
${chalk.green('√')} SUCCESS\t${trackDirs[watchPath]}\n
|
|
22
|
-
\t - ${watchPath}\n\n`,
|
|
23
|
-
` ${chalk.underline('STATUS\t\tCOMPONENT ID')}\n`
|
|
24
|
-
);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* todo: this was implemented incorrectly.
|
|
29
|
-
* the original idea of `SerializableResults` was to have each one of the aspects registered to the slot, the
|
|
30
|
-
* ability to have their own formatting to their results, and then `toString()` method to print them.
|
|
31
|
-
* Here, the printing is specifically to the Compiler aspect. It should move to where it belongs.
|
|
32
|
-
*/
|
|
33
|
-
export function formatCompileResults(compileResults: OnComponentEventResult[], verbose: boolean) {
|
|
34
|
-
if (!compileResults.length || !Array.isArray(compileResults)) return '';
|
|
35
|
-
return compileResults
|
|
36
|
-
.filter((compileResult) => compileResult.results?.results && Array.isArray(compileResult.results?.results))
|
|
37
|
-
.map((compileResult) => ({
|
|
38
|
-
extensionId: compileResult.extensionId,
|
|
39
|
-
resultsForExtension: compileResult.results?.results?.map((resultForExtension) => ({
|
|
40
|
-
component: resultForExtension.component,
|
|
41
|
-
componentFilesAsString: verboseComponentFilesArrayToString(resultForExtension.buildResults),
|
|
42
|
-
})),
|
|
43
|
-
}))
|
|
44
|
-
.reduce(
|
|
45
|
-
(outputString, compileResult) =>
|
|
46
|
-
`${outputString}
|
|
47
|
-
${resultsForExtensionArrayToString(compileResult.resultsForExtension, verbose)}`,
|
|
48
|
-
` ${chalk.underline('STATUS\tCOMPONENT ID')}`
|
|
49
|
-
);
|
|
50
|
-
}
|
package/watch/watch.cmd.tsx
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import moment from 'moment';
|
|
3
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
4
|
-
import type { Logger } from '@teambit/logger';
|
|
5
|
-
import type { BitBaseEvent, PubsubMain } from '@teambit/pubsub';
|
|
6
|
-
|
|
7
|
-
// import IDs and events
|
|
8
|
-
import { CompilerAspect, CompilerErrorEvent } from '@teambit/compiler';
|
|
9
|
-
|
|
10
|
-
import { Watcher, WatchOptions } from './watcher';
|
|
11
|
-
import { formatCompileResults, formatWatchPathsSortByComponent } from './output-formatter';
|
|
12
|
-
import { OnComponentEventResult } from '../on-component-events';
|
|
13
|
-
import { CheckTypes } from './check-types';
|
|
14
|
-
|
|
15
|
-
export type WatchCmdOpts = {
|
|
16
|
-
verbose?: boolean;
|
|
17
|
-
skipPreCompilation?: boolean;
|
|
18
|
-
checkTypes?: string | boolean;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export class WatchCommand implements Command {
|
|
22
|
-
msgs = {
|
|
23
|
-
onAll: (event, path) => this.logger.console(`Event: "${event}". Path: ${path}`),
|
|
24
|
-
onStart: () => {},
|
|
25
|
-
onReady: (workspace, watchPathsSortByComponent, verbose) => {
|
|
26
|
-
clearOutdatedData();
|
|
27
|
-
if (verbose) {
|
|
28
|
-
this.logger.console(formatWatchPathsSortByComponent(watchPathsSortByComponent));
|
|
29
|
-
}
|
|
30
|
-
this.logger.console(
|
|
31
|
-
chalk.yellow(
|
|
32
|
-
`Watching for component changes in workspace ${workspace.config.name} (${moment().format('HH:mm:ss')})...\n`
|
|
33
|
-
)
|
|
34
|
-
);
|
|
35
|
-
},
|
|
36
|
-
onChange: (filePath: string, buildResults: OnComponentEventResult[], verbose: boolean, duration) => {
|
|
37
|
-
clearOutdatedData();
|
|
38
|
-
if (!buildResults.length) {
|
|
39
|
-
this.logger.console(`The file ${filePath} has been changed, but nothing to compile.\n\n`);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
this.logger.console(`The file ${filePath} has been changed.\n\n`);
|
|
43
|
-
this.logger.console(formatCompileResults(buildResults, verbose));
|
|
44
|
-
this.logger.console(`Finished. (${duration}ms)`);
|
|
45
|
-
this.logger.console(chalk.yellow(`Watching for component changes (${moment().format('HH:mm:ss')})...`));
|
|
46
|
-
},
|
|
47
|
-
onAdd: (filePath: string, buildResults: OnComponentEventResult[], verbose: boolean, duration) => {
|
|
48
|
-
clearOutdatedData();
|
|
49
|
-
this.logger.console(`The file ${filePath} has been added.\n\n`);
|
|
50
|
-
this.logger.console(formatCompileResults(buildResults, verbose));
|
|
51
|
-
this.logger.console(`Finished. (${duration}ms)`);
|
|
52
|
-
this.logger.console(chalk.yellow(`Watching for component changes (${moment().format('HH:mm:ss')})...`));
|
|
53
|
-
},
|
|
54
|
-
onUnlink: (p) => {
|
|
55
|
-
this.logger.console(`file ${p} has been removed`);
|
|
56
|
-
},
|
|
57
|
-
onError: (err) => {
|
|
58
|
-
this.logger.console(`Watcher error ${err}`);
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
name = 'watch';
|
|
63
|
-
description = 'watch a set of components';
|
|
64
|
-
alias = '';
|
|
65
|
-
group = 'development';
|
|
66
|
-
shortDescription = '';
|
|
67
|
-
options = [
|
|
68
|
-
['v', 'verbose', 'showing npm verbose output for inspection and prints stack trace'],
|
|
69
|
-
['', 'skip-pre-compilation', 'skip the compilation step before starting to watch'],
|
|
70
|
-
[
|
|
71
|
-
't',
|
|
72
|
-
'check-types [string]',
|
|
73
|
-
'EXPERIMENTAL. show errors/warnings for types. options are [file, project] to investigate only changed file or entire project. defaults to project',
|
|
74
|
-
],
|
|
75
|
-
] as CommandOptions;
|
|
76
|
-
|
|
77
|
-
constructor(
|
|
78
|
-
/**
|
|
79
|
-
* logger extension.
|
|
80
|
-
*/
|
|
81
|
-
private pubsub: PubsubMain,
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* logger extension.
|
|
85
|
-
*/
|
|
86
|
-
private logger: Logger,
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* watcher extension.
|
|
90
|
-
*/
|
|
91
|
-
private watcher: Watcher
|
|
92
|
-
) {
|
|
93
|
-
this.registerToEvents();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private registerToEvents() {
|
|
97
|
-
this.pubsub.sub(CompilerAspect.id, this.eventsListener);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
private eventsListener = (event: BitBaseEvent<any>) => {
|
|
101
|
-
switch (event.type) {
|
|
102
|
-
case CompilerErrorEvent.TYPE:
|
|
103
|
-
this.logger.console(`Watcher error ${event.data.error}, 'error'`);
|
|
104
|
-
break;
|
|
105
|
-
default:
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
async report(cliArgs: [], watchCmdOpts: WatchCmdOpts) {
|
|
110
|
-
const { verbose, checkTypes } = watchCmdOpts;
|
|
111
|
-
const getCheckTypesEnum = () => {
|
|
112
|
-
switch (checkTypes) {
|
|
113
|
-
case undefined:
|
|
114
|
-
case false:
|
|
115
|
-
return CheckTypes.None;
|
|
116
|
-
case 'project':
|
|
117
|
-
case true: // project is the default
|
|
118
|
-
return CheckTypes.EntireProject;
|
|
119
|
-
case 'file':
|
|
120
|
-
return CheckTypes.ChangedFile;
|
|
121
|
-
default:
|
|
122
|
-
throw new Error(`check-types can be either "file" or "project". got "${checkTypes}"`);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
const watchOpts: WatchOptions = {
|
|
126
|
-
msgs: this.msgs,
|
|
127
|
-
verbose,
|
|
128
|
-
preCompile: !watchCmdOpts.skipPreCompilation,
|
|
129
|
-
spawnTSServer: Boolean(checkTypes), // if check-types is enabled, it must spawn the tsserver.
|
|
130
|
-
checkTypes: getCheckTypesEnum(),
|
|
131
|
-
};
|
|
132
|
-
await this.watcher.watchAll(watchOpts);
|
|
133
|
-
return 'watcher terminated';
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* with console.clear() all history is deleted from the console. this function preserver the history.
|
|
139
|
-
*/
|
|
140
|
-
function clearOutdatedData() {
|
|
141
|
-
process.stdout.write('\x1Bc');
|
|
142
|
-
}
|