kirby-deploy 0.0.3 → 0.0.4
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/cli.js +26 -10
- package/package.json +1 -1
- package/src/config.ts +14 -6
- package/src/sync.ts +17 -4
- package/src/types.ts +4 -1
package/dist/cli.js
CHANGED
|
@@ -78,9 +78,10 @@ var loadConfig = async () => {
|
|
|
78
78
|
${info}`);
|
|
79
79
|
return null;
|
|
80
80
|
}
|
|
81
|
+
let folderStructure;
|
|
81
82
|
config.folderStructure ??= "flat";
|
|
82
83
|
if (config.folderStructure === "public") {
|
|
83
|
-
|
|
84
|
+
folderStructure = {
|
|
84
85
|
content: "content",
|
|
85
86
|
media: "public/media",
|
|
86
87
|
accounts: "storage/accounts",
|
|
@@ -88,17 +89,20 @@ ${info}`);
|
|
|
88
89
|
cache: "storage/cache"
|
|
89
90
|
};
|
|
90
91
|
} else if (config.folderStructure === "flat") {
|
|
91
|
-
|
|
92
|
+
folderStructure = {
|
|
92
93
|
content: "content",
|
|
93
94
|
media: "site/media",
|
|
94
95
|
accounts: "site/accounts",
|
|
95
96
|
sessions: "site/sessions",
|
|
96
97
|
cache: "site/cache"
|
|
97
98
|
};
|
|
99
|
+
} else {
|
|
100
|
+
folderStructure = config.folderStructure;
|
|
98
101
|
}
|
|
99
|
-
|
|
102
|
+
const configResolved = {
|
|
100
103
|
remoteDir: "./",
|
|
101
104
|
dryRun: true,
|
|
105
|
+
verbose: false,
|
|
102
106
|
parallel: 10,
|
|
103
107
|
checkComposerLock: true,
|
|
104
108
|
callWebhooks: true,
|
|
@@ -107,13 +111,15 @@ ${info}`);
|
|
|
107
111
|
include: [],
|
|
108
112
|
includeGlob: [],
|
|
109
113
|
...config,
|
|
114
|
+
folderStructure,
|
|
110
115
|
lftpSettings: {
|
|
111
116
|
"ftp:ssl-force": true,
|
|
112
117
|
...config.lftpSettings
|
|
113
118
|
},
|
|
114
|
-
lftpFlags: ["--parallel=10", "--dereference", ...config.lftpFlags ?? []]
|
|
119
|
+
lftpFlags: ["--parallel=10", "--dereference", ...config.lftpFlags ?? []],
|
|
120
|
+
url: "fu"
|
|
115
121
|
};
|
|
116
|
-
return
|
|
122
|
+
return configResolved;
|
|
117
123
|
};
|
|
118
124
|
|
|
119
125
|
// src/lftp/cat.ts
|
|
@@ -254,8 +260,17 @@ var callWebhook = async (url, token) => {
|
|
|
254
260
|
var sync = async (source, mode, config) => {
|
|
255
261
|
const reverse = mode === "push";
|
|
256
262
|
const targetName = mode === "push" ? "remote" : "local";
|
|
257
|
-
const
|
|
263
|
+
const webhookBase = `${config.url}/plugin-kirby-deploy`;
|
|
264
|
+
const shouldCallWebhooks = mode === "push" && config.callWebhooks;
|
|
258
265
|
const destination = source === "./" ? config.remoteDir : `./${join2(config.remoteDir, source)}`;
|
|
266
|
+
if (shouldCallWebhooks && !config.token) {
|
|
267
|
+
consola5.error("token needed to call webhooks");
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
if (shouldCallWebhooks && !config.url) {
|
|
271
|
+
consola5.error("url needed to call webhooks");
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
259
274
|
const flags = [
|
|
260
275
|
"--continue",
|
|
261
276
|
"--only-newer",
|
|
@@ -292,8 +307,9 @@ var sync = async (source, mode, config) => {
|
|
|
292
307
|
consola5.log("");
|
|
293
308
|
}
|
|
294
309
|
consola5.log("Apply changes...\n");
|
|
295
|
-
if (
|
|
296
|
-
await callWebhook(`${
|
|
310
|
+
if (shouldCallWebhooks) {
|
|
311
|
+
await callWebhook(`${webhookBase}/start`, config.token);
|
|
312
|
+
}
|
|
297
313
|
let hasChanges, hasErrors;
|
|
298
314
|
try {
|
|
299
315
|
;
|
|
@@ -307,8 +323,8 @@ var sync = async (source, mode, config) => {
|
|
|
307
323
|
consola5.error(e);
|
|
308
324
|
return false;
|
|
309
325
|
} finally {
|
|
310
|
-
if (
|
|
311
|
-
await callWebhook(`${
|
|
326
|
+
if (shouldCallWebhooks) {
|
|
327
|
+
await callWebhook(`${webhookBase}/finish`, config.token);
|
|
312
328
|
}
|
|
313
329
|
}
|
|
314
330
|
if (!hasChanges) {
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { loadConfig as load } from 'c12'
|
|
2
2
|
import consola from 'consola'
|
|
3
3
|
import { flatten, parse } from 'valibot'
|
|
4
|
-
import { Config, ConfigResolved, ConfigSchema } from './types'
|
|
4
|
+
import { Config, ConfigResolved, ConfigSchema, FolderStructure } from './types'
|
|
5
5
|
|
|
6
6
|
export const loadConfig = async (): Promise<ConfigResolved | null> => {
|
|
7
7
|
let { config, configFile } = await load<Config>({
|
|
@@ -27,9 +27,11 @@ export const loadConfig = async (): Promise<ConfigResolved | null> => {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// Resolve shorthands
|
|
30
|
+
|
|
31
|
+
let folderStructure: FolderStructure
|
|
30
32
|
config.folderStructure ??= 'flat'
|
|
31
33
|
if (config.folderStructure === 'public') {
|
|
32
|
-
|
|
34
|
+
folderStructure = {
|
|
33
35
|
content: 'content',
|
|
34
36
|
media: 'public/media',
|
|
35
37
|
accounts: 'storage/accounts',
|
|
@@ -37,18 +39,22 @@ export const loadConfig = async (): Promise<ConfigResolved | null> => {
|
|
|
37
39
|
cache: 'storage/cache',
|
|
38
40
|
}
|
|
39
41
|
} else if (config.folderStructure === 'flat') {
|
|
40
|
-
|
|
42
|
+
// 'flat' structure is the default.
|
|
43
|
+
folderStructure = {
|
|
41
44
|
content: 'content',
|
|
42
45
|
media: 'site/media',
|
|
43
46
|
accounts: 'site/accounts',
|
|
44
47
|
sessions: 'site/sessions',
|
|
45
48
|
cache: 'site/cache',
|
|
46
49
|
}
|
|
50
|
+
} else {
|
|
51
|
+
folderStructure = config.folderStructure
|
|
47
52
|
}
|
|
48
53
|
|
|
49
|
-
|
|
54
|
+
const configResolved = {
|
|
50
55
|
remoteDir: './',
|
|
51
56
|
dryRun: true,
|
|
57
|
+
verbose: false,
|
|
52
58
|
parallel: 10,
|
|
53
59
|
checkComposerLock: true,
|
|
54
60
|
callWebhooks: true,
|
|
@@ -57,12 +63,14 @@ export const loadConfig = async (): Promise<ConfigResolved | null> => {
|
|
|
57
63
|
include: [],
|
|
58
64
|
includeGlob: [],
|
|
59
65
|
...config,
|
|
66
|
+
folderStructure,
|
|
60
67
|
lftpSettings: {
|
|
61
68
|
'ftp:ssl-force': true,
|
|
62
69
|
...config.lftpSettings,
|
|
63
70
|
},
|
|
64
71
|
lftpFlags: ['--parallel=10', '--dereference', ...(config.lftpFlags ?? [])],
|
|
65
|
-
|
|
72
|
+
url: 'fu',
|
|
73
|
+
} satisfies ConfigResolved
|
|
66
74
|
|
|
67
|
-
return
|
|
75
|
+
return configResolved
|
|
68
76
|
}
|
package/src/sync.ts
CHANGED
|
@@ -11,10 +11,21 @@ export const sync = async (
|
|
|
11
11
|
): Promise<boolean> => {
|
|
12
12
|
const reverse = mode === 'push'
|
|
13
13
|
const targetName = mode === 'push' ? 'remote' : 'local'
|
|
14
|
-
const
|
|
14
|
+
const webhookBase = `${config.url}/plugin-kirby-deploy`
|
|
15
|
+
const shouldCallWebhooks = mode === 'push' && config.callWebhooks
|
|
15
16
|
const destination =
|
|
16
17
|
source === './' ? config.remoteDir : `./${join(config.remoteDir, source)}`
|
|
17
18
|
|
|
19
|
+
if (shouldCallWebhooks && !config.token) {
|
|
20
|
+
consola.error('token needed to call webhooks')
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (shouldCallWebhooks && !config.url) {
|
|
25
|
+
consola.error('url needed to call webhooks')
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
|
|
18
29
|
const flags = [
|
|
19
30
|
'--continue',
|
|
20
31
|
'--only-newer',
|
|
@@ -57,8 +68,10 @@ export const sync = async (
|
|
|
57
68
|
|
|
58
69
|
consola.log('Apply changes...\n')
|
|
59
70
|
|
|
71
|
+
if (shouldCallWebhooks) {
|
|
72
|
+
await callWebhook(`${webhookBase}/start`, config.token!)
|
|
73
|
+
}
|
|
60
74
|
// Make sure the finish hook is called even if an unexpected error occurs.
|
|
61
|
-
if (config.callWebhooks) await callWebhook(`${webhook}/start`, config.token)
|
|
62
75
|
let hasChanges, hasErrors
|
|
63
76
|
try {
|
|
64
77
|
;({ hasChanges, hasErrors } = await mirror(
|
|
@@ -71,8 +84,8 @@ export const sync = async (
|
|
|
71
84
|
consola.error(e)
|
|
72
85
|
return false
|
|
73
86
|
} finally {
|
|
74
|
-
if (
|
|
75
|
-
await callWebhook(`${
|
|
87
|
+
if (shouldCallWebhooks) {
|
|
88
|
+
await callWebhook(`${webhookBase}/finish`, config.token!)
|
|
76
89
|
}
|
|
77
90
|
}
|
|
78
91
|
|
package/src/types.ts
CHANGED
|
@@ -47,6 +47,9 @@ export const ConfigSchema = object({
|
|
|
47
47
|
|
|
48
48
|
export type Config = Output<typeof ConfigSchema>
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
type ConfigWithDefaults = Pick<Config, 'url' | 'token'> &
|
|
51
|
+
Required<Omit<Config, 'url' | 'token'>>
|
|
52
|
+
|
|
53
|
+
export type ConfigResolved = Omit<ConfigWithDefaults, 'folderStructure'> & {
|
|
51
54
|
folderStructure: FolderStructure
|
|
52
55
|
}
|