@pipelab/plugin-discord 1.0.0-beta.1 → 1.0.0-beta.4

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,12 +1,15 @@
1
1
  {
2
2
  "name": "@pipelab/plugin-discord",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.4",
4
4
  "license": "FSL-1.1-MIT",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/CynToolkit/pipelab.git",
8
8
  "directory": "plugins/plugin-discord"
9
9
  },
10
+ "files": [
11
+ "dist"
12
+ ],
10
13
  "type": "module",
11
14
  "main": "./dist/index.cjs",
12
15
  "module": "./dist/index.mjs",
@@ -19,13 +22,13 @@
19
22
  "electron": "32.1.2",
20
23
  "ts-deepmerge": "7.0.1",
21
24
  "untun": "0.1.3",
22
- "@pipelab/plugin-core": "1.0.0-beta.1",
23
- "@pipelab/shared": "1.0.0-beta.0"
25
+ "@pipelab/plugin-core": "1.0.0-beta.4",
26
+ "@pipelab/shared": "1.0.0-beta.2"
24
27
  },
25
28
  "devDependencies": {
26
29
  "tsdown": "0.21.2",
27
30
  "typescript": "5.9.3",
28
- "@pipelab/tsconfig": "1.0.0-beta.0"
31
+ "@pipelab/tsconfig": "1.0.0-beta.2"
29
32
  },
30
33
  "scripts": {
31
34
  "format": "oxfmt .",
package/CHANGELOG.md DELETED
@@ -1,19 +0,0 @@
1
- # @pipelab/plugin-discord
2
-
3
- ## 1.0.0-beta.1
4
-
5
- ### Patch Changes
6
-
7
- - @pipelab/plugin-core@1.0.0-beta.1
8
-
9
- ## 1.0.0-beta.0
10
-
11
- ### Major Changes
12
-
13
- - e1befbf: initial release
14
-
15
- ### Patch Changes
16
-
17
- - Updated dependencies [e1befbf]
18
- - @pipelab/plugin-core@1.0.0-beta.0
19
- - @pipelab/shared@1.0.0-beta.0
@@ -1 +0,0 @@
1
- declare module "*.webp";
package/src/discord.ts DELETED
@@ -1,338 +0,0 @@
1
- import {
2
- ActionRunnerData,
3
- createAction,
4
- createPathParam,
5
- createStringParam,
6
- detectRuntime,
7
- InputsDefinition,
8
- OutputsDefinition,
9
- runWithLiveLogs,
10
- fetchPipelabAsset,
11
- runPnpm,
12
- } from "@pipelab/plugin-core";
13
- import { dirname, join, basename, delimiter } from "node:path";
14
- import { cp, readFile, writeFile } from "node:fs/promises";
15
- import { platform as osPlatform, arch as osArch } from "node:os";
16
- import { kebabCase } from "change-case";
17
- import { createServer } from "node:http";
18
- import serve from "serve-handler";
19
- import { startTunnel } from "untun";
20
-
21
- export const IDPackage = "discord:package";
22
- export const IDPreview = "discord:preview";
23
-
24
- const paramsInputFolder = {
25
- "input-folder": createPathParam("", {
26
- label: "Folder to package",
27
- required: true,
28
- control: {
29
- type: "path",
30
- options: {
31
- properties: ["openDirectory"],
32
- },
33
- },
34
- }),
35
- } satisfies InputsDefinition;
36
-
37
- // const paramsInputURL = {
38
- // 'input-url': createStringParam('', {
39
- // label: 'URL to preview',
40
- // required: true
41
- // })
42
- // } satisfies InputsDefinition
43
-
44
- export const configureParams = {
45
- name: createStringParam("Pipelab", {
46
- label: "Application name",
47
- description: "The name of the application",
48
- required: true,
49
- }),
50
- } satisfies InputsDefinition;
51
-
52
- const outputs = {
53
- outputDir: {
54
- label: "Output folder",
55
- value: "",
56
- description: "The folder where the packaged application is located",
57
- },
58
- } satisfies OutputsDefinition;
59
-
60
- export const createPackageProps = (
61
- id: string,
62
- name: string,
63
- description: string,
64
- icon: string,
65
- displayString: string,
66
- advanced?: boolean,
67
- deprecated?: boolean,
68
- deprecatedMessage?: string,
69
- disabled?: false,
70
- updateAvailable?: boolean,
71
- ) => {
72
- return createAction({
73
- id,
74
- name,
75
- description,
76
- icon,
77
- displayString,
78
- meta: {},
79
- advanced,
80
- deprecated,
81
- deprecatedMessage,
82
- disabled,
83
- updateAvailable,
84
- params: {
85
- ...paramsInputFolder,
86
- ...configureParams,
87
- },
88
- outputs: {
89
- outputDir: outputs.outputDir,
90
- },
91
- });
92
- };
93
-
94
- export const createPreviewProps = (
95
- id: string,
96
- name: string,
97
- description: string,
98
- icon: string,
99
- displayString: string,
100
- ) =>
101
- createAction({
102
- id,
103
- name,
104
- description,
105
- icon,
106
- displayString,
107
- meta: {},
108
- params: {
109
- ...paramsInputFolder,
110
- ...configureParams,
111
- customHostname: createStringParam("", {
112
- required: false,
113
- label: "Custom hostname",
114
- description: "The hostname to use for the preview",
115
- }),
116
- },
117
- outputs: {
118
- // ...outputs.outputDir
119
- },
120
- });
121
-
122
- const createAppServer = async (folder: string) => {
123
- try {
124
- const server = createServer();
125
-
126
- server.on("request", (req, res) => {
127
- return serve(req, res, {
128
- maxAge: 0,
129
- public: folder,
130
- headers: {
131
- "bypass-tunnel-reminder": "false",
132
- },
133
- });
134
- });
135
-
136
- const listen = async () => {
137
- return new Promise((resolve, reject) => {
138
- server.listen(40400, "127.0.0.1", () => {
139
- return resolve(server);
140
- });
141
- });
142
- };
143
-
144
- await listen();
145
- console.log("listening2");
146
- console.log("address", server.address);
147
- const addressRes = server.address();
148
- console.log("addressRes", addressRes);
149
- if (addressRes && typeof addressRes !== "string") {
150
- return { port: addressRes.port };
151
- }
152
- throw new Error("Unable to bind server: adress is not an object");
153
- } catch (e) {
154
- console.error(e);
155
- throw e;
156
- }
157
- };
158
-
159
- export const waitForAbort = (signal: AbortSignal): Promise<void> => {
160
- return new Promise<void>((resolve, reject) => {
161
- if (signal.aborted) {
162
- return resolve(); // Already aborted
163
- }
164
-
165
- const onAbort = () => {
166
- signal.removeEventListener("abort", onAbort);
167
- resolve();
168
- };
169
-
170
- signal.addEventListener("abort", onAbort);
171
- });
172
- };
173
-
174
- export const discord = async (
175
- action: "package" | "preview",
176
- appFolder: string | undefined,
177
- {
178
- cwd,
179
- log,
180
- inputs,
181
- setOutput,
182
- paths,
183
- abortSignal,
184
- context,
185
- }:
186
- | ActionRunnerData<ReturnType<typeof createPackageProps>>
187
- | ActionRunnerData<ReturnType<typeof createPreviewProps>>,
188
- completeConfiguration: DesktopApp.Config,
189
- ): Promise<{ folder: string; binary: string | undefined } | undefined> => {
190
- console.log("appFolder", appFolder);
191
-
192
- log("Building discord");
193
-
194
- const runtime = await detectRuntime(appFolder);
195
-
196
- const { modules, cache, node } = paths;
197
-
198
- const destinationFolder = join(cwd, "build");
199
-
200
- const rawAssetFolder = await fetchPipelabAsset("@pipelab/asset-discord", "^1.0.0", { context });
201
- const templateFolder = join(rawAssetFolder, "template");
202
-
203
- // copy template to destination
204
- await cp(templateFolder, destinationFolder, {
205
- recursive: true,
206
- filter: (src) => {
207
- log("src", src);
208
- // log('dest', dest)
209
- // TODO: support other oses
210
- return (
211
- basename(src) !== "node_modules" &&
212
- !src.includes(".nitro") &&
213
- !src.includes(".output") &&
214
- !src.includes(".env")
215
- );
216
- },
217
- });
218
-
219
- const placeAppFolder = join(destinationFolder, "src", "app");
220
-
221
- // if input is folder, copy folder to destination
222
- if (appFolder) {
223
- // copy app to template
224
- await cp(appFolder, placeAppFolder, { recursive: true });
225
- }
226
-
227
- writeFile(
228
- join(destinationFolder, ".env"),
229
- `DISCORD_CLIENT_ID=1357217738241736724
230
- DISCORD_CLIENT_SECRET=yJ4vRnzDtKAqg2Le3_Sap2CqHybkTp2U`,
231
- "utf8",
232
- );
233
-
234
- const sanitizedName = kebabCase(completeConfiguration.name);
235
-
236
- // package.json update
237
- // const pkgJSONPath = join(destinationFolder, 'package.json')
238
- // const pkgJSONContent = await readFile(pkgJSONPath, 'utf8')
239
- // const pkgJSON = JSON.parse(pkgJSONContent)
240
- // log('Setting name to', sanitizedName)
241
- // pkgJSON.name = sanitizedName
242
- // log('Setting productName to', completeConfiguration.name)
243
- // pkgJSON.productName = completeConfiguration.name
244
- // await writeFile(pkgJSONPath, JSON.stringify(pkgJSON, null, 2))
245
-
246
- // discord.conf.json update
247
- // const tauriConfJSONPath = join(destinationFolder, 'src-discord', 'discord.conf.json')
248
- // const tauriConfJSONContent = await readFile(tauriConfJSONPath, 'utf8')
249
- // const tauriConfJSON = JSON.parse(tauriConfJSONContent)
250
- // log('Setting productName to', completeConfiguration.name)
251
- // tauriConfJSON.productName = completeConfiguration.name
252
- // log('Setting version to', completeConfiguration.appVersion)
253
- // tauriConfJSON.version = completeConfiguration.appVersion
254
- // log('Setting identifier to', completeConfiguration.appBundleId)
255
- // tauriConfJSON.identifier = completeConfiguration.appBundleId
256
- // log('Setting build.devUrl to', appFolder)
257
- // tauriConfJSON.build.devUrl = appFolder
258
- // await writeFile(tauriConfJSONPath, JSON.stringify(tauriConfJSON, null, 2))
259
-
260
- log("Installing packages");
261
- const { all: installOut } = await runPnpm(destinationFolder, {
262
- args: ["install", "--prefer-offline"],
263
- signal: abortSignal,
264
- context,
265
- });
266
- if (installOut) log(installOut);
267
-
268
- // override discord version
269
- // if (completeConfiguration.electronVersion && completeConfiguration.electronVersion !== '') {
270
- // log(`Installing discord@${completeConfiguration.electronVersion}`)
271
- // await runWithLiveLogs(
272
- // process.execPath,
273
- // [pnpm, 'install', `discord@${completeConfiguration.electronVersion}`, '--prefer-offline'],
274
- // {
275
- // cwd: destinationFolder,
276
- // env: {
277
- // // DEBUG: '*',
278
- // PNPM_HOME: pnpmHome
279
- // },
280
- // cancelSignal: abortSignal
281
- // },
282
- // log,
283
- // {
284
- // onStderr(data) {
285
- // log(data)
286
- // },
287
- // onStdout(data) {
288
- // log(data)
289
- // }
290
- // }
291
- // )
292
- // }
293
-
294
- try {
295
- if (action === "preview") {
296
- const port = 14141;
297
-
298
- const modulesPath = modules;
299
- const nitro = join(modulesPath, "nitropack", "dist", "cli", "index.mjs");
300
-
301
- console.log("nitro", nitro);
302
-
303
- await Promise.allSettled([
304
- runPnpm(destinationFolder, {
305
- args: ["dlx", "nitropack", "dev"],
306
- extraEnv: {
307
- PORT: port.toString(),
308
- },
309
- signal: abortSignal,
310
- context,
311
- }).then(({ all }) => {
312
- if (all) log(all);
313
- }),
314
- (async () => {
315
- const tunnel = await startTunnel({ port, acceptCloudflareNotice: true });
316
- console.log("tunnel", tunnel);
317
- const url = await tunnel.getURL();
318
- console.log("Public URL:", url);
319
- })(),
320
- ]);
321
- } else {
322
- throw new Error("TODO");
323
- }
324
-
325
- return undefined;
326
- } catch (e) {
327
- if (e instanceof Error) {
328
- if (e.name === "RequestError") {
329
- log("Request error");
330
- }
331
- if (e.name === "RequestError") {
332
- log("Request error");
333
- }
334
- }
335
- log(e);
336
- return undefined;
337
- }
338
- };
package/src/index.ts DELETED
@@ -1,43 +0,0 @@
1
- import { previewRunner } from "./preview";
2
-
3
- import { createNodeDefinition } from "@pipelab/plugin-core";
4
- const icon = new URL("./public/discord.webp", import.meta.url).href;
5
- import { createPackageProps, createPreviewProps, IDPreview, IDPackage } from "./discord";
6
- import { packageV2Runner } from "./package";
7
-
8
- export default createNodeDefinition({
9
- description: "Discord",
10
- name: "Discord",
11
- id: "dicord",
12
- icon: {
13
- type: "image",
14
- image: icon,
15
- },
16
- nodes: [
17
- {
18
- node: createPackageProps(
19
- IDPackage,
20
- "Package as Discord Activity",
21
- "Package your app as a Discord Activity",
22
- "",
23
- "`Package app from ${fmt.param(params['input-folder'], 'primary', 'Input folder not set')}`",
24
- false,
25
- false,
26
- undefined,
27
- false,
28
- false,
29
- ),
30
- runner: packageV2Runner,
31
- },
32
- {
33
- node: createPreviewProps(
34
- IDPreview,
35
- "Preview Discord Acitivity app",
36
- "Package and preview your app as a Discord Activity",
37
- "",
38
- "`Preview app from ${fmt.param(params['input-folder'], 'primary', 'Input folder not set')}`",
39
- ),
40
- runner: previewRunner,
41
- },
42
- ],
43
- });
package/src/make.spec.ts DELETED
@@ -1,57 +0,0 @@
1
- import { expect, test, vi } from "vitest";
2
- import { makeRunner } from "./make.js";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
- import { type fs } from "memfs";
6
- import { browserWindow } from "@pipelab/shared";
7
-
8
- // ...
9
-
10
- // vi.mock('node:fs/promises', async () => {
11
- // const memfs: { fs: typeof fs } = await vi.importActual('memfs')
12
-
13
- // return memfs.fs.promises
14
- // })
15
-
16
- test("adds 1 + 2 to equal 3", async () => {
17
- const outputs: Record<string, unknown> = {};
18
-
19
- const id = "ut-electron-build";
20
- const tmpDir = join(tmpdir(), id);
21
-
22
- console.log("tmpDir", tmpDir);
23
-
24
- const inputFolder = join(process.cwd(), "fixtures", "build");
25
-
26
- console.log("inputFolder", inputFolder);
27
-
28
- // await makeRunner({
29
- // inputs: {
30
- // 'input-folder': inputFolder,
31
- // configuration: {},
32
- // arch: undefined,
33
- // platform: undefined
34
- // },
35
- // log: (...args) => {
36
- // console.log(...args)
37
- // },
38
- // setOutput: (key, value) => {
39
- // outputs[key] = value
40
- // },
41
- // meta: {
42
- // definition: ''
43
- // },
44
- // setMeta: () => {
45
- // console.log('set meta defined here')
46
- // },
47
- // cwd: tmpDir,
48
- // paths: {
49
- // assets: '',
50
- // unpack: ''
51
- // },
52
- // api: undefined,
53
- // browserWindow
54
- // })
55
- console.log("outputs", outputs);
56
- expect(true).toBe(true);
57
- }, 120_000);
package/src/package.ts DELETED
@@ -1,37 +0,0 @@
1
- import { createActionRunner, fetchPipelabAsset } from "@pipelab/plugin-core";
2
- import { createPackageProps, discord } from "./discord";
3
- import { merge } from "ts-deepmerge";
4
- import { defaultTauriConfig } from "./utils";
5
- import { basename, join } from "path";
6
- import { cp } from "fs/promises";
7
-
8
- export const packageV2Runner = createActionRunner<ReturnType<typeof createPackageProps>>(
9
- async ({ inputs, cwd, paths, log, setOutput, context }) => {
10
- const appFolder = inputs["input-folder"];
11
-
12
- const { cache, node, pnpm } = paths;
13
- const destinationFolder = join(cwd);
14
- const rawAssetFolder = await fetchPipelabAsset("@pipelab/asset-discord", "^1.0.0", { context });
15
- const templateFolder = join(rawAssetFolder, "template");
16
-
17
- // copy template to destination
18
- await cp(templateFolder, destinationFolder, {
19
- recursive: true,
20
- filter: (src) => {
21
- log("src", src);
22
- // log('dest', dest)
23
- // TODO: support other oses
24
- return basename(src) !== "node_modules" && !src.includes(".nitro") && !src.includes("dist");
25
- },
26
- });
27
- const placeAppFolder = join(destinationFolder, "server", "public", ".proxy");
28
- if (appFolder) {
29
- // copy app to template
30
- await cp(appFolder, placeAppFolder, { recursive: true });
31
- }
32
-
33
- log("destinationFolder", destinationFolder);
34
-
35
- setOutput("outputDir", destinationFolder);
36
- },
37
- );
package/src/preview.ts DELETED
@@ -1,25 +0,0 @@
1
- import { createActionRunner } from "@pipelab/plugin-core";
2
- import { createPreviewProps, discord } from "./discord";
3
- import { merge } from "ts-deepmerge";
4
-
5
- export const previewRunner = createActionRunner<ReturnType<typeof createPreviewProps>>(
6
- async (options) => {
7
- const inputFolder = options.inputs["input-folder"];
8
- if (inputFolder === "") {
9
- throw new Error("URL can't be empty");
10
- }
11
-
12
- // if (!options.inputs.configuration) {
13
- // throw new Error('Missing tauri configuration')
14
- // }
15
-
16
- const completeConfiguration = merge({}, {
17
- ...options.inputs,
18
- } satisfies any) as any;
19
-
20
- console.log("completeConfiguration", completeConfiguration);
21
-
22
- await discord("preview", inputFolder, options, completeConfiguration);
23
- return;
24
- },
25
- );
Binary file
package/src/utils.ts DELETED
@@ -1,27 +0,0 @@
1
- export const defaultTauriConfig = {
2
- alwaysOnTop: false,
3
- appBundleId: "com.pipelab.app",
4
- appCategoryType: "",
5
- appCopyright: "Copyright © 2024 Pipelab",
6
- appVersion: "1.0.0",
7
- author: "Pipelab",
8
- description: "A simple Electron application",
9
- tauriVersion: "",
10
- enableExtraLogging: false,
11
- clearServiceWorkerOnBoot: false,
12
- frame: true,
13
- fullscreen: false,
14
- icon: "",
15
- height: 600,
16
- name: "Pipelab",
17
- toolbar: true,
18
- transparent: false,
19
- width: 800,
20
- enableSteamSupport: false,
21
- steamGameId: 480,
22
- enableDiscordSupport: false,
23
- discordAppId: "",
24
- ignore: [] as string[],
25
- backgroundColor: "#FFF",
26
- openDevtoolsOnStart: false,
27
- } satisfies DesktopApp.Tauri;
package/tsconfig.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "@pipelab/tsconfig/vue.json",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "rootDir": "src",
6
- "types": ["node"],
7
- "skipLibCheck": true
8
- },
9
- "include": ["src"]
10
- }
package/tsdown.config.ts DELETED
@@ -1,15 +0,0 @@
1
- import { defineConfig } from "tsdown";
2
-
3
- export default defineConfig({
4
- entry: ["src/index.ts"],
5
- format: ["esm", "cjs"],
6
- dts: true,
7
- clean: true,
8
- loader: {
9
- ".webp": "dataurl",
10
- ".png": "dataurl",
11
- ".jpg": "dataurl",
12
- ".jpeg": "dataurl",
13
- ".svg": "dataurl",
14
- },
15
- });