@peachy/core 0.0.1
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/README.md +26 -0
- package/dist/bin.mjs +41 -0
- package/dist/build.mjs +17 -0
- package/dist/options.mjs +42 -0
- package/dist/watch.mjs +15 -0
- package/dist/ws.mjs +33 -0
- package/package.json +34 -0
- package/tsconfig.json +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @peachy/core
|
|
2
|
+
|
|
3
|
+
This packages contains a CLI tool for writing, building and running GJS applications, and several other nice utilities.
|
|
4
|
+
|
|
5
|
+
It allows you to build, run, and develop GJS applications faster.
|
|
6
|
+
|
|
7
|
+
## Commands:
|
|
8
|
+
|
|
9
|
+
### Build
|
|
10
|
+
|
|
11
|
+
`peachy build` will compile your application into the `dist` folder. This will bundle any Node modules you might be using
|
|
12
|
+
as well, and you can distribute the folder to things like flatpak, or install it globally.
|
|
13
|
+
|
|
14
|
+
You should be able to run the resulting file with:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
gjs -m dist/main.js
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Run
|
|
21
|
+
|
|
22
|
+
`peachy run` will build and run your application. This is a shortcut for `peachy build && gjs -m dist/main.js`.
|
|
23
|
+
|
|
24
|
+
### Develop
|
|
25
|
+
|
|
26
|
+
`peachy dev` will compile your application into the `dist` folder, and watch for changes. When combined with plugins like `@peachy/plugin-react`, you can develop your application in React with HMR without having to rebuild it every time.
|
package/dist/bin.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { build } from "./build.mjs";
|
|
2
|
+
import { watch } from "./watch.mjs";
|
|
3
|
+
import { minArgs } from "minargs";
|
|
4
|
+
|
|
5
|
+
//#region src/bin.ts
|
|
6
|
+
const { positionals } = minArgs();
|
|
7
|
+
const config = { input: positionals[2] || "./src/index.tsx" };
|
|
8
|
+
switch (positionals[0]) {
|
|
9
|
+
case "build":
|
|
10
|
+
await build({
|
|
11
|
+
...config,
|
|
12
|
+
prod: true
|
|
13
|
+
});
|
|
14
|
+
break;
|
|
15
|
+
case "run":
|
|
16
|
+
await build({
|
|
17
|
+
...config,
|
|
18
|
+
run: true,
|
|
19
|
+
prod: true
|
|
20
|
+
});
|
|
21
|
+
break;
|
|
22
|
+
case "dev":
|
|
23
|
+
await watch({
|
|
24
|
+
...config,
|
|
25
|
+
run: true
|
|
26
|
+
});
|
|
27
|
+
break;
|
|
28
|
+
case "default": console.info(`
|
|
29
|
+
Usage:
|
|
30
|
+
$ peachy build [input]
|
|
31
|
+
$ peachy run [input]
|
|
32
|
+
$ peachy watch [input]
|
|
33
|
+
|
|
34
|
+
Positional arguments:
|
|
35
|
+
input: The input file to build or watch. Defaults to "./src/index.tsx".
|
|
36
|
+
`);
|
|
37
|
+
}
|
|
38
|
+
process.exit(0);
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { };
|
package/dist/build.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getOptions } from "./options.mjs";
|
|
2
|
+
import { build } from "rolldown";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
//#region src/build.ts
|
|
6
|
+
async function build$1(config) {
|
|
7
|
+
const { input, output } = getOptions(config);
|
|
8
|
+
const result = await build({
|
|
9
|
+
...input,
|
|
10
|
+
output
|
|
11
|
+
});
|
|
12
|
+
const firstOut = resolve(process.cwd(), join("dist", result.output[0].fileName));
|
|
13
|
+
console.log(firstOut);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { build$1 as build };
|
package/dist/options.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { broadcastMessage, createWebSocketServer } from "./ws.mjs";
|
|
2
|
+
import { react } from "@peachy/plugin-react";
|
|
3
|
+
import { gjsRunner } from "@peachy/plugin-runner";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { replacePlugin } from "rolldown/plugins";
|
|
6
|
+
import { cleandir } from "rollup-plugin-cleandir";
|
|
7
|
+
|
|
8
|
+
//#region src/options.ts
|
|
9
|
+
function getOptions({ input, run = false, prod = false }) {
|
|
10
|
+
const { wss, port, setReloadHandler } = createWebSocketServer();
|
|
11
|
+
return {
|
|
12
|
+
input: {
|
|
13
|
+
input: [resolve(process.cwd(), input)],
|
|
14
|
+
platform: "browser",
|
|
15
|
+
external: [/gi:\/\/.*/],
|
|
16
|
+
tsconfig: true,
|
|
17
|
+
plugins: [
|
|
18
|
+
prod ? cleandir(["dist"]) : void 0,
|
|
19
|
+
prod ? void 0 : react(port),
|
|
20
|
+
run ? gjsRunner({
|
|
21
|
+
sendMessage: (message) => {
|
|
22
|
+
if (wss.clients.size === 0) {
|
|
23
|
+
console.warn("[HMR] Can't communicate with GJS");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
broadcastMessage(wss, JSON.stringify(message));
|
|
27
|
+
},
|
|
28
|
+
setReloadHandler
|
|
29
|
+
}) : void 0,
|
|
30
|
+
replacePlugin({ "process.env.NODE_ENV": JSON.stringify(prod ? "production" : "development") })
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
output: {
|
|
34
|
+
format: "esm",
|
|
35
|
+
dir: "./dist",
|
|
36
|
+
preserveModules: true
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { getOptions };
|
package/dist/watch.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getOptions } from "./options.mjs";
|
|
2
|
+
import { watch } from "rolldown";
|
|
3
|
+
|
|
4
|
+
//#region src/watch.ts
|
|
5
|
+
async function watch$1(config) {
|
|
6
|
+
const { input, output } = getOptions(config);
|
|
7
|
+
watch({
|
|
8
|
+
...input,
|
|
9
|
+
output
|
|
10
|
+
});
|
|
11
|
+
await new Promise(() => {});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { watch$1 as watch };
|
package/dist/ws.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { WebSocketServer } from "ws";
|
|
2
|
+
|
|
3
|
+
//#region src/ws.ts
|
|
4
|
+
function createWebSocketServer() {
|
|
5
|
+
const wss = new WebSocketServer({ port: 0 });
|
|
6
|
+
let reloadHandler = null;
|
|
7
|
+
wss.on("connection", (ws) => {
|
|
8
|
+
ws.on("error", console.error);
|
|
9
|
+
ws.on("message", (data) => {
|
|
10
|
+
try {
|
|
11
|
+
if (JSON.parse(data.toString()).type === "reload") if (reloadHandler) reloadHandler();
|
|
12
|
+
else console.warn("[HMR] No reload handler registered");
|
|
13
|
+
} catch {}
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
const address = wss.address();
|
|
17
|
+
if (typeof address !== "object" || address === null) throw new Error("Websocket server failed to start");
|
|
18
|
+
return {
|
|
19
|
+
port: address.port,
|
|
20
|
+
wss,
|
|
21
|
+
setReloadHandler: (handler) => {
|
|
22
|
+
reloadHandler = handler;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function broadcastMessage(wss, message) {
|
|
27
|
+
wss.clients.forEach((client) => {
|
|
28
|
+
if (client.readyState === WebSocket.OPEN) client.send(message);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { broadcastMessage, createWebSocketServer };
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@peachy/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Base peachy CLI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"peachy": "./dist/bin.mjs"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
"./tsconfig": "./tsconfig.json"
|
|
11
|
+
},
|
|
12
|
+
"author": "Angelo Verlain <hey@vixalien.com>",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"tsdown": "0.20.0-beta.3",
|
|
16
|
+
"tsx": "^4.21.0"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@peachy/types": "^2025.1.18",
|
|
20
|
+
"minargs": "^2.1.0",
|
|
21
|
+
"rolldown": "1.0.0-beta.58",
|
|
22
|
+
"rollup-plugin-cleandir": "^3.0.0",
|
|
23
|
+
"ws": "^8.18.3",
|
|
24
|
+
"@peachy/plugin-runner": "0.0.1",
|
|
25
|
+
"@peachy/plugin-react": "0.0.1"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"tsconfig.json"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsdown"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"checkJs": true,
|
|
4
|
+
"esModuleInterop": true,
|
|
5
|
+
"lib": ["es2024"],
|
|
6
|
+
"allowSyntheticDefaultImports": true,
|
|
7
|
+
"target": "ES2020",
|
|
8
|
+
"module": "es2022",
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"./node_modules/@peachy/types/types/index.d.ts",
|
|
15
|
+
"${configDir}/src/**/*",
|
|
16
|
+
],
|
|
17
|
+
}
|