@goodfellow-cms/github 0.1.0 → 0.3.0
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/README.md +2 -2
- package/dist/index.d.ts +114 -6
- package/dist/index.js +1352 -47
- package/dist/testing.d.ts +133 -1
- package/dist/testing.js +798 -15
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@ import { github } from "@goodfellow-cms/github";
|
|
|
8
8
|
export default defineConfig({ blocks, backend: github({ repo: "your-name/your-site" }) });
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
[Goodfellow](https://github.com/
|
|
11
|
+
[Goodfellow](https://github.com/goodfellow-cms/goodfellow-cms) is a website builder for people who aren't developers, with no server or database: pages are files in your own GitHub or GitLab repository, edited in a visual editor built on [Puck](https://puckeditor.com). To start a new site, run `npm create goodfellow@latest my-site`. See the [documentation](https://goodfellow-cms.github.io/goodfellow-cms/) for everything else.
|
|
12
12
|
|
|
13
|
-
More in the docs: [Hosts and business sites](https://
|
|
13
|
+
More in the docs: [Hosts and business sites](https://goodfellow-cms.github.io/goodfellow-cms/docs/hosts).
|
|
14
14
|
|
|
15
15
|
## License
|
|
16
16
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
import { DeployStatus, FileChange, GitBackend, GitHost, GitUser, StorageLike, WriteOptions } from "@goodfellow-cms/core";
|
|
1
|
+
import { ConnectDomainOptions, DeployStatus, DnsRecord, FileChange, FileVersion, GitBackend, GitHost, GitUser, HistoryOptions, OwnerAccess, PagesDomains, RedirectOptions, SetupHost, SignInError, SiteDrafts, SiteEditors, SiteUpdates, StorageLike, TokenLink, WriteOptions } from "@goodfellow-cms/core";
|
|
2
|
+
//#region src/sign-in.d.ts
|
|
3
|
+
/** The sign-in worker Goodfellow runs for every site. Sites can run their own and name it in `github({ signIn })`. */
|
|
4
|
+
export declare const GOODFELLOW_SIGN_IN = "https://sign-in.goodfellow-cms.workers.dev";
|
|
5
|
+
/** The page's address and how to change it. Replaceable in tests. */
|
|
6
|
+
interface BrowserLocation {
|
|
7
|
+
href(): string;
|
|
8
|
+
/** Navigates away, for example to GitHub's sign-in page. */
|
|
9
|
+
assign(url: string): void;
|
|
10
|
+
/** Changes the address without reloading, for example to remove the sign-in's details after coming back. */
|
|
11
|
+
replace(url: string): void;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
2
14
|
//#region src/api.d.ts
|
|
15
|
+
/** A token that renews itself, such as one from the sign-in worker. `refresh` asks for a new one even if it hasn't expired. */
|
|
16
|
+
type TokenSource = (options?: {
|
|
17
|
+
refresh?: boolean;
|
|
18
|
+
}) => Promise<string>;
|
|
3
19
|
interface ApiOptions {
|
|
4
20
|
apiUrl: string;
|
|
5
|
-
token: string;
|
|
21
|
+
token: string | TokenSource;
|
|
6
22
|
fetch: typeof fetch;
|
|
7
23
|
}
|
|
8
24
|
//#endregion
|
|
@@ -13,6 +29,19 @@ interface GitHubBackendOptions {
|
|
|
13
29
|
branch: string;
|
|
14
30
|
user: GitUser;
|
|
15
31
|
onSignOut: () => void;
|
|
32
|
+
/** Where to create the owner token, which can change editors and GitHub Pages settings. */
|
|
33
|
+
ownerTokenLink: TokenLink;
|
|
34
|
+
/** Signs in as an owner through the sign-in worker instead of with a token, where it's available. */
|
|
35
|
+
ownerRedirect?: (options?: RedirectOptions) => Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Who commits name as their author. Set when the token is an app's
|
|
38
|
+
* installation token from the sign-in worker, whose commits would otherwise
|
|
39
|
+
* name the app. Commits are then made with Git's data API, which can name them.
|
|
40
|
+
*/
|
|
41
|
+
author?: {
|
|
42
|
+
name: string;
|
|
43
|
+
email: string;
|
|
44
|
+
};
|
|
16
45
|
}
|
|
17
46
|
/**
|
|
18
47
|
* The site's files on GitHub. Reads come from the commit `revision()` last
|
|
@@ -21,33 +50,102 @@ interface GitHubBackendOptions {
|
|
|
21
50
|
*/
|
|
22
51
|
export declare class GitHubBackend implements GitBackend {
|
|
23
52
|
readonly user: GitUser;
|
|
53
|
+
readonly pages: PagesDomains;
|
|
54
|
+
readonly editors: SiteEditors;
|
|
55
|
+
readonly ownerAccess: OwnerAccess;
|
|
56
|
+
readonly updates: SiteUpdates;
|
|
57
|
+
readonly drafts: SiteDrafts;
|
|
58
|
+
private readonly options;
|
|
24
59
|
private readonly api;
|
|
25
60
|
private readonly repo;
|
|
26
61
|
private readonly branch;
|
|
27
62
|
private readonly onSignOut;
|
|
63
|
+
private readonly author?;
|
|
64
|
+
private readonly owner;
|
|
28
65
|
private pinned?;
|
|
29
66
|
private readonly trees;
|
|
67
|
+
/** Each file's size in bytes at a commit, which GitHub lists with its tree. */
|
|
68
|
+
private readonly treeSizes;
|
|
30
69
|
private readonly blobs;
|
|
31
70
|
constructor(options: GitHubBackendOptions);
|
|
71
|
+
/** Drafts on branches of the repository, with pull requests for review. */
|
|
72
|
+
private draftHost;
|
|
32
73
|
revision(): Promise<string>;
|
|
33
74
|
/** Path → blob id for every file at a commit. Commits never change, so this is cached. */
|
|
34
75
|
private tree;
|
|
35
76
|
private currentTree;
|
|
36
77
|
read(path: string): Promise<string | undefined>;
|
|
78
|
+
private readFrom;
|
|
79
|
+
/** Reads many text files in a few GraphQL requests rather than one request each. */
|
|
80
|
+
readFiles(paths: string[]): Promise<Map<string, string>>;
|
|
37
81
|
readBytes(path: string): Promise<Uint8Array | undefined>;
|
|
38
82
|
list(dir: string): Promise<string[]>;
|
|
39
|
-
|
|
83
|
+
fileSizes(dir: string): Promise<Map<string, number>>;
|
|
84
|
+
/** Uses an owner's sign-in through the worker for editors and GitHub Pages settings, until it's forgotten. */
|
|
85
|
+
useOwnerSignIn(token: TokenSource, end: () => void): void;
|
|
86
|
+
/** Remembers why an owner's sign-in through the worker didn't work, which the Editors and Domain screens show. */
|
|
87
|
+
ownerSignInFailed(error: unknown): void;
|
|
88
|
+
write(changes: FileChange[], options: WriteOptions): Promise<{
|
|
40
89
|
revision: string;
|
|
41
90
|
}>;
|
|
91
|
+
/**
|
|
92
|
+
* Saves with Git's data API, naming the editor as the commit's author:
|
|
93
|
+
* GitHub refuses to move the branch unless the commit follows on from it, so
|
|
94
|
+
* nothing is overwritten.
|
|
95
|
+
*/
|
|
96
|
+
private writeCommit;
|
|
97
|
+
private writeGraphQL;
|
|
98
|
+
history(path: string, { page, perPage }?: HistoryOptions): Promise<FileVersion[]>;
|
|
99
|
+
readAt(path: string, revision: string): Promise<string | undefined>;
|
|
42
100
|
changedPaths(from: string, to: string): Promise<string[]>;
|
|
43
101
|
/**
|
|
44
|
-
* Reads the deployment GitHub Pages or Vercel created for a commit
|
|
45
|
-
*
|
|
102
|
+
* Reads the deployment GitHub Pages or Vercel created for a commit, and for
|
|
103
|
+
* GitHub Actions, the workflow run that builds it: a build that fails never
|
|
104
|
+
* creates a deployment. Before either exists, the site counts as building
|
|
105
|
+
* if it has ever been deployed.
|
|
46
106
|
*/
|
|
47
107
|
deployStatus(revision: string): Promise<DeployStatus>;
|
|
108
|
+
/** The site's deploy workflow run for a commit, or `undefined` if there's none or the token can't see Actions. */
|
|
109
|
+
private workflowRun;
|
|
110
|
+
/** Which step of a failed run failed. */
|
|
111
|
+
private runProblem;
|
|
48
112
|
signOut(): void;
|
|
49
113
|
}
|
|
50
114
|
//#endregion
|
|
115
|
+
//#region src/pages.d.ts
|
|
116
|
+
/** The records GitHub Pages needs: its addresses for an apex domain, or an alias of the owner's github.io. */
|
|
117
|
+
export declare function githubPagesRecords(repo: string, domain: string, { apex, www }: ConnectDomainOptions): DnsRecord[];
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/setup.d.ts
|
|
120
|
+
interface GitHubSetupOptions {
|
|
121
|
+
/** For GitHub Enterprise. Defaults to `https://api.github.com`. */
|
|
122
|
+
apiUrl?: string;
|
|
123
|
+
/** For GitHub Enterprise. Defaults to `https://github.com`. */
|
|
124
|
+
webUrl?: string;
|
|
125
|
+
/** The sign-in worker, for "Sign in with GitHub". Defaults to Goodfellow's; `false` for token sign-in only. */
|
|
126
|
+
signIn?: string | false;
|
|
127
|
+
/** For tests. */
|
|
128
|
+
fetch?: typeof fetch;
|
|
129
|
+
/** For tests. */
|
|
130
|
+
storage?: {
|
|
131
|
+
local?: StorageLike;
|
|
132
|
+
session?: StorageLike;
|
|
133
|
+
};
|
|
134
|
+
/** For tests. */
|
|
135
|
+
location?: BrowserLocation;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Links to GitHub's token pages with what creating a site needs: creating the
|
|
139
|
+
* repository (administration), writing its files and its build setup
|
|
140
|
+
* (contents and workflows), and turning on GitHub Pages (pages).
|
|
141
|
+
*/
|
|
142
|
+
export declare function githubSetupTokenLinks(webUrl?: string): {
|
|
143
|
+
fineGrained: string;
|
|
144
|
+
classic: string;
|
|
145
|
+
};
|
|
146
|
+
/** Signing in to GitHub to create a site's repository, with GitHub Pages if wanted. */
|
|
147
|
+
export declare function githubSetup(options?: GitHubSetupOptions): SetupHost;
|
|
148
|
+
//#endregion
|
|
51
149
|
//#region src/index.d.ts
|
|
52
150
|
export interface GitHubOptions {
|
|
53
151
|
/** The site's repository, as `owner/name`. */
|
|
@@ -58,6 +156,12 @@ export interface GitHubOptions {
|
|
|
58
156
|
apiUrl?: string;
|
|
59
157
|
/** For GitHub Enterprise. Defaults to `https://github.com`. */
|
|
60
158
|
webUrl?: string;
|
|
159
|
+
/**
|
|
160
|
+
* The sign-in worker, which lets editors sign in with GitHub instead of
|
|
161
|
+
* pasting a token. Defaults to Goodfellow's (`GOODFELLOW_SIGN_IN`); give the
|
|
162
|
+
* address of your own copy, or `false` for token sign-in only.
|
|
163
|
+
*/
|
|
164
|
+
signIn?: string | false;
|
|
61
165
|
/** For tests. */
|
|
62
166
|
fetch?: typeof fetch;
|
|
63
167
|
/** For tests. */
|
|
@@ -65,6 +169,8 @@ export interface GitHubOptions {
|
|
|
65
169
|
local?: StorageLike;
|
|
66
170
|
session?: StorageLike;
|
|
67
171
|
};
|
|
172
|
+
/** For tests. */
|
|
173
|
+
location?: BrowserLocation;
|
|
68
174
|
}
|
|
69
175
|
/**
|
|
70
176
|
* Links to GitHub's token page with everything filled in except the
|
|
@@ -73,7 +179,9 @@ export interface GitHubOptions {
|
|
|
73
179
|
export declare function githubTokenLinks(repo: string, webUrl?: string): {
|
|
74
180
|
fineGrained: string;
|
|
75
181
|
classic: string;
|
|
182
|
+
owner: string;
|
|
76
183
|
};
|
|
77
184
|
/** Sign-in and storage for a site whose repository is on GitHub. */
|
|
78
185
|
export declare function github(options: GitHubOptions): GitHost;
|
|
79
|
-
//#endregion
|
|
186
|
+
//#endregion
|
|
187
|
+
export type { BrowserLocation, GitHubSetupOptions };
|