@peachy/core 0.0.9 → 0.0.10

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.
@@ -0,0 +1 @@
1
+ export { };
@@ -1,11 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import { build } from "./build.mjs";
3
3
  import { watch } from "./watch.mjs";
4
+ import { loadUserOptions } from "../load.mjs";
4
5
  import { minArgs } from "minargs";
6
+ import { join } from "node:path";
5
7
 
6
- //#region src/bin.ts
8
+ //#region src/cli/bin.ts
7
9
  const { positionals } = minArgs();
8
- const config = { input: positionals[2] || "./src/index.tsx" };
10
+ const config = {
11
+ input: positionals[2] || "./src/index.tsx",
12
+ output: join(process.cwd(), "dist"),
13
+ user: await loadUserOptions(),
14
+ runner: { env: {} }
15
+ };
9
16
  switch (positionals[0]) {
10
17
  case "build":
11
18
  await build({
@@ -1,8 +1,8 @@
1
- import { getOptions } from "./options.mjs";
1
+ import { getOptions } from "../options.mjs";
2
2
  import { build } from "rolldown";
3
3
  import { join, resolve } from "node:path";
4
4
 
5
- //#region src/build.ts
5
+ //#region src/cli/build.ts
6
6
  async function build$1(config) {
7
7
  const { input, output } = getOptions(config);
8
8
  const result = await build({
@@ -0,0 +1,22 @@
1
+ import { getOptions } from "../options.mjs";
2
+ import { watch } from "rolldown";
3
+
4
+ //#region src/cli/watch.ts
5
+ function watch$1(config) {
6
+ return new Promise((resolve) => {
7
+ const { input, output } = getOptions(config);
8
+ const watcher = watch({
9
+ ...input,
10
+ output
11
+ });
12
+ watcher.on("event", (event) => {
13
+ switch (event.code) {
14
+ case "ERROR": console.error(event.error.message);
15
+ }
16
+ });
17
+ watcher.on("close", () => resolve());
18
+ });
19
+ }
20
+
21
+ //#endregion
22
+ export { watch$1 as watch };
@@ -1,14 +1,14 @@
1
1
  import { WebSocketServer } from "ws";
2
2
 
3
- //#region src/ws.ts
3
+ //#region src/cli/ws.ts
4
4
  function createWebSocketServer() {
5
5
  const wss = new WebSocketServer({ port: 0 });
6
6
  let reloadHandler = null;
7
7
  wss.on("connection", (ws) => {
8
8
  ws.on("error", console.error);
9
- ws.on("message", (data) => {
9
+ ws.on("message", async (data) => {
10
10
  try {
11
- if (JSON.parse(data.toString()).type === "reload") if (reloadHandler) reloadHandler();
11
+ if (JSON.parse(data.toString()).type === "reload") if (reloadHandler) await reloadHandler();
12
12
  else console.warn("[HMR] No reload handler registered");
13
13
  } catch {}
14
14
  });
@@ -0,0 +1,6 @@
1
+ import { UserOptions } from "./types.mjs";
2
+
3
+ //#region src/config.d.ts
4
+ declare function defineConfig(options: UserOptions): UserOptions;
5
+ //#endregion
6
+ export { defineConfig };
@@ -0,0 +1,7 @@
1
+ //#region src/config.ts
2
+ function defineConfig(options) {
3
+ return options;
4
+ }
5
+
6
+ //#endregion
7
+ export { defineConfig };
@@ -0,0 +1,5 @@
1
+ //#region src/constants.ts
2
+ const PEACHY_ICONS_DEFAULT_PATH = "data/icons";
3
+
4
+ //#endregion
5
+ export { PEACHY_ICONS_DEFAULT_PATH };
@@ -0,0 +1,3 @@
1
+ import { InternalOptions, UserOptions } from "./types.mjs";
2
+ import { defineConfig } from "./config.mjs";
3
+ export { InternalOptions, UserOptions, defineConfig };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { defineConfig } from "./config.mjs";
2
+
3
+ export { defineConfig };
package/dist/load.mjs ADDED
@@ -0,0 +1,42 @@
1
+ import fs from "fs/promises";
2
+ import path from "path";
3
+
4
+ //#region src/load.ts
5
+ const CONFIG_NAMES = [
6
+ "peachy.config.ts",
7
+ "peachy.config.mts",
8
+ "peachy.config.js",
9
+ "peachy.config.mjs"
10
+ ];
11
+ /**
12
+ * Loads the user configuration from `process.cwd()`
13
+ */
14
+ async function loadUserOptions() {
15
+ for (const name of CONFIG_NAMES) {
16
+ const confName = path.resolve(process.cwd(), name);
17
+ if (!await exists(confName)) continue;
18
+ let module;
19
+ try {
20
+ module = await import(confName);
21
+ } catch (error) {
22
+ throw new TypeError(`The config file at "${confName}" is not a valid module`, { cause: error });
23
+ }
24
+ if (!module.default) throw new TypeError(`The config file at "${confName}" doesn't have a default export`);
25
+ return module.default;
26
+ }
27
+ const packageJsonPath = path.resolve(process.cwd(), "package.json");
28
+ if (await exists(packageJsonPath)) {
29
+ const packageJson = await fs.readFile(packageJsonPath, "utf8");
30
+ try {
31
+ const { peachy } = JSON.parse(packageJson);
32
+ if (typeof peachy === "object") return peachy;
33
+ } catch {}
34
+ }
35
+ return {};
36
+ }
37
+ async function exists(path) {
38
+ return fs.stat(path).then((info) => info.isFile()).catch(() => false);
39
+ }
40
+
41
+ //#endregion
42
+ export { loadUserOptions };
package/dist/options.mjs CHANGED
@@ -1,13 +1,16 @@
1
- import { broadcastMessage, createWebSocketServer } from "./ws.mjs";
2
- import { react } from "@peachy/plugin-react";
1
+ import { broadcastMessage, createWebSocketServer } from "./cli/ws.mjs";
2
+ import { PEACHY_ICONS_DEFAULT_PATH } from "./constants.mjs";
3
+ import { reactHMRPlugin } from "@peachy/plugin-react";
3
4
  import { gjsRunner } from "@peachy/plugin-runner";
4
5
  import { resolve } from "node:path";
5
6
  import { replacePlugin } from "rolldown/plugins";
6
7
  import { cleandir } from "rollup-plugin-cleandir";
8
+ import { resourcesPlugin } from "@peachy/plugin-resources";
7
9
 
8
10
  //#region src/options.ts
9
- function getOptions({ input, run = false, prod = false }) {
11
+ function getOptions(options) {
10
12
  const { wss, port, setReloadHandler } = createWebSocketServer();
13
+ const { input, run = false, prod = false, output } = options;
11
14
  return {
12
15
  input: {
13
16
  input: resolve(process.cwd(), input),
@@ -16,7 +19,7 @@ function getOptions({ input, run = false, prod = false }) {
16
19
  tsconfig: true,
17
20
  plugins: [
18
21
  prod ? cleandir(["dist"]) : void 0,
19
- prod ? void 0 : react(port),
22
+ prod ? void 0 : reactHMRPlugin(port),
20
23
  run ? gjsRunner({
21
24
  sendMessage: (message) => {
22
25
  if (wss.clients.size === 0) {
@@ -25,15 +28,26 @@ function getOptions({ input, run = false, prod = false }) {
25
28
  }
26
29
  broadcastMessage(wss, JSON.stringify(message));
27
30
  },
28
- setReloadHandler
31
+ setReloadHandler,
32
+ options: options.runner
29
33
  }) : void 0,
30
- replacePlugin({ "process.env.NODE_ENV": JSON.stringify(prod ? "production" : "development") })
34
+ replacePlugin({ "process.env.NODE_ENV": JSON.stringify(prod ? "production" : "development") }),
35
+ options.user.resources !== false ? resourcesPlugin({
36
+ applicationId: options.user.applicationId,
37
+ outdir: output,
38
+ prod,
39
+ setRunnerEnv(key, value) {
40
+ options.runner.env[key] = value;
41
+ },
42
+ iconsPath: options.user.resources == true || options.user.resources?.icons === true ? PEACHY_ICONS_DEFAULT_PATH : options.user.resources?.icons == false ? false : options.user.resources?.icons ?? PEACHY_ICONS_DEFAULT_PATH
43
+ }) : null
31
44
  ]
32
45
  },
33
46
  output: {
34
47
  format: "esm",
35
- dir: "./dist",
48
+ dir: output,
36
49
  preserveModules: !prod,
50
+ preserveModulesRoot: process.cwd(),
37
51
  sourcemap: true,
38
52
  minify: prod
39
53
  }
@@ -0,0 +1,35 @@
1
+ import { RunnerOptions } from "@peachy/plugin-runner";
2
+
3
+ //#region src/types.d.ts
4
+ interface UserOptions {
5
+ /**
6
+ * Options pertaining to the package
7
+ */
8
+ /**
9
+ * The name of this application, in RDNSS name format (i.e. dev.peach.Example)
10
+ */
11
+ applicationId?: string;
12
+ /**
13
+ * Whether to enable the automatic resources handling
14
+ */
15
+ resources?: boolean | {
16
+ /**
17
+ * Whether to automatically enable loading of icons from this directory.
18
+ *
19
+ * If set to true, will default to the default directory: `./data/icons`
20
+ *
21
+ * Default is true
22
+ */
23
+ icons?: boolean | string;
24
+ };
25
+ }
26
+ interface InternalOptions {
27
+ input: string;
28
+ output: string;
29
+ run?: boolean;
30
+ prod?: boolean;
31
+ user: UserOptions;
32
+ runner: RunnerOptions;
33
+ }
34
+ //#endregion
35
+ export { InternalOptions, UserOptions };
package/package.json CHANGED
@@ -1,29 +1,35 @@
1
1
  {
2
2
  "name": "@peachy/core",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "Base peachy CLI",
5
5
  "type": "module",
6
6
  "bin": {
7
- "peachy": "./dist/bin.mjs"
7
+ "peachy": "./dist/cli/bin.mjs"
8
8
  },
9
9
  "exports": {
10
+ ".": {
11
+ "import": "./dist/index.mjs",
12
+ "types": "./dist/index.d.ts"
13
+ },
10
14
  "./tsconfig": "./tsconfig.json"
11
15
  },
12
16
  "author": "Angelo Verlain <hey@vixalien.com>",
13
17
  "license": "MIT",
14
18
  "devDependencies": {
15
- "@types/node": "^25.0.9",
16
- "tsdown": "0.20.0-beta.4",
19
+ "@types/node": "^25.2.1",
20
+ "@types/ws": "^8.18.1",
21
+ "tsdown": "0.20.3",
17
22
  "tsx": "^4.21.0"
18
23
  },
19
24
  "dependencies": {
20
- "@peachy/types": "^2025.1.18",
25
+ "@peachy/types": "^2025.2.4",
21
26
  "minargs": "^2.1.0",
22
- "rolldown": "1.0.0-beta.60",
27
+ "rolldown": "1.0.0-rc.3",
23
28
  "rollup-plugin-cleandir": "^3.0.0",
24
29
  "ws": "^8.19.0",
25
- "@peachy/plugin-react": "0.0.9",
26
- "@peachy/plugin-runner": "0.0.9"
30
+ "@peachy/plugin-runner": "0.0.10",
31
+ "@peachy/plugin-react": "0.0.10",
32
+ "@peachy/plugin-resources": "0.0.10"
27
33
  },
28
34
  "files": [
29
35
  "dist",
package/tsconfig.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "strict": true,
3
4
  "checkJs": true,
4
5
  "esModuleInterop": true,
5
6
  "lib": ["es2024"],
6
7
  "allowSyntheticDefaultImports": true,
7
8
  "target": "ES2020",
8
- "module": "es2022",
9
+ "module": "Preserve",
9
10
  "moduleResolution": "bundler",
10
11
  "noEmit": true,
11
12
  "skipLibCheck": true,
@@ -13,8 +14,10 @@
13
14
  "include": [
14
15
  // when installed locally
15
16
  "./node_modules/@peachy/types/types/index.d.ts",
17
+ "./node_modules/@peachy/plugin-resources/src/types/global.d.ts",
16
18
  // when installed via npm/pnpm
17
19
  "../types/types/index.d.ts",
20
+ "../plugin-resources/src/types/global.d.ts",
18
21
  "${configDir}/src/**/*",
19
22
  ],
20
23
  }
package/dist/watch.mjs DELETED
@@ -1,15 +0,0 @@
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 };