Skip to content

Commit 83351ab

Browse files
authored
Fix exports (#132)
* Fix exports * Use Options type rather than any * Update README
1 parent 1e16956 commit 83351ab

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@ If the `branch` provided does not exist, the plugin will error. To automatically
1717
In addition, it accepts `changes` which is an array of objects containing a `message` and a `files` object
1818

1919
```javascript
20-
let { Octokit } = require("@octokit/rest");
21-
Octokit = Octokit.plugin(require("octokit-commit-multiple-files"));
20+
import { Octokit } from "@octokit/rest";
21+
import { CreateOrUpdateFiles } from "octokit-commit-multiple-files";
2222

23-
const octokit = new Octokit();
23+
const OctokitWithPlugin = Octokit.plugin(CreateOrUpdateFiles);
24+
25+
const octokit = new OctokitWithPlugin();
26+
27+
// Define your repository details
28+
const owner = "your-username";
29+
const repo = "your-repo";
30+
const branch = "main";
31+
const createBranch = false;
2432

2533
const commits = await octokit.createOrUpdateFiles({
2634
owner,
@@ -71,7 +79,7 @@ const commits = await octokit.createOrUpdateFiles({
7179
By default the plugin will append commits to an existing branch. If you want to reset the branch to the state of `base` before adding any changes, set `forkFromBaseBranch: true`:
7280

7381
```javascript
74-
const commits = await octokit.rest.repos.createOrUpdateFiles({
82+
const commits = await octokit.createOrUpdateFiles({
7583
owner,
7684
repo,
7785
branch,

create-or-update-files.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import CreateOrUpdateMultipleFiles from ".";
2-
import CreateOrUpdateMultipleFilesHandler from "./create-or-update-files";
1+
import { CreateOrUpdateFiles } from ".";
2+
import { createOrUpdateFiles } from "./create-or-update-files";
33
const { Octokit } = require("@octokit/rest");
44

55
const nock = require("nock");
66
nock.disableNetConnect();
77
const octokit = new Octokit();
88

99
function run(body: any) {
10-
return CreateOrUpdateMultipleFilesHandler(octokit, body);
10+
return createOrUpdateFiles(octokit, body);
1111
}
1212

1313
type RequestStructure = {
@@ -512,13 +512,13 @@ test("failure (fileToDelete is missing)", async () => {
512512
});
513513

514514
test("Loads plugin", () => {
515-
const TestOctokit = Octokit.plugin(CreateOrUpdateMultipleFiles);
515+
const TestOctokit = Octokit.plugin(CreateOrUpdateFiles);
516516
const testOctokit = new TestOctokit();
517517
expect(testOctokit).toHaveProperty("createOrUpdateFiles");
518518
});
519519

520520
test("Does not overwrite other methods", () => {
521-
const TestOctokit = Octokit.plugin(CreateOrUpdateMultipleFiles);
521+
const TestOctokit = Octokit.plugin(CreateOrUpdateFiles);
522522
const testOctokit = new TestOctokit();
523523
expect(testOctokit).toHaveProperty("rest.repos.acceptInvitation");
524524
});

create-or-update-files.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { Octokit } from "@octokit/rest";
22
import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods";
33

4-
interface FileChange {
4+
export interface FileChange {
55
contents?: string | Buffer;
66
mode?: "100644" | "100755" | "040000" | "160000" | "120000";
77
type?: "blob" | "tree" | "commit";
88
}
99

10-
interface Change {
10+
export interface Change {
1111
message: string;
1212
files?: Record<string, string | Buffer | FileChange>;
1313
filesToDelete?: string[];
1414
ignoreDeletionFailures?: boolean;
1515
}
1616

17-
interface Options {
17+
export interface Options {
1818
owner: string;
1919
repo: string;
2020
branch: string;
@@ -27,7 +27,7 @@ interface Options {
2727
forkFromBaseBranch?: boolean;
2828
}
2929

30-
interface CommitResult {
30+
export interface CommitResult {
3131
commits: Array<
3232
RestEndpointMethodTypes["git"]["createCommit"]["response"]["data"]
3333
>;
@@ -56,7 +56,7 @@ function isBase64(str: string | Buffer): boolean {
5656
);
5757
}
5858

59-
export default function (
59+
const createOrUpdateFiles = function (
6060
octokit: Octokit | any,
6161
opts: Options,
6262
): Promise<CommitResult> {
@@ -292,7 +292,7 @@ export default function (
292292
return reject(e);
293293
}
294294
});
295-
}
295+
};
296296

297297
async function fileExistsInRepo(
298298
octokit: Octokit | any,
@@ -414,3 +414,5 @@ const chunk = <T>(input: T[], size: number): T[][] => {
414414
: [...arr.slice(0, -1), [...arr.slice(-1)[0], item]];
415415
}, []);
416416
};
417+
418+
export { createOrUpdateFiles };

index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Octokit } from "@octokit/rest";
22

3-
import createOrUpdateFilesPlugin from "./create-or-update-files";
3+
import { createOrUpdateFiles, Options } from "./create-or-update-files";
44

5-
export default function (octokit: Octokit | any) {
5+
const CreateOrUpdateFiles = function (octokit: Octokit | any) {
66
return {
7-
createOrUpdateFiles: createOrUpdateFilesPlugin.bind(null, octokit),
7+
createOrUpdateFiles: (opts: Options) => createOrUpdateFiles(octokit, opts),
88
};
9-
}
9+
};
10+
11+
export { CreateOrUpdateFiles };

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
"description": "Octokit plugin to create/update multiple files at once",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
7+
"exports": {
8+
".": {
9+
"types": "./dist/index.d.ts",
10+
"require": "./dist/index.js",
11+
"import": "./dist/index.js",
12+
"default": "./dist/index.js"
13+
}
14+
},
715
"files": [
816
"dist"
917
],

0 commit comments

Comments
 (0)