@atomicsmash/cli 12.0.0-beta.1 → 12.0.0-beta.3
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/commands/add-media-proxy-to-herd.d.ts +4 -0
- package/dist/commands/add-media-proxy-to-herd.d.ts.map +1 -0
- package/dist/commands/{toggle-media-proxy.js → add-media-proxy-to-herd.js} +33 -25
- package/dist/commands/pull-database.d.ts.map +1 -1
- package/dist/commands/pull-database.js +3 -2
- package/package.json +1 -1
- package/dist/commands/toggle-media-proxy.d.ts +0 -4
- package/dist/commands/toggle-media-proxy.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-media-proxy-to-herd.d.ts","sourceRoot":"","sources":["../../src/commands/add-media-proxy-to-herd.ts"],"names":[],"mappings":"AA6FA,eAAO,MAAM,OAAO,4BAA4B,CAAC;AACjD,eAAO,MAAM,QAAQ,+DACwC,CAAC;AAE9D,wBAAsB,OAAO,kBAiD5B"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { exec } from "node:child_process";
|
|
2
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
3
|
-
import { homedir, type } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
2
|
import { promisify } from "node:util";
|
|
6
3
|
import { getSmashConfig } from "@atomicsmash/smash-config";
|
|
4
|
+
import { homedir, type } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
7
7
|
const PROXY_MARKER = "location @uploadsproxy";
|
|
8
|
-
const execute = promisify(exec);
|
|
9
8
|
function buildProxyBlock(stagingURL, httpAuth) {
|
|
10
9
|
const authHeader = httpAuth
|
|
11
10
|
? `\n proxy_set_header Authorization "Basic ${httpAuth}";`
|
|
@@ -43,43 +42,52 @@ function addProxyBlock(config, stagingURL, httpAuth) {
|
|
|
43
42
|
"\n" +
|
|
44
43
|
config.slice(serverBlockEnd));
|
|
45
44
|
}
|
|
46
|
-
function
|
|
47
|
-
return config.replace(/\n\s*location \^~ \/wp-content\/uploads\/\s*\{[\s\S]*?location @uploadsproxy\s*\{[\s\S]*?\}/, "");
|
|
48
|
-
}
|
|
49
|
-
export const command = "toggle-media-proxy";
|
|
50
|
-
export const describe = "Toggle the media proxy in the local NGINX config within Herd.";
|
|
51
|
-
export async function handler() {
|
|
52
|
-
const smashConfig = await getSmashConfig(2);
|
|
53
|
-
const { projectName, staging: { url: stagingURL, httpAuth: stagingHttpAuth }, } = smashConfig;
|
|
45
|
+
function getNginxConfigPath(projectName) {
|
|
54
46
|
const isMacOS = type() === "Darwin";
|
|
55
|
-
|
|
47
|
+
return join(homedir(), isMacOS
|
|
56
48
|
? "Library/Application Support/Herd/config/valet/Nginx"
|
|
57
49
|
: ".config\\herd\\config\\nginx", `${projectName}.test`);
|
|
58
|
-
|
|
50
|
+
}
|
|
51
|
+
async function getNginxConfig(projectName) {
|
|
52
|
+
const nginxConfigPath = getNginxConfigPath(projectName);
|
|
59
53
|
try {
|
|
60
|
-
|
|
54
|
+
return await readFile(nginxConfigPath, "utf-8");
|
|
61
55
|
}
|
|
62
56
|
catch {
|
|
63
57
|
throw new Error(`Could not read NGINX config at: ${nginxConfigPath}\nMake sure the site exists in Herd.`);
|
|
64
58
|
}
|
|
59
|
+
}
|
|
60
|
+
async function updateNginxConfig(projectName, updatedConfig) {
|
|
61
|
+
const nginxConfigPath = getNginxConfigPath(projectName);
|
|
62
|
+
await writeFile(nginxConfigPath, updatedConfig, "utf-8");
|
|
63
|
+
}
|
|
64
|
+
const execute = promisify(exec);
|
|
65
|
+
export const command = "add-media-proxy-to-herd";
|
|
66
|
+
export const describe = "Add the media proxy to the local NGINX config within Herd.";
|
|
67
|
+
export async function handler() {
|
|
68
|
+
const smashConfig = await getSmashConfig(2);
|
|
69
|
+
const { projectName, staging: { url: stagingURL, httpAuth: stagingHttpAuth }, } = smashConfig;
|
|
70
|
+
const nginxConfig = await getNginxConfig(projectName);
|
|
71
|
+
if (nginxConfig.includes(PROXY_MARKER)) {
|
|
72
|
+
console.log("Media proxy is already set up in your NGINX config. To remove please delete the site in Herd, remove your .env file and re-run setup.");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
65
75
|
const httpAuth = stagingHttpAuth
|
|
66
76
|
? Buffer.from(`${stagingHttpAuth.username}:${stagingHttpAuth.password}`).toString("base64")
|
|
67
77
|
: undefined;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
console.log("Media proxy removed from NGINX config.");
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
updatedConfig = addProxyBlock(config, stagingURL, httpAuth);
|
|
78
|
+
const updatedConfig = addProxyBlock(nginxConfig, stagingURL, httpAuth);
|
|
79
|
+
await updateNginxConfig(projectName, updatedConfig)
|
|
80
|
+
.then(() => {
|
|
75
81
|
if (httpAuth) {
|
|
76
82
|
console.log("Media proxy added to NGINX config (with HTTP auth).");
|
|
77
83
|
}
|
|
78
84
|
else {
|
|
79
|
-
console.log("Media proxy added to NGINX config (no HTTP auth —
|
|
85
|
+
console.log("Media proxy added to NGINX config (no HTTP auth — httpAuth not set in smash.config.ts).");
|
|
80
86
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
87
|
+
})
|
|
88
|
+
.catch(() => {
|
|
89
|
+
console.log("Failed to update your NGINX config. Please try running the command again.");
|
|
90
|
+
});
|
|
83
91
|
console.log("Restarting Herd...");
|
|
84
92
|
await execute("herd restart")
|
|
85
93
|
.then(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull-database.d.ts","sourceRoot":"","sources":["../../src/commands/pull-database.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,OAAO,kBAAkB,CAAC;AACvC,eAAO,MAAM,QAAQ,oEAC6C,CAAC;AAEnE,wBAAsB,OAAO,
|
|
1
|
+
{"version":3,"file":"pull-database.d.ts","sourceRoot":"","sources":["../../src/commands/pull-database.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,OAAO,kBAAkB,CAAC;AACvC,eAAO,MAAM,QAAQ,oEAC6C,CAAC;AAEnE,wBAAsB,OAAO,kBAgJ5B"}
|
|
@@ -9,7 +9,7 @@ export const describe = "Pull the database down from staging and replace local d
|
|
|
9
9
|
export async function handler() {
|
|
10
10
|
const execute = promisify(exec);
|
|
11
11
|
const smashConfig = await getSmashConfig(2);
|
|
12
|
-
const { projectName, staging: { url: stagingURL, dbPrefix: stagingDBPrefix, webRoot: stagingWebRoot, ssh: { username: stagingSSHUsername, host: stagingSSHHost, port: stagingSSHPort, }, }, } = smashConfig;
|
|
12
|
+
const { projectName, staging: { url: stagingURL, dbPrefix: stagingDBPrefix, webRoot: stagingWebRoot, ssh: { username: stagingSSHUsername, host: stagingSSHHost, port: stagingSSHPort, }, }, cli: { pullMedia: { monthsToPull }, }, } = smashConfig;
|
|
13
13
|
const stopRunningMessage = startRunningMessage("Pulling database from staging");
|
|
14
14
|
performance.mark("Start");
|
|
15
15
|
await (async () => {
|
|
@@ -92,7 +92,8 @@ export async function handler() {
|
|
|
92
92
|
await stopRunningMessage4();
|
|
93
93
|
});
|
|
94
94
|
console.log(`Database import complete! ${convertMeasureToPrettyString(performance.measure("everything", "Start"))}`);
|
|
95
|
-
console.log(
|
|
95
|
+
console.log(`If you're using Herd, you can now run the proxy-media command to avoid having to download images.
|
|
96
|
+
Otherwise, you can use pull:media for a slow download of ${monthsToPull === -1 ? "all the images" : `${monthsToPull.toString()} months worth of images`} from staging.`);
|
|
96
97
|
})
|
|
97
98
|
.catch(async (error) => {
|
|
98
99
|
await stopRunningMessage();
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-media-proxy.d.ts","sourceRoot":"","sources":["../../src/commands/toggle-media-proxy.ts"],"names":[],"mappings":"AAuEA,eAAO,MAAM,OAAO,uBAAuB,CAAC;AAC5C,eAAO,MAAM,QAAQ,kEAC2C,CAAC;AAEjE,wBAAsB,OAAO,kBA2D5B"}
|