@pipelab/plugin-construct 1.0.0-beta.0
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/CHANGELOG.md +12 -0
- package/LICENSE +110 -0
- package/README.md +3 -0
- package/dist/index.cjs +433 -0
- package/dist/index.d.cts +132 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +132 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +428 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +50 -0
- package/src/assets/construct.webp +0 -0
- package/src/assets/script.ts +288 -0
- package/src/declarations.d.ts +1 -0
- package/src/export-c3p.ts +75 -0
- package/src/export-project.ts +75 -0
- package/src/export-shared.ts +286 -0
- package/src/export.test.ts +37 -0
- package/src/index.ts +34 -0
- package/tests/e2e/construct.spec.ts +60 -0
- package/tests/e2e/fixtures/c3-export/test.c3p +0 -0
- package/tests/e2e/fixtures/c3-export.json +51 -0
- package/tests/e2e/fixtures/html-export/index.html +29 -0
- package/tests/e2e/vitest.config.mts +20 -0
- package/tsconfig.json +10 -0
- package/tsdown.config.ts +15 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-MIT
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 CynToolkit
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
91
|
+
the Software available. On or after that date, you may use the Software under
|
|
92
|
+
the MIT license, in which case the following will apply:
|
|
93
|
+
|
|
94
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
95
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
96
|
+
the Software without restriction, including without limitation the rights to
|
|
97
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
98
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
99
|
+
so, subject to the following conditions:
|
|
100
|
+
|
|
101
|
+
The above copyright notice and this permission notice shall be included in all
|
|
102
|
+
copies or substantial portions of the Software.
|
|
103
|
+
|
|
104
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
105
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
106
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
107
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
108
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
109
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
110
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
Object.create;
|
|
2
|
+
Object.defineProperty;
|
|
3
|
+
Object.getOwnPropertyDescriptor;
|
|
4
|
+
Object.getOwnPropertyNames;
|
|
5
|
+
Object.getPrototypeOf;
|
|
6
|
+
Object.prototype.hasOwnProperty;
|
|
7
|
+
//#endregion
|
|
8
|
+
let _pipelab_plugin_core = require("@pipelab/plugin-core");
|
|
9
|
+
let node_path = require("node:path");
|
|
10
|
+
require("valibot");
|
|
11
|
+
let node_fs_promises = require("node:fs/promises");
|
|
12
|
+
let node_os = require("node:os");
|
|
13
|
+
let node_module = require("node:module");
|
|
14
|
+
//#region src/assets/script.ts
|
|
15
|
+
const registerInstallButtonListener = (page, log) => {
|
|
16
|
+
const installBtn = page.locator("#addonConfirmInstallDialog").locator(".okButton");
|
|
17
|
+
installBtn.waitFor({ timeout: 0 }).then(async () => {
|
|
18
|
+
await installBtn.click();
|
|
19
|
+
log("installBtn clicked");
|
|
20
|
+
registerInstallButtonListener(page, log);
|
|
21
|
+
}).catch(async (e) => {
|
|
22
|
+
if (e.message.includes("Target page, context or browser has been closed")) return;
|
|
23
|
+
log("installBtn.click() failed", e.message);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
const registerSaveLoginExpiredistener = (page, log) => {
|
|
27
|
+
const cancelBtn = page.locator("#confirmDialog").locator(".cancelConfirmButton");
|
|
28
|
+
cancelBtn.waitFor({ timeout: 0 }).then(async () => {
|
|
29
|
+
await cancelBtn.click();
|
|
30
|
+
log("cancelBtn clicked");
|
|
31
|
+
registerSaveLoginExpiredistener(page, log);
|
|
32
|
+
}).catch(async (e) => {
|
|
33
|
+
if (e.message.includes("Target page, context or browser has been closed")) return;
|
|
34
|
+
log("cancelBtn.click() failed", e.message);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const registerWebglErrorListener = (page, log) => {
|
|
38
|
+
const okDialog = page.locator("#okDialog");
|
|
39
|
+
const webglErrorButton = okDialog.locator(".okButton");
|
|
40
|
+
webglErrorButton.waitFor({ timeout: 0 }).then(async () => {
|
|
41
|
+
if ((await okDialog.allInnerTexts()).join().toLowerCase().includes("webgl")) {
|
|
42
|
+
await webglErrorButton.click();
|
|
43
|
+
log("webglErrorButton clicked");
|
|
44
|
+
registerWebglErrorListener(page, log);
|
|
45
|
+
}
|
|
46
|
+
}).catch(async (e) => {
|
|
47
|
+
if (e.message.includes("Target page, context or browser has been closed")) return;
|
|
48
|
+
log("webglErrorButton.click() failed", e.message);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const registerDeprecatedFeatures = (page, log) => {
|
|
52
|
+
const okButton = page.locator("#deprecatedFeaturesDialog").locator(".okButton");
|
|
53
|
+
okButton.waitFor({ timeout: 0 }).then(async () => {
|
|
54
|
+
await okButton.click();
|
|
55
|
+
log("okButton clicked");
|
|
56
|
+
registerDeprecatedFeatures(page, log);
|
|
57
|
+
}).catch(async (e) => {
|
|
58
|
+
if (e.message.includes("Target page, context or browser has been closed")) return;
|
|
59
|
+
log("deprecatedFeatures.okButton.click() failed", e.message);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
const registerWelcomeToConstructListener = (page, log) => {
|
|
63
|
+
const okButton = page.locator("#welcomeTourDialog").locator(".noThanksLink");
|
|
64
|
+
okButton.waitFor({ timeout: 0 }).then(async () => {
|
|
65
|
+
await okButton.click();
|
|
66
|
+
log("okButton clicked");
|
|
67
|
+
}).catch(async (e) => {
|
|
68
|
+
if (e.message.includes("Target page, context or browser has been closed")) return;
|
|
69
|
+
log("welcomeTour.okButton.click() failed", e.message);
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
const registerMissingAddonErrorListener = (page, log) => {
|
|
73
|
+
page.locator("#missingAddonsDialog").locator(".okButton").waitFor({ timeout: 0 }).then(async () => {
|
|
74
|
+
throw new Error("Missing addon. You should bundle addons with your project");
|
|
75
|
+
}).catch(async (e) => {
|
|
76
|
+
if (e.message.includes("Target page, context or browser has been closed")) return;
|
|
77
|
+
log("missingAddon.okButton.waitFor() failed", e.message);
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
const registerNewVersionAvailableListener = (page, log) => {
|
|
81
|
+
const cancelButton = page.locator("#confirmDialog").locator(".cancelConfirmButton");
|
|
82
|
+
cancelButton.waitFor({ timeout: 0 }).then(async () => {
|
|
83
|
+
await cancelButton.click();
|
|
84
|
+
log("cancelButton clicked");
|
|
85
|
+
registerNewVersionAvailableListener(page, log);
|
|
86
|
+
}).catch(async (e) => {
|
|
87
|
+
if (e.message.includes("Target page, context or browser has been closed")) return;
|
|
88
|
+
log("cancelButton.click() failed", e.message);
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
const script = async (page, log, filePath, username, password, version, downloadDir) => {
|
|
92
|
+
let url = "https://editor.construct.net/";
|
|
93
|
+
if (version) url += version;
|
|
94
|
+
log("Navigating to URL", url);
|
|
95
|
+
await page.goto(url);
|
|
96
|
+
log("after navigating");
|
|
97
|
+
registerWelcomeToConstructListener(page, log);
|
|
98
|
+
registerNewVersionAvailableListener(page, log);
|
|
99
|
+
log("after event");
|
|
100
|
+
await page.waitForTimeout(2e3);
|
|
101
|
+
log("after wait");
|
|
102
|
+
if (username && password) {
|
|
103
|
+
log("Authenticating");
|
|
104
|
+
await page.getByTitle("User account").locator("ui-icon").click();
|
|
105
|
+
await page.getByRole("menuitem", { name: "Log in" }).locator("span").click();
|
|
106
|
+
await page.frameLocator("#loginDialog iframe").getByLabel("Username").fill(username);
|
|
107
|
+
await page.frameLocator("#loginDialog iframe").getByLabel("Password").fill(password);
|
|
108
|
+
const tokenPromise = page.waitForResponse(/https:\/\/account.*\.construct\.net\/login.json/i);
|
|
109
|
+
await page.frameLocator("#loginDialog iframe").getByRole("button", { name: "Log in" }).click();
|
|
110
|
+
if ((await (await tokenPromise).json()).request.status === "error") {
|
|
111
|
+
await page.close();
|
|
112
|
+
throw new Error("Invalid credentials");
|
|
113
|
+
}
|
|
114
|
+
log("Authenticated");
|
|
115
|
+
}
|
|
116
|
+
await page.waitForTimeout(2e3);
|
|
117
|
+
const [fileChooser] = await Promise.all([page.waitForEvent("filechooser"), page.keyboard.press("ControlOrMeta+O")]);
|
|
118
|
+
log("filechooser");
|
|
119
|
+
console.log("filePath", filePath);
|
|
120
|
+
await fileChooser.setFiles([filePath]);
|
|
121
|
+
log("Set file");
|
|
122
|
+
const progressDialog = page.locator("#progressDialog");
|
|
123
|
+
const progessBar = progressDialog.locator(".progressBar");
|
|
124
|
+
log("Waiting for progress dialog");
|
|
125
|
+
await progressDialog.waitFor({ timeout: 0 });
|
|
126
|
+
log("Got loading progress dialog");
|
|
127
|
+
const progressInterval = setInterval(async () => {
|
|
128
|
+
const text = await progessBar.getAttribute("value");
|
|
129
|
+
const textAsNumber = parseFloat(text);
|
|
130
|
+
log("progress", `${(Number.isNaN(textAsNumber) ? 0 : textAsNumber) * 100}%`);
|
|
131
|
+
}, 500);
|
|
132
|
+
const notNowBtn = page.getByText("Not now");
|
|
133
|
+
notNowBtn.waitFor({ timeout: 0 }).then(async () => {
|
|
134
|
+
return notNowBtn.click();
|
|
135
|
+
}).then(() => {
|
|
136
|
+
log("notNowBtn clicked");
|
|
137
|
+
}).catch(async (e) => {
|
|
138
|
+
if (e.message.includes("Target page, context or browser has been closed")) return;
|
|
139
|
+
log("notNowBtn.click() failed", e.message);
|
|
140
|
+
});
|
|
141
|
+
registerInstallButtonListener(page, log);
|
|
142
|
+
registerWebglErrorListener(page, log);
|
|
143
|
+
registerMissingAddonErrorListener(page, log);
|
|
144
|
+
registerDeprecatedFeatures(page, log);
|
|
145
|
+
registerSaveLoginExpiredistener(page, log);
|
|
146
|
+
log("Waiting for progress dialog to disapear");
|
|
147
|
+
await progressDialog.waitFor({
|
|
148
|
+
state: "detached",
|
|
149
|
+
timeout: 0
|
|
150
|
+
});
|
|
151
|
+
log("Got progress dialog to disapear");
|
|
152
|
+
clearTimeout(progressInterval);
|
|
153
|
+
await page.getByRole("button", { name: "Menu" }).click();
|
|
154
|
+
await page.getByRole("menuitem", { name: "Project" }).click();
|
|
155
|
+
await page.getByRole("menuitem", { name: "Export" }).click();
|
|
156
|
+
log("\"Export\" clicked");
|
|
157
|
+
await page.locator("ui-iconviewitem").filter({ hasText: "Web (HTML5)" }).locator("ui-icon").click();
|
|
158
|
+
log("\"Web\" clicked");
|
|
159
|
+
await page.locator("#exportSelectPlatformDialog").getByRole("button", { name: "Next" }).click();
|
|
160
|
+
await page.getByLabel("Offline support").uncheck();
|
|
161
|
+
log("Disabled offline support");
|
|
162
|
+
await page.locator("#exportStandardOptionsDialog").getByRole("button", { name: "Next" }).click();
|
|
163
|
+
log("\"Next\" clicked");
|
|
164
|
+
const downloadPromise = page.waitForEvent("download");
|
|
165
|
+
await page.locator(".downloadExportedProject").click();
|
|
166
|
+
const download = await downloadPromise;
|
|
167
|
+
await page.getByRole("button", { name: "OK" }).click();
|
|
168
|
+
log("\"Download\" clicked");
|
|
169
|
+
const finalPath = (0, node_path.join)(downloadDir, download.suggestedFilename());
|
|
170
|
+
await download.saveAs(finalPath);
|
|
171
|
+
log("File Downloaded");
|
|
172
|
+
await page.close();
|
|
173
|
+
return finalPath;
|
|
174
|
+
};
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/export-shared.ts
|
|
177
|
+
const platform = process.platform;
|
|
178
|
+
const { LOCALAPPDATA, XDG_CONFIG_HOME } = process.env;
|
|
179
|
+
const isCI = process.env.CI === "true";
|
|
180
|
+
let baseProfile;
|
|
181
|
+
if (platform === "win32") baseProfile = (0, node_path.join)(LOCALAPPDATA ?? "", "Google", "Chrome", "User Data");
|
|
182
|
+
else if (platform === "linux") baseProfile = (0, node_path.join)(XDG_CONFIG_HOME ?? "", "google-chrome");
|
|
183
|
+
else if (platform === "darwin") baseProfile = (0, node_path.join)((0, node_os.homedir)(), "Library", "Application Support", "Google", "Chrome");
|
|
184
|
+
const sharedParams = {
|
|
185
|
+
username: (0, _pipelab_plugin_core.createStringParam)("", {
|
|
186
|
+
label: "Username",
|
|
187
|
+
required: false,
|
|
188
|
+
description: "Your Construct username"
|
|
189
|
+
}),
|
|
190
|
+
password: (0, _pipelab_plugin_core.createPasswordParam)("", {
|
|
191
|
+
description: "Your Construct password. Will only be used locally to automate the export on Construct website via a local browser. Will not be sent to any server.",
|
|
192
|
+
required: false,
|
|
193
|
+
label: "Password"
|
|
194
|
+
}),
|
|
195
|
+
version: (0, _pipelab_plugin_core.createStringParam)("", {
|
|
196
|
+
description: "The Construct version you want to use",
|
|
197
|
+
label: "Version",
|
|
198
|
+
required: false
|
|
199
|
+
}),
|
|
200
|
+
headless: {
|
|
201
|
+
description: "Whether to show the browser while export",
|
|
202
|
+
required: false,
|
|
203
|
+
control: { type: "boolean" },
|
|
204
|
+
value: false,
|
|
205
|
+
label: "Start headless"
|
|
206
|
+
},
|
|
207
|
+
timeout: (0, _pipelab_plugin_core.createNumberParam)(120, {
|
|
208
|
+
description: "The timeout (in seconds) to close the browser if it's stuck",
|
|
209
|
+
required: false,
|
|
210
|
+
label: "Timeout"
|
|
211
|
+
}),
|
|
212
|
+
customProfile: (0, _pipelab_plugin_core.createPathParam)(void 0, {
|
|
213
|
+
required: false,
|
|
214
|
+
description: "Use your own profile (X:\\Users\\XXX\\AppData\\Local\\Google\\Chrome\\User Data). Usefull if you want to reuse plugins installed in your current browser",
|
|
215
|
+
control: {
|
|
216
|
+
type: "path",
|
|
217
|
+
options: {
|
|
218
|
+
properties: ["openDirectory"],
|
|
219
|
+
defaultPath: baseProfile
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
label: "Custom profile"
|
|
223
|
+
})
|
|
224
|
+
};
|
|
225
|
+
const exportc3p = async (file, { cwd, log, inputs, setOutput, paths, abortSignal, context: ctx }) => {
|
|
226
|
+
let browserContext = void 0;
|
|
227
|
+
let browser = void 0;
|
|
228
|
+
abortSignal.addEventListener("abort", () => {
|
|
229
|
+
console.error("aborted");
|
|
230
|
+
browserContext?.close();
|
|
231
|
+
});
|
|
232
|
+
const newInputs = inputs;
|
|
233
|
+
const { thirdparty, node, pnpm } = paths;
|
|
234
|
+
const browserName = "chromium";
|
|
235
|
+
const { packageDir: playwrightPkgPath } = await (0, _pipelab_plugin_core.fetchPackage)("playwright-core", "1.48.2", {
|
|
236
|
+
installDeps: true,
|
|
237
|
+
context: ctx
|
|
238
|
+
});
|
|
239
|
+
const playwrightCli = (0, node_path.join)(playwrightPkgPath, "cli.js");
|
|
240
|
+
const browsersPath = (0, node_path.join)(thirdparty, "playwright-browsers");
|
|
241
|
+
process.env.PLAYWRIGHT_BROWSERS_PATH = browsersPath;
|
|
242
|
+
log("Downloading browser to", browsersPath);
|
|
243
|
+
await (0, _pipelab_plugin_core.runWithLiveLogs)(node, [
|
|
244
|
+
playwrightCli,
|
|
245
|
+
"install",
|
|
246
|
+
browserName
|
|
247
|
+
], {
|
|
248
|
+
env: {
|
|
249
|
+
...process.env,
|
|
250
|
+
PLAYWRIGHT_BROWSERS_PATH: browsersPath,
|
|
251
|
+
PATH: `${(0, node_path.dirname)(node)}${node_path.delimiter}${process.env.PATH}`
|
|
252
|
+
},
|
|
253
|
+
cancelSignal: abortSignal
|
|
254
|
+
}, log, {
|
|
255
|
+
onStdout(data) {
|
|
256
|
+
log(data);
|
|
257
|
+
},
|
|
258
|
+
onStderr(data) {
|
|
259
|
+
log(data);
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
const playwrightModule = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)((0, node_path.join)(playwrightPkgPath, "index.js"));
|
|
263
|
+
const playwright = playwrightModule.default || playwrightModule;
|
|
264
|
+
const downloadDir = (0, node_path.join)(cwd, "playwright");
|
|
265
|
+
log("Browser downloaded to", downloadDir);
|
|
266
|
+
log("Exporting construct project");
|
|
267
|
+
console.log("newInputs", newInputs);
|
|
268
|
+
const browserInstance = playwright[browserName];
|
|
269
|
+
let version = newInputs.version;
|
|
270
|
+
if (version && /^\d+$/.test(version)) version = `r${version}`;
|
|
271
|
+
const headless = newInputs.headless;
|
|
272
|
+
if (newInputs.customProfile) {
|
|
273
|
+
const customProfile = (0, node_path.join)(cwd, "playwright-profile");
|
|
274
|
+
await (0, node_fs_promises.mkdir)(customProfile, { recursive: true });
|
|
275
|
+
const indexedDbPathSource = (0, node_path.join)(newInputs.customProfile, "Default", "IndexedDB");
|
|
276
|
+
const indexedDbPathDestination = (0, node_path.join)(customProfile, "Default", "IndexedDB");
|
|
277
|
+
for (const p of ["https_editor.construct.net_0.indexeddb.blob", "https_editor.construct.net_0.indexeddb.leveldb"]) await (0, node_fs_promises.cp)((0, node_path.join)(indexedDbPathSource, p), (0, node_path.join)(indexedDbPathDestination, p), { recursive: true });
|
|
278
|
+
browserContext = await browserInstance.launchPersistentContext(customProfile, {
|
|
279
|
+
headless,
|
|
280
|
+
locale: "en-US",
|
|
281
|
+
recordVideo: isCI ? { dir: (0, node_path.join)(process.cwd(), "playwright") } : void 0
|
|
282
|
+
});
|
|
283
|
+
} else {
|
|
284
|
+
browser = await browserInstance.launch({ headless });
|
|
285
|
+
browserContext = await browser.newContext({
|
|
286
|
+
locale: "en-US",
|
|
287
|
+
recordVideo: isCI ? { dir: (0, node_path.join)(process.cwd(), "playwright") } : void 0
|
|
288
|
+
});
|
|
289
|
+
await browserContext?.clearPermissions();
|
|
290
|
+
}
|
|
291
|
+
if (!browserContext) throw new Error("Failed to initialize browser context");
|
|
292
|
+
const page = await browserContext.newPage();
|
|
293
|
+
page.setDefaultTimeout(newInputs.timeout * 1e3);
|
|
294
|
+
await page.addInitScript(() => {
|
|
295
|
+
delete self.showOpenFilePicker;
|
|
296
|
+
});
|
|
297
|
+
page.on("filechooser", (worker) => {
|
|
298
|
+
console.log("filechooser created: " + worker.page.name);
|
|
299
|
+
});
|
|
300
|
+
try {
|
|
301
|
+
const result = await script(page, log, file, newInputs.username, newInputs.password, version, downloadDir);
|
|
302
|
+
log("Setting output result to ", result);
|
|
303
|
+
setOutput("folder", result);
|
|
304
|
+
setOutput("parentFolder", (0, node_path.dirname)(result));
|
|
305
|
+
setOutput("zipFile", result);
|
|
306
|
+
} catch (e) {
|
|
307
|
+
log("error, no result, crashed", e);
|
|
308
|
+
throw new Error("ConstructExport failed: " + e.message);
|
|
309
|
+
} finally {
|
|
310
|
+
if (browserContext) await browserContext.close();
|
|
311
|
+
if (browser) await browser.close();
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
const exportAction = (0, _pipelab_plugin_core.createAction)({
|
|
315
|
+
id: "export-construct-project",
|
|
316
|
+
name: "Export .c3p",
|
|
317
|
+
displayString: "`Export project ${fmt.param(params.file, 'primary', 'No path selected')} with version ${params.version ? params.version : 'stable'}`",
|
|
318
|
+
meta: {},
|
|
319
|
+
params: {
|
|
320
|
+
file: (0, _pipelab_plugin_core.createPathParam)("", {
|
|
321
|
+
label: "File (.c3p)",
|
|
322
|
+
required: true,
|
|
323
|
+
control: {
|
|
324
|
+
type: "path",
|
|
325
|
+
label: "Pick a file (.c3p)",
|
|
326
|
+
options: {
|
|
327
|
+
properties: ["openFile"],
|
|
328
|
+
filters: [{
|
|
329
|
+
name: "Construct Project",
|
|
330
|
+
extensions: ["c3p"]
|
|
331
|
+
}],
|
|
332
|
+
title: "aaaa",
|
|
333
|
+
message: "bbbb"
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}),
|
|
337
|
+
...sharedParams
|
|
338
|
+
},
|
|
339
|
+
outputs: {
|
|
340
|
+
folder: {
|
|
341
|
+
type: "path",
|
|
342
|
+
deprecated: true,
|
|
343
|
+
value: void 0,
|
|
344
|
+
label: "Exported zip"
|
|
345
|
+
},
|
|
346
|
+
parentFolder: {
|
|
347
|
+
type: "path",
|
|
348
|
+
deprecated: false,
|
|
349
|
+
value: void 0,
|
|
350
|
+
label: "Path to parent folder of exported zip"
|
|
351
|
+
},
|
|
352
|
+
zipFile: {
|
|
353
|
+
type: "path",
|
|
354
|
+
deprecated: false,
|
|
355
|
+
value: void 0,
|
|
356
|
+
label: "Exported zip"
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
description: "Export construct project from .c3p file",
|
|
360
|
+
icon: ""
|
|
361
|
+
});
|
|
362
|
+
const ExportActionRunner = (0, _pipelab_plugin_core.createActionRunner)(async (options) => {
|
|
363
|
+
const file = options.inputs.file;
|
|
364
|
+
if (!await (0, _pipelab_plugin_core.fileExists)(file)) throw new Error("You must specify a valid .c3p file");
|
|
365
|
+
await exportc3p(file, options);
|
|
366
|
+
options.log("exportc3p done");
|
|
367
|
+
});
|
|
368
|
+
const exportProjectAction = (0, _pipelab_plugin_core.createAction)({
|
|
369
|
+
id: "export-construct-project-folder",
|
|
370
|
+
name: "Export folder",
|
|
371
|
+
displayString: "`Export project ${params.version ? `r${params.version}` : ''}`",
|
|
372
|
+
meta: {},
|
|
373
|
+
params: {
|
|
374
|
+
folder: (0, _pipelab_plugin_core.createPathParam)("", {
|
|
375
|
+
required: true,
|
|
376
|
+
label: "Folder",
|
|
377
|
+
control: {
|
|
378
|
+
type: "path",
|
|
379
|
+
options: { properties: ["openDirectory"] }
|
|
380
|
+
}
|
|
381
|
+
}),
|
|
382
|
+
...sharedParams
|
|
383
|
+
},
|
|
384
|
+
outputs: {
|
|
385
|
+
folder: {
|
|
386
|
+
type: "path",
|
|
387
|
+
deprecated: true,
|
|
388
|
+
value: void 0,
|
|
389
|
+
label: "Exported zip"
|
|
390
|
+
},
|
|
391
|
+
parentFolder: {
|
|
392
|
+
type: "path",
|
|
393
|
+
deprecated: false,
|
|
394
|
+
value: void 0,
|
|
395
|
+
label: "Path to parent folder of exported zip"
|
|
396
|
+
},
|
|
397
|
+
zipFile: {
|
|
398
|
+
type: "path",
|
|
399
|
+
deprecated: false,
|
|
400
|
+
value: void 0,
|
|
401
|
+
label: "Exported zip"
|
|
402
|
+
}
|
|
403
|
+
},
|
|
404
|
+
description: "Export construct project from folder",
|
|
405
|
+
icon: ""
|
|
406
|
+
});
|
|
407
|
+
const ExportProjectActionRunner = (0, _pipelab_plugin_core.createActionRunner)(async (options) => {
|
|
408
|
+
if (!await (0, _pipelab_plugin_core.fileExists)(options.inputs.folder)) throw new Error("You must specify a valid construct project folder");
|
|
409
|
+
const outputPath = (0, node_path.join)(options.cwd, "c3_tmp_proj.c3p");
|
|
410
|
+
await exportc3p(await (0, _pipelab_plugin_core.zipFolder)(options.inputs.folder, outputPath, options.log), options);
|
|
411
|
+
});
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region src/index.ts
|
|
414
|
+
const icon = new URL("./assets/construct.webp", require("url").pathToFileURL(__filename).href).href;
|
|
415
|
+
var src_default = (0, _pipelab_plugin_core.createNodeDefinition)({
|
|
416
|
+
description: "Construct",
|
|
417
|
+
name: "Construct",
|
|
418
|
+
id: "construct",
|
|
419
|
+
icon: {
|
|
420
|
+
type: "image",
|
|
421
|
+
image: icon
|
|
422
|
+
},
|
|
423
|
+
nodes: [{
|
|
424
|
+
node: exportAction,
|
|
425
|
+
runner: ExportActionRunner
|
|
426
|
+
}, {
|
|
427
|
+
node: exportProjectAction,
|
|
428
|
+
runner: ExportProjectActionRunner
|
|
429
|
+
}],
|
|
430
|
+
validators: []
|
|
431
|
+
});
|
|
432
|
+
//#endregion
|
|
433
|
+
module.exports = src_default;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { ExtractInputsFromAction } from "@pipelab/plugin-core";
|
|
2
|
+
|
|
3
|
+
//#region src/export-c3p.d.ts
|
|
4
|
+
declare const exportAction: {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
displayString: string;
|
|
8
|
+
meta: {};
|
|
9
|
+
params: {
|
|
10
|
+
username: {
|
|
11
|
+
control: {
|
|
12
|
+
type: "input";
|
|
13
|
+
options: {
|
|
14
|
+
kind: "text";
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
value: string;
|
|
18
|
+
description?: string | undefined;
|
|
19
|
+
platforms?: NodeJS.Platform[] | undefined;
|
|
20
|
+
label: string;
|
|
21
|
+
validator?: (() => any) | undefined;
|
|
22
|
+
required: boolean;
|
|
23
|
+
onNodeUpdate?: ((value: any, settings: undefined<any>) => void) | undefined;
|
|
24
|
+
};
|
|
25
|
+
password: {
|
|
26
|
+
control: {
|
|
27
|
+
type: "input";
|
|
28
|
+
options: {
|
|
29
|
+
kind: "text";
|
|
30
|
+
password: true;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
value: string;
|
|
34
|
+
description?: string | undefined;
|
|
35
|
+
platforms?: NodeJS.Platform[] | undefined;
|
|
36
|
+
label: string;
|
|
37
|
+
validator?: (() => any) | undefined;
|
|
38
|
+
required: boolean;
|
|
39
|
+
onNodeUpdate?: ((value: any, settings: undefined<any>) => void) | undefined;
|
|
40
|
+
};
|
|
41
|
+
version: {
|
|
42
|
+
control: {
|
|
43
|
+
type: "input";
|
|
44
|
+
options: {
|
|
45
|
+
kind: "text";
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
value: string;
|
|
49
|
+
description?: string | undefined;
|
|
50
|
+
platforms?: NodeJS.Platform[] | undefined;
|
|
51
|
+
label: string;
|
|
52
|
+
validator?: (() => any) | undefined;
|
|
53
|
+
required: boolean;
|
|
54
|
+
onNodeUpdate?: ((value: any, settings: undefined<any>) => void) | undefined;
|
|
55
|
+
};
|
|
56
|
+
headless: {
|
|
57
|
+
description: string;
|
|
58
|
+
required: false;
|
|
59
|
+
control: {
|
|
60
|
+
type: "boolean";
|
|
61
|
+
};
|
|
62
|
+
value: boolean;
|
|
63
|
+
label: string;
|
|
64
|
+
};
|
|
65
|
+
timeout: {
|
|
66
|
+
control: {
|
|
67
|
+
type: "input";
|
|
68
|
+
options: {
|
|
69
|
+
kind: "number";
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
value: number;
|
|
73
|
+
description?: string | undefined;
|
|
74
|
+
platforms?: NodeJS.Platform[] | undefined;
|
|
75
|
+
label: string;
|
|
76
|
+
validator?: (() => any) | undefined;
|
|
77
|
+
required: boolean;
|
|
78
|
+
onNodeUpdate?: ((value: any, settings: undefined<any>) => void) | undefined;
|
|
79
|
+
};
|
|
80
|
+
customProfile: {
|
|
81
|
+
value: string | undefined;
|
|
82
|
+
description?: string | undefined;
|
|
83
|
+
platforms?: NodeJS.Platform[] | undefined;
|
|
84
|
+
label: string;
|
|
85
|
+
validator?: (() => any) | undefined;
|
|
86
|
+
required: boolean;
|
|
87
|
+
control: undefined;
|
|
88
|
+
onNodeUpdate?: ((value: any, settings: undefined<any>) => void) | undefined;
|
|
89
|
+
};
|
|
90
|
+
file: {
|
|
91
|
+
value: string | undefined;
|
|
92
|
+
description?: string | undefined;
|
|
93
|
+
platforms?: NodeJS.Platform[] | undefined;
|
|
94
|
+
label: string;
|
|
95
|
+
validator?: (() => any) | undefined;
|
|
96
|
+
required: boolean;
|
|
97
|
+
control: undefined;
|
|
98
|
+
onNodeUpdate?: ((value: any, settings: undefined<any>) => void) | undefined;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
outputs: {
|
|
102
|
+
folder: {
|
|
103
|
+
type: string;
|
|
104
|
+
deprecated: true;
|
|
105
|
+
value: undefined | string;
|
|
106
|
+
label: string;
|
|
107
|
+
};
|
|
108
|
+
parentFolder: {
|
|
109
|
+
type: string;
|
|
110
|
+
deprecated: false;
|
|
111
|
+
value: undefined | string;
|
|
112
|
+
label: string;
|
|
113
|
+
};
|
|
114
|
+
zipFile: {
|
|
115
|
+
type: string;
|
|
116
|
+
deprecated: false;
|
|
117
|
+
value: undefined | string;
|
|
118
|
+
label: string;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
description: string;
|
|
122
|
+
icon: string;
|
|
123
|
+
} & {
|
|
124
|
+
type: "action";
|
|
125
|
+
};
|
|
126
|
+
type Params = ExtractInputsFromAction<typeof exportAction>;
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/index.d.ts
|
|
129
|
+
declare const _default: undefined;
|
|
130
|
+
//#endregion
|
|
131
|
+
export { type Params as ExportParams, _default as default };
|
|
132
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/export-c3p.ts","../src/index.ts"],"mappings":";;;cAWa,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA+DD,MAAA,GAAS,uBAAA,QAA+B,YAAA"}
|