@bridgebrew/project 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/branches.ts +1220 -0
- package/browser/branches.tsx +642 -0
- package/browser/browser.tsx +265 -0
- package/browser/mobile.tsx +62 -0
- package/browser/new-project.tsx +185 -0
- package/browser/overview.tsx +192 -0
- package/browser/project.d.ts +60 -0
- package/browser/sources.tsx +310 -0
- package/browser/tsconfig.json +15 -0
- package/names.ts +28 -0
- package/package.json +108 -4
- package/server.ts +338 -0
- package/tsconfig.json +1 -0
- package/README.md +0 -3
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// A project's Overview (research-083): its home, which its row in the sidebar opens, its Sessions and
|
|
2
|
+
// Branches listed under it. Its folder and git state (`project`'s `/projects?git=1`), its branches and what each holds
|
|
3
|
+
// (this plugin's `/branches`, a git project's), its latest sessions (`sessions`), each a link to its screen. The start of
|
|
4
|
+
// the project dashboard.
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { EmptyState, Icon, ScreenLink, isRecord, readJson } from '@bridge/ui';
|
|
7
|
+
import type { Context } from 'cordis';
|
|
8
|
+
import type {} from '@bridge/ui-renderer/client';
|
|
9
|
+
import { projectBranchesRoute } from './branches.tsx';
|
|
10
|
+
|
|
11
|
+
interface Project {
|
|
12
|
+
id: string;
|
|
13
|
+
title: string;
|
|
14
|
+
path: string;
|
|
15
|
+
git?: { own?: boolean; branch?: string; changes?: number; remote?: string };
|
|
16
|
+
}
|
|
17
|
+
interface Branch {
|
|
18
|
+
name: string;
|
|
19
|
+
main: boolean;
|
|
20
|
+
dirty: number;
|
|
21
|
+
ahead: number;
|
|
22
|
+
active: boolean;
|
|
23
|
+
}
|
|
24
|
+
interface Session {
|
|
25
|
+
id: string;
|
|
26
|
+
title: string;
|
|
27
|
+
updatedAt?: string;
|
|
28
|
+
createdAt: string;
|
|
29
|
+
running?: boolean;
|
|
30
|
+
branch?: { name: string };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const ago = (time: string) => {
|
|
34
|
+
const minutes = Math.round((Date.now() - Date.parse(time)) / 60_000);
|
|
35
|
+
if (minutes < 1) return 'now';
|
|
36
|
+
if (minutes < 60) return `${minutes} min`;
|
|
37
|
+
const hours = Math.round(minutes / 60);
|
|
38
|
+
return hours < 24 ? `${hours} h` : `${Math.round(hours / 24)} d`;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** `url`'s JSON, `undefined` when it does not answer 200. */
|
|
42
|
+
const read = async (url: string, init?: RequestInit): Promise<unknown> => {
|
|
43
|
+
const res = await fetch(url, { cache: 'no-store', ...init });
|
|
44
|
+
return res.ok ? readJson(res) : undefined;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function Section({
|
|
48
|
+
title,
|
|
49
|
+
icon,
|
|
50
|
+
to,
|
|
51
|
+
children,
|
|
52
|
+
}: {
|
|
53
|
+
title: string;
|
|
54
|
+
icon: string;
|
|
55
|
+
to: { node: string; screen: { plugin: string; id: string } };
|
|
56
|
+
children: React.ReactNode;
|
|
57
|
+
}) {
|
|
58
|
+
return (
|
|
59
|
+
<section className="flex flex-col gap-1.5">
|
|
60
|
+
<h2 className="m-0 flex items-center gap-1.5 text-[13px] font-semibold text-foreground">
|
|
61
|
+
<Icon name={icon} size={13} className="text-muted" />
|
|
62
|
+
<ScreenLink to={to} className="hover:underline">
|
|
63
|
+
{title}
|
|
64
|
+
</ScreenLink>
|
|
65
|
+
</h2>
|
|
66
|
+
{children}
|
|
67
|
+
</section>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function Overview({ ctx, node }: { ctx: Context; node: string }) {
|
|
72
|
+
const slug = ctx.workspace.slug;
|
|
73
|
+
const [project, setProject] = React.useState<Project>();
|
|
74
|
+
const [branches, setBranches] = React.useState<Branch[]>();
|
|
75
|
+
const [sessions, setSessions] = React.useState<Session[]>();
|
|
76
|
+
React.useEffect(() => {
|
|
77
|
+
let gone = false;
|
|
78
|
+
void (async () => {
|
|
79
|
+
// In a stage (research-083), its Sessions are its workspace's, those bound to it.
|
|
80
|
+
const workspaces = await read('/_bridge/workspaces');
|
|
81
|
+
const parent =
|
|
82
|
+
isRecord(workspaces) && Array.isArray(workspaces.workspaces)
|
|
83
|
+
? (workspaces.workspaces as { slug: string; parent?: string }[]).find(
|
|
84
|
+
(each) => each.slug === slug,
|
|
85
|
+
)?.parent
|
|
86
|
+
: undefined;
|
|
87
|
+
const [projects, mine] = await Promise.all([
|
|
88
|
+
read(`/${slug}/api/project/projects?git=1`),
|
|
89
|
+
read(
|
|
90
|
+
parent
|
|
91
|
+
? `/${parent}/api/sessions/sessions?worktree=${encodeURIComponent(slug)}`
|
|
92
|
+
: `/${slug}/api/sessions/sessions`,
|
|
93
|
+
{ headers: { 'x-bridge-node': node } },
|
|
94
|
+
),
|
|
95
|
+
]);
|
|
96
|
+
// The answers of Bridge's own routes: typed once where they are read.
|
|
97
|
+
const found = Array.isArray(projects)
|
|
98
|
+
? (projects as Project[]).find((each) => each.id === node)
|
|
99
|
+
: undefined;
|
|
100
|
+
// Branches only for a repository of its own (the host refuses the others).
|
|
101
|
+
const listed = found?.git?.own
|
|
102
|
+
? await read(
|
|
103
|
+
projectBranchesRoute(slug, node),
|
|
104
|
+
)
|
|
105
|
+
: undefined;
|
|
106
|
+
if (gone) return;
|
|
107
|
+
setProject(found);
|
|
108
|
+
if (isRecord(listed) && Array.isArray(listed.branches))
|
|
109
|
+
setBranches(listed.branches as Branch[]);
|
|
110
|
+
if (isRecord(mine) && Array.isArray(mine.sessions))
|
|
111
|
+
setSessions((mine.sessions as Session[]).slice(0, 5));
|
|
112
|
+
})().catch((error: unknown) => console.warn('Overview unavailable', error));
|
|
113
|
+
return () => {
|
|
114
|
+
gone = true;
|
|
115
|
+
};
|
|
116
|
+
}, [slug, node]);
|
|
117
|
+
const screen = (plugin: string, id: string) => ({ node, screen: { plugin, id } });
|
|
118
|
+
// The screen's landmark, as every screen has, from its first render.
|
|
119
|
+
if (!project) return <section aria-label="Screen" />;
|
|
120
|
+
return (
|
|
121
|
+
<section aria-label="Screen" className="flex flex-col gap-6 px-6 pb-10 pt-5" data-overview>
|
|
122
|
+
<header className="flex flex-col gap-1">
|
|
123
|
+
<h1 className="m-0 text-lg font-semibold text-foreground">{project.title}</h1>
|
|
124
|
+
<p className="m-0 truncate font-mono text-xs text-secondary" title={project.path}>
|
|
125
|
+
{project.path}
|
|
126
|
+
</p>
|
|
127
|
+
{project.git && (
|
|
128
|
+
<p className="m-0 flex items-center gap-1.5 text-xs text-secondary">
|
|
129
|
+
<Icon name="git-branch" size={12} />
|
|
130
|
+
<span className="font-mono">{project.git.branch ?? '(detached)'}</span>
|
|
131
|
+
{project.git.changes ? <span>· {project.git.changes} uncommitted</span> : null}
|
|
132
|
+
{project.git.remote && <span className="truncate">· {project.git.remote}</span>}
|
|
133
|
+
</p>
|
|
134
|
+
)}
|
|
135
|
+
</header>
|
|
136
|
+
{branches && (
|
|
137
|
+
<Section title="Branches" icon="git-branch" to={screen('project', 'branches')}>
|
|
138
|
+
<ul className="m-0 flex list-none flex-col p-0 text-[13px]">
|
|
139
|
+
{branches.map((branch) => (
|
|
140
|
+
<li key={branch.name} className="flex min-h-7 items-center gap-2">
|
|
141
|
+
<span className="truncate font-mono">{branch.name}</span>
|
|
142
|
+
{branch.active && <span className="text-xs text-accent">active</span>}
|
|
143
|
+
<span className="ml-auto shrink-0 text-xs text-secondary">
|
|
144
|
+
{branch.main
|
|
145
|
+
? 'main folder'
|
|
146
|
+
: branch.dirty || branch.ahead
|
|
147
|
+
? [
|
|
148
|
+
branch.dirty && `${branch.dirty} uncommitted`,
|
|
149
|
+
branch.ahead && `${branch.ahead} commits`,
|
|
150
|
+
]
|
|
151
|
+
.filter(Boolean)
|
|
152
|
+
.join(' · ')
|
|
153
|
+
: 'no change yet'}
|
|
154
|
+
</span>
|
|
155
|
+
</li>
|
|
156
|
+
))}
|
|
157
|
+
</ul>
|
|
158
|
+
</Section>
|
|
159
|
+
)}
|
|
160
|
+
<Section title="Latest sessions" icon="scroll-text" to={screen('sessions', 'sessions')}>
|
|
161
|
+
{sessions?.length ? (
|
|
162
|
+
<ul className="m-0 flex list-none flex-col p-0 text-[13px]">
|
|
163
|
+
{sessions.map((session) => (
|
|
164
|
+
<li key={session.id}>
|
|
165
|
+
<ScreenLink
|
|
166
|
+
to={{ ...screen('sessions', 'sessions'), item: session.id }}
|
|
167
|
+
className="flex min-h-7 w-full items-center gap-2 rounded-md px-1 text-left hover:bg-surface-hover text-foreground no-underline"
|
|
168
|
+
>
|
|
169
|
+
{session.running && (
|
|
170
|
+
<Icon name="loader-circle" size={12} className="text-accent" />
|
|
171
|
+
)}
|
|
172
|
+
<span className="min-w-0 flex-1 truncate">{session.title}</span>
|
|
173
|
+
{session.branch && (
|
|
174
|
+
<span className="flex shrink-0 items-center gap-1 text-xs text-muted">
|
|
175
|
+
<Icon name="git-branch" size={12} />
|
|
176
|
+
<span className="font-mono">{session.branch.name}</span>
|
|
177
|
+
</span>
|
|
178
|
+
)}
|
|
179
|
+
<span className="shrink-0 text-xs text-muted tabular-nums">
|
|
180
|
+
{ago(session.updatedAt ?? session.createdAt)}
|
|
181
|
+
</span>
|
|
182
|
+
</ScreenLink>
|
|
183
|
+
</li>
|
|
184
|
+
))}
|
|
185
|
+
</ul>
|
|
186
|
+
) : (
|
|
187
|
+
<EmptyState title="No session yet" className="items-start px-0 py-2 text-left" />
|
|
188
|
+
)}
|
|
189
|
+
</Section>
|
|
190
|
+
</section>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// The project sources' contract (bridge#126): the `projectSources` service the `project` plugin provides in a
|
|
2
|
+
// workspace, where a project comes from in its New project wizard, as source providers. `project` registers its own
|
|
3
|
+
// (New project, Existing folder, Git URL); another plugin extending it registers one more (a GitHub repository), read
|
|
4
|
+
// with `ctx.get('projectSources')` (never a required `inject`). Included by the plugins' type-check (./tsconfig.json);
|
|
5
|
+
// no plugin imports it (AD-8).
|
|
6
|
+
import type {} from 'cordis';
|
|
7
|
+
import type * as React from 'react';
|
|
8
|
+
|
|
9
|
+
/** What a project is made from: an empty folder (`name`, its folder name; `git` its own repository), a clone of
|
|
10
|
+
* `clone` into the folder `name`, or an existing folder inside the parent's (`path`); `title`, anything, is what
|
|
11
|
+
* Bridge shows (its folder name by default). */
|
|
12
|
+
type ProjectInput =
|
|
13
|
+
| { name: string; title?: string; git?: boolean; clone?: string }
|
|
14
|
+
| { path: string; title?: string };
|
|
15
|
+
|
|
16
|
+
/** What a source's step gets. */
|
|
17
|
+
interface ProjectSourceStepProps {
|
|
18
|
+
/** Its step's id in the wizard: the `id` of the `WizardStep` it renders. */
|
|
19
|
+
step: string;
|
|
20
|
+
/** The node the project goes under (its nearest project's folder holds it). */
|
|
21
|
+
parent: string;
|
|
22
|
+
/** That parent's folder, once known: a step shows where the project goes. */
|
|
23
|
+
folder: string | undefined;
|
|
24
|
+
/** Makes the project; rejects with the refusal's message (its `details` when the refusal gives them). The wizard
|
|
25
|
+
* closes and the new project's node shows once the step's submit resolves. */
|
|
26
|
+
make(input: ProjectInput): Promise<{ id: string; title: string }>;
|
|
27
|
+
/** Shows another source's step with `prefill` (Existing folder's "Clone it here" opens Git URL with its URL). */
|
|
28
|
+
goTo(source: string, prefill?: Record<string, string>): void;
|
|
29
|
+
/** What another step sent with `goTo`. */
|
|
30
|
+
prefill: Record<string, string> | undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface ProjectSource {
|
|
34
|
+
/** Unique among the sources (its plugin key, say). */
|
|
35
|
+
id: string;
|
|
36
|
+
title: string;
|
|
37
|
+
/** One line under its title. */
|
|
38
|
+
description: string;
|
|
39
|
+
/** A kit `Icon`, or the plugin's own 16px drawing (a brand's mark). */
|
|
40
|
+
icon: React.ReactNode;
|
|
41
|
+
/** Its place in the list, lowest first; `project`'s own are 10, 20 and 30. */
|
|
42
|
+
order?: number;
|
|
43
|
+
/** Its step: a kit `WizardStep` with `id={step}`, its form, and a submit that calls `make`. */
|
|
44
|
+
Step: React.ComponentType<ProjectSourceStepProps>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface ProjectSources {
|
|
48
|
+
/** Adds a source; returns its removal (call it from `ctx.effect`, so it goes with its plugin). A taken id throws. */
|
|
49
|
+
register(source: ProjectSource): () => void;
|
|
50
|
+
/** The sources, by `order`. */
|
|
51
|
+
list(): readonly ProjectSource[];
|
|
52
|
+
/** Calls `listener` after each registration or removal; returns the unsubscribe. */
|
|
53
|
+
subscribe(listener: () => void): () => void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare module 'cordis' {
|
|
57
|
+
interface Context {
|
|
58
|
+
projectSources: ProjectSources;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
// The project plugin's own sources (bridge#126), each a step of the New project wizard (./new-project.tsx): New
|
|
2
|
+
// project (an empty folder in the parent's `projects/`, named after its title, which may be anything; its own git
|
|
3
|
+
// repository if asked), Existing folder (one inside
|
|
4
|
+
// the parent's folder, browsed; one outside is refused, a clone offered to be cloned there), Git URL (cloned into
|
|
5
|
+
// `projects/<name>`, the parent's bridge.yml naming it by URL and commit). Another plugin adds its own through
|
|
6
|
+
// `projectSources` (./project.d.ts).
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
import {
|
|
9
|
+
Button,
|
|
10
|
+
Checkbox,
|
|
11
|
+
Field,
|
|
12
|
+
FieldDescription,
|
|
13
|
+
FieldLabel,
|
|
14
|
+
Icon,
|
|
15
|
+
Input,
|
|
16
|
+
List,
|
|
17
|
+
ListItem,
|
|
18
|
+
WizardStep,
|
|
19
|
+
useWizard,
|
|
20
|
+
} from '@bridge/ui';
|
|
21
|
+
import type { Context } from 'cordis';
|
|
22
|
+
import { folderOf, nameOfUrl } from '../names.ts';
|
|
23
|
+
|
|
24
|
+
type Source = Context['projectSources'] extends { register(source: infer S): unknown } ? S : never;
|
|
25
|
+
type StepProps = React.ComponentProps<Source['Step']>;
|
|
26
|
+
|
|
27
|
+
/** Where a project in folder `name` goes under `folder`. */
|
|
28
|
+
const where = (folder: string | undefined, name: string) =>
|
|
29
|
+
folder ? `${folder}/projects/${name || '…'}` : undefined;
|
|
30
|
+
|
|
31
|
+
/** Where the project's folder goes: a small folder icon, then its path. */
|
|
32
|
+
function Where({ path }: { path: string | undefined }) {
|
|
33
|
+
if (!path) return null;
|
|
34
|
+
return (
|
|
35
|
+
<FieldDescription data-folder className="flex items-start gap-1.5">
|
|
36
|
+
<Icon name="folder" size={12} className="mt-0.5 shrink-0" />
|
|
37
|
+
<span className="sr-only">Its folder:</span>
|
|
38
|
+
<span className="break-all">{path}</span>
|
|
39
|
+
</FieldDescription>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A title's folder: its own name made a folder name, `project` when nothing of it fits one. */
|
|
44
|
+
const folderFor = (title: string) => (title.trim() ? folderOf(title) || 'project' : '');
|
|
45
|
+
|
|
46
|
+
function NewFolder({ step, folder, make }: StepProps) {
|
|
47
|
+
/** Its title, anything; its folder is made of it. */
|
|
48
|
+
const [name, setName] = React.useState('');
|
|
49
|
+
const [git, setGit] = React.useState(false);
|
|
50
|
+
const own = folderFor(name);
|
|
51
|
+
return (
|
|
52
|
+
<WizardStep
|
|
53
|
+
id={step}
|
|
54
|
+
title="New project"
|
|
55
|
+
submitLabel="Create"
|
|
56
|
+
busyLabel="Creating…"
|
|
57
|
+
canSubmit={own !== ''}
|
|
58
|
+
onSubmit={async () => {
|
|
59
|
+
await make({ name: own, title: name.trim(), ...(git && { git }) });
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
<Field>
|
|
63
|
+
<FieldLabel>Name</FieldLabel>
|
|
64
|
+
<Input
|
|
65
|
+
variant="outline"
|
|
66
|
+
value={name}
|
|
67
|
+
onChange={(event) => setName(event.currentTarget.value)}
|
|
68
|
+
/>
|
|
69
|
+
<Where path={where(folder, own)} />
|
|
70
|
+
</Field>
|
|
71
|
+
<Field className="flex-row items-center gap-2">
|
|
72
|
+
<Checkbox checked={git} onCheckedChange={(on) => setGit(on === true)} />
|
|
73
|
+
<FieldLabel>Its own git repository</FieldLabel>
|
|
74
|
+
</Field>
|
|
75
|
+
</WizardStep>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface Folders {
|
|
80
|
+
root: string;
|
|
81
|
+
path: string;
|
|
82
|
+
folders: { name: string; path: string; project?: string }[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
type ListFolders = (parent: string, path: string) => Promise<Folders>;
|
|
86
|
+
|
|
87
|
+
export function existingFolder(list: ListFolders) {
|
|
88
|
+
function Step({ step, parent, make, goTo }: StepProps) {
|
|
89
|
+
const wizard = useWizard();
|
|
90
|
+
const [path, setPath] = React.useState('');
|
|
91
|
+
const [found, setFound] = React.useState<Folders>();
|
|
92
|
+
/** The folders could not be read: why, and Retry (`attempt`). */
|
|
93
|
+
const [failed, setFailed] = React.useState<string>();
|
|
94
|
+
const [attempt, setAttempt] = React.useState(0);
|
|
95
|
+
const [chosen, setChosen] = React.useState<string>();
|
|
96
|
+
const [typed, setTyped] = React.useState('');
|
|
97
|
+
/** The refusal's remote, when the folder chosen is a clone outside the parent's. */
|
|
98
|
+
const [remote, setRemote] = React.useState<{ url: string; name: string }>();
|
|
99
|
+
React.useEffect(() => {
|
|
100
|
+
let live = true;
|
|
101
|
+
setFailed(undefined);
|
|
102
|
+
list(parent, path).then(
|
|
103
|
+
(answer) => live && setFound(answer),
|
|
104
|
+
(cause: Error) => live && setFailed(cause.message),
|
|
105
|
+
);
|
|
106
|
+
return () => {
|
|
107
|
+
live = false;
|
|
108
|
+
};
|
|
109
|
+
}, [parent, path, attempt]);
|
|
110
|
+
const target = typed.trim() || chosen;
|
|
111
|
+
return (
|
|
112
|
+
<WizardStep
|
|
113
|
+
id={step}
|
|
114
|
+
title="Existing folder"
|
|
115
|
+
description={found && `A folder inside ${found.root}`}
|
|
116
|
+
submitLabel="Add"
|
|
117
|
+
busyLabel="Adding…"
|
|
118
|
+
canSubmit={target !== undefined}
|
|
119
|
+
onSubmit={async () => {
|
|
120
|
+
setRemote(undefined);
|
|
121
|
+
try {
|
|
122
|
+
await make({ path: target! });
|
|
123
|
+
} catch (error) {
|
|
124
|
+
const details: unknown =
|
|
125
|
+
typeof error === 'object' && error !== null
|
|
126
|
+
? Reflect.get(error, 'details')
|
|
127
|
+
: undefined;
|
|
128
|
+
const url: unknown =
|
|
129
|
+
typeof details === 'object' && details !== null
|
|
130
|
+
? Reflect.get(details, 'remote')
|
|
131
|
+
: undefined;
|
|
132
|
+
if (typeof url === 'string')
|
|
133
|
+
setRemote({ url, name: target!.split('/').filter(Boolean).at(-1) ?? '' });
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
<div className="flex items-center gap-2 text-sm text-muted">
|
|
139
|
+
<Button
|
|
140
|
+
type="button"
|
|
141
|
+
variant="ghost"
|
|
142
|
+
size="icon-sm"
|
|
143
|
+
aria-label="Up"
|
|
144
|
+
disabled={!found?.path}
|
|
145
|
+
onClick={() => {
|
|
146
|
+
setChosen(undefined);
|
|
147
|
+
setPath(found!.path.split('/').slice(0, -1).join('/'));
|
|
148
|
+
}}
|
|
149
|
+
>
|
|
150
|
+
<Icon name="chevron-left" />
|
|
151
|
+
</Button>
|
|
152
|
+
<span className="truncate">{found ? found.path || '.' : failed ? '' : 'Loading…'}</span>
|
|
153
|
+
</div>
|
|
154
|
+
{failed && (
|
|
155
|
+
<div className="flex items-center justify-end gap-2">
|
|
156
|
+
<span role="alert" className="flex-1 text-sm text-destructive">
|
|
157
|
+
The folders could not be read: {failed}
|
|
158
|
+
</span>
|
|
159
|
+
<Button type="button" onClick={() => setAttempt((was) => was + 1)}>
|
|
160
|
+
Retry
|
|
161
|
+
</Button>
|
|
162
|
+
</div>
|
|
163
|
+
)}
|
|
164
|
+
{found && found.folders.length === 0 ? (
|
|
165
|
+
<p className="text-sm text-muted">No folder here.</p>
|
|
166
|
+
) : (
|
|
167
|
+
<List
|
|
168
|
+
aria-label="Folders"
|
|
169
|
+
selectionMode="single"
|
|
170
|
+
selectedKey={chosen ?? ''}
|
|
171
|
+
onSelectionChange={(keys) => {
|
|
172
|
+
setTyped('');
|
|
173
|
+
setChosen(keys[0]);
|
|
174
|
+
}}
|
|
175
|
+
className="max-h-56 overflow-y-auto"
|
|
176
|
+
>
|
|
177
|
+
{(found?.folders ?? []).map((each) => (
|
|
178
|
+
<ListItem
|
|
179
|
+
key={each.path}
|
|
180
|
+
value={each.path}
|
|
181
|
+
textValue={each.name}
|
|
182
|
+
size="sm"
|
|
183
|
+
disabled={each.project !== undefined}
|
|
184
|
+
leading={<Icon name="folder" />}
|
|
185
|
+
trailing={
|
|
186
|
+
each.project !== undefined ? (
|
|
187
|
+
`Project ${each.project}`
|
|
188
|
+
) : (
|
|
189
|
+
<Button
|
|
190
|
+
type="button"
|
|
191
|
+
variant="ghost"
|
|
192
|
+
size="icon-sm"
|
|
193
|
+
aria-label={`Open ${each.name}`}
|
|
194
|
+
onClick={(event) => {
|
|
195
|
+
event.stopPropagation();
|
|
196
|
+
setChosen(undefined);
|
|
197
|
+
setPath(found!.path ? `${found!.path}/${each.name}` : each.name);
|
|
198
|
+
}}
|
|
199
|
+
>
|
|
200
|
+
<Icon name="chevron-right" />
|
|
201
|
+
</Button>
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
>
|
|
205
|
+
{each.name}
|
|
206
|
+
</ListItem>
|
|
207
|
+
))}
|
|
208
|
+
</List>
|
|
209
|
+
)}
|
|
210
|
+
<Field>
|
|
211
|
+
<FieldLabel>Or its path</FieldLabel>
|
|
212
|
+
<Input
|
|
213
|
+
variant="outline"
|
|
214
|
+
value={typed}
|
|
215
|
+
onChange={(event) => setTyped(event.currentTarget.value)}
|
|
216
|
+
/>
|
|
217
|
+
</Field>
|
|
218
|
+
{remote && wizard.error && (
|
|
219
|
+
<div className="flex items-center justify-end gap-2">
|
|
220
|
+
<span className="text-sm text-muted">It is a clone of {remote.url}.</span>
|
|
221
|
+
<Button
|
|
222
|
+
type="button"
|
|
223
|
+
onClick={() =>
|
|
224
|
+
goTo('git', { url: remote.url, name: nameOfUrl(remote.url) || remote.name })
|
|
225
|
+
}
|
|
226
|
+
>
|
|
227
|
+
Clone it here
|
|
228
|
+
</Button>
|
|
229
|
+
</div>
|
|
230
|
+
)}
|
|
231
|
+
</WizardStep>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
return Step;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function GitUrl({ step, folder, make, prefill }: StepProps) {
|
|
238
|
+
const [url, setUrl] = React.useState(prefill?.url ?? '');
|
|
239
|
+
/** The name typed, optional: empty, the URL's. */
|
|
240
|
+
const [typedName, setTypedName] = React.useState(prefill?.name ?? '');
|
|
241
|
+
// Sent by another step (Existing folder's Clone it here): its URL and name replace what was there.
|
|
242
|
+
React.useEffect(() => {
|
|
243
|
+
if (prefill?.url === undefined) return;
|
|
244
|
+
setUrl(prefill.url);
|
|
245
|
+
setTypedName(prefill.name ?? '');
|
|
246
|
+
}, [prefill]);
|
|
247
|
+
const fromUrl = nameOfUrl(url);
|
|
248
|
+
// A name typed is its title, anything, and its folder made of it; none: the URL's name for both.
|
|
249
|
+
const own = folderFor(typedName) || fromUrl;
|
|
250
|
+
const title = typedName.trim() || own;
|
|
251
|
+
return (
|
|
252
|
+
<WizardStep
|
|
253
|
+
id={step}
|
|
254
|
+
title="Clone a repository"
|
|
255
|
+
submitLabel="Clone"
|
|
256
|
+
busyLabel="Cloning…"
|
|
257
|
+
canSubmit={url.trim() !== '' && own !== ''}
|
|
258
|
+
onSubmit={async () => {
|
|
259
|
+
await make({ name: own, title, clone: url.trim() });
|
|
260
|
+
}}
|
|
261
|
+
>
|
|
262
|
+
<Field>
|
|
263
|
+
<FieldLabel>Git URL</FieldLabel>
|
|
264
|
+
<Input
|
|
265
|
+
variant="outline"
|
|
266
|
+
value={url}
|
|
267
|
+
onChange={(event) => setUrl(event.currentTarget.value)}
|
|
268
|
+
/>
|
|
269
|
+
</Field>
|
|
270
|
+
<Field>
|
|
271
|
+
<FieldLabel>Name (optional)</FieldLabel>
|
|
272
|
+
<Input
|
|
273
|
+
variant="outline"
|
|
274
|
+
value={typedName}
|
|
275
|
+
placeholder={fromUrl}
|
|
276
|
+
onChange={(event) => setTypedName(event.currentTarget.value)}
|
|
277
|
+
/>
|
|
278
|
+
<Where path={where(folder, own)} />
|
|
279
|
+
</Field>
|
|
280
|
+
</WizardStep>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** The project plugin's own sources; `list` reads the folders inside a parent's. */
|
|
285
|
+
export const ownSources = (list: ListFolders): Source[] => [
|
|
286
|
+
{
|
|
287
|
+
id: 'new',
|
|
288
|
+
title: 'New project',
|
|
289
|
+
description: 'An empty folder in projects/, its own git repository if you like',
|
|
290
|
+
icon: <Icon name="folder-plus" />,
|
|
291
|
+
order: 10,
|
|
292
|
+
Step: NewFolder,
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
id: 'folder',
|
|
296
|
+
title: 'Existing folder',
|
|
297
|
+
description: 'A folder already inside this one',
|
|
298
|
+
icon: <Icon name="folder-open" />,
|
|
299
|
+
order: 20,
|
|
300
|
+
Step: existingFolder(list),
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
id: 'git',
|
|
304
|
+
title: 'Git URL',
|
|
305
|
+
description: 'Clone a repository into projects/',
|
|
306
|
+
icon: <Icon name="git-branch" />,
|
|
307
|
+
order: 30,
|
|
308
|
+
Step: GitUrl,
|
|
309
|
+
},
|
|
310
|
+
];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"//": "The page (its tests are typed with the tests project): its services through the Bridge checkout this repository links (../../bridge), the contracts of the plugins it uses from their folders here.",
|
|
3
|
+
"extends": "../.bridge/tsconfig.browser.json",
|
|
4
|
+
"include": [
|
|
5
|
+
".",
|
|
6
|
+
"../../bridge/packages/browser-boot/src/workspace.d.ts",
|
|
7
|
+
"../../bridge/vendor/types/client-build-environment.d.ts",
|
|
8
|
+
"../../shell/browser/shell.d.ts",
|
|
9
|
+
"../../session-prompt/browser/session-prompt.d.ts"
|
|
10
|
+
],
|
|
11
|
+
"exclude": [
|
|
12
|
+
"./**/*.test.ts",
|
|
13
|
+
"./**/*.test.tsx"
|
|
14
|
+
]
|
|
15
|
+
}
|
package/names.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Project names (bridge#126): a git URL's repository name, the Git URL step's default; a title made a folder name.
|
|
2
|
+
|
|
3
|
+
/** A git URL's repository name, as a folder name: `https://host/acme/shop.git` → `shop`. */
|
|
4
|
+
export const nameOfUrl = (url: string) =>
|
|
5
|
+
(
|
|
6
|
+
url
|
|
7
|
+
.trim()
|
|
8
|
+
.replace(/[#?].*$/, '')
|
|
9
|
+
.replace(/\/+$/, '')
|
|
10
|
+
.split(/[/:]/)
|
|
11
|
+
.at(-1) ?? ''
|
|
12
|
+
)
|
|
13
|
+
.replace(/\.git$/, '')
|
|
14
|
+
.replace(/[^\w.-]/g, '-')
|
|
15
|
+
.replace(/^[.-]+/, '');
|
|
16
|
+
|
|
17
|
+
/** A project's folder name from its title, which may be anything: `Test git` → `test-git`, `Café` → `cafe`. Empty
|
|
18
|
+
* when nothing of it fits a folder name (letters, digits, `_ - .`, at most 100). */
|
|
19
|
+
export const folderOf = (title: string) =>
|
|
20
|
+
title
|
|
21
|
+
.normalize('NFKD')
|
|
22
|
+
.replace(/[̀-ͯ]/g, '')
|
|
23
|
+
.toLowerCase()
|
|
24
|
+
.replace(/[^\w.-]+/g, '-')
|
|
25
|
+
.replace(/-{2,}/g, '-')
|
|
26
|
+
.replace(/^[.-]+|-+$/g, '')
|
|
27
|
+
.slice(0, 100)
|
|
28
|
+
.replace(/-+$/, '');
|