-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
103 lines (96 loc) · 3.1 KB
/
worker.js
File metadata and controls
103 lines (96 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Template JSON stored as a constant
const template = {
landingPage: "/wp-admin/admin.php?page=wc-admin",
login: true,
features: { networking: true, intl: true },
steps: [
{
step: "installPlugin",
pluginData: {
resource: "url",
url: "https://github-proxy.com/proxy/?repo=woocommerce/woocommerce&release={release}&asset={asset}",
},
},
{
step: "writeFile",
path: "/wordpress/wp-content/mu-plugins/rewrite.php",
data: "<?php /* Use pretty permalinks */ add_action( 'after_setup_theme', function() { global $wp_rewrite; $wp_rewrite->set_permalink_structure('/%postname%/'); $wp_rewrite->flush_rules(); } );",
},
{
step: "setSiteOptions",
options: {
blogname: "WooCommerce",
woocommerce_store_city: "Los Angeles",
woocommerce_store_address: "123 Main St",
woocommerce_store_postcode: "90038",
woocommerce_default_country: "United States",
woocommerce_onboarding_profile: {
skipped: true,
},
woocommerce_currency: "USD",
woocommerce_weight_unit: "lbs",
woocommerce_dimension_unit: "in",
woocommerce_allow_tracking: "no",
woocommerce_cheque_settings: {
enabled: "yes",
},
},
},
{
step: "importWxr",
file: {
resource: "url",
url: "https://raw.githubusercontent.com/woocommerce/woocommerce/refs/heads/trunk/plugins/woocommerce/sample-data/sample_products.xml",
},
},
],
};
export default {
async fetch(request, env, ctx) {
// Parse the URL to get the release parameter
const url = new URL(request.url);
const release = url.searchParams.get("release") || "latest";
const smoothGen = url.searchParams.get("smooth-generator") || "false";
// Create a deep copy of the template
const response = JSON.parse(JSON.stringify(template));
// Update the release in the URL
response.steps[0].pluginData.url = response.steps[0].pluginData.url.replace(
"{release}",
release
);
if (smoothGen === "true") {
// Add smooth generator plugin install as the last step
response.steps.push({
step: "installPlugin",
pluginData: {
resource: "url",
url: "https://github-proxy.com/proxy/?repo=woocommerce/wc-smooth-generator&release=latest&asset=wc-smooth-generator.zip",
},
options: {
activate: true,
targetFolderName: "wc-smooth-generator",
},
});
response.steps.push({
step: "wp-cli",
command: "wp wc generate orders 10",
});
}
let asset = "woocommerce.zip";
if (release === "nightly") {
asset = "woocommerce-trunk-nightly.zip";
}
response.steps[0].pluginData.url = response.steps[0].pluginData.url.replace(
"{asset}",
asset
);
// Return the JSON with proper headers
return new Response(JSON.stringify(response, null, 2), {
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Cache-Control": "public, max-age=3600",
},
});
},
};