@rathnasgala/cli 0.0.4 → 0.0.7
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rathnasgala/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"src"
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"test": "node --test",
|
|
17
|
-
"lint": "node scripts/lint.js"
|
|
17
|
+
"lint": "node scripts/lint.js",
|
|
18
|
+
"preversion": "npm test && npm run lint",
|
|
19
|
+
"push": "node scripts/push.js"
|
|
18
20
|
},
|
|
19
21
|
"engines": {
|
|
20
22
|
"node": ">=18"
|
|
@@ -24,7 +26,7 @@
|
|
|
24
26
|
"url": "git+https://github.com/rathnasgala/cli.git"
|
|
25
27
|
},
|
|
26
28
|
"dependencies": {
|
|
27
|
-
"@rathnasgala/content-validation": "0.0.
|
|
29
|
+
"@rathnasgala/content-validation": "0.0.2",
|
|
28
30
|
"libsodium-wrappers": "0.8.4",
|
|
29
31
|
"tar": "7.5.22",
|
|
30
32
|
"yaml": "2.9.0"
|
package/src/configure-site.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { lstat, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { normalizeSiteConfigurationOptions } from '@rathnasgala/content-validation';
|
|
4
|
-
import {
|
|
4
|
+
import { parseDocument } from 'yaml';
|
|
5
5
|
|
|
6
6
|
import { scaffoldOptionNames } from './scaffold-options.js';
|
|
7
7
|
|
|
@@ -25,14 +25,18 @@ export async function configureSite(root, designOptions) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
let config;
|
|
28
|
+
let document;
|
|
28
29
|
try {
|
|
29
|
-
|
|
30
|
+
document = parseDocument(await readFile(configPath, 'utf8'));
|
|
31
|
+
if (document.errors.length > 0) throw document.errors[0];
|
|
32
|
+
config = document.toJS();
|
|
30
33
|
} catch (error) {
|
|
31
34
|
throw new TypeError(`Invalid site.config.yml: ${error.message}`);
|
|
32
35
|
}
|
|
33
36
|
if (config.schemaVersion !== 1 || config.design == null || Array.isArray(config.design)) {
|
|
34
37
|
throw new TypeError('Unsupported site configuration schema');
|
|
35
38
|
}
|
|
39
|
+
if (Object.keys(designOptions).length === 0) return config;
|
|
36
40
|
|
|
37
41
|
const siteOptions = Object.fromEntries(
|
|
38
42
|
Object.entries(designOptions).filter(([name]) => !scaffoldOptionNames.includes(name))
|
|
@@ -42,25 +46,38 @@ export async function configureSite(root, designOptions) {
|
|
|
42
46
|
for (const [name, value] of Object.entries(designOptions)) {
|
|
43
47
|
if (scaffoldOptionNames.includes(name)) {
|
|
44
48
|
config.design[name] = nonEmptyString(value, `Design option ${name}`);
|
|
49
|
+
document.setIn(['design', name], config.design[name]);
|
|
45
50
|
}
|
|
46
51
|
}
|
|
47
|
-
if (normalizedSiteOptions.siteName != null)
|
|
48
|
-
|
|
52
|
+
if (normalizedSiteOptions.siteName != null) {
|
|
53
|
+
config.site.name = normalizedSiteOptions.siteName;
|
|
54
|
+
document.setIn(['site', 'name'], config.site.name);
|
|
55
|
+
}
|
|
56
|
+
if (normalizedSiteOptions.siteAuthor != null) {
|
|
57
|
+
config.site.author = normalizedSiteOptions.siteAuthor;
|
|
58
|
+
document.setIn(['site', 'author'], config.site.author);
|
|
59
|
+
}
|
|
49
60
|
if (normalizedSiteOptions.defaultLanguage != null) {
|
|
50
61
|
config.site.defaultLanguage = normalizedSiteOptions.defaultLanguage;
|
|
62
|
+
document.setIn(['site', 'defaultLanguage'], config.site.defaultLanguage);
|
|
63
|
+
}
|
|
64
|
+
if (normalizedSiteOptions.timezone != null) {
|
|
65
|
+
config.site.timezone = normalizedSiteOptions.timezone;
|
|
66
|
+
document.setIn(['site', 'timezone'], config.site.timezone);
|
|
51
67
|
}
|
|
52
|
-
if (normalizedSiteOptions.timezone != null) config.site.timezone = normalizedSiteOptions.timezone;
|
|
53
68
|
if (normalizedSiteOptions.shareTargets != null) {
|
|
54
69
|
config.sharing.targets = normalizedSiteOptions.shareTargets;
|
|
70
|
+
document.setIn(['sharing', 'targets'], config.sharing.targets);
|
|
55
71
|
}
|
|
56
72
|
if (normalizedSiteOptions.socialProfiles != null) {
|
|
57
73
|
config.sharing.socialProfiles = normalizedSiteOptions.socialProfiles;
|
|
74
|
+
document.setIn(['sharing', 'socialProfiles'], config.sharing.socialProfiles);
|
|
58
75
|
}
|
|
59
76
|
|
|
60
77
|
const temporary = `${configPath}.gala-config-${process.pid}`;
|
|
61
78
|
const backup = `${configPath}.gala-backup-${process.pid}`;
|
|
62
79
|
try {
|
|
63
|
-
await writeFile(temporary,
|
|
80
|
+
await writeFile(temporary, String(document), { flag: 'wx' });
|
|
64
81
|
await rename(configPath, backup);
|
|
65
82
|
try {
|
|
66
83
|
await rename(temporary, configPath);
|
package/src/scaffold-site.js
CHANGED
|
@@ -21,9 +21,8 @@ function segment(value, field) {
|
|
|
21
21
|
return value;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function providerDefaultBase(owner
|
|
25
|
-
|
|
26
|
-
return `https://${owner.toLowerCase()}.github.io${rootRepository ? '/' : `/${repository}/`}`;
|
|
24
|
+
function providerDefaultBase(owner) {
|
|
25
|
+
return `https://${owner.toLowerCase()}.github.io`;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
export async function scaffoldSite({
|
|
@@ -77,7 +76,7 @@ export async function scaffoldSite({
|
|
|
77
76
|
if (emptyExistingRepository) await setOrigin({ root, owner: repositoryOwner, repository: repositoryName });
|
|
78
77
|
}
|
|
79
78
|
const configured = await configure(root, siteOptions ?? {});
|
|
80
|
-
const canonicalBaseUrl = providerDefaultBase(repositoryOwner
|
|
79
|
+
const canonicalBaseUrl = providerDefaultBase(repositoryOwner);
|
|
81
80
|
const idempotencyKey = `scaffold-${createHash('sha256').update(`${repositoryOwner.toLowerCase()}/${repositoryName.toLowerCase()}`).digest('hex')}`;
|
|
82
81
|
const registration = await register({
|
|
83
82
|
apiBaseUrl: gala.apiBaseUrl, galaAccessToken: gala.accessToken, idempotencyKey,
|
|
@@ -87,6 +86,7 @@ export async function scaffoldSite({
|
|
|
87
86
|
await finalize(root, {
|
|
88
87
|
siteId: registration.siteId,
|
|
89
88
|
canonicalBaseUrl: registration.canonicalBaseUrl,
|
|
89
|
+
pathPrefix: registration.pathPrefix,
|
|
90
90
|
topology: 'provider-default'
|
|
91
91
|
});
|
|
92
92
|
await writeWorkflow({
|
|
@@ -2,12 +2,20 @@ import { lstat, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { parse, stringify } from 'yaml';
|
|
4
4
|
|
|
5
|
-
export async function writeRegisteredSiteConfiguration(root, {
|
|
5
|
+
export async function writeRegisteredSiteConfiguration(root, {
|
|
6
|
+
siteId, canonicalBaseUrl, pathPrefix, topology
|
|
7
|
+
}) {
|
|
6
8
|
if (!/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(siteId)) throw new TypeError('siteId is invalid');
|
|
7
9
|
if (topology !== 'provider-default') throw new TypeError('Only provider-default topology is implemented');
|
|
8
10
|
const canonical = new URL(canonicalBaseUrl);
|
|
9
|
-
if (canonical.protocol !== 'https:' || canonical.username || canonical.password || canonical.search
|
|
10
|
-
|
|
11
|
+
if (canonical.protocol !== 'https:' || canonical.username || canonical.password || canonical.search
|
|
12
|
+
|| canonical.hash || canonical.pathname !== '/') {
|
|
13
|
+
throw new TypeError('canonicalBaseUrl must be a credential-free HTTPS origin; put the URL path in pathPrefix');
|
|
14
|
+
}
|
|
15
|
+
const normalizedPrefix = pathPrefix === '' ? '/' : pathPrefix;
|
|
16
|
+
if (typeof normalizedPrefix !== 'string'
|
|
17
|
+
|| !/^\/(?:[^/?#]+(?:\/[^/?#]+)*)?$/.test(normalizedPrefix)) {
|
|
18
|
+
throw new TypeError('pathPrefix must be a normalized URL path');
|
|
11
19
|
}
|
|
12
20
|
const target = path.resolve(root, 'site.config.yml');
|
|
13
21
|
const metadata = await lstat(target);
|
|
@@ -19,8 +27,8 @@ export async function writeRegisteredSiteConfiguration(root, { siteId, canonical
|
|
|
19
27
|
config.site.id = siteId;
|
|
20
28
|
config.hosting.provider = 'github-pages';
|
|
21
29
|
config.hosting.topology = topology;
|
|
22
|
-
config.hosting.canonicalBaseUrl = canonical.
|
|
23
|
-
config.hosting.pathPrefix =
|
|
30
|
+
config.hosting.canonicalBaseUrl = canonical.origin;
|
|
31
|
+
config.hosting.pathPrefix = normalizedPrefix;
|
|
24
32
|
const temporary = `${target}.gala-register-${process.pid}`;
|
|
25
33
|
const backup = `${target}.gala-backup-${process.pid}`;
|
|
26
34
|
try {
|
|
@@ -72,9 +72,13 @@ export async function registerSite({
|
|
|
72
72
|
}
|
|
73
73
|
const canonical = new URL(payload.canonicalBaseUrl);
|
|
74
74
|
if (canonical.protocol !== 'https:' || canonical.username || canonical.password
|
|
75
|
-
|| canonical.search || canonical.hash) {
|
|
75
|
+
|| canonical.search || canonical.hash || canonical.pathname !== '/') {
|
|
76
76
|
throw new TypeError('Gala site registration returned an invalid canonicalBaseUrl');
|
|
77
77
|
}
|
|
78
|
+
if (typeof payload.pathPrefix !== 'string'
|
|
79
|
+
|| !/^\/(?:[^/?#]+(?:\/[^/?#]+)*)?$/.test(payload.pathPrefix)) {
|
|
80
|
+
throw new TypeError('Gala site registration returned an invalid pathPrefix');
|
|
81
|
+
}
|
|
78
82
|
const location = response.headers?.get?.('location');
|
|
79
83
|
if (location !== `/v1/sites/${payload.siteId}`) {
|
|
80
84
|
throw new TypeError('Gala site registration returned an invalid Location header');
|
|
@@ -82,6 +86,7 @@ export async function registerSite({
|
|
|
82
86
|
return Object.freeze({
|
|
83
87
|
siteId: payload.siteId,
|
|
84
88
|
siteSecret: payload.siteSecret,
|
|
85
|
-
canonicalBaseUrl: canonical.
|
|
89
|
+
canonicalBaseUrl: canonical.origin,
|
|
90
|
+
pathPrefix: payload.pathPrefix === '' ? '/' : payload.pathPrefix
|
|
86
91
|
});
|
|
87
92
|
}
|