wp-studio 1.7.7-alpha1

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.
Files changed (48) hide show
  1. package/LICENSE.md +257 -0
  2. package/README.md +87 -0
  3. package/dist/cli/_events-BeOo0LuG.js +116 -0
  4. package/dist/cli/appdata-07CF2rhg.js +21090 -0
  5. package/dist/cli/archive-xDmkN4wb.js +15942 -0
  6. package/dist/cli/browser-CgWK-yoe.js +44 -0
  7. package/dist/cli/certificate-manager-DdBumKZp.js +250 -0
  8. package/dist/cli/create-BHVhkvTx.js +80 -0
  9. package/dist/cli/create-ZS29BDDi.js +40999 -0
  10. package/dist/cli/delete-BgQn-elT.js +56 -0
  11. package/dist/cli/delete-g8pgaLna.js +132 -0
  12. package/dist/cli/get-wordpress-version-BwSCJujO.js +18 -0
  13. package/dist/cli/index-7pbG_s_U.js +434 -0
  14. package/dist/cli/index-BXRYeCYG.js +1393 -0
  15. package/dist/cli/index-T3F1GwxX.js +2668 -0
  16. package/dist/cli/is-errno-exception-t38xF2pB.js +6 -0
  17. package/dist/cli/list-BE_UBjL5.js +105 -0
  18. package/dist/cli/list-DKz0XxM7.js +1032 -0
  19. package/dist/cli/logger-actions-OaIvl-ai.js +45 -0
  20. package/dist/cli/login-B4PkfKOu.js +82 -0
  21. package/dist/cli/logout-BC9gKlTj.js +48 -0
  22. package/dist/cli/main.js +5 -0
  23. package/dist/cli/mu-plugins-GEfKsl5U.js +530 -0
  24. package/dist/cli/passwords-DyzWd9Xi.js +80 -0
  25. package/dist/cli/process-manager-daemon.js +327 -0
  26. package/dist/cli/process-manager-ipc-AUZeYYDT.js +454 -0
  27. package/dist/cli/proxy-daemon.js +197 -0
  28. package/dist/cli/run-wp-cli-command-BctnMDWG.js +88 -0
  29. package/dist/cli/sequential-BQFuixXz.js +46 -0
  30. package/dist/cli/server-files-C_oy-mnI.js +26 -0
  31. package/dist/cli/set-DknhAZpw.js +327 -0
  32. package/dist/cli/site-utils-CfsabjUn.js +243 -0
  33. package/dist/cli/snapshots-6XE53y_F.js +874 -0
  34. package/dist/cli/sqlite-integration-H4OwSlwR.js +83 -0
  35. package/dist/cli/start-CRJqm09_.js +90 -0
  36. package/dist/cli/status-CWNHIOaY.js +44 -0
  37. package/dist/cli/status-CWWx9jYF.js +110 -0
  38. package/dist/cli/stop-CQosmjqA.js +117 -0
  39. package/dist/cli/update-BgL2HKHW.js +101 -0
  40. package/dist/cli/validation-error-DqLxqQuA.js +40 -0
  41. package/dist/cli/wordpress-server-child.js +514 -0
  42. package/dist/cli/wordpress-server-ipc-Dwsg9jSb.js +140 -0
  43. package/dist/cli/wordpress-server-manager-CtiuJqEb.js +566 -0
  44. package/dist/cli/wordpress-version-utils-B6UVeTh_.js +51 -0
  45. package/dist/cli/wp-UGSnlkN0.js +103 -0
  46. package/package.json +73 -0
  47. package/patches/@wp-playground+wordpress+3.1.12.patch +28 -0
  48. package/scripts/postinstall-npm.mjs +38 -0
@@ -0,0 +1,56 @@
1
+ import { P as PreviewCommandLoggerAction } from "./logger-actions-OaIvl-ai.js";
2
+ import { __ } from "@wordpress/i18n";
3
+ import { a as Logger, g as getAuthToken, L as LoggerError, n as deleteSnapshot } from "./appdata-07CF2rhg.js";
4
+ import { g as getSnapshotsFromAppdata, a as deleteSnapshotFromAppdata } from "./snapshots-6XE53y_F.js";
5
+ import { n as normalizeHostname } from "./index-7pbG_s_U.js";
6
+ async function runCommand(host) {
7
+ const logger = new Logger();
8
+ try {
9
+ logger.reportStart(PreviewCommandLoggerAction.VALIDATE, __("Validating…"));
10
+ const token = await getAuthToken();
11
+ const snapshots = await getSnapshotsFromAppdata(token.id);
12
+ const snapshotToDelete = snapshots.find((s) => s.url === host);
13
+ if (!snapshotToDelete) {
14
+ throw new LoggerError(
15
+ __(
16
+ "Preview site not found. Use the `studio preview list` command to see available preview sites."
17
+ )
18
+ );
19
+ }
20
+ logger.reportSuccess(__("Validation successful"), true);
21
+ logger.reportStart(PreviewCommandLoggerAction.DELETE, __("Deleting…"));
22
+ await deleteSnapshot(snapshotToDelete.atomicSiteId, token.accessToken);
23
+ await deleteSnapshotFromAppdata(snapshotToDelete.url);
24
+ logger.reportSuccess(__("Deletion successful"));
25
+ } catch (error) {
26
+ if (error instanceof LoggerError) {
27
+ logger.reportError(error);
28
+ } else {
29
+ const loggerError = new LoggerError(__("Failed to delete preview site"), error);
30
+ logger.reportError(loggerError);
31
+ }
32
+ }
33
+ }
34
+ const registerCommand = (yargs) => {
35
+ return yargs.command({
36
+ command: "delete <host>",
37
+ describe: __("Delete a preview site"),
38
+ builder: (yargs2) => {
39
+ return yargs2.positional("host", {
40
+ type: "string",
41
+ description: __("Hostname of the preview site to delete"),
42
+ demandOption: true
43
+ }).option("path", {
44
+ hidden: true
45
+ });
46
+ },
47
+ handler: async (argv) => {
48
+ const normalizedHost = normalizeHostname(argv.host);
49
+ await runCommand(normalizedHost);
50
+ }
51
+ });
52
+ };
53
+ export {
54
+ registerCommand,
55
+ runCommand
56
+ };
@@ -0,0 +1,132 @@
1
+ import fs from "fs";
2
+ import { L as LoggerError, a as Logger, k as getSiteByFolder, g as getAuthToken, l as lockAppdata, r as readAppdata, G as arePathsEqual, s as saveAppdata, u as unlockAppdata, S as SITE_EVENTS, n as deleteSnapshot } from "./appdata-07CF2rhg.js";
3
+ import { S as SiteCommandLoggerAction } from "./logger-actions-OaIvl-ai.js";
4
+ import { __, sprintf, _n } from "@wordpress/i18n";
5
+ import { d as deleteSiteCertificate } from "./certificate-manager-DdBumKZp.js";
6
+ import { c as connectToDaemon, i as isServerRunning, a as stopWordPressServer, e as emitSiteEvent, d as disconnectFromDaemon } from "./wordpress-server-manager-CtiuJqEb.js";
7
+ import { a as stopProxyIfNoSitesNeedIt, r as removeDomainFromHosts } from "./site-utils-CfsabjUn.js";
8
+ import { g as getSnapshotsFromAppdata, a as deleteSnapshotFromAppdata } from "./snapshots-6XE53y_F.js";
9
+ const logger = new Logger();
10
+ async function deletePreviewSites(authToken, siteFolder) {
11
+ try {
12
+ const snapshots = await getSnapshotsFromAppdata(authToken.id, siteFolder);
13
+ if (snapshots.length > 0) {
14
+ logger.reportStart(
15
+ SiteCommandLoggerAction.DELETE_PREVIEW_SITES,
16
+ // translators: %d is the number of associated preview sites
17
+ sprintf(
18
+ _n(
19
+ "Deleting %d associated preview site…",
20
+ "Deleting %d associated preview sites…",
21
+ snapshots.length
22
+ ),
23
+ snapshots.length
24
+ )
25
+ );
26
+ await Promise.all(
27
+ snapshots.map(async (snapshot) => {
28
+ await deleteSnapshot(snapshot.atomicSiteId, authToken.accessToken);
29
+ await deleteSnapshotFromAppdata(snapshot.url);
30
+ })
31
+ );
32
+ logger.reportSuccess(__("Associated preview sites deleted"));
33
+ }
34
+ } catch (error) {
35
+ logger.reportError(
36
+ new LoggerError(
37
+ __("Failed to delete associated preview sites. Proceeding anyway…"),
38
+ error
39
+ ),
40
+ false
41
+ );
42
+ }
43
+ }
44
+ async function runCommand(siteFolder, deleteFiles = false) {
45
+ try {
46
+ logger.reportStart(SiteCommandLoggerAction.START_DAEMON, __("Starting process daemon…"));
47
+ await connectToDaemon();
48
+ logger.reportSuccess(__("Process daemon started"));
49
+ logger.reportStart(SiteCommandLoggerAction.LOAD_SITES, __("Loading site…"));
50
+ const site = await getSiteByFolder(siteFolder);
51
+ logger.reportSuccess(__("Site loaded"));
52
+ const runningProcess = await isServerRunning(site.id);
53
+ if (runningProcess) {
54
+ logger.reportStart(SiteCommandLoggerAction.STOP_SITE, __("Stopping WordPress server…"));
55
+ await stopWordPressServer(site.id);
56
+ logger.reportSuccess(__("WordPress server stopped"));
57
+ await stopProxyIfNoSitesNeedIt(site.id, logger);
58
+ }
59
+ if (site.customDomain) {
60
+ logger.reportStart(
61
+ SiteCommandLoggerAction.REMOVE_DOMAIN_FROM_HOSTS,
62
+ __("Removing domain from hosts file…")
63
+ );
64
+ await removeDomainFromHosts(site.customDomain);
65
+ logger.reportSuccess(__("Domain removed from hosts file"));
66
+ if (site.enableHttps) {
67
+ logger.reportStart(SiteCommandLoggerAction.DELETE_CERT, __("Deleting SSL certificates…"));
68
+ deleteSiteCertificate(site.customDomain);
69
+ logger.reportSuccess(__("SSL certificates deleted"));
70
+ }
71
+ }
72
+ try {
73
+ const authToken = await getAuthToken();
74
+ await deletePreviewSites(authToken, siteFolder);
75
+ } catch (error) {
76
+ }
77
+ try {
78
+ await lockAppdata();
79
+ const appdata = await readAppdata();
80
+ const siteIndex = appdata.sites.findIndex((s) => arePathsEqual(s.path, siteFolder));
81
+ if (siteIndex === -1) {
82
+ throw new LoggerError(__("The specified directory is not added to Studio."));
83
+ }
84
+ appdata.sites.splice(siteIndex, 1);
85
+ await saveAppdata(appdata);
86
+ } finally {
87
+ await unlockAppdata();
88
+ }
89
+ if (deleteFiles) {
90
+ if (fs.existsSync(siteFolder)) {
91
+ logger.reportStart(SiteCommandLoggerAction.DELETE_FILES, __("Moving site files to trash…"));
92
+ const trash = (await import("trash")).default;
93
+ await trash(siteFolder);
94
+ logger.reportSuccess(__("Site files moved to trash"));
95
+ } else {
96
+ logger.reportSuccess(__("Site files already removed"));
97
+ }
98
+ }
99
+ await emitSiteEvent(SITE_EVENTS.DELETED, { siteId: site.id });
100
+ } finally {
101
+ await disconnectFromDaemon();
102
+ }
103
+ }
104
+ const registerCommand = (yargs) => {
105
+ return yargs.command({
106
+ command: "delete",
107
+ describe: __("Delete site"),
108
+ builder: (yargs2) => {
109
+ return yargs2.option("files", {
110
+ type: "boolean",
111
+ description: __("Also move site files to trash"),
112
+ default: false
113
+ });
114
+ },
115
+ handler: async (argv) => {
116
+ try {
117
+ await runCommand(argv.path, argv.files);
118
+ } catch (error) {
119
+ if (error instanceof LoggerError) {
120
+ logger.reportError(error);
121
+ } else {
122
+ const loggerError = new LoggerError(__("Failed to delete site"), error);
123
+ logger.reportError(loggerError);
124
+ }
125
+ }
126
+ }
127
+ });
128
+ };
129
+ export {
130
+ registerCommand,
131
+ runCommand
132
+ };
@@ -0,0 +1,18 @@
1
+ import path from "path";
2
+ import { f as fs } from "./index-BXRYeCYG.js";
3
+ function getWordPressVersion(wordPressPath) {
4
+ let versionFileContent = "";
5
+ try {
6
+ versionFileContent = fs.readFileSync(
7
+ path.join(wordPressPath, "wp-includes", "version.php"),
8
+ "utf8"
9
+ );
10
+ } catch (err) {
11
+ return "-";
12
+ }
13
+ const matches = versionFileContent.match(/\$wp_version\s*=\s*'([0-9a-zA-Z.-]+)'/);
14
+ return matches?.[1] || "-";
15
+ }
16
+ export {
17
+ getWordPressVersion as g
18
+ };