Skip to content

Commit 82f221b

Browse files
feat: content store plug-ins use IndiekitStorePlugin
1 parent 44ff4a7 commit 82f221b

File tree

15 files changed

+242
-256
lines changed

15 files changed

+242
-256
lines changed

helpers/store/index.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { IndiekitError } from "@indiekit/error";
2+
import { IndiekitStorePlugin } from "@indiekit/plugin";
23

34
const defaults = {
45
baseUrl: "https://store.example",
@@ -8,17 +9,22 @@ const defaults = {
89
* @typedef Response
910
* @property {object} response - HTTP response
1011
*/
11-
export default class TestStore {
12+
export default class TestStorePlugin extends IndiekitStorePlugin {
13+
name = "Test store";
14+
15+
/**
16+
* @param {object} [options] - Plug-in options
17+
* @param {string} [options.baseUrl] - Base URL
18+
* @param {string} [options.user] - Username
19+
*/
1220
constructor(options = {}) {
13-
this.name = "Test store";
21+
super(options);
22+
1423
this.options = { ...defaults, ...options };
15-
}
1624

17-
get info() {
18-
const { baseUrl, user } = this.options;
19-
return {
25+
this.info = {
2026
name: "Test store",
21-
uid: `${baseUrl}/${user}`,
27+
uid: `${this.options.baseUrl}/${this.options.user}`,
2228
};
2329
}
2430

@@ -102,8 +108,4 @@ export default class TestStore {
102108
await this.#client(path, "DELETE", { message });
103109
return true;
104110
}
105-
106-
init(Indiekit) {
107-
Indiekit.addStore(this);
108-
}
109111
}

packages/store-bitbucket/index.js

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from "node:path";
22
import process from "node:process";
33

44
import { IndiekitError } from "@indiekit/error";
5+
import { IndiekitStorePlugin } from "@indiekit/plugin";
56
// eslint-disable-next-line import/default
67
import bitbucket from "bitbucket";
78

@@ -13,7 +14,33 @@ const defaults = {
1314
/**
1415
* @typedef {import("bitbucket").APIClient} APIClient
1516
*/
16-
export default class BitbucketStore {
17+
export default class BitbucketStorePlugin extends IndiekitStorePlugin {
18+
environment = ["BITBUCKET_PASSWORD"];
19+
20+
name = "Bitbucket store";
21+
22+
/**
23+
* @type {import('prompts').PromptObject[]}
24+
*/
25+
prompts = [
26+
{
27+
type: "text",
28+
name: "user",
29+
message: "What is your Bitbucket username?",
30+
},
31+
{
32+
type: "text",
33+
name: "repo",
34+
message: "Which repository is your publication stored on?",
35+
},
36+
{
37+
type: "text",
38+
name: "branch",
39+
message: "Which branch are you publishing from?",
40+
initial: defaults.branch,
41+
},
42+
];
43+
1744
/**
1845
* @param {object} [options] - Plug-in options
1946
* @param {string} [options.user] - Username
@@ -22,44 +49,16 @@ export default class BitbucketStore {
2249
* @param {string} [options.password] - Password
2350
*/
2451
constructor(options = {}) {
25-
this.name = "Bitbucket store";
26-
this.options = { ...defaults, ...options };
27-
}
28-
29-
get environment() {
30-
return ["BITBUCKET_PASSWORD"];
31-
}
52+
super(options);
3253

33-
get info() {
34-
const { repo, user } = this.options;
54+
this.options = { ...defaults, ...options };
3555

36-
return {
37-
name: `${user}/${repo} on Bitbucket`,
38-
uid: `https://bitbucket.org/${user}/${repo}`,
56+
this.info = {
57+
name: `${this.options.user}/${this.options.repo} on Bitbucket`,
58+
uid: `https://bitbucket.org/${this.options.user}/${this.options.repo}`,
3959
};
4060
}
4161

42-
get prompts() {
43-
return [
44-
{
45-
type: "text",
46-
name: "user",
47-
message: "What is your Bitbucket username?",
48-
},
49-
{
50-
type: "text",
51-
name: "repo",
52-
message: "Which repository is your publication stored on?",
53-
},
54-
{
55-
type: "text",
56-
name: "branch",
57-
message: "Which branch are you publishing from?",
58-
initial: defaults.branch,
59-
},
60-
];
61-
}
62-
6362
/**
6463
* @access private
6564
* @returns {APIClient} Bitbucket client interface
@@ -228,8 +227,4 @@ export default class BitbucketStore {
228227
});
229228
}
230229
}
231-
232-
init(Indiekit) {
233-
Indiekit.addStore(this);
234-
}
235230
}

packages/store-bitbucket/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
},
3434
"dependencies": {
3535
"@indiekit/error": "^1.0.0-beta.15",
36+
"@indiekit/plugin": "^1.0.0-beta.19",
3637
"bitbucket": "^2.6.2"
3738
},
3839
"publishConfig": {

packages/store-file-system/index.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from "node:path";
44
import process from "node:process";
55

66
import { IndiekitError } from "@indiekit/error";
7+
import { IndiekitStorePlugin } from "@indiekit/plugin";
78

89
const defaults = {
910
directory: process.cwd(),
@@ -13,31 +14,35 @@ const defaults = {
1314
* @typedef Response
1415
* @property {object} response - Response
1516
*/
16-
export default class FileSystemStore {
17+
export default class FileSystemStorePlugin extends IndiekitStorePlugin {
18+
name = "File system store";
19+
20+
/**
21+
* @type {import('prompts').PromptObject[]}
22+
*/
23+
prompts = [
24+
{
25+
type: "text",
26+
name: "directory",
27+
message: "Which directory do you want to save files in?",
28+
},
29+
];
30+
31+
/**
32+
* @param {object} [options] - Plug-in options
33+
* @param {string} [options.directory] - Directory to save files to
34+
*/
1735
constructor(options = {}) {
18-
this.name = "File system store";
19-
this.options = { ...defaults, ...options };
20-
}
36+
super(options);
2137

22-
get info() {
23-
const { directory } = this.options;
38+
this.options = { ...defaults, ...options };
2439

25-
return {
26-
name: directory,
27-
uid: `file://${directory}`,
40+
this.info = {
41+
name: this.options.directory,
42+
uid: `file://${this.options.directory}`,
2843
};
2944
}
3045

31-
get prompts() {
32-
return [
33-
{
34-
type: "text",
35-
name: "directory",
36-
message: "Which directory do you want to save files in?",
37-
},
38-
];
39-
}
40-
4146
/**
4247
* Get absolute file path
4348
* @access private
@@ -133,8 +138,4 @@ export default class FileSystemStore {
133138
});
134139
}
135140
}
136-
137-
init(Indiekit) {
138-
Indiekit.addStore(this);
139-
}
140141
}

packages/store-file-system/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"directory": "packages/store-file-system"
3333
},
3434
"dependencies": {
35-
"@indiekit/error": "^1.0.0-beta.15"
35+
"@indiekit/error": "^1.0.0-beta.15",
36+
"@indiekit/plugin": "^1.0.0-beta.19"
3637
},
3738
"publishConfig": {
3839
"access": "public"

packages/store-ftp/index.js

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import process from "node:process";
33
import { Readable } from "node:stream";
44

55
import { IndiekitError } from "@indiekit/error";
6+
import { IndiekitStorePlugin } from "@indiekit/plugin";
67
import Client from "ssh2-sftp-client";
78

89
const defaults = {
@@ -12,7 +13,32 @@ const defaults = {
1213
user: process.env.FTP_USER,
1314
};
1415

15-
export default class FtpStore {
16+
export default class FtpStorePlugin extends IndiekitStorePlugin {
17+
environment = ["FTP_PASSWORD", "FTP_USER"];
18+
19+
name = "FTP store";
20+
21+
/**
22+
* @type {import('prompts').PromptObject[]}
23+
*/
24+
prompts = [
25+
{
26+
type: "text",
27+
name: "host",
28+
message: "Where is your FTP server hosted?",
29+
},
30+
{
31+
type: "text",
32+
name: "user",
33+
message: "What is your FTP username?",
34+
},
35+
{
36+
type: "text",
37+
name: "directory",
38+
message: "Which directory do you want to save files in?",
39+
},
40+
];
41+
1642
/**
1743
* @param {object} [options] - Plug-in options
1844
* @param {string} [options.host] - FTP hostname
@@ -22,44 +48,16 @@ export default class FtpStore {
2248
* @param {string} [options.directory] - Directory
2349
*/
2450
constructor(options = {}) {
25-
this.name = "FTP store";
26-
this.options = { ...defaults, ...options };
27-
}
51+
super(options);
2852

29-
get environment() {
30-
return ["FTP_PASSWORD", "FTP_USER"];
31-
}
32-
33-
get info() {
34-
const { directory, host, user } = this.options;
53+
this.options = { ...defaults, ...options };
3554

36-
return {
37-
name: `${user} on ${host}`,
38-
uid: `sftp://${host}/${directory}`,
55+
this.info = {
56+
name: `${this.options.user} on ${this.options.host}`,
57+
uid: `sftp://${this.options.host}/${this.options.directory}`,
3958
};
4059
}
4160

42-
get prompts() {
43-
return [
44-
{
45-
type: "text",
46-
name: "host",
47-
message: "Where is your FTP server hosted?",
48-
description: "i.e. ftp.server.example",
49-
},
50-
{
51-
type: "text",
52-
name: "user",
53-
message: "What is your FTP username?",
54-
},
55-
{
56-
type: "text",
57-
name: "directory",
58-
message: "Which directory do you want to save files in?",
59-
},
60-
];
61-
}
62-
6361
/**
6462
* Get FTP client interface
6563
* @access private
@@ -232,8 +230,4 @@ export default class FtpStore {
232230
await client.end();
233231
}
234232
}
235-
236-
init(Indiekit) {
237-
Indiekit.addStore(this);
238-
}
239233
}

packages/store-ftp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
},
3535
"dependencies": {
3636
"@indiekit/error": "^1.0.0-beta.15",
37+
"@indiekit/plugin": "^1.0.0-beta.19",
3738
"ssh2-sftp-client": "^11.0.0"
3839
},
3940
"publishConfig": {

0 commit comments

Comments
 (0)